Each schema can use different attribute types to describe the different data shapes it needs to store.
Attribute keys should be singular and camelCase:
// hatchify-app/schemas.ts
export const SalesPerson = {
name: "SalesPerson",
attributes: {
firstName: string(), // 👀
lastName: string(),
age: integer(),
yearsWorked: integer({ displayName: "Years of Experience" }),
hireDate: datetime(),
bio: text(),
status: enumerate({ values: ["active", "inactive"] }),
isDeleted: boolean(),
birthday: dateonly(),
uniqueId: uuid(),
},
} satisfies PartialSchema
Creates columns first_name
, last_name
, age
, etc. in the sales_person
table.
Querying Data
Creates a /sales-persons
API.
firstName
will be used in the query parameters:
GET /api/sales-persons?fields[SalesPerson]=firstName
Data Response
firstName
will be used in the mutation and response payloads:
{
"data": {
"type": "SalesPerson",
"id": "c98b2123-78e7-45e4-b57f-f9c1189bfd19",
"attributes": {
"firstName": "Mary" // 👀
}
}
}
The displayName
is an optional parameter that can be used to customize the display name of an individual attribute in the UI. If displayName
is not set, then the attribute key will be transformed to Title Case.
const SalesPerson = {
name: "SalesPerson",
attributes: {
firstName: string(),
lastName: string({ displayName: "Surname" }), // 👀
},
} satisfies PartialSchema
This has no effect on the database.
This has no effect on the API.
The lastName
attribute will be displayed as "Surname" in the table header and filter dropdowns.
The readOnly
is an optional parameter to prevent updates to the attribute using Hatchify.
const SalesPerson = {
name: "SalesPerson",
attributes: {
firstName: string(),
lastName: string({ readOnly: true }), // 👀
},
} satisfies PartialSchema
This will prevent updating the attribute via Hatchify.
This will prevent updating the attribute via Hatchify.
This has no effect on the UI.
Each of these types renders differently on the UI and have different customization options. For more reading: