Use Payload with Postgres

To use Payload with Postgres, install the package @payloadcms/db-postgres. It leverages Drizzle ORM and node-postgres to interact with a Postgres database that you provide.

It automatically manages changes to your database for you in development mode, and exposes a full suite of migration controls for you to leverage in order to keep other database environments in sync with your schema. DDL transformations are automatically generated.

To configure Payload to use Postgres, pass the postgresAdapter to your Payload config as follows:

import { postgresAdapter } from ‘@payloadcms/db-postgres’

export default buildConfig({

 // Your config goes here

 collections: [

  // Collections go here

 ],

 // Configure the Postgres adapter here

 db: postgresAdapter({

  // Postgres-specific arguments go here.

  // `pool` is required.

  pool: {

   connectionString: process.env.DATABASE_URI,

  }

 }),

})

After Payload is initialized, this adapter will expose the full power of Drizzle to you for use if you need it.

You can access Drizzle as follows:

payload.db.drizzle

Leave a comment

Your email address will not be published. Required fields are marked *