kysely-postgres-js
Advanced tools
Comparing version
@@ -42,2 +42,5 @@ "use strict"; | ||
} | ||
function createPostgres(config) { | ||
return "connectionString" in config ? config.postgres(config.connectionString, config.options) : config.postgres(config.options); | ||
} | ||
@@ -58,3 +61,3 @@ // src/connection.ts | ||
const { isolationLevel } = settings; | ||
this.#transaction = this.#config.postgres({ ...this.#config.options, max: 1 }); | ||
this.#transaction = createPostgres({ ...this.#config, options: { ...this.#config.options, max: 1 } }); | ||
const statement = `start transaction${isolationLevel ? ` ${isolationLevel}` : ""}`; | ||
@@ -115,3 +118,3 @@ await this.#transaction.unsafe(statement); | ||
this.#config = freeze({ ...config }); | ||
this.#sql = this.#config.postgres(this.#config.options); | ||
this.#sql = createPostgres(this.#config); | ||
} | ||
@@ -118,0 +121,0 @@ async init() { |
import { DatabaseConnection, TransactionSettings, CompiledQuery, QueryResult, Dialect, DialectAdapter, Driver, Kysely, DatabaseIntrospector, QueryCompiler } from 'kysely'; | ||
import postgres, { Options, Sql } from 'postgres'; | ||
interface PostgresJSDialectConfig { | ||
type PostgresJSDialectConfig = { | ||
connectionString: string; | ||
options?: Options<any>; | ||
postgres: typeof postgres; | ||
} | { | ||
options: Options<any>; | ||
postgres: typeof postgres; | ||
} | ||
}; | ||
@@ -9,0 +13,0 @@ declare class PostgresJSConnection implements DatabaseConnection { |
@@ -42,2 +42,5 @@ "use strict"; | ||
} | ||
function createPostgres(config) { | ||
return "connectionString" in config ? config.postgres(config.connectionString, config.options) : config.postgres(config.options); | ||
} | ||
@@ -58,3 +61,3 @@ // src/connection.ts | ||
const { isolationLevel } = settings; | ||
this.#transaction = this.#config.postgres({ ...this.#config.options, max: 1 }); | ||
this.#transaction = createPostgres({ ...this.#config, options: { ...this.#config.options, max: 1 } }); | ||
const statement = `start transaction${isolationLevel ? ` ${isolationLevel}` : ""}`; | ||
@@ -115,3 +118,3 @@ await this.#transaction.unsafe(statement); | ||
this.#config = freeze({ ...config }); | ||
this.#sql = this.#config.postgres(this.#config.options); | ||
this.#sql = createPostgres(this.#config); | ||
} | ||
@@ -118,0 +121,0 @@ async init() { |
import { DatabaseConnection, TransactionSettings, CompiledQuery, QueryResult, Dialect, DialectAdapter, Driver, Kysely, DatabaseIntrospector, QueryCompiler } from 'kysely'; | ||
import postgres, { Options, Sql } from 'postgres'; | ||
interface PostgresJSDialectConfig { | ||
type PostgresJSDialectConfig = { | ||
connectionString: string; | ||
options?: Options<any>; | ||
postgres: typeof postgres; | ||
} | { | ||
options: Options<any>; | ||
postgres: typeof postgres; | ||
} | ||
}; | ||
@@ -9,0 +13,0 @@ declare class PostgresJSConnection implements DatabaseConnection { |
@@ -14,2 +14,5 @@ /// <reference types="./index.d.ts" /> | ||
} | ||
function createPostgres(config) { | ||
return "connectionString" in config ? config.postgres(config.connectionString, config.options) : config.postgres(config.options); | ||
} | ||
@@ -30,3 +33,3 @@ // src/connection.ts | ||
const { isolationLevel } = settings; | ||
this.#transaction = this.#config.postgres({ ...this.#config.options, max: 1 }); | ||
this.#transaction = createPostgres({ ...this.#config, options: { ...this.#config.options, max: 1 } }); | ||
const statement = `start transaction${isolationLevel ? ` ${isolationLevel}` : ""}`; | ||
@@ -91,3 +94,3 @@ await this.#transaction.unsafe(statement); | ||
this.#config = freeze({ ...config }); | ||
this.#sql = this.#config.postgres(this.#config.options); | ||
this.#sql = createPostgres(this.#config); | ||
} | ||
@@ -94,0 +97,0 @@ async init() { |
{ | ||
"name": "kysely-postgres-js", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "Kysely dialect for PostgreSQL using the Postgres.js client", | ||
@@ -37,2 +37,3 @@ "repository": "https://github.com/igalklebanov/kysely-postgres-js.git", | ||
"@types/mocha": "^10.0.1", | ||
"@types/mocha-each": "^2.0.0", | ||
"@types/node": "^18.15.11", | ||
@@ -51,2 +52,3 @@ "@typescript-eslint/eslint-plugin": "^5.57.1", | ||
"mocha": "^10.2.0", | ||
"mocha-each": "^2.0.1", | ||
"postgres": "^3.3.4", | ||
@@ -53,0 +55,0 @@ "prettier": "^2.8.7", |
@@ -66,5 +66,18 @@ # kysely-postgres-js | ||
dialect: new PostgresJSDialect({ | ||
connectionString: 'postgres://admin@localhost:5434/test', | ||
options: { | ||
max: 10, | ||
}, | ||
postgres, | ||
}), | ||
}) | ||
// or... | ||
const db = new Kysely<Database>({ | ||
dialect: new PostgresJSDialect({ | ||
options: { | ||
database: 'test', | ||
host: 'localhost', | ||
max: 10, | ||
port: 5434, | ||
@@ -71,0 +84,0 @@ user: 'admin', |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
40104
5.04%532
3.3%105
14.13%26
8.33%