@bknd/postgres
v0.2.0
Published
This packages adds an adapter to use a Postgres database with [`bknd`](https://github.com/bknd-io/bknd). It works with both `pg` and `postgres` drivers, and supports custom postgres connections. * works with any Postgres database (tested with Supabase, Ne
Readme
Postgres adapter for bknd (experimental)
This packages adds an adapter to use a Postgres database with bknd. It works with both pg and postgres drivers, and supports custom postgres connections.
- works with any Postgres database (tested with Supabase, Neon, Xata, and RDS)
- choose between
pgandpostgresdrivers - create custom postgres connections with any kysely postgres dialect
Installation
Install the adapter with:
npm install @bknd/postgresUsing pg driver
Install the pg driver with:
npm install pgCreate a connection:
import { pg } from "@bknd/postgres";
// accepts `pg` configuration
const connection = pg({
host: "localhost",
port: 5432,
user: "postgres",
password: "postgres",
database: "postgres",
});
// or with a connection string
const connection = pg({
connectionString: "postgres://postgres:postgres@localhost:5432/postgres",
});Using postgres driver
Install the postgres driver with:
npm install postgresCreate a connection:
import { postgresJs } from "@bknd/postgres";
// accepts `postgres` configuration
const connection = postgresJs("postgres://postgres:postgres@localhost:5432/postgres");Using custom postgres dialects
You can create a custom kysely postgres dialect by using the createCustomPostgresConnection function.
import { createCustomPostgresConnection } from "@bknd/postgres";
const connection = createCustomPostgresConnection("my_postgres_dialect", MyDialect)({
// your custom dialect configuration
supports: {
batching: true
},
excludeTables: ["my_table"],
plugins: [new MyKyselyPlugin()],
});Custom neon connection
import { createCustomPostgresConnection } from "@bknd/postgres";
import { NeonDialect } from "kysely-neon";
const connection = createCustomPostgresConnection("neon", NeonDialect)({
connectionString: process.env.NEON,
});Custom xata connection
import { createCustomPostgresConnection } from "@bknd/postgres";
import { XataDialect } from "@xata.io/kysely";
import { buildClient } from "@xata.io/client";
const client = buildClient();
const xata = new client({
databaseURL: process.env.XATA_URL,
apiKey: process.env.XATA_API_KEY,
branch: process.env.XATA_BRANCH,
});
const connection = createCustomPostgresConnection("xata", XataDialect, {
supports: {
batching: false,
},
})({ xata });