Skip to content

Commit f79ddeb

Browse files
committed
initial commit pt. 1.
1 parent 7f741e8 commit f79ddeb

14 files changed

+2902
-104
lines changed

Diff for: .eslintignore

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
node_modules
2+
dist
3+
assets
4+
.prettierrc.js
5+
jest.config.js
6+
package.json
7+
pnpm-lock.yaml
8+
README.md
9+
tsconfig.json
10+
tsup.config.ts
11+
scripts
12+
examples
13+
tests

Diff for: .eslintrc.json

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"root": true,
3+
"extends": ["prettier"],
4+
"parser": "@typescript-eslint/parser",
5+
"parserOptions": {"project": ["./tsconfig.json"]},
6+
"plugins": ["prettier", "import", "@typescript-eslint"],
7+
"rules": {
8+
"prettier/prettier": ["error"],
9+
"import/extensions": [2, "ignorePackages"]
10+
},
11+
"settings": {
12+
"import/extensions": [".ts"]
13+
}
14+
}

Diff for: .github/workflows/tests.yml

+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
name: Tests
2+
on:
3+
pull_request:
4+
branches: [main]
5+
push:
6+
branches: [main]
7+
jobs:
8+
run-node-tests:
9+
runs-on: ubuntu-latest
10+
11+
strategy:
12+
matrix:
13+
node-version: [14.x, 16.x, 18.x]
14+
fail-fast: false
15+
16+
steps:
17+
- name: Checkout
18+
uses: actions/checkout@v3
19+
20+
- name: Run docker compose
21+
run: docker-compose up -d
22+
23+
- name: Install Node.js ${{ matrix.node-version }}
24+
uses: actions/setup-node@v3
25+
with:
26+
node-version: ${{ matrix.node-version }}
27+
28+
- name: Install pnpm
29+
uses: pnpm/[email protected]
30+
with:
31+
version: 7
32+
run_install: false
33+
34+
- name: Get pnpm store directory
35+
id: pnpm-cache
36+
run: |
37+
echo "::set-output name=pnpm_cache_dir::$(pnpm store path)"
38+
39+
- name: Setup pnpm cache
40+
uses: actions/cache@v3
41+
with:
42+
path: ${{ steps.pnpm-cache.outputs.pnpm_cache_dir }}
43+
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
44+
restore-keys: |
45+
${{ runner.os }}-pnpm-store-
46+
47+
- name: Install dependencies
48+
run: pnpm i
49+
50+
- name: Build
51+
run: pnpm run build
52+
53+
- name: Test
54+
run: pnpm run test:nodejs
55+
56+
run-misc-checks:
57+
runs-on: ubuntu-latest
58+
59+
steps:
60+
- name: Checkout
61+
uses: actions/checkout@v3
62+
63+
- name: Install Node.js
64+
uses: actions/setup-node@v3
65+
with:
66+
node-version: 16.x
67+
68+
- name: Install pnpm
69+
uses: pnpm/[email protected]
70+
with:
71+
version: 7
72+
run_install: false
73+
74+
- name: Get pnpm store directory
75+
id: pnpm-cache
76+
run: |
77+
echo "::set-output name=pnpm_cache_dir::$(pnpm store path)"
78+
79+
- name: Setup pnpm cache
80+
uses: actions/cache@v3
81+
with:
82+
path: ${{ steps.pnpm-cache.outputs.pnpm_cache_dir }}
83+
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
84+
restore-keys: |
85+
${{ runner.os }}-pnpm-store-
86+
87+
- name: Install dependencies
88+
run: pnpm i
89+
90+
- name: Build
91+
run: pnpm run build
92+
93+
- name: Type Check
94+
run: pnpm run type-check
95+
96+
- name: Lint
97+
run: pnpm run lint

Diff for: .gitignore

+4-103
Original file line numberDiff line numberDiff line change
@@ -1,104 +1,5 @@
1-
# Logs
2-
logs
3-
*.log
4-
npm-debug.log*
5-
yarn-debug.log*
6-
yarn-error.log*
7-
lerna-debug.log*
8-
9-
# Diagnostic reports (https://nodejs.org/api/report.html)
10-
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
11-
12-
# Runtime data
13-
pids
14-
*.pid
15-
*.seed
16-
*.pid.lock
17-
18-
# Directory for instrumented libs generated by jscoverage/JSCover
19-
lib-cov
20-
21-
# Coverage directory used by tools like istanbul
22-
coverage
23-
*.lcov
24-
25-
# nyc test coverage
26-
.nyc_output
27-
28-
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
29-
.grunt
30-
31-
# Bower dependency directory (https://bower.io/)
32-
bower_components
33-
34-
# node-waf configuration
35-
.lock-wscript
36-
37-
# Compiled binary addons (https://nodejs.org/api/addons.html)
38-
build/Release
39-
40-
# Dependency directories
1+
coverage/
2+
dist/
413
node_modules/
42-
jspm_packages/
43-
44-
# TypeScript v1 declaration files
45-
typings/
46-
47-
# TypeScript cache
48-
*.tsbuildinfo
49-
50-
# Optional npm cache directory
51-
.npm
52-
53-
# Optional eslint cache
54-
.eslintcache
55-
56-
# Microbundle cache
57-
.rpt2_cache/
58-
.rts2_cache_cjs/
59-
.rts2_cache_es/
60-
.rts2_cache_umd/
61-
62-
# Optional REPL history
63-
.node_repl_history
64-
65-
# Output of 'npm pack'
66-
*.tgz
67-
68-
# Yarn Integrity file
69-
.yarn-integrity
70-
71-
# dotenv environment variables file
72-
.env
73-
.env.test
74-
75-
# parcel-bundler cache (https://parceljs.org/)
76-
.cache
77-
78-
# Next.js build output
79-
.next
80-
81-
# Nuxt.js build / generate output
82-
.nuxt
83-
dist
84-
85-
# Gatsby files
86-
.cache/
87-
# Comment in the public line in if your project uses Gatsby and *not* Next.js
88-
# https://nextjs.org/blog/next-9-1#public-directory-support
89-
# public
90-
91-
# vuepress build output
92-
.vuepress/dist
93-
94-
# Serverless directories
95-
.serverless/
96-
97-
# FuseBox cache
98-
.fusebox/
99-
100-
# DynamoDB Local files
101-
.dynamodb/
102-
103-
# TernJS port file
104-
.tern-port
4+
*.log
5+
.env*

Diff for: .mocharc.json

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"extension": ["ts"],
3+
"recursive": true,
4+
"require": ["esbuild-runner/register"],
5+
"timeout": 30000
6+
}

Diff for: .prettierignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
dist/
2+
pnpm-lock.yaml

Diff for: .prettierrc.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module.exports = {
2+
printWidth: 120,
3+
semi: false,
4+
singleQuote: true,
5+
trailingComma: 'all',
6+
bracketSpacing: false,
7+
plugins: [require('prettier-plugin-organize-imports'), require('prettier-plugin-pkg')],
8+
}

Diff for: README.md

+91-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,91 @@
1-
# kysely-postgres-js
1+
# kysely-postgres-js
2+
3+
![Powered by TypeScript](https://img.shields.io/badge/powered%20by-typescript-blue.svg)
4+
5+
[Kysely](https://github.com/koskimas/kysely) dialect for [PostgreSQL](https://www.postgresql.org/) using the [Postgres.js](https://github.com/porsager/postgres) client under the hood.
6+
7+
## Installation
8+
9+
#### NPM 7+
10+
11+
```bash
12+
npm i kysely-postgres-js
13+
```
14+
15+
#### NPM <7
16+
17+
```bash
18+
npm i kysely-postgres-js kysely postgres
19+
```
20+
21+
#### Yarn
22+
23+
```bash
24+
yarn add kysely-postgres-js kysely postgres
25+
```
26+
27+
#### PNPM
28+
29+
```bash
30+
pnpm add kysely-postgres-js kysely postgres
31+
```
32+
33+
### Deno
34+
35+
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.
36+
37+
To fix that, add an [`import_map.json`](https://deno.land/[email protected]/linking_to_external_code/import_maps) file.
38+
39+
```json
40+
{
41+
"imports": {
42+
"kysely": "https://cdn.jsdelivr.net/npm/[email protected]/dist/esm/index.js",
43+
"postgres": "https://deno.land/x/[email protected]"
44+
}
45+
}
46+
```
47+
48+
## Usage
49+
50+
```ts
51+
import {Kysely} from 'kysely'
52+
import {PostgresJSDialect} from 'kysely-postgres-js'
53+
import postgres from 'postgres'
54+
55+
interface Database {
56+
person: {
57+
id: GeneratedAlways<number>
58+
first_name: string | null
59+
last_name: string | null
60+
age: number
61+
}
62+
}
63+
64+
const db = new Kysely<Database>({
65+
dialect: new PostgresJSDialect({
66+
options: {
67+
database: 'test',
68+
host: 'localhost',
69+
port: 5434,
70+
user: 'admin',
71+
},
72+
postgres,
73+
}),
74+
})
75+
```
76+
77+
## Caveats
78+
79+
### Single connection
80+
81+
[Postgres.js](https://github.com/porsager/postgres) doesn't provide single connection getter method/s. To get a single connection, you have to create an instance with a pool that has at most one connection (`max: 1`). This is not aligned with Kysely's current design. As a result, `db.connection()` will not work as expected when using a pool with more than one connection.
82+
If you need to use a single connection, you should instantiate a new `Kysely`
83+
instance with a pool that has at most one connection.
84+
85+
### Transactions
86+
87+
For transactions, this dialect creates additional pools with at most one connection, so `db.transaction().execute(...)` will work as expected. Keep in mind, this means that total number of connections to the database might exceed the pool size passed to Kysely initially.
88+
89+
## License
90+
91+
MIT License, see `LICENSE`

Diff for: docker-compose.yml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
version: '3'
2+
3+
services:
4+
postgres:
5+
image: 'postgres'
6+
environment:
7+
POSTGRES_DB: test
8+
POSTGRES_USER: admin
9+
POSTGRES_HOST_AUTH_METHOD: trust
10+
ports:
11+
- '5434:5432'

0 commit comments

Comments
 (0)