Skip to content

Commit

Permalink
Merge branch 'master' into logan/runtime-enum-support
Browse files Browse the repository at this point in the history
  • Loading branch information
RobinBlomberg committed Mar 17, 2024
2 parents d6a9b95 + d199d82 commit 73d81a2
Show file tree
Hide file tree
Showing 26 changed files with 1,620 additions and 843 deletions.
45 changes: 41 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,34 @@

## Installation

```
```sh
npm install --save-dev kysely-codegen
```

You will also need to install Kysely with your driver of choice:

# You will also need to install Kysely with your driver of choice:
```sh
# PostgreSQL
npm install kysely pg

# MySQL
npm install kysely mysql2

# SQLite
npm install kysely better-sqlite3

# MSSQL
npm install kysely tedious tarn @tediousjs/connection-string

# LibSQL
npm install @libsql/kysely-libsql
```

## Generating type definitions

The most convenient way to get started is to create an `.env` file with your database connection string:

```
```sh
# PostgreSQL
DATABASE_URL=postgres://username:password@yourdomain.com/database

Expand All @@ -34,6 +47,9 @@ DATABASE_URL=mysql://username:password@yourdomain.com/database
# SQLite
DATABASE_URL=C:/Program Files/sqlite3/db

# MSSQL
DATABASE_URL=Server=mssql;Database=database;User Id=user;Password=password

# LibSQL
DATABASE_URL=libsql://token@host:port/database
```
Expand All @@ -44,12 +60,13 @@ DATABASE_URL=libsql://token@host:port/database
Then run:

```
```sh
kysely-codegen
```

This command will generate a `.d.ts` file from your database, for example:

<!-- prettier-ignore -->
```ts
import { ColumnType } from 'kysely';

Expand Down Expand Up @@ -80,6 +97,26 @@ export interface DB {
}
```

## Include/exclude patterns

You can choose which tables should be included during code generation by providing a glob pattern to the `--include` and `--exclude` flags. We use [micromatch](https://github.com/micromatch/micromatch) under the hood which provides advanced glob support. For instance, if you only want to include your public tables:

```bash
kysely-codegen --include="public.*"
```

You can also include only certain tables within a schema:

```bash
kysely-codegen --include="public.+(user|post)"
```

Or exclude an entire class of tables:
```bash
kysely-codegen --exclude="documents.*"
```

## Help
For more options, run `kysely-codegen --help`.

## Using the type definitions
Expand Down
53 changes: 34 additions & 19 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "kysely-codegen",
"version": "0.12.0",
"version": "0.13.1",
"author": "Robin Blomberg",
"license": "MIT",
"main": "./dist/index.js",
Expand All @@ -18,6 +18,7 @@
"homepage": "https://github.com/RobinBlomberg/kysely-codegen#readme",
"scripts": {
"build": "rimraf dist && tsc",
"check": "tsc --noEmit",
"ci": "run-s ci:*",
"ci:build": "pnpm build",
"ci:eslint": "pnpm lint:eslint --max-warnings=0 --report-unused-disable-directives",
Expand All @@ -39,64 +40,78 @@
},
"dependencies": {
"chalk": "4.1.2",
"dotenv": "^16.4.1",
"dotenv": "^16.4.5",
"dotenv-expand": "^11.0.6",
"git-diff": "^2.0.6",
"micromatch": "^4.0.5",
"minimist": "^1.2.8"
},
"devDependencies": {
"@libsql/kysely-libsql": "^0.3.0",
"@robinblomberg/eslint-config-prettier": "^0.1.4",
"@robinblomberg/eslint-config-robinblomberg": "0.25.0",
"@robinblomberg/eslint-config-robinblomberg": "0.27.0",
"@robinblomberg/prettier-config": "^0.1.2",
"@types/better-sqlite3": "^7.6.9",
"@types/git-diff": "^2.0.7",
"@types/micromatch": "^4.0.6",
"@types/minimist": "^1.2.5",
"@types/node": "^20.11.16",
"@types/pg": "^8.11.0",
"@typescript-eslint/parser": "^6.20.0",
"better-sqlite3": "^9.3.0",
"eslint": "^8.56.0",
"kysely-bun-worker": "^0.5.6",
"kysely": "^0.27.2",
"mysql2": "^3.9.1",
"@types/node": "^20.11.28",
"@types/pg": "^8.11.2",
"@types/tedious": "^4.0.14",
"@typescript-eslint/parser": "^7.2.0",
"better-sqlite3": "^9.4.3",
"eslint": "^8.57.0",
"kysely": "^0.27.3",
"kysely-bun-worker": "^0.5.7",
"mysql2": "^3.9.2",
"npm-run-all": "^4.1.5",
"pg": "^8.11.3",
"pnpm": "^8.15.1",
"prettier": "^3.2.4",
"pnpm": "^8.15.4",
"prettier": "^3.2.5",
"rimraf": "^5.0.5",
"ts-node-dev": "^2.0.0",
"tsx": "^4.7.0",
"typescript": "^5.3.3",
"vitest": "^1.2.2"
"tsx": "^4.7.1",
"typescript": "^5.4.2",
"vitest": "^1.4.0"
},
"peerDependencies": {
"@libsql/kysely-libsql": "^0.3.0",
"@tediousjs/connection-string": "^0.5.0",
"better-sqlite3": ">=7.6.2",
"kysely": "^0.27.0",
"kysely-bun-worker": "^0.5.3",
"kysely": ">=0.19.12",
"mysql2": "^2.3.3 || ^3.0.0",
"pg": "^8.8.0"
"pg": "^8.8.0",
"tarn": "^3.0.0",
"tedious": "^16.6.0 || ^17.0.0"
},
"peerDependenciesMeta": {
"@libsql/kysely-libsql": {
"optional": true
},
"@tediousjs/connection-string": {
"optional": true
},
"better-sqlite3": {
"optional": true
},
"kysely": {
"optional": false
},
"kysely-bun-worker": {
"optional": false
"optional": true
},
"mysql2": {
"optional": true
},
"pg": {
"optional": true
},
"tarn": {
"optional": true
},
"tedious": {
"optional": true
}
},
"eslintConfig": {
Expand Down
Loading

0 comments on commit 73d81a2

Please sign in to comment.