Skip to content

sandros94/nuxt-pglite

Repository files navigation

Nuxt PGlite

npm version npm downloads License Nuxt

A Nuxt module aimed to simplify the use of PGlite.

PGlite, an Embeddable Postgres Run a full Postgres database locally in WASM with reactivity and live sync.

Warning

This is an highly experimental project. No docs are available (although planned), please refer to the playground code.

Features

  • 🧑‍💻  Client side usePGlite, running inside Web Workers.
  • ⚡️  Server side usePGlite, running in your Node or Bun server.

Quick Setup

Install the module to your Nuxt application with one command:

npx nuxi module add nuxt-pglite

That's it! You can now use Nuxt PGlite in your Nuxt app ✨

Persisten Storage

By default this module will persist data in memory. You can set where to store data in your nuxt.config.ts:

export default defineNuxtConfig({
  modules: ['nuxt-pglite'],

  pglite: {
    client: {
      options: {
        dataDir: 'idb://nuxt-pglite',
      },
    },
    server: {
      options: {
        dataDir: './database/pglite',
      },
    },
  },
})

Extensions

Extensions are automatically configured with full type support and can be added via nuxt.config.ts:

export default defineNuxtConfig({
  modules: ['nuxt-pglite'],

  pglite: {
    client: {
      extensions: ['live', 'electricSync'],
    },
  },
})

For a full list of available extensions please refer to the official docs. If a new extension is missing feel free to open up a new PR by adding it to this file, (I do plan to support only official and contrib).

Warning

Auto configuration for server-side extensions is currently not supported, the simplest approach is to create a wrapper util like /server/utils/db.ts:

import { vector } from '@electric-sql/pglite/vector'

export function useDB() {
  return usePGlite({ vector })
}

Contribution

Local development
# Install dependencies
pnpm install

# Generate type stubs
pnpm run dev:prepare

# Develop with the playground
pnpm run dev

# Build the playground
pnpm run dev:build

# Run ESLint
pnpm run lint

# Run Vitest
pnpm run test
pnpm run test:watch

# Release new version
pnpm run release