forked from tmrclark/kysely-codegen-mssql
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
30 changed files
with
4,716 additions
and
3,428 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 |
---|---|---|
|
@@ -6,26 +6,41 @@ | |
|
||
- [Installation](#installation) | ||
- [Generating type definitions](#generating-type-definitions) | ||
- [Include/exclude patterns](#includeexclude-patterns) | ||
- [Help](#help) | ||
- [Using the type definitions](#using-the-type-definitions) | ||
- [Issue funding](#issue-funding) | ||
|
||
## 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 | ||
npm install @libsql/kysely-libsql | ||
|
||
# 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:[email protected]/database | ||
|
||
|
@@ -35,11 +50,11 @@ DATABASE_URL=mysql://username:[email protected]/database | |
# SQLite | ||
DATABASE_URL=C:/Program Files/sqlite3/db | ||
|
||
# LibSQL | ||
DATABASE_URL=libsql://token@host:port/database | ||
# MSSQL | ||
DATABASE_URL=Server=mssql;Database=database;User Id=user;Password=password | ||
|
||
# LibSQL | ||
DATABASE_URL=libsql://token@host:port/database | ||
``` | ||
|
||
> If your URL contains a password with special characters, those characters may need to be [percent-encoded](https://en.wikipedia.org/wiki/Percent-encoding#Reserved_characters). | ||
|
@@ -48,12 +63,13 @@ DATABASE_URL=Server=mssql;Database=database;User Id=user;Password=password | |
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'; | ||
|
||
|
@@ -84,6 +100,28 @@ 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-pattern` and `--exclude-pattern` 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-pattern="public.*" | ||
``` | ||
|
||
You can also include only certain tables within a schema: | ||
|
||
```bash | ||
kysely-codegen --include-pattern="public.+(user|post)" | ||
``` | ||
|
||
Or exclude an entire class of tables: | ||
|
||
```bash | ||
kysely-codegen --exclude-pattern="documents.*" | ||
``` | ||
|
||
## Help | ||
|
||
For more options, run `kysely-codegen --help`. | ||
|
||
## Using the type definitions | ||
|
@@ -106,3 +144,9 @@ const db = new Kysely<DB>({ | |
const rows = await db.selectFrom('user').selectAll().execute(); | ||
// ^ { company_id: number | null; created_at: Date; email: string; id: number; ... }[] | ||
``` | ||
|
||
## Issue funding | ||
|
||
We use [Polar.sh](https://polar.sh/RobinBlomberg) to upvote and promote specific features that you would like to see implemented. Check the backlog and help out: | ||
|
||
<a href="https://polar.sh/RobinBlomberg"><img src="https://polar.sh/embed/fund-our-backlog.svg?org=RobinBlomberg" /></a> |
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
Oops, something went wrong.