-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: accept postgres instance. (#7)
* accept postgres instance. * bump kysely. * fix test. * update readme.
- Loading branch information
1 parent
824a2e6
commit 529778b
Showing
8 changed files
with
37 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
|
||
![Powered by TypeScript](https://img.shields.io/badge/powered%20by-typescript-blue.svg) | ||
|
||
[Kysely](https://github.com/koskimas/kysely) dialect for [PostgreSQL](https://www.postgresql.org/) using the [Postgres.js](https://github.com/porsager/postgres) client library under the hood. | ||
[Kysely](https://github.com/koskimas/kysely) dialect for [PostgreSQL](https://www.postgresql.org/) using the [Postgres.js](https://github.com/porsager/postgres) client library under the hood (version >= 3.4). | ||
|
||
This dialect should not be confused with Kysely's built-in PostgreSQL dialect, which uses the [pg](https://github.com/brianc/node-postgres) client library instead. | ||
|
||
|
@@ -41,8 +41,8 @@ To fix that, add an [`import_map.json`](https://deno.land/[email protected]/linking | |
```json | ||
{ | ||
"imports": { | ||
"kysely": "https://cdn.jsdelivr.net/npm/kysely@0.23.5/dist/esm/index.js", | ||
"postgres": "https://deno.land/x/postgresjs@v3.3.4/mod.js" | ||
"kysely": "https://cdn.jsdelivr.net/npm/kysely@0.26.3/dist/esm/index.js", | ||
"postgres": "https://deno.land/x/postgresjs@v3.4.0/mod.js" | ||
} | ||
} | ||
``` | ||
|
@@ -65,26 +65,13 @@ interface Database { | |
|
||
const db = new Kysely<Database>({ | ||
dialect: new PostgresJSDialect({ | ||
connectionString: 'postgres://admin@localhost:5434/test', | ||
options: { | ||
max: 10, | ||
}, | ||
postgres, | ||
}), | ||
}) | ||
|
||
// or... | ||
|
||
const db = new Kysely<Database>({ | ||
dialect: new PostgresJSDialect({ | ||
options: { | ||
postgres: postgres({ | ||
database: 'test', | ||
host: 'localhost', | ||
max: 10, | ||
port: 5434, | ||
user: 'admin', | ||
}, | ||
postgres, | ||
}), | ||
}), | ||
}) | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,5 @@ | ||
import type postgres from 'postgres' | ||
import type {Options} from 'postgres' | ||
import type {Sql} from 'postgres' | ||
|
||
export type PostgresJSDialectConfig = | ||
| { | ||
connectionString: string | ||
options?: Options<any> | ||
postgres: typeof postgres | ||
} | ||
| { | ||
options: Options<any> | ||
postgres: typeof postgres | ||
} | ||
export interface PostgresJSDialectConfig { | ||
readonly postgres: Sql | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,3 @@ | ||
import type {Sql} from 'postgres' | ||
|
||
import type {PostgresJSDialectConfig} from './types' | ||
|
||
export function freeze<T>(obj: T): Readonly<T> { | ||
return Object.freeze(obj) | ||
} | ||
|
||
export function createPostgres(config: PostgresJSDialectConfig): Sql { | ||
return 'connectionString' in config | ||
? config.postgres(config.connectionString, config.options) | ||
: config.postgres(config.options) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters