mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-15 20:17:22 +00:00
refactor postgres functions to not rely on the packages
This commit is contained in:
@@ -196,7 +196,7 @@ npm install @bknd/sqlocal
|
||||
|
||||
This package uses `sqlocal` under the hood. Consult the [sqlocal documentation](https://sqlocal.dallashoffman.com/guide/setup) for connection options:
|
||||
|
||||
```js
|
||||
```ts
|
||||
import { createApp } from "bknd";
|
||||
import { SQLocalConnection } from "@bknd/sqlocal";
|
||||
|
||||
@@ -210,42 +210,35 @@ const app = createApp({
|
||||
|
||||
## PostgreSQL
|
||||
|
||||
To use bknd with Postgres, you need to install the `@bknd/postgres` package. You can do so by running the following command:
|
||||
|
||||
```bash
|
||||
npm install @bknd/postgres
|
||||
```
|
||||
|
||||
You can connect to your Postgres database using `pg` or `postgres` dialects. Additionally, you may also define your custom connection.
|
||||
Postgres is built-in to bknd, you can connect to your Postgres database using `pg` or `postgres` dialects. Additionally, you may also define your custom connection.
|
||||
|
||||
### Using `pg`
|
||||
|
||||
To establish a connection to your database, you can use any connection options available on the [`pg`](https://node-postgres.com/apis/client) package.
|
||||
To establish a connection to your database, you can use any connection options available on the [`pg`](https://node-postgres.com/apis/client) package. Wrap the `Pool` in the `pg` function to create a connection.
|
||||
|
||||
```js
|
||||
```ts
|
||||
import { serve } from "bknd/adapter/node";
|
||||
import { pg } from "@bknd/postgres";
|
||||
import { pg } from "bknd";
|
||||
import { Pool } from "pg";
|
||||
|
||||
/** @type {import("bknd/adapter/node").NodeBkndConfig} */
|
||||
const config = {
|
||||
connection: pg({
|
||||
serve({
|
||||
connection: pg(new Pool({
|
||||
connectionString: "postgresql://user:password@localhost:5432/database",
|
||||
}),
|
||||
};
|
||||
|
||||
serve(config);
|
||||
})),
|
||||
});
|
||||
```
|
||||
|
||||
### Using `postgres`
|
||||
|
||||
To establish a connection to your database, you can use any connection options available on the [`postgres`](https://github.com/porsager/postgres) package.
|
||||
To establish a connection to your database, you can use any connection options available on the [`postgres`](https://github.com/porsager/postgres) package. Wrap the `Sql` in the `postgresJs` function to create a connection.
|
||||
|
||||
```js
|
||||
```ts
|
||||
import { serve } from "bknd/adapter/node";
|
||||
import { postgresJs } from "@bknd/postgres";
|
||||
import { postgresJs } from "bknd";
|
||||
import postgres from 'postgres'
|
||||
|
||||
serve({
|
||||
connection: postgresJs("postgresql://user:password@localhost:5432/database"),
|
||||
connection: postgresJs(postgres("postgresql://user:password@localhost:5432/database")),
|
||||
});
|
||||
```
|
||||
|
||||
@@ -255,8 +248,8 @@ Several Postgres hosting providers offer their own clients to connect to their d
|
||||
|
||||
Example using `@neondatabase/serverless`:
|
||||
|
||||
```js
|
||||
import { createCustomPostgresConnection } from "@bknd/postgres";
|
||||
```ts
|
||||
import { createCustomPostgresConnection } from "bknd";
|
||||
import { NeonDialect } from "kysely-neon";
|
||||
|
||||
const neon = createCustomPostgresConnection("neon", NeonDialect);
|
||||
@@ -270,8 +263,8 @@ serve({
|
||||
|
||||
Example using `@xata.io/client`:
|
||||
|
||||
```js
|
||||
import { createCustomPostgresConnection } from "@bknd/postgres";
|
||||
```ts
|
||||
import { createCustomPostgresConnection } from "bknd";
|
||||
import { XataDialect } from "@xata.io/kysely";
|
||||
import { buildClient } from "@xata.io/client";
|
||||
|
||||
|
||||
Reference in New Issue
Block a user