npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

payload-db-pglite

v0.1.2

Published

PGlite database adapter for PayloadCMS

Readme

payload-db-pglite

npm version

A PGlite database adapter for PayloadCMS.

PGlite is a WASM Postgres build that runs in Node.js, Bun, and the browser, with no need to install any other dependencies. It's perfect for development, testing, and edge deployments.

Features

  • 🚀 Zero-config: No PostgreSQL server required
  • 🔄 Drop-in replacement: Compatible with existing Payload PostgreSQL workflows
  • 🧠 In-memory option: Perfect for testing and development
  • 📁 File-based storage: Persistent database stored in your project
  • Fast: Runs directly in your Node.js process
  • 🌐 Edge-ready: Works in serverless and edge environments

Installation

npm install payload-db-pglite @electric-sql/pglite

Quick Start

1. Configure Payload

Update your payload.config.ts:

import { buildConfig } from 'payload'
import { pgliteAdapter } from 'payload-db-pglite'

export default buildConfig({
  // ... other config
  db: pgliteAdapter({
    dataDir: './database', // or 'memory://' for in-memory
  }),
})

2. Configure Next.js (if using)

Add to your next.config.mjs:

/** @type {import('next').NextConfig} */
const nextConfig = {
  serverExternalPackages: ['@electric-sql/pglite'],
}

export default nextConfig

3. Start developing

npm run dev

That's it! PGlite will automatically create and manage your database.

Transactions

Transactions are disabled by default because PGlite uses a single connection. Real transactions on a single connection would cause deadlocks. If you understand the implications, you can opt in:

pgliteAdapter({
  dataDir: './database',
  transactionOptions: { isolationLevel: 'read committed' },
})

Configuration Options

interface PGliteAdapterArgs {
  /** Directory where PGlite stores its data. Use 'memory://' for in-memory. @default './pglite-data' */
  dataDir?: string
  /** ID type to use for documents. @default 'serial' */
  idType?: 'serial' | 'uuid'
  /** Enable automatic schema push in development. @default true */
  push?: boolean
  /** Store blocks as JSON instead of relational structure. @default false */
  blocksAsJSON?: boolean
  /** PostgreSQL extensions to enable. @default [] */
  extensions?: string[]
  /** The schema name to use. */
  schemaName?: string
  /** Migration directory path. */
  migrationDir?: string
  /** Production migrations. */
  prodMigrations?: Array<{ name: string; up: Function; down: Function }>
  /** Transform schema before/after initialization. */
  beforeSchemaInit?: PostgresSchemaHook[]
  afterSchemaInit?: PostgresSchemaHook[]
  /** Table name suffixes. */
  localesSuffix?: string
  relationshipsSuffix?: string
  versionsSuffix?: string
  /** Transaction configuration. Pass false to disable (default). */
  transactionOptions?: false | PgTransactionConfig
  /** Drizzle logger. */
  logger?: DrizzleConfig['logger']
}

Usage Examples

Development with File Storage

export default buildConfig({
  db: pgliteAdapter({
    dataDir: './database',
    push: true,
  }),
})

Testing with In-Memory Database

export default buildConfig({
  db: pgliteAdapter({
    dataDir: 'memory://',
    push: true,
  }),
})

Production with Migrations

export default buildConfig({
  db: pgliteAdapter({
    dataDir: process.env.DATABASE_DIR || './database',
    push: false,
    prodMigrations: [
      // Your production migrations
    ],
  }),
})

Deployment

Vercel

export default buildConfig({
  db: pgliteAdapter({
    dataDir: '/tmp/database',
  }),
})

Docker

FROM node:18-alpine
WORKDIR /app
COPY . .
RUN npm install
RUN mkdir -p /app/database
CMD ["npm", "start"]

Development Workflow

  1. Start fresh: Delete the dataDir folder to reset your database
  2. Schema changes: Enable push: true for automatic schema updates in development
  3. Migrations: Use payload migrate:create to generate migration files
  4. Production: Set push: false and use prodMigrations for production deployments

Troubleshooting

"Module not found" errors

Make sure to add @electric-sql/pglite to serverExternalPackages in your Next.js config.

Database locked errors

PGlite databases can only be opened by one process at a time. Make sure you're not running multiple instances pointing to the same dataDir.

Performance considerations

  • In-memory databases (memory://) are fastest but don't persist data
  • File-based databases are slightly slower but provide persistence
  • PGlite is single-threaded, so it's best for small to medium applications

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

MIT License — see LICENSE file for details.

Related