Files
payload/examples/db-example
Dan Ribbens f07783a279 chore: move db-example to examples (#6532)
- Moved to examples
- Removed unnecessary dependencies
- Improved the readme with instructions for writing the db adapter
2024-05-28 10:28:18 -04:00
..

Example Database Adapter for Payload

To build a fully working database adapter for Payload you must implement the database adapter interface. There is a mix of required and not required methods depending on the areas you need to support. Payload will call the adapter's init function followed by the connect method if it exists. The adapter must create any schema necessary on the target database in the init function. The adapter can be extended as needed to keep track of models for collections and other artifacts necessary to perform all the needed operations.

Installation

npm install @payloadcms/db-example

Usage

import { buildConfig } from 'payload/config'
import { exampleAdapter } from '@payloadcms/db-example'

export default buildConfig({
  db: exampleAdapter({
    url: process.env.DATABASE_URI,
  }),
  // ...rest of config
})

More detailed usage can be found in the Payload Docs.