feat: @payloadcms/db-vercel-postgres adapter (#7806)

Dedicated adapter for Vercel Postgres

- Uses the `@vercel/postgres` package under the hood.
- No `pg` dependency, speeds up invocation
- Includes refactoring all base postgres functionality into a
`BasePostgresAdapter` type, which will ease implementation of [other
adapters supported by
drizzle-orm](https://orm.drizzle.team/docs/get-started-postgresql)

## Usage

```ts
import { buildConfig } from 'payload'
import { vercelPostgresAdapter } from '@payloadcms/db-vercel-postgres'

export default buildConfig({
  db: vercelPostgresAdapter({
    pool: {
      connectionString: process.env.DATABASE_URI,
    },
  }),
  // ...rest of config
})
```

### Automatic Connection String Detection

Have Vercel automatically detect from environment variable (typically
`process.env.POSTGRES_URL`)

```ts
export default buildConfig({
  db: postgresAdapter(),
  // ...rest of config
})
```
This commit is contained in:
Elliot DeNolf
2024-08-21 22:54:47 -04:00
committed by GitHub
parent 492d920133
commit 631431e006
33 changed files with 1674 additions and 18 deletions

View File

@@ -9,6 +9,8 @@ import { fileURLToPath } from 'node:url'
import path from 'path'
import util from 'util'
import type { PackageDetails } from './lib/getPackageDetails.js'
import { getPackageDetails } from './lib/getPackageDetails.js'
const execOpts: ExecSyncOptions = { stdio: 'inherit' }
@@ -47,6 +49,7 @@ async function main() {
'drizzle',
'db-sqlite',
'db-postgres',
'db-vercel-postgres',
'richtext-lexical',
'translations',
'plugin-cloud',
@@ -58,19 +61,17 @@ async function main() {
// Prebuild all packages
header(`\n🔨 Prebuilding all packages...`)
//await execa('pnpm', ['install'], execaOpts)
const filtered = packageDetails.filter((p): p is Exclude<typeof p, null> => p !== null)
header(`\nOutputting ${filtered.length} packages...
${chalk.white.bold(filtered.map((p) => p.name).join('\n'))}
`)
if (!noBuild) {
execSync('pnpm build:all --output-logs=errors-only', { stdio: 'inherit' })
}
header(`\n 📦 Packing all packages to ${dest}...`)
header(`\nOutputting ${filtered.length} packages...
${chalk.white.bold(listPackages(filtered))}`)
header(`\n📦 Packing all packages to ${dest}...`)
await Promise.all(
filtered.map(async (p) => {
@@ -84,3 +85,7 @@ ${chalk.white.bold(filtered.map((p) => p.name).join('\n'))}
function header(message: string, opts?: { enable?: boolean }) {
console.log(chalk.bold.green(`${message}\n`))
}
function listPackages(packages: PackageDetails[]) {
return packages.map((p) => ` - ${p.name}`).join('\n')
}