Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kysely-org/kysely-postgres-js
Kysely dialect for PostgreSQL using the Postgres.js client.
https://github.com/kysely-org/kysely-postgres-js
dialect kysely postgres postgresql query-builder sql type-safety typescript
Last synced: 3 days ago
JSON representation
Kysely dialect for PostgreSQL using the Postgres.js client.
- Host: GitHub
- URL: https://github.com/kysely-org/kysely-postgres-js
- Owner: kysely-org
- License: mit
- Created: 2023-04-08T22:33:09.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-10-29T14:15:09.000Z (15 days ago)
- Last Synced: 2024-10-29T17:23:06.672Z (15 days ago)
- Topics: dialect, kysely, postgres, postgresql, query-builder, sql, type-safety, typescript
- Language: TypeScript
- Homepage:
- Size: 766 KB
- Stars: 68
- Watchers: 2
- Forks: 3
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# kysely-postgres-js
![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 (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.
## Installation
#### NPM 7+
```bash
npm i kysely-postgres-js
```#### NPM <7
```bash
npm i kysely-postgres-js kysely postgres
```#### Yarn
```bash
yarn add kysely-postgres-js kysely postgres
```#### PNPM
```bash
pnpm add kysely-postgres-js kysely postgres
```### Deno
This package uses/extends some [Kysely](https://github.com/koskimas/kysely) types and classes, which are imported using its NPM package name -- not a relative file path or CDN url. It also uses [Postgres.js] which is imported using its NPM package name -- not a relative file path or CDN url.
To fix that, add an [`import_map.json`](https://deno.land/[email protected]/linking_to_external_code/import_maps) file.
```json
{
"imports": {
"kysely": "https://cdn.jsdelivr.net/npm/[email protected]/dist/esm/index.js",
"postgres": "https://deno.land/x/[email protected]/mod.js"
}
}
```## Usage
```ts
import {type GeneratedAlways, Kysely} from 'kysely'
import {PostgresJSDialect} from 'kysely-postgres-js'
import postgres from 'postgres'interface Database {
person: {
id: GeneratedAlways
first_name: string | null
last_name: string | null
age: number
}
}const db = new Kysely({
dialect: new PostgresJSDialect({
postgres: postgres({
database: 'test',
host: 'localhost',
max: 10,
port: 5434,
user: 'admin',
}),
}),
})
```## License
MIT License, see `LICENSE`