Properties configuration allows you to configure how your database properties will be used to generate the shape and behavior of your content.
#Usage
#By using array
const Post = defineDatabase(() => ({
name: 'Post',
databaseId: '<database_id>',
properties: [
{
key: 'metaDescription',
name: 'Short description',
},
],
}))
#By using object
const Post = defineDatabase(() => ({
name: 'Post',
databaseId: '<database_id>',
properties: {
metaDescription: {
name: 'Short description',
},
},
}))
#Shared options
#name|id
string
(required)
Will map this property configuration to a database property. You can choose to use the id
or the name
depending
on your use case.
Defines the generated field name in your schema for this property.
Example:
defineDatabase(() => ({
name: 'Post',
databaseId: '<databaseId>',
properties: [
{
key: 'metaDescription',
name: 'Short description'
}
]
}))
allPosts.forEach(
(post) => console.log(post.metaDescription)
)
Pages that does not have this property defined will not be generated.
Defaults to false
.
A short description to editors how the field is to be used.
#Relation property
#type
'relation'
(required)
Defines the type of this property.
#relation
DatabaseType
(required)
The database definition of the relation.
Example:
const Category = defineDatabase(() => ({
name: 'Category',
databaseId: '<database_id>',
}))
const Post = defineDatabase(() => ({
name: 'Post',
databaseId: '<database_id>',
properties: {
category: {
type: 'relation',
name: 'Category',
relation: Category,
},
},
}))
#Rollup property
A rollup property allows you to aggregate a property of the pages defined in a relation property (e.g. average numbers).
The cool thing is that you only have to configure the relation property and everything will work by itself!
Was this article helpful to you?
Provide feedback
Last edited on April 01, 2024.
Edit this page