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
npm install @bknd/postgresbknd (experimental)bknd. It works with both pg and postgres drivers, and supports custom postgres connections.pg and postgres driversbash
npm install @bknd/postgres
`Using
pg driver
Install the pg driver with:
`bash
npm install pg
`Create a connection:
`ts
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 driverpostgres driver with:
`bash
npm install postgres
`Create a connection:
`ts
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.`ts
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()],
});
`$3
`typescript
import { createCustomPostgresConnection } from "@bknd/postgres";
import { NeonDialect } from "kysely-neon";const connection = createCustomPostgresConnection("neon", NeonDialect)({
connectionString: process.env.NEON,
});
`$3
`typescript
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 });
``