| global_id | e6e079ee |
|---|---|
| title | Properties |
| excerpt | defineDatabase provides Contentlayer with the schema and configuration when using local files as the content source. |
Properties configuration allows you to configure how your database properties will be used to generate the shape and behavior of your content.
const Post = defineDatabase(() => ({
name: 'Post',
databaseId: '<database_id>',
properties: [
{
key: 'metaDescription',
name: 'Short description',
},
],
}))const Post = defineDatabase(() => ({
name: 'Post',
databaseId: '<database_id>',
properties: {
metaDescription: {
name: 'Short description',
},
},
}))**Example:**
```js
defineDatabase(() => ({
name: 'Post',
databaseId: '<databaseId>',
properties: [
{
key: 'metaDescription',
name: 'Short description'
}
]
}))
```
```js
allPosts.forEach(
(post) => console.log(post.metaDescription)
)
```
Defaults to `false`.
**Example:**
```js
const Category = defineDatabase(() => ({
name: 'Category',
databaseId: '<database_id>',
}))
const Post = defineDatabase(() => ({
name: 'Post',
databaseId: '<database_id>',
properties: {
category: {
type: 'relation',
name: 'Category',
relation: Category,
},
},
}))
```
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!