kysely 0.13.0 → 0.15.1
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.
- package/README.md +92 -32
- package/dist/cjs/{introspection → dialect}/database-introspector.d.ts +0 -0
- package/dist/cjs/{introspection → dialect}/database-introspector.js +0 -0
- package/dist/cjs/dialect/dialect.d.ts +1 -1
- package/dist/cjs/dialect/mysql/mysql-dialect.d.ts +1 -1
- package/dist/cjs/dialect/mysql/mysql-introspector.d.ts +1 -1
- package/dist/cjs/dialect/mysql/mysql-introspector.js +3 -3
- package/dist/cjs/dialect/postgres/postgres-dialect.d.ts +1 -1
- package/dist/cjs/dialect/postgres/postgres-introspector.d.ts +1 -1
- package/dist/cjs/dialect/postgres/postgres-introspector.js +3 -3
- package/dist/cjs/dialect/sqlite/sqlite-dialect.d.ts +1 -1
- package/dist/cjs/dialect/sqlite/sqlite-introspector.d.ts +1 -1
- package/dist/cjs/dialect/sqlite/sqlite-introspector.js +3 -3
- package/dist/cjs/index.d.ts +6 -3
- package/dist/cjs/index.js +6 -3
- package/dist/cjs/kysely.d.ts +8 -40
- package/dist/cjs/kysely.js +8 -40
- package/dist/cjs/migration/file-migration-provider.d.ts +52 -0
- package/dist/cjs/migration/file-migration-provider.js +52 -0
- package/dist/{esm/migration/migration.d.ts → cjs/migration/migrator.d.ts} +159 -134
- package/dist/cjs/migration/{migration.js → migrator.js} +166 -57
- package/dist/cjs/operation-node/check-constraint-node.d.ts +1 -1
- package/dist/cjs/operation-node/check-constraint-node.js +2 -3
- package/dist/cjs/operation-node/column-definition-node.d.ts +2 -2
- package/dist/cjs/operation-node/data-type-node.d.ts +1 -1
- package/dist/cjs/operation-node/generated-node.d.ts +20 -0
- package/dist/cjs/operation-node/generated-node.js +31 -0
- package/dist/cjs/operation-node/on-conflict-node.d.ts +13 -2
- package/dist/cjs/operation-node/on-conflict-node.js +39 -1
- package/dist/cjs/operation-node/operation-node-transformer.d.ts +2 -2
- package/dist/cjs/operation-node/operation-node-transformer.js +11 -5
- package/dist/cjs/operation-node/operation-node-visitor.d.ts +2 -2
- package/dist/cjs/operation-node/operation-node-visitor.js +1 -1
- package/dist/cjs/operation-node/operation-node.d.ts +1 -1
- package/dist/cjs/parser/insert-values-parser.d.ts +4 -4
- package/dist/cjs/parser/insert-values-parser.js +2 -3
- package/dist/cjs/parser/reference-parser.d.ts +4 -3
- package/dist/cjs/parser/select-parser.d.ts +10 -4
- package/dist/cjs/parser/update-set-parser.d.ts +2 -1
- package/dist/cjs/query-builder/delete-query-builder.d.ts +2 -4
- package/dist/cjs/query-builder/insert-query-builder.d.ts +80 -95
- package/dist/cjs/query-builder/insert-query-builder.js +145 -15
- package/dist/cjs/query-builder/on-conflict-builder.d.ts +686 -0
- package/dist/cjs/query-builder/on-conflict-builder.js +323 -0
- package/dist/cjs/query-builder/returning-interface.d.ts +2 -4
- package/dist/cjs/query-builder/select-query-builder.d.ts +1 -1
- package/dist/cjs/query-builder/update-query-builder.d.ts +2 -4
- package/dist/cjs/query-compiler/default-query-compiler.d.ts +2 -2
- package/dist/cjs/query-compiler/default-query-compiler.js +33 -7
- package/dist/cjs/query-creator.d.ts +0 -2
- package/dist/cjs/query-creator.js +0 -2
- package/dist/cjs/schema/alter-table-builder.d.ts +29 -9
- package/dist/cjs/schema/alter-table-builder.js +33 -9
- package/dist/cjs/schema/column-definition-builder.d.ts +28 -8
- package/dist/cjs/schema/column-definition-builder.js +17 -7
- package/dist/cjs/schema/create-index-builder.d.ts +3 -2
- package/dist/cjs/schema/create-index-builder.js +2 -2
- package/dist/cjs/schema/create-table-builder.d.ts +3 -2
- package/dist/cjs/schema/create-table-builder.js +2 -2
- package/dist/cjs/util/column-type.d.ts +165 -0
- package/dist/cjs/util/column-type.js +2 -0
- package/dist/cjs/util/private-symbols.d.ts +5 -0
- package/dist/cjs/util/private-symbols.js +8 -0
- package/dist/cjs/util/type-utils.d.ts +6 -42
- package/dist/esm/{introspection → dialect}/database-introspector.d.ts +0 -0
- package/dist/esm/{introspection → dialect}/database-introspector.js +0 -0
- package/dist/esm/dialect/dialect.d.ts +1 -1
- package/dist/esm/dialect/mysql/mysql-dialect.d.ts +1 -1
- package/dist/esm/dialect/mysql/mysql-introspector.d.ts +1 -1
- package/dist/esm/dialect/mysql/mysql-introspector.js +1 -1
- package/dist/esm/dialect/postgres/postgres-dialect.d.ts +1 -1
- package/dist/esm/dialect/postgres/postgres-introspector.d.ts +1 -1
- package/dist/esm/dialect/postgres/postgres-introspector.js +1 -1
- package/dist/esm/dialect/sqlite/sqlite-dialect.d.ts +1 -1
- package/dist/esm/dialect/sqlite/sqlite-introspector.d.ts +1 -1
- package/dist/esm/dialect/sqlite/sqlite-introspector.js +1 -1
- package/dist/esm/index.d.ts +6 -3
- package/dist/esm/index.js +6 -3
- package/dist/esm/kysely.d.ts +8 -40
- package/dist/esm/kysely.js +8 -40
- package/dist/esm/migration/file-migration-provider.d.ts +52 -0
- package/dist/esm/migration/file-migration-provider.js +48 -0
- package/dist/{cjs/migration/migration.d.ts → esm/migration/migrator.d.ts} +159 -134
- package/dist/esm/migration/{migration.js → migrator.js} +165 -56
- package/dist/esm/operation-node/check-constraint-node.d.ts +1 -1
- package/dist/esm/operation-node/check-constraint-node.js +2 -3
- package/dist/esm/operation-node/column-definition-node.d.ts +2 -2
- package/dist/esm/operation-node/data-type-node.d.ts +1 -1
- package/dist/esm/operation-node/generated-node.d.ts +20 -0
- package/dist/esm/operation-node/generated-node.js +28 -0
- package/dist/esm/operation-node/on-conflict-node.d.ts +13 -2
- package/dist/esm/operation-node/on-conflict-node.js +39 -1
- package/dist/esm/operation-node/operation-node-transformer.d.ts +2 -2
- package/dist/esm/operation-node/operation-node-transformer.js +11 -5
- package/dist/esm/operation-node/operation-node-visitor.d.ts +2 -2
- package/dist/esm/operation-node/operation-node-visitor.js +1 -1
- package/dist/esm/operation-node/operation-node.d.ts +1 -1
- package/dist/esm/parser/insert-values-parser.d.ts +4 -4
- package/dist/esm/parser/insert-values-parser.js +2 -3
- package/dist/esm/parser/reference-parser.d.ts +4 -3
- package/dist/esm/parser/select-parser.d.ts +10 -4
- package/dist/esm/parser/update-set-parser.d.ts +2 -1
- package/dist/esm/query-builder/delete-query-builder.d.ts +2 -4
- package/dist/esm/query-builder/insert-query-builder.d.ts +80 -95
- package/dist/esm/query-builder/insert-query-builder.js +145 -15
- package/dist/esm/query-builder/on-conflict-builder.d.ts +686 -0
- package/dist/esm/query-builder/on-conflict-builder.js +317 -0
- package/dist/esm/query-builder/returning-interface.d.ts +2 -4
- package/dist/esm/query-builder/select-query-builder.d.ts +1 -1
- package/dist/esm/query-builder/update-query-builder.d.ts +2 -4
- package/dist/esm/query-compiler/default-query-compiler.d.ts +2 -2
- package/dist/esm/query-compiler/default-query-compiler.js +33 -7
- package/dist/esm/query-creator.d.ts +0 -2
- package/dist/esm/query-creator.js +0 -2
- package/dist/esm/schema/alter-table-builder.d.ts +29 -9
- package/dist/esm/schema/alter-table-builder.js +33 -9
- package/dist/esm/schema/column-definition-builder.d.ts +28 -8
- package/dist/esm/schema/column-definition-builder.js +17 -7
- package/dist/esm/schema/create-index-builder.d.ts +3 -2
- package/dist/esm/schema/create-index-builder.js +2 -2
- package/dist/esm/schema/create-table-builder.d.ts +3 -2
- package/dist/esm/schema/create-table-builder.js +2 -2
- package/dist/esm/util/column-type.d.ts +165 -0
- package/dist/esm/util/column-type.js +1 -0
- package/dist/esm/util/private-symbols.d.ts +5 -0
- package/dist/esm/util/private-symbols.js +5 -0
- package/dist/esm/util/type-utils.d.ts +6 -42
- package/package.json +1 -1
- package/dist/cjs/operation-node/generated-always-as-node.d.ts +0 -16
- package/dist/cjs/operation-node/generated-always-as-node.js +0 -25
- package/dist/cjs/parser/on-conflict-parser.d.ts +0 -10
- package/dist/cjs/parser/on-conflict-parser.js +0 -35
- package/dist/cjs/util/generated-placeholder.d.ts +0 -3
- package/dist/cjs/util/generated-placeholder.js +0 -11
- package/dist/esm/operation-node/generated-always-as-node.d.ts +0 -16
- package/dist/esm/operation-node/generated-always-as-node.js +0 -22
- package/dist/esm/parser/on-conflict-parser.d.ts +0 -10
- package/dist/esm/parser/on-conflict-parser.js +0 -30
- package/dist/esm/util/generated-placeholder.d.ts +0 -3
- package/dist/esm/util/generated-placeholder.js +0 -7
package/README.md
CHANGED
|
@@ -4,8 +4,7 @@
|
|
|
4
4
|
# [Kysely](https://koskimas.github.io/kysely/index.html)
|
|
5
5
|
|
|
6
6
|
A type-safe and autocompletion-friendly typescript SQL query builder for node.js. Inspired by
|
|
7
|
-
[knex](http://knexjs.org/).
|
|
8
|
-
an introductory blog post for you.
|
|
7
|
+
[knex](http://knexjs.org/).
|
|
9
8
|
|
|
10
9
|

|
|
11
10
|
|
|
@@ -29,6 +28,9 @@ Kysely is still young and some useful features are propably not yet implemented.
|
|
|
29
28
|
using Kysely and can't find something you'd want to use, please open an issue or join our
|
|
30
29
|
[discord server](https://discord.gg/C9aJ49mCra).
|
|
31
30
|
|
|
31
|
+
[Here's](https://www.jakso.me/blog/kysely-a-type-safe-sql-query-builder-for-typescript)
|
|
32
|
+
an introductory blog post.
|
|
33
|
+
|
|
32
34
|
# Table of contents
|
|
33
35
|
|
|
34
36
|
- [Installation](#installation)
|
|
@@ -36,6 +38,7 @@ using Kysely and can't find something you'd want to use, please open an issue or
|
|
|
36
38
|
- [Query examples](#query-examples)
|
|
37
39
|
- [Migrations](#migrations)
|
|
38
40
|
- [API reference](https://koskimas.github.io/kysely/index.html)
|
|
41
|
+
- [Changelog](https://github.com/koskimas/kysely/releases)
|
|
39
42
|
|
|
40
43
|
# Installation
|
|
41
44
|
|
|
@@ -65,34 +68,55 @@ All you need to do is define an interface for each table in the database and pas
|
|
|
65
68
|
interfaces to the `Kysely` constructor:
|
|
66
69
|
|
|
67
70
|
```ts
|
|
68
|
-
import {
|
|
71
|
+
import {
|
|
72
|
+
Kysely,
|
|
73
|
+
PostgresDialect,
|
|
74
|
+
Generated,
|
|
75
|
+
ColumnType,
|
|
76
|
+
Selectable,
|
|
77
|
+
Insertable,
|
|
78
|
+
Updateable,
|
|
79
|
+
} from 'kysely'
|
|
80
|
+
|
|
81
|
+
interface PersonTable {
|
|
82
|
+
// Columns that are generated by the database should be marked
|
|
83
|
+
// using the `Generated` type. This way they are automatically
|
|
84
|
+
// made optional in inserts.
|
|
85
|
+
id: Generated<number>
|
|
69
86
|
|
|
70
|
-
interface Person {
|
|
71
|
-
id: number
|
|
72
87
|
first_name: string
|
|
73
|
-
// If the column is nullable in the db, make its type nullable.
|
|
74
|
-
// Don't use optional properties.
|
|
75
|
-
last_name: string | null
|
|
76
88
|
gender: 'male' | 'female' | 'other'
|
|
89
|
+
|
|
90
|
+
// If the column is nullable in the database, make its type nullable.
|
|
91
|
+
// Don't use optional properties. Optionality is always determined
|
|
92
|
+
// automatically by Kysely.
|
|
93
|
+
last_name: string | null
|
|
94
|
+
|
|
95
|
+
// You can specity a type for each operation (select, insert and update)
|
|
96
|
+
// using the `ColumnType<SelectType, InsertType, UpdateType>` wrapper.
|
|
97
|
+
// Here we define a column `modified_at` that is selected as a `Date`,
|
|
98
|
+
// can optionally be provided as a `string` in inserts and can never
|
|
99
|
+
// be updated:
|
|
100
|
+
modified_at: ColumnType<Date, string | undefined, never>
|
|
77
101
|
}
|
|
78
102
|
|
|
79
|
-
interface
|
|
80
|
-
id: number
|
|
103
|
+
interface PetTable {
|
|
104
|
+
id: Generated<number>
|
|
81
105
|
name: string
|
|
82
106
|
owner_id: number
|
|
83
107
|
species: 'dog' | 'cat'
|
|
84
108
|
}
|
|
85
109
|
|
|
86
|
-
interface
|
|
87
|
-
id: string
|
|
110
|
+
interface MovieTable {
|
|
111
|
+
id: Generated<string>
|
|
88
112
|
stars: number
|
|
89
113
|
}
|
|
90
114
|
|
|
91
115
|
// Keys of this interface are table names.
|
|
92
116
|
interface Database {
|
|
93
|
-
person:
|
|
94
|
-
pet:
|
|
95
|
-
movie:
|
|
117
|
+
person: PersonTable
|
|
118
|
+
pet: PetTable
|
|
119
|
+
movie: MovieTable
|
|
96
120
|
}
|
|
97
121
|
|
|
98
122
|
// You'd create one of these when you start your app.
|
|
@@ -101,15 +125,26 @@ const db = new Kysely<Database>({
|
|
|
101
125
|
dialect: new PostgresDialect({
|
|
102
126
|
host: 'localhost',
|
|
103
127
|
database: 'kysely_test',
|
|
104
|
-
})
|
|
128
|
+
}),
|
|
105
129
|
})
|
|
106
130
|
|
|
107
131
|
async function demo() {
|
|
132
|
+
const { id } = await db
|
|
133
|
+
.insertInto('person')
|
|
134
|
+
.values({ first_name: 'Jennifer', gender: 'female' })
|
|
135
|
+
.returning('id')
|
|
136
|
+
.executeTakeFirstOrThrow()
|
|
137
|
+
|
|
138
|
+
await db
|
|
139
|
+
.insertInto('pet')
|
|
140
|
+
.values({ name: 'Catto', species: 'cat', owner_id: id })
|
|
141
|
+
.execute()
|
|
142
|
+
|
|
108
143
|
const person = await db
|
|
109
144
|
.selectFrom('person')
|
|
110
145
|
.innerJoin('pet', 'pet.owner_id', 'person.id')
|
|
111
146
|
.select(['first_name', 'pet.name as pet_name'])
|
|
112
|
-
.where('person.id', '=',
|
|
147
|
+
.where('person.id', '=', id)
|
|
113
148
|
.executeTakeFirst()
|
|
114
149
|
|
|
115
150
|
if (person) {
|
|
@@ -118,6 +153,14 @@ async function demo() {
|
|
|
118
153
|
}
|
|
119
154
|
```
|
|
120
155
|
|
|
156
|
+
```ts
|
|
157
|
+
// You can extract the select, insert and update interfaces like this
|
|
158
|
+
// if you want (you don't need to):
|
|
159
|
+
type Person = Selectable<PersonTable>
|
|
160
|
+
type InsertablePerson = Insertable<PersonTable>
|
|
161
|
+
type UpdateablePerson = Updateable<PersonTable>
|
|
162
|
+
```
|
|
163
|
+
|
|
121
164
|
# Query examples
|
|
122
165
|
|
|
123
166
|
## Select queries
|
|
@@ -248,37 +291,54 @@ export async function down(db: Kysely<any>): Promise<void> {
|
|
|
248
291
|
You can then use
|
|
249
292
|
|
|
250
293
|
```ts
|
|
251
|
-
|
|
294
|
+
const migrator = new Migrator(migratorConfig);
|
|
295
|
+
await migrator.migrateToLatest(pathToMigrationsFolder)
|
|
252
296
|
```
|
|
253
297
|
|
|
254
298
|
to run all migrations that have not yet been run. The migrations are executed in alphabetical
|
|
255
|
-
order by their name. See the [
|
|
299
|
+
order by their name. See the [Migrator](https://koskimas.github.io/kysely/classes/Migrator.html)
|
|
256
300
|
documentation for more info.
|
|
257
301
|
|
|
258
302
|
Kysely doesn't have a CLI for running migrations and probably never will. This is because Kysely's
|
|
259
303
|
migrations are also written in typescript. To run the migrations, you need to first build the
|
|
260
|
-
typescript code into javascript.
|
|
304
|
+
typescript code into javascript. A CLI would cause confusion over which migrations are being
|
|
261
305
|
run, the typescript ones or the javascript ones. If we added support for both, the CLI would
|
|
262
306
|
need to depend on a typescript compiler, which most production environments don't (and shouldn't)
|
|
263
307
|
have. You will probably want to add a simple migration script to your projects like this:
|
|
264
308
|
|
|
265
309
|
```ts
|
|
266
|
-
import path from 'path'
|
|
310
|
+
import * as path from 'path'
|
|
311
|
+
import * as fs from 'fs/promises'
|
|
267
312
|
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
313
|
+
import {
|
|
314
|
+
Kysely,
|
|
315
|
+
Migrator,
|
|
316
|
+
PostgresDialect,
|
|
317
|
+
FileMigrationProvider
|
|
318
|
+
} from 'kysely'
|
|
274
319
|
|
|
275
320
|
async function migrateToLatest() {
|
|
276
|
-
const
|
|
277
|
-
|
|
278
|
-
|
|
321
|
+
const db = new Kysely<Database>({
|
|
322
|
+
dialect: new PostgresDialect({
|
|
323
|
+
host: 'localhost',
|
|
324
|
+
database: 'kysely_test',
|
|
325
|
+
}),
|
|
326
|
+
})
|
|
327
|
+
|
|
328
|
+
const migrator = new Migrator({
|
|
329
|
+
db,
|
|
330
|
+
// The constructor signature of FileMigrationProvider is a
|
|
331
|
+
// bit weird to keep Kysely independent of node.js or any
|
|
332
|
+
// other environment.
|
|
333
|
+
provider: new FileMigrationProvider(
|
|
334
|
+
fs.readdir,
|
|
335
|
+
path.join,
|
|
336
|
+
// Path to the folder that contains all your migrations.
|
|
337
|
+
'migrations'
|
|
338
|
+
)
|
|
339
|
+
})
|
|
279
340
|
|
|
280
|
-
|
|
281
|
-
await db.destroy()
|
|
341
|
+
const { error, results } = await migrator.migrateToLatest()
|
|
282
342
|
|
|
283
343
|
results?.forEach((it) => {
|
|
284
344
|
if (it.status === 'Success') {
|
|
File without changes
|
|
File without changes
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Driver } from '../driver/driver.js';
|
|
2
2
|
import { Kysely } from '../kysely.js';
|
|
3
3
|
import { QueryCompiler } from '../query-compiler/query-compiler.js';
|
|
4
|
-
import { DatabaseIntrospector } from '
|
|
4
|
+
import { DatabaseIntrospector } from './database-introspector.js';
|
|
5
5
|
import { DialectAdapter } from './dialect-adapter.js';
|
|
6
6
|
/**
|
|
7
7
|
* A Dialect is the glue between Kysely and the underlying database engine.
|
|
@@ -2,7 +2,7 @@ import { Driver } from '../../driver/driver.js';
|
|
|
2
2
|
import { Kysely } from '../../kysely.js';
|
|
3
3
|
import { QueryCompiler } from '../../query-compiler/query-compiler.js';
|
|
4
4
|
import { Dialect } from '../dialect.js';
|
|
5
|
-
import { DatabaseIntrospector } from '
|
|
5
|
+
import { DatabaseIntrospector } from '../database-introspector.js';
|
|
6
6
|
import { DialectAdapter } from '../dialect-adapter.js';
|
|
7
7
|
import { DatabaseConnection } from '../../driver/database-connection.js';
|
|
8
8
|
/**
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DatabaseIntrospector, DatabaseMetadata, DatabaseMetadataOptions } from '
|
|
1
|
+
import { DatabaseIntrospector, DatabaseMetadata, DatabaseMetadataOptions } from '../database-introspector.js';
|
|
2
2
|
import { Kysely } from '../../kysely.js';
|
|
3
3
|
export declare class MysqlIntrospector implements DatabaseIntrospector {
|
|
4
4
|
#private;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.MysqlIntrospector = void 0;
|
|
4
|
-
const
|
|
4
|
+
const migrator_js_1 = require("../../migration/migrator.js");
|
|
5
5
|
const object_utils_js_1 = require("../../util/object-utils.js");
|
|
6
6
|
class MysqlIntrospector {
|
|
7
7
|
#db;
|
|
@@ -16,8 +16,8 @@ class MysqlIntrospector {
|
|
|
16
16
|
.castTo();
|
|
17
17
|
if (!options.withInternalKyselyTables) {
|
|
18
18
|
query = query
|
|
19
|
-
.where('table_name', '!=',
|
|
20
|
-
.where('table_name', '!=',
|
|
19
|
+
.where('table_name', '!=', migrator_js_1.MIGRATION_TABLE)
|
|
20
|
+
.where('table_name', '!=', migrator_js_1.MIGRATION_LOCK_TABLE);
|
|
21
21
|
}
|
|
22
22
|
const rawColumns = await query.execute();
|
|
23
23
|
return {
|
|
@@ -5,7 +5,7 @@ import { Driver } from '../../driver/driver.js';
|
|
|
5
5
|
import { Kysely } from '../../kysely.js';
|
|
6
6
|
import { QueryCompiler } from '../../query-compiler/query-compiler.js';
|
|
7
7
|
import { Dialect } from '../dialect.js';
|
|
8
|
-
import { DatabaseIntrospector } from '
|
|
8
|
+
import { DatabaseIntrospector } from '../database-introspector.js';
|
|
9
9
|
import { DialectAdapter } from '../dialect-adapter.js';
|
|
10
10
|
import { DatabaseConnection } from '../../driver/database-connection.js';
|
|
11
11
|
/**
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DatabaseIntrospector, DatabaseMetadata, DatabaseMetadataOptions } from '
|
|
1
|
+
import { DatabaseIntrospector, DatabaseMetadata, DatabaseMetadataOptions } from '../database-introspector.js';
|
|
2
2
|
import { Kysely } from '../../kysely.js';
|
|
3
3
|
export declare class PostgresIntrospector implements DatabaseIntrospector {
|
|
4
4
|
#private;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.PostgresIntrospector = void 0;
|
|
4
|
-
const
|
|
4
|
+
const migrator_js_1 = require("../../migration/migrator.js");
|
|
5
5
|
const object_utils_js_1 = require("../../util/object-utils.js");
|
|
6
6
|
class PostgresIntrospector {
|
|
7
7
|
#db;
|
|
@@ -28,8 +28,8 @@ class PostgresIntrospector {
|
|
|
28
28
|
.castTo();
|
|
29
29
|
if (!options.withInternalKyselyTables) {
|
|
30
30
|
query = query
|
|
31
|
-
.where('t.tablename', '!=',
|
|
32
|
-
.where('t.tablename', '!=',
|
|
31
|
+
.where('t.tablename', '!=', migrator_js_1.MIGRATION_TABLE)
|
|
32
|
+
.where('t.tablename', '!=', migrator_js_1.MIGRATION_LOCK_TABLE);
|
|
33
33
|
}
|
|
34
34
|
const rawColumns = await query.execute();
|
|
35
35
|
return {
|
|
@@ -2,7 +2,7 @@ import { Driver } from '../../driver/driver.js';
|
|
|
2
2
|
import { Kysely } from '../../kysely.js';
|
|
3
3
|
import { QueryCompiler } from '../../query-compiler/query-compiler.js';
|
|
4
4
|
import { Dialect } from '../dialect.js';
|
|
5
|
-
import { DatabaseIntrospector } from '
|
|
5
|
+
import { DatabaseIntrospector } from '../database-introspector.js';
|
|
6
6
|
import { DialectAdapter } from '../dialect-adapter.js';
|
|
7
7
|
import { DatabaseConnection } from '../../driver/database-connection.js';
|
|
8
8
|
/**
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DatabaseIntrospector, DatabaseMetadata, DatabaseMetadataOptions } from '
|
|
1
|
+
import { DatabaseIntrospector, DatabaseMetadata, DatabaseMetadataOptions } from '../database-introspector.js';
|
|
2
2
|
import { Kysely } from '../../kysely.js';
|
|
3
3
|
export declare class SqliteIntrospector implements DatabaseIntrospector {
|
|
4
4
|
#private;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.SqliteIntrospector = void 0;
|
|
4
|
-
const
|
|
4
|
+
const migrator_js_1 = require("../../migration/migrator.js");
|
|
5
5
|
class SqliteIntrospector {
|
|
6
6
|
#db;
|
|
7
7
|
constructor(db) {
|
|
@@ -16,8 +16,8 @@ class SqliteIntrospector {
|
|
|
16
16
|
.castTo();
|
|
17
17
|
if (!options.withInternalKyselyTables) {
|
|
18
18
|
query = query
|
|
19
|
-
.where('name', '!=',
|
|
20
|
-
.where('name', '!=',
|
|
19
|
+
.where('name', '!=', migrator_js_1.MIGRATION_TABLE)
|
|
20
|
+
.where('name', '!=', migrator_js_1.MIGRATION_LOCK_TABLE);
|
|
21
21
|
}
|
|
22
22
|
const tables = await query.execute();
|
|
23
23
|
return {
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -15,6 +15,7 @@ export * from './query-builder/function-builder.js';
|
|
|
15
15
|
export * from './query-builder/insert-result.js';
|
|
16
16
|
export * from './query-builder/delete-result.js';
|
|
17
17
|
export * from './query-builder/update-result.js';
|
|
18
|
+
export * from './query-builder/on-conflict-builder.js';
|
|
18
19
|
export * from './raw-builder/raw-builder.js';
|
|
19
20
|
export * from './query-executor/query-executor.js';
|
|
20
21
|
export * from './query-executor/default-query-executor.js';
|
|
@@ -56,7 +57,8 @@ export * from './dialect/sqlite/sqlite-introspector.js';
|
|
|
56
57
|
export * from './dialect/sqlite/sqlite-adapter.js';
|
|
57
58
|
export * from './query-compiler/default-query-compiler.js';
|
|
58
59
|
export * from './query-compiler/query-compiler.js';
|
|
59
|
-
export * from './migration/
|
|
60
|
+
export * from './migration/migrator.js';
|
|
61
|
+
export * from './migration/file-migration-provider.js';
|
|
60
62
|
export * from './dialect/dialect.js';
|
|
61
63
|
export * from './dialect/dialect-adapter.js';
|
|
62
64
|
export * from './dialect/dialect-adapter-base.js';
|
|
@@ -91,7 +93,7 @@ export * from './operation-node/drop-view-node.js';
|
|
|
91
93
|
export * from './operation-node/filter-node.js';
|
|
92
94
|
export * from './operation-node/foreign-key-constraint-node.js';
|
|
93
95
|
export * from './operation-node/from-node.js';
|
|
94
|
-
export * from './operation-node/generated-
|
|
96
|
+
export * from './operation-node/generated-node.js';
|
|
95
97
|
export * from './operation-node/group-by-item-node.js';
|
|
96
98
|
export * from './operation-node/group-by-node.js';
|
|
97
99
|
export * from './operation-node/having-node.js';
|
|
@@ -136,7 +138,8 @@ export * from './operation-node/value-node.js';
|
|
|
136
138
|
export * from './operation-node/values-node.js';
|
|
137
139
|
export * from './operation-node/where-node.js';
|
|
138
140
|
export * from './operation-node/with-node.js';
|
|
139
|
-
export * from './
|
|
141
|
+
export * from './dialect/database-introspector.js';
|
|
142
|
+
export * from './util/column-type.js';
|
|
140
143
|
export * from './util/compilable.js';
|
|
141
144
|
export * from './util/log.js';
|
|
142
145
|
export { AnyColumn, UnknownRow, AnySelectQueryBuilder, } from './util/type-utils.js';
|
package/dist/cjs/index.js
CHANGED
|
@@ -27,6 +27,7 @@ __exportStar(require("./query-builder/function-builder.js"), exports);
|
|
|
27
27
|
__exportStar(require("./query-builder/insert-result.js"), exports);
|
|
28
28
|
__exportStar(require("./query-builder/delete-result.js"), exports);
|
|
29
29
|
__exportStar(require("./query-builder/update-result.js"), exports);
|
|
30
|
+
__exportStar(require("./query-builder/on-conflict-builder.js"), exports);
|
|
30
31
|
__exportStar(require("./raw-builder/raw-builder.js"), exports);
|
|
31
32
|
__exportStar(require("./query-executor/query-executor.js"), exports);
|
|
32
33
|
__exportStar(require("./query-executor/default-query-executor.js"), exports);
|
|
@@ -68,7 +69,8 @@ __exportStar(require("./dialect/sqlite/sqlite-introspector.js"), exports);
|
|
|
68
69
|
__exportStar(require("./dialect/sqlite/sqlite-adapter.js"), exports);
|
|
69
70
|
__exportStar(require("./query-compiler/default-query-compiler.js"), exports);
|
|
70
71
|
__exportStar(require("./query-compiler/query-compiler.js"), exports);
|
|
71
|
-
__exportStar(require("./migration/
|
|
72
|
+
__exportStar(require("./migration/migrator.js"), exports);
|
|
73
|
+
__exportStar(require("./migration/file-migration-provider.js"), exports);
|
|
72
74
|
__exportStar(require("./dialect/dialect.js"), exports);
|
|
73
75
|
__exportStar(require("./dialect/dialect-adapter.js"), exports);
|
|
74
76
|
__exportStar(require("./dialect/dialect-adapter-base.js"), exports);
|
|
@@ -103,7 +105,7 @@ __exportStar(require("./operation-node/drop-view-node.js"), exports);
|
|
|
103
105
|
__exportStar(require("./operation-node/filter-node.js"), exports);
|
|
104
106
|
__exportStar(require("./operation-node/foreign-key-constraint-node.js"), exports);
|
|
105
107
|
__exportStar(require("./operation-node/from-node.js"), exports);
|
|
106
|
-
__exportStar(require("./operation-node/generated-
|
|
108
|
+
__exportStar(require("./operation-node/generated-node.js"), exports);
|
|
107
109
|
__exportStar(require("./operation-node/group-by-item-node.js"), exports);
|
|
108
110
|
__exportStar(require("./operation-node/group-by-node.js"), exports);
|
|
109
111
|
__exportStar(require("./operation-node/having-node.js"), exports);
|
|
@@ -148,6 +150,7 @@ __exportStar(require("./operation-node/value-node.js"), exports);
|
|
|
148
150
|
__exportStar(require("./operation-node/values-node.js"), exports);
|
|
149
151
|
__exportStar(require("./operation-node/where-node.js"), exports);
|
|
150
152
|
__exportStar(require("./operation-node/with-node.js"), exports);
|
|
151
|
-
__exportStar(require("./
|
|
153
|
+
__exportStar(require("./dialect/database-introspector.js"), exports);
|
|
154
|
+
__exportStar(require("./util/column-type.js"), exports);
|
|
152
155
|
__exportStar(require("./util/compilable.js"), exports);
|
|
153
156
|
__exportStar(require("./util/log.js"), exports);
|
package/dist/cjs/kysely.d.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { Dialect } from './dialect/dialect.js';
|
|
2
2
|
import { SchemaModule } from './schema/schema.js';
|
|
3
3
|
import { DynamicModule } from './dynamic/dynamic.js';
|
|
4
|
-
import { MigrationModule } from './migration/migration.js';
|
|
5
4
|
import { QueryExecutor } from './query-executor/query-executor.js';
|
|
6
5
|
import { QueryCreator } from './query-creator.js';
|
|
7
6
|
import { KyselyPlugin } from './plugin/kysely-plugin.js';
|
|
8
|
-
import {
|
|
9
|
-
import { DatabaseIntrospector } from './introspection/database-introspector.js';
|
|
7
|
+
import { DatabaseIntrospector } from './dialect/database-introspector.js';
|
|
10
8
|
import { Driver, IsolationLevel } from './driver/driver.js';
|
|
11
9
|
import { ParseContext } from './parser/parse-context.js';
|
|
12
10
|
import { FunctionBuilder } from './query-builder/function-builder.js';
|
|
13
11
|
import { LogConfig } from './util/log.js';
|
|
12
|
+
import { PRIVATE_ADAPTER } from './util/private-symbols.js';
|
|
13
|
+
import { DialectAdapter } from './dialect/dialect-adapter.js';
|
|
14
14
|
/**
|
|
15
15
|
* The main Kysely class.
|
|
16
16
|
*
|
|
@@ -60,10 +60,6 @@ export declare class Kysely<DB> extends QueryCreator<DB> {
|
|
|
60
60
|
* Returns the {@link SchemaModule} module for building database schema.
|
|
61
61
|
*/
|
|
62
62
|
get schema(): SchemaModule;
|
|
63
|
-
/**
|
|
64
|
-
* Returns the {@link MigrationModule} module for managing and running migrations.
|
|
65
|
-
*/
|
|
66
|
-
get migration(): MigrationModule;
|
|
67
63
|
/**
|
|
68
64
|
* Returns a the {@link DynamicModule} module.
|
|
69
65
|
*
|
|
@@ -75,31 +71,6 @@ export declare class Kysely<DB> extends QueryCreator<DB> {
|
|
|
75
71
|
* Returns a {@link DatabaseIntrospector | database introspector}.
|
|
76
72
|
*/
|
|
77
73
|
get introspection(): DatabaseIntrospector;
|
|
78
|
-
/**
|
|
79
|
-
* A value to be used in place of columns that are generated in the database
|
|
80
|
-
* when inserting rows.
|
|
81
|
-
*
|
|
82
|
-
* ### Examples
|
|
83
|
-
*
|
|
84
|
-
* In this example the `Person` table has non-null properties `id` and `created_at`
|
|
85
|
-
* which are both automatically genereted by the database. Since their types are
|
|
86
|
-
* `number` and `string` respectively instead of `number | null` and `string | null`
|
|
87
|
-
* the `values` method requires you to give a value for them. the `generated`
|
|
88
|
-
* placeholder can be used in these cases.
|
|
89
|
-
*
|
|
90
|
-
* ```ts
|
|
91
|
-
* await db.insertInto('person')
|
|
92
|
-
* .values({
|
|
93
|
-
* id: db.generated,
|
|
94
|
-
* created_at: db.generated,
|
|
95
|
-
* first_name: 'Jennifer',
|
|
96
|
-
* last_name: 'Aniston',
|
|
97
|
-
* gender: 'female'
|
|
98
|
-
* })
|
|
99
|
-
* .execute()
|
|
100
|
-
* ```
|
|
101
|
-
*/
|
|
102
|
-
get generated(): GeneratedPlaceholder;
|
|
103
74
|
/**
|
|
104
75
|
* Returns a {@link FunctionBuilder} that can be used to write type safe function
|
|
105
76
|
* calls.
|
|
@@ -149,7 +120,6 @@ export declare class Kysely<DB> extends QueryCreator<DB> {
|
|
|
149
120
|
* const catto = await db.transaction().execute(async (trx) => {
|
|
150
121
|
* const jennifer = await trx.insertInto('person')
|
|
151
122
|
* .values({
|
|
152
|
-
* id: db.generated,
|
|
153
123
|
* first_name: 'Jennifer',
|
|
154
124
|
* last_name: 'Aniston',
|
|
155
125
|
* })
|
|
@@ -160,7 +130,6 @@ export declare class Kysely<DB> extends QueryCreator<DB> {
|
|
|
160
130
|
*
|
|
161
131
|
* return await trx.insertInto('pet')
|
|
162
132
|
* .values({
|
|
163
|
-
* id: db.generated,
|
|
164
133
|
* user_id: jennifer.id,
|
|
165
134
|
* name: 'Catto',
|
|
166
135
|
* species: 'cat'
|
|
@@ -251,6 +220,11 @@ export declare class Kysely<DB> extends QueryCreator<DB> {
|
|
|
251
220
|
* You can also use `db instanceof Transaction`.
|
|
252
221
|
*/
|
|
253
222
|
get isTransaction(): boolean;
|
|
223
|
+
/**
|
|
224
|
+
* @internal
|
|
225
|
+
* @private
|
|
226
|
+
*/
|
|
227
|
+
get [PRIVATE_ADAPTER](): DialectAdapter;
|
|
254
228
|
}
|
|
255
229
|
export declare class Transaction<DB> extends Kysely<DB> {
|
|
256
230
|
#private;
|
|
@@ -261,10 +235,6 @@ export declare class Transaction<DB> extends Kysely<DB> {
|
|
|
261
235
|
* You can also use `db instanceof Transaction`.
|
|
262
236
|
*/
|
|
263
237
|
get isTransaction(): true;
|
|
264
|
-
/**
|
|
265
|
-
* Returns the {@link MigrationModule} module for managing and running migrations.
|
|
266
|
-
*/
|
|
267
|
-
get migration(): MigrationModule;
|
|
268
238
|
/**
|
|
269
239
|
* Creates a {@link TransactionBuilder} that can be used to run queries inside a transaction.
|
|
270
240
|
*
|
|
@@ -285,7 +255,6 @@ export declare class Transaction<DB> extends Kysely<DB> {
|
|
|
285
255
|
* const catto = await db.transaction().execute(async (trx) => {
|
|
286
256
|
* const jennifer = await trx.insertInto('person')
|
|
287
257
|
* .values({
|
|
288
|
-
* id: db.generated,
|
|
289
258
|
* first_name: 'Jennifer',
|
|
290
259
|
* last_name: 'Aniston',
|
|
291
260
|
* })
|
|
@@ -296,7 +265,6 @@ export declare class Transaction<DB> extends Kysely<DB> {
|
|
|
296
265
|
*
|
|
297
266
|
* return await trx.insertInto('pet')
|
|
298
267
|
* .values({
|
|
299
|
-
* id: db.generated,
|
|
300
268
|
* user_id: jennifer.id,
|
|
301
269
|
* name: 'Catto',
|
|
302
270
|
* species: 'cat'
|
package/dist/cjs/kysely.js
CHANGED
|
@@ -4,9 +4,7 @@ exports.TransactionBuilder = exports.ConnectionBuilder = exports.isKyselyProps =
|
|
|
4
4
|
const schema_js_1 = require("./schema/schema.js");
|
|
5
5
|
const dynamic_js_1 = require("./dynamic/dynamic.js");
|
|
6
6
|
const default_connection_provider_js_1 = require("./driver/default-connection-provider.js");
|
|
7
|
-
const migration_js_1 = require("./migration/migration.js");
|
|
8
7
|
const query_creator_js_1 = require("./query-creator.js");
|
|
9
|
-
const generated_placeholder_js_1 = require("./util/generated-placeholder.js");
|
|
10
8
|
const default_query_executor_js_1 = require("./query-executor/default-query-executor.js");
|
|
11
9
|
const object_utils_js_1 = require("./util/object-utils.js");
|
|
12
10
|
const runtime_driver_js_1 = require("./driver/runtime-driver.js");
|
|
@@ -16,6 +14,7 @@ const prevent_await_js_1 = require("./util/prevent-await.js");
|
|
|
16
14
|
const parse_context_js_1 = require("./parser/parse-context.js");
|
|
17
15
|
const function_builder_js_1 = require("./query-builder/function-builder.js");
|
|
18
16
|
const log_js_1 = require("./util/log.js");
|
|
17
|
+
const private_symbols_js_1 = require("./util/private-symbols.js");
|
|
19
18
|
/**
|
|
20
19
|
* The main Kysely class.
|
|
21
20
|
*
|
|
@@ -90,12 +89,6 @@ class Kysely extends query_creator_js_1.QueryCreator {
|
|
|
90
89
|
get schema() {
|
|
91
90
|
return new schema_js_1.SchemaModule(this.#props.executor);
|
|
92
91
|
}
|
|
93
|
-
/**
|
|
94
|
-
* Returns the {@link MigrationModule} module for managing and running migrations.
|
|
95
|
-
*/
|
|
96
|
-
get migration() {
|
|
97
|
-
return new migration_js_1.MigrationModule(this, this.#props.parseContext.adapter);
|
|
98
|
-
}
|
|
99
92
|
/**
|
|
100
93
|
* Returns a the {@link DynamicModule} module.
|
|
101
94
|
*
|
|
@@ -111,33 +104,6 @@ class Kysely extends query_creator_js_1.QueryCreator {
|
|
|
111
104
|
get introspection() {
|
|
112
105
|
return this.#props.dialect.createIntrospector(this.withoutPlugins());
|
|
113
106
|
}
|
|
114
|
-
/**
|
|
115
|
-
* A value to be used in place of columns that are generated in the database
|
|
116
|
-
* when inserting rows.
|
|
117
|
-
*
|
|
118
|
-
* ### Examples
|
|
119
|
-
*
|
|
120
|
-
* In this example the `Person` table has non-null properties `id` and `created_at`
|
|
121
|
-
* which are both automatically genereted by the database. Since their types are
|
|
122
|
-
* `number` and `string` respectively instead of `number | null` and `string | null`
|
|
123
|
-
* the `values` method requires you to give a value for them. the `generated`
|
|
124
|
-
* placeholder can be used in these cases.
|
|
125
|
-
*
|
|
126
|
-
* ```ts
|
|
127
|
-
* await db.insertInto('person')
|
|
128
|
-
* .values({
|
|
129
|
-
* id: db.generated,
|
|
130
|
-
* created_at: db.generated,
|
|
131
|
-
* first_name: 'Jennifer',
|
|
132
|
-
* last_name: 'Aniston',
|
|
133
|
-
* gender: 'female'
|
|
134
|
-
* })
|
|
135
|
-
* .execute()
|
|
136
|
-
* ```
|
|
137
|
-
*/
|
|
138
|
-
get generated() {
|
|
139
|
-
return generated_placeholder_js_1.GENERATED_PLACEHOLDER;
|
|
140
|
-
}
|
|
141
107
|
/**
|
|
142
108
|
* Returns a {@link FunctionBuilder} that can be used to write type safe function
|
|
143
109
|
* calls.
|
|
@@ -189,7 +155,6 @@ class Kysely extends query_creator_js_1.QueryCreator {
|
|
|
189
155
|
* const catto = await db.transaction().execute(async (trx) => {
|
|
190
156
|
* const jennifer = await trx.insertInto('person')
|
|
191
157
|
* .values({
|
|
192
|
-
* id: db.generated,
|
|
193
158
|
* first_name: 'Jennifer',
|
|
194
159
|
* last_name: 'Aniston',
|
|
195
160
|
* })
|
|
@@ -200,7 +165,6 @@ class Kysely extends query_creator_js_1.QueryCreator {
|
|
|
200
165
|
*
|
|
201
166
|
* return await trx.insertInto('pet')
|
|
202
167
|
* .values({
|
|
203
|
-
* id: db.generated,
|
|
204
168
|
* user_id: jennifer.id,
|
|
205
169
|
* name: 'Catto',
|
|
206
170
|
* species: 'cat'
|
|
@@ -311,6 +275,13 @@ class Kysely extends query_creator_js_1.QueryCreator {
|
|
|
311
275
|
get isTransaction() {
|
|
312
276
|
return false;
|
|
313
277
|
}
|
|
278
|
+
/**
|
|
279
|
+
* @internal
|
|
280
|
+
* @private
|
|
281
|
+
*/
|
|
282
|
+
get [private_symbols_js_1.PRIVATE_ADAPTER]() {
|
|
283
|
+
return this.#props.parseContext.adapter;
|
|
284
|
+
}
|
|
314
285
|
}
|
|
315
286
|
exports.Kysely = Kysely;
|
|
316
287
|
class Transaction extends Kysely {
|
|
@@ -325,9 +296,6 @@ class Transaction extends Kysely {
|
|
|
325
296
|
get isTransaction() {
|
|
326
297
|
return true;
|
|
327
298
|
}
|
|
328
|
-
get migration() {
|
|
329
|
-
throw new Error('the migration module is not available for a transaction. Use the main Kysely instance to run migrations');
|
|
330
|
-
}
|
|
331
299
|
transaction() {
|
|
332
300
|
throw new Error('calling the transaction method for a Transaction is not supported');
|
|
333
301
|
}
|