Files
bknd/packages/postgres/README.md
2025-03-15 16:37:03 +01:00

1.4 KiB

Postgres adapter for bknd (experimental)

This packages adds an adapter to use a Postgres database with bknd. It is based on pg and the driver included in kysely.

Installation

Install the adapter with:

npm install @bknd/postgres

Usage

Create a connection:

import { PostgresConnection } from "@bknd/postgres";

const connection = new PostgresConnection({
   host: "localhost",
   port: 5432,
   user: "postgres",
   password: "postgres",
   database: "bknd",
});

Use the connection depending on which framework or runtime you are using. E.g., when using createApp, you can use the connection as follows:

import { createApp } from "bknd";
import { PostgresConnection } from "@bknd/postgres";

const connection = new PostgresConnection();
const app = createApp({ connection });

Or if you're using it with a framework, say Next.js, you can add the connection object to where you're initializating the app:

// e.g. in src/app/api/[[...bknd]]/route.ts
import { serve } from "bknd/adapter/nextjs";
import { PostgresConnection } from "@bknd/postgres";

const connection = new PostgresConnection();
const handler = serve({
   connection
})

// ...

For more information about how to integrate Next.js in general, check out the Next.js documentation.