mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-16 04:27:21 +00:00
postgres: move examples up
This commit is contained in:
@@ -1,102 +0,0 @@
|
||||
# Postgres adapter for `bknd` (experimental)
|
||||
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, Neon, Xata, and RDS)
|
||||
* choose between `pg` and `postgres` drivers
|
||||
* create custom postgres connections with any kysely postgres dialect
|
||||
|
||||
## Installation
|
||||
Install the adapter with:
|
||||
```bash
|
||||
npm install @bknd/postgres
|
||||
```
|
||||
|
||||
## Using `pg` driver
|
||||
Install the [`pg`](https://github.com/brianc/node-postgres) 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` driver
|
||||
|
||||
Install the [`postgres`](https://github.com/porsager/postgres) 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()],
|
||||
});
|
||||
```
|
||||
|
||||
### Custom `neon` connection
|
||||
|
||||
```typescript
|
||||
import { createCustomPostgresConnection } from "@bknd/postgres";
|
||||
import { NeonDialect } from "kysely-neon";
|
||||
|
||||
const connection = createCustomPostgresConnection("neon", NeonDialect)({
|
||||
connectionString: process.env.NEON,
|
||||
});
|
||||
```
|
||||
|
||||
### Custom `xata` connection
|
||||
|
||||
```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 });
|
||||
```
|
||||
@@ -1,14 +0,0 @@
|
||||
import { serve } from "bknd/adapter/bun";
|
||||
import { createCustomPostgresConnection } from "../src";
|
||||
import { NeonDialect } from "kysely-neon";
|
||||
|
||||
const neon = createCustomPostgresConnection(NeonDialect);
|
||||
|
||||
export default serve({
|
||||
connection: neon({
|
||||
connectionString: process.env.NEON,
|
||||
}),
|
||||
// ignore this, it's only required within this repository
|
||||
// because bknd is installed via "workspace:*"
|
||||
distPath: "../../app/dist",
|
||||
});
|
||||
@@ -1,24 +0,0 @@
|
||||
import { serve } from "bknd/adapter/bun";
|
||||
import { createCustomPostgresConnection } from "../src";
|
||||
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(XataDialect, {
|
||||
supports: {
|
||||
batching: false,
|
||||
},
|
||||
})({ xata });
|
||||
|
||||
export default serve({
|
||||
connection,
|
||||
// ignore this, it's only required within this repository
|
||||
// because bknd is installed via "workspace:*"
|
||||
distPath: "../../../app/dist",
|
||||
});
|
||||
@@ -1,47 +0,0 @@
|
||||
{
|
||||
"name": "@bknd/postgres",
|
||||
"version": "0.2.0",
|
||||
"type": "module",
|
||||
"main": "dist/index.js",
|
||||
"module": "dist/index.js",
|
||||
"types": "dist/index.d.ts",
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "tsup",
|
||||
"test": "bun test",
|
||||
"typecheck": "tsc --noEmit",
|
||||
"updater": "bun x npm-check-updates -ui",
|
||||
"prepublishOnly": "bun run typecheck && bun run test && bun run build",
|
||||
"docker:start": "docker run --rm --name bknd-test-postgres -d -e POSTGRES_PASSWORD=postgres -e POSTGRES_USER=postgres -e POSTGRES_DB=bknd -p 5430:5432 postgres:17",
|
||||
"docker:stop": "docker stop bknd-test-postgres"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"kysely": "^0.27.6",
|
||||
"kysely-postgres-js": "^2.0.0",
|
||||
"pg": "^8.14.0",
|
||||
"postgres": "^3.4.7"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/bun": "^1.2.5",
|
||||
"@types/node": "^22.13.10",
|
||||
"@types/pg": "^8.11.11",
|
||||
"@xata.io/client": "^0.0.0-next.v93343b9646f57a1e5c51c35eccf0767c2bb80baa",
|
||||
"@xata.io/kysely": "^0.2.1",
|
||||
"bknd": "workspace:*",
|
||||
"kysely-neon": "^1.3.0",
|
||||
"tsup": "^8.4.0"
|
||||
},
|
||||
"tsup": {
|
||||
"entry": ["src/index.ts"],
|
||||
"format": ["esm"],
|
||||
"target": "es2022",
|
||||
"metafile": true,
|
||||
"clean": true,
|
||||
"minify": true,
|
||||
"dts": true,
|
||||
"external": ["bknd", "pg", "postgres", "kysely", "kysely-postgres-js"]
|
||||
},
|
||||
"files": ["dist", "README.md", "!*.map", "!metafile*.json"]
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"composite": false,
|
||||
"module": "ESNext",
|
||||
"moduleResolution": "bundler",
|
||||
"allowImportingTsExtensions": false,
|
||||
"target": "ES2022",
|
||||
"noImplicitAny": false,
|
||||
"allowJs": true,
|
||||
"verbatimModuleSyntax": true,
|
||||
"declaration": true,
|
||||
"strict": true,
|
||||
"allowUnusedLabels": false,
|
||||
"allowUnreachableCode": false,
|
||||
"exactOptionalPropertyTypes": false,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
"noImplicitOverride": true,
|
||||
"noImplicitReturns": true,
|
||||
"noPropertyAccessFromIndexSignature": false,
|
||||
"noUncheckedIndexedAccess": true,
|
||||
"noUnusedLocals": false,
|
||||
"noUnusedParameters": false,
|
||||
"isolatedModules": true,
|
||||
"esModuleInterop": true,
|
||||
"skipLibCheck": true,
|
||||
"baseUrl": ".",
|
||||
"paths": {
|
||||
"$bknd/*": ["../../app/src/*"]
|
||||
}
|
||||
},
|
||||
"include": ["./src/**/*.ts"],
|
||||
"exclude": ["node_modules"]
|
||||
}
|
||||
Reference in New Issue
Block a user