kysely-gen 0.3.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +92 -3
  2. package/dist/cli.js +27620 -4974
  3. package/package.json +21 -3
package/README.md CHANGED
@@ -1,23 +1,43 @@
1
1
  # kysely-gen
2
2
 
3
- Generate TypeScript types from your PostgreSQL database for [Kysely](https://kysely.dev/).
3
+ Generate TypeScript types from your database for [Kysely](https://kysely.dev/).
4
+
5
+ Supports PostgreSQL, MySQL, and SQLite.
4
6
 
5
7
  ## Install
6
8
 
7
9
  ```sh
10
+ # PostgreSQL
8
11
  npm install kysely-gen kysely pg
12
+
13
+ # MySQL
14
+ npm install kysely-gen kysely mysql2
15
+
16
+ # SQLite
17
+ npm install kysely-gen kysely better-sqlite3
9
18
  ```
10
19
 
11
20
  ## Usage
12
21
 
13
22
  ```sh
23
+ # PostgreSQL (auto-detected from URL)
14
24
  DATABASE_URL=postgres://user:pass@localhost:5432/db npx kysely-gen
25
+
26
+ # MySQL (auto-detected from URL)
27
+ DATABASE_URL=mysql://user:pass@localhost:3306/db npx kysely-gen
28
+
29
+ # SQLite (auto-detected from file extension)
30
+ npx kysely-gen --url ./database.db
31
+
32
+ # Explicit dialect
33
+ npx kysely-gen --dialect mysql --url mysql://user:pass@localhost:3306/db
15
34
  ```
16
35
 
17
36
  ## Options
18
37
 
19
38
  | Option | Description |
20
39
  |--------|-------------|
40
+ | `--dialect <name>` | Database dialect: `postgres`, `mysql`, or `sqlite` (auto-detected) |
21
41
  | `--out <path>` | Output file (default: `./db.d.ts`) |
22
42
  | `--schema <name>` | Schema to introspect (repeatable) |
23
43
  | `--url <string>` | Database URL (overrides `DATABASE_URL`) |
@@ -56,11 +76,80 @@ export interface DB {
56
76
 
57
77
  ## Features
58
78
 
59
- - PostgreSQL enums mapped to union types
79
+ ### PostgreSQL
80
+ - Enums mapped to union types
60
81
  - `ColumnType` for select/insert/update type differences
61
82
  - `Generated<T>` for auto-increment and default columns
62
83
  - Materialized views, domains, partitioned tables
63
- - Glob patterns for table filtering
84
+ - Array columns
85
+
86
+ ### MySQL
87
+ - Enums parsed from column definitions
88
+ - `ColumnType` for timestamps, bigint, decimal
89
+ - `Generated<T>` for auto_increment columns
90
+ - Views
91
+ - Geometry types (Point, LineString, Polygon)
92
+ - `tinyint(1)` mapped to boolean
93
+
94
+ ### SQLite
95
+ - `Generated<T>` for INTEGER PRIMARY KEY (auto-increment)
96
+ - Views
97
+ - JSON columns mapped to `JsonValue`
98
+ - Simple type affinity mapping (no ColumnType wrappers)
99
+
100
+ ## Type Mappings
101
+
102
+ Types are generated to match the default behavior of each database driver. If you customize your driver's type parsers, the generated types may not match.
103
+
104
+ ### PostgreSQL
105
+
106
+ Generated types match `node-postgres` (pg) defaults:
107
+
108
+ - **Dates** (`timestamp`, `date`): Driver returns `Date` objects. Inserts accept `Date | string`.
109
+ - **Bigint** (`int8`): Driver returns `string` (JS Number can't represent full int8 range). Inserts accept `string | number | bigint`.
110
+ - **Numeric** (`numeric`, `decimal`): Driver returns `string` for precision. Inserts accept `string | number`.
111
+
112
+ | PostgreSQL | TypeScript |
113
+ |------------|------------|
114
+ | `int2`, `int4`, `integer` | `number` |
115
+ | `int8`, `bigint` | `ColumnType<string, string \| number \| bigint, ...>` |
116
+ | `numeric`, `decimal` | `ColumnType<string, number \| string, ...>` |
117
+ | `timestamp`, `date` | `ColumnType<Date, Date \| string, ...>` |
118
+ | `jsonb`, `json` | `JsonValue` |
119
+ | `text[]`, `int4[]` | `string[]`, `number[]` |
120
+
121
+ ### MySQL
122
+
123
+ Generated types match `mysql2` defaults:
124
+
125
+ - **Dates** (`datetime`, `timestamp`): Driver returns `Date` objects. Inserts accept `Date | string`.
126
+ - **Bigint**: Driver returns `string`. Inserts accept `string | number | bigint`.
127
+ - **Decimal**: Driver returns `string` for precision. Inserts accept `string | number`.
128
+
129
+ | MySQL | TypeScript |
130
+ |-------|------------|
131
+ | `tinyint(1)` | `boolean` |
132
+ | `int`, `smallint` | `number` |
133
+ | `bigint` | `ColumnType<string, string \| number \| bigint, ...>` |
134
+ | `decimal` | `ColumnType<string, number \| string, ...>` |
135
+ | `datetime`, `timestamp` | `ColumnType<Date, Date \| string, ...>` |
136
+ | `json` | `JsonValue` |
137
+ | `point` | `Point` |
138
+ | `enum('a','b')` | `'a' \| 'b'` |
139
+
140
+ ### SQLite
141
+
142
+ Generated types match `better-sqlite3` defaults. SQLite has simpler type affinity - no `ColumnType` wrappers needed since values are returned as-is.
143
+
144
+ | SQLite | TypeScript |
145
+ |--------|------------|
146
+ | `INTEGER`, `INT`, `BIGINT` | `number` |
147
+ | `REAL`, `DOUBLE`, `FLOAT` | `number` |
148
+ | `TEXT`, `VARCHAR`, `CHAR` | `string` |
149
+ | `BLOB` | `Buffer` |
150
+ | `DATE`, `DATETIME`, `TIMESTAMP` | `string` |
151
+ | `JSON` | `JsonValue` |
152
+ | `BOOLEAN` | `number` (0/1) |
64
153
 
65
154
  ## License
66
155