defineDatabase defines how Contentlayer should generate your schema for one particular database.

Database definitions are used within the options for makeSource, which is how the definition is passed onto Contentlayer.


import { defineDatabase } from 'contentlayer-source-notion'

const Post = defineDatabase(() => ({
  name: 'Post',
  databaseId: '<database_id>',



boolean (required)

Name of the document. This defines the types and functions that are generated for documents of this type.

const Doc = defineDatabase(() => ({
  name: "Doc",
  // ...

In the usage example, the name was Doc, which would generate a data object allDocs representing the collection of pages of this database (see databaseId). And it would add a type definition for Doc, representing the shape of the data object created from your content.


string (required)

The ID of the database used to generate the schema.

You can find the ID of the database in the URL:


Options to configure how properties should be used to generate the data shape for the document type. See the properties types reference for more information


Computed fields can be calculated on the fly rather than being read directly from the content source.

Here's an example that transforms the page title to a slug.

export const Post = defineDatabase(() => ({
  // ...
  computedFields: {
    slug: {
      type: 'string',
      resolve: (doc) => slugify(doc.title),



Provides a description for the generated type definition.



The Notion source automatically import all properties of your database.

If thoses properties can contain sensitive information you can set this option to true and only properties defined in properties will be in your schema.



Notion requires a request for each pages to query their content. (That can lead to other requests)

As Notion can be slow, you can disable this feature if you only use the page properties.


This option allows you to sort and filter your database.


In this example only published posts will be queried ordered by name.

const Post = defineDatabase(() => ({
  name: 'Post',
  databaseId: '<database_id>',
  query: {
    filter: {
      property: 'Status',
      status: {
        equals: 'Published',
    sort: [
        property: 'Name',
        direction: 'ascending',

You can find more information on the Notion API Documentation.

Was this article helpful to you?
Provide feedback

Last edited on August 22, 2023.
Edit this page