File tree 5 files changed +32
-16
lines changed
5 files changed +32
-16
lines changed Original file line number Diff line number Diff line change 3
3
## usage
4
4
5
5
``` ts
6
- import { Kysely } from " https://cdn.jsdelivr.net/npm/kysely/dist/esm/index.js" ;
6
+ import {
Pool }
from " https://deno.land/x/[email protected] /mod.ts" ;
7
+ import {
Kysely ,
Generated }
from " https://esm.sh/[email protected] " ;
7
8
import { PostgresDialect } from " https://deno.land/x/kysely_postgres/mod.ts" ;
8
9
9
- const db = new Kysely <{}>({
10
- dialect: new PostgresDialect ({
11
- // ...
12
- }),
10
+ // Create a database pool with one connection.
11
+ const pool = new Pool (
12
+ {
13
+ database: " postgres" ,
14
+ hostname: " localhost" ,
15
+ user: " postgres" ,
16
+ port: 54322 ,
17
+ password: Deno .env .get (" DB_PASSWORD" ),
18
+ },
19
+ 1
20
+ );
21
+
22
+ // You'd create one of these when you start your app.
23
+ const db = new Kysely <Database >({
24
+ dialect: new PostgresDialect ({ pool }),
13
25
});
14
26
```
15
27
Original file line number Diff line number Diff line change 1
- export * from "https://cdn.jsdelivr.net/npm/ kysely/dist/esm/index.js " ;
2
- export * from "https://cdn.jsdelivr.net/npm/ kysely/dist/esm/util/stack-trace-utils.js" ;
1
+ export * from "https://esm.sh/ kysely@0.23.4 " ;
2
+ export * from "https://esm.sh/ kysely@0.23.4 /dist/esm/util/stack-trace-utils.js" ;
Original file line number Diff line number Diff line change 1
- export * from "https://deno.land/x/postgres@v0.16.1 /mod.ts" ;
1
+ export * from "https://deno.land/x/postgres@v0.17.0 /mod.ts" ;
Original file line number Diff line number Diff line change 1
- import type { ClientOptions } from "../deps/postgres.ts" ;
1
+ import type { Pool } from "../deps/postgres.ts" ;
2
2
3
- export type PostgresDialectConfig = ClientOptions ;
3
+ export interface PostgresDialectConfig {
4
+ pool : Pool | ( ( ) => Promise < Pool > ) ;
5
+ }
Original file line number Diff line number Diff line change 1
1
import { Pool } from "../deps/postgres.ts" ;
2
- import type { PoolClient , ClientOptions } from "../deps/postgres.ts" ;
2
+ import type { PoolClient } from "../deps/postgres.ts" ;
3
+ import { PostgresDialectConfig } from "./postgres-dialect-config.ts" ;
3
4
import { CompiledQuery , PostgresCursorConstructor } from "../deps/kysely.ts" ;
4
5
import type {
5
6
DatabaseConnection ,
@@ -12,18 +13,19 @@ import { extendStackTrace } from "../deps/kysely.ts";
12
13
const PRIVATE_RELEASE_METHOD = Symbol ( ) ;
13
14
14
15
export class PostgresDriver implements Driver {
15
- readonly #config: ClientOptions ;
16
+ readonly #config: PostgresDialectConfig ;
16
17
readonly #connections = new WeakMap < PoolClient , DatabaseConnection > ( ) ;
17
18
#pool: Pool | null = null ;
18
19
19
- constructor ( config : ClientOptions ) {
20
+ constructor ( config : PostgresDialectConfig ) {
20
21
this . #config = config ;
21
22
}
22
23
23
24
async init ( ) : Promise < void > {
24
- // TODO: size is required unlike the node `pg` module.
25
- // Need to figure out what is a good value to use here
26
- this . #pool = new Pool ( this . #config, 1 ) ;
25
+ this . #pool =
26
+ typeof this . #config. pool === "function"
27
+ ? await this . #config. pool ( )
28
+ : this . #config. pool ;
27
29
}
28
30
29
31
async acquireConnection ( ) : Promise < DatabaseConnection > {
You can’t perform that action at this time.
0 commit comments