11import {
2- CompiledQuery ,
2+ type CompiledQuery ,
33 type DatabaseConnection ,
4- type Driver ,
5- type QueryCompiler ,
4+ PostgresDriver ,
65 type QueryResult ,
7- type TransactionSettings ,
86} from 'kysely'
97import type {
108 PostgresJSDialectConfig ,
@@ -13,73 +11,39 @@ import type {
1311} from './dialect-config.mjs'
1412import { freeze } from './utils.mjs'
1513
16- export class PostgresJSDriver implements Driver {
14+ const RELEASE_CONNECTION_SYMBOL = Symbol ( 'release' )
15+
16+ export class PostgresJSDriver extends PostgresDriver {
1717 readonly #config: PostgresJSDialectConfig
1818 #postgres: PostgresJSSql | undefined
1919
2020 constructor ( config : PostgresJSDialectConfig ) {
21+ super ( { } as never )
2122 this . #config = freeze ( { ...config } )
2223 }
2324
24- async acquireConnection ( ) : Promise < PostgresJSConnection > {
25+ override async acquireConnection ( ) : Promise < PostgresJSConnection > {
2526 // biome-ignore lint/style/noNonNullAssertion: `init` ran at this point.
2627 const reservedConnection = await this . #postgres! . reserve ( )
2728
2829 return new PostgresJSConnection ( reservedConnection )
2930 }
3031
31- async beginTransaction (
32- connection : PostgresJSConnection ,
33- settings : TransactionSettings ,
34- ) : Promise < void > {
35- await connection . beginTransaction ( settings )
36- }
37-
38- async commitTransaction ( connection : PostgresJSConnection ) : Promise < void > {
39- await connection . commitTransaction ( )
40- }
41-
42- async destroy ( ) : Promise < void > {
32+ override async destroy ( ) : Promise < void > {
4333 // biome-ignore lint/style/noNonNullAssertion: `init` ran at this point.
4434 await this . #postgres! . end ( )
4535 }
4636
47- async init ( ) : Promise < void > {
37+ override async init ( ) : Promise < void > {
4838 const { postgres } = this . #config
4939
5040 this . #postgres = isPostgresJSSql ( postgres ) ? postgres : await postgres ( )
5141 }
5242
53- async releaseConnection ( connection : PostgresJSConnection ) : Promise < void > {
54- connection . releaseConnection ( )
55- }
56-
57- releaseSavepoint (
58- connection : DatabaseConnection ,
59- savepointName : string ,
60- compileQuery : QueryCompiler [ 'compileQuery' ] ,
61- ) : Promise < void > {
62- // TODO: ...
63- }
64-
65- rollbackToSavepoint (
66- connection : DatabaseConnection ,
67- savepointName : string ,
68- compileQuery : QueryCompiler [ 'compileQuery' ] ,
69- ) : Promise < void > {
70- // TODO: ...
71- }
72-
73- async rollbackTransaction ( connection : PostgresJSConnection ) : Promise < void > {
74- await connection . rollbackTransaction ( )
75- }
76-
77- savepoint (
43+ override async releaseConnection (
7844 connection : DatabaseConnection ,
79- savepointName : string ,
80- compileQuery : QueryCompiler [ 'compileQuery' ] ,
8145 ) : Promise < void > {
82- // TODO: ...
46+ ; ( connection as PostgresJSConnection ) [ RELEASE_CONNECTION_SYMBOL ] ( )
8347 }
8448}
8549
@@ -94,22 +58,6 @@ class PostgresJSConnection implements DatabaseConnection {
9458 this . #reservedConnection = reservedConnection
9559 }
9660
97- async beginTransaction ( settings : TransactionSettings ) : Promise < void > {
98- const { isolationLevel } = settings
99-
100- const compiledQuery = CompiledQuery . raw (
101- isolationLevel
102- ? `start transaction isolation level ${ isolationLevel } `
103- : 'begin' ,
104- )
105-
106- await this . executeQuery ( compiledQuery )
107- }
108-
109- async commitTransaction ( ) : Promise < void > {
110- await this . executeQuery ( CompiledQuery . raw ( 'commit' ) )
111- }
112-
11361 async executeQuery < R > (
11462 compiledQuery : CompiledQuery < unknown > ,
11563 ) : Promise < QueryResult < R > > {
@@ -131,14 +79,6 @@ class PostgresJSConnection implements DatabaseConnection {
13179 }
13280 }
13381
134- releaseConnection ( ) : void {
135- this . #reservedConnection. release ( )
136- }
137-
138- async rollbackTransaction ( ) : Promise < void > {
139- await this . executeQuery ( CompiledQuery . raw ( 'rollback' ) )
140- }
141-
14282 async * streamQuery < R > (
14383 compiledQuery : CompiledQuery < unknown > ,
14484 chunkSize : number ,
@@ -163,6 +103,10 @@ class PostgresJSConnection implements DatabaseConnection {
163103 yield { rows }
164104 }
165105 }
106+
107+ [ RELEASE_CONNECTION_SYMBOL ] ( ) : void {
108+ this . #reservedConnection. release ( )
109+ }
166110}
167111
168112export class PostgresJSDialectError extends Error {
0 commit comments