kysely 0.10.0 → 0.11.2

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 (174) hide show
  1. package/README.md +7 -3
  2. package/dist/cjs/dialect/dialect-adapter.d.ts +3 -2
  3. package/dist/cjs/dialect/mysql/mysql-adapter.js +1 -1
  4. package/dist/cjs/dialect/mysql/mysql-dialect.d.ts +3 -3
  5. package/dist/cjs/dialect/mysql/mysql-driver.js +25 -32
  6. package/dist/cjs/dialect/postgres/postgres-dialect.d.ts +2 -2
  7. package/dist/cjs/dialect/postgres/postgres-driver.js +8 -19
  8. package/dist/cjs/dialect/sqlite/sqlite-adapter.d.ts +7 -0
  9. package/dist/cjs/dialect/sqlite/sqlite-adapter.js +18 -0
  10. package/dist/cjs/dialect/sqlite/sqlite-dialect.d.ts +64 -0
  11. package/dist/cjs/dialect/sqlite/sqlite-dialect.js +33 -0
  12. package/dist/cjs/dialect/sqlite/sqlite-driver.d.ts +14 -0
  13. package/dist/cjs/dialect/sqlite/sqlite-driver.js +116 -0
  14. package/dist/cjs/dialect/sqlite/sqlite-introspector.d.ts +7 -0
  15. package/dist/cjs/dialect/sqlite/sqlite-introspector.js +44 -0
  16. package/dist/cjs/dialect/sqlite/sqlite-query-compiler.d.ts +7 -0
  17. package/dist/cjs/dialect/sqlite/sqlite-query-compiler.js +19 -0
  18. package/dist/cjs/driver/database-connection.d.ts +2 -2
  19. package/dist/cjs/driver/runtime-driver.js +3 -4
  20. package/dist/cjs/index.d.ts +45 -30
  21. package/dist/cjs/index.js +44 -29
  22. package/dist/cjs/kysely.d.ts +6 -4
  23. package/dist/cjs/kysely.js +6 -4
  24. package/dist/cjs/migration/migration.d.ts +1 -1
  25. package/dist/cjs/migration/migration.js +3 -3
  26. package/dist/cjs/operation-node/alias-node.d.ts +1 -1
  27. package/dist/cjs/operation-node/column-definition-node.d.ts +4 -2
  28. package/dist/cjs/operation-node/create-view-node.d.ts +1 -0
  29. package/dist/cjs/operation-node/default-value-node.d.ts +14 -0
  30. package/dist/cjs/operation-node/default-value-node.js +18 -0
  31. package/dist/cjs/operation-node/generated-always-as-node.d.ts +16 -0
  32. package/dist/cjs/operation-node/generated-always-as-node.js +25 -0
  33. package/dist/cjs/operation-node/having-node.d.ts +4 -8
  34. package/dist/cjs/operation-node/having-node.js +3 -3
  35. package/dist/cjs/operation-node/join-node.d.ts +6 -9
  36. package/dist/cjs/operation-node/join-node.js +10 -7
  37. package/dist/cjs/operation-node/on-node.d.ts +14 -0
  38. package/dist/cjs/operation-node/on-node.js +28 -0
  39. package/dist/cjs/operation-node/operation-node-transformer.d.ts +6 -0
  40. package/dist/cjs/operation-node/operation-node-transformer.js +26 -2
  41. package/dist/cjs/operation-node/operation-node-utils.d.ts +1 -1
  42. package/dist/cjs/operation-node/operation-node-visitor.d.ts +7 -0
  43. package/dist/cjs/operation-node/operation-node-visitor.js +9 -2
  44. package/dist/cjs/operation-node/operation-node.d.ts +1 -1
  45. package/dist/cjs/operation-node/query-node.d.ts +3 -3
  46. package/dist/cjs/operation-node/raw-node.d.ts +1 -1
  47. package/dist/cjs/operation-node/select-query-node.d.ts +4 -4
  48. package/dist/cjs/operation-node/where-node.d.ts +4 -8
  49. package/dist/cjs/operation-node/where-node.js +3 -3
  50. package/dist/cjs/parser/filter-parser.d.ts +1 -0
  51. package/dist/cjs/parser/filter-parser.js +49 -52
  52. package/dist/cjs/parser/returning-parser.d.ts +4 -2
  53. package/dist/cjs/parser/select-parser.d.ts +2 -2
  54. package/dist/cjs/plugin/immediate-value.ts/immediate-value-plugin.d.ts +1 -1
  55. package/dist/cjs/query-builder/delete-result.d.ts +5 -0
  56. package/dist/cjs/query-builder/delete-result.js +13 -0
  57. package/dist/cjs/query-builder/expression-builder.d.ts +2 -2
  58. package/dist/cjs/query-builder/expression-builder.js +1 -1
  59. package/dist/cjs/query-builder/function-builder.d.ts +5 -5
  60. package/dist/cjs/query-builder/function-builder.js +3 -3
  61. package/dist/cjs/query-builder/insert-result.d.ts +27 -0
  62. package/dist/cjs/query-builder/insert-result.js +35 -0
  63. package/dist/cjs/query-builder/join-builder.d.ts +3 -0
  64. package/dist/cjs/query-builder/query-builder.d.ts +95 -81
  65. package/dist/cjs/query-builder/query-builder.js +38 -41
  66. package/dist/cjs/query-builder/update-result.d.ts +5 -0
  67. package/dist/cjs/query-builder/update-result.js +13 -0
  68. package/dist/cjs/query-compiler/compiled-query.d.ts +5 -0
  69. package/dist/cjs/query-compiler/compiled-query.js +12 -0
  70. package/dist/cjs/query-compiler/default-query-compiler.d.ts +6 -0
  71. package/dist/cjs/query-compiler/default-query-compiler.js +41 -14
  72. package/dist/cjs/query-creator.d.ts +36 -26
  73. package/dist/cjs/query-creator.js +25 -17
  74. package/dist/cjs/raw-builder/raw-builder.d.ts +1 -1
  75. package/dist/cjs/schema/alter-table-builder.d.ts +4 -0
  76. package/dist/cjs/schema/alter-table-builder.js +24 -0
  77. package/dist/cjs/schema/column-definition-builder.d.ts +41 -0
  78. package/dist/cjs/schema/column-definition-builder.js +18 -1
  79. package/dist/cjs/schema/create-table-builder.d.ts +6 -7
  80. package/dist/cjs/schema/create-table-builder.js +6 -7
  81. package/dist/cjs/schema/create-view-builder.d.ts +4 -0
  82. package/dist/cjs/schema/create-view-builder.js +11 -0
  83. package/dist/cjs/util/dynamic-import.d.ts +2 -0
  84. package/dist/cjs/util/dynamic-import.js +32 -0
  85. package/dist/cjs/util/performance-now.d.ts +1 -0
  86. package/dist/cjs/util/performance-now.js +13 -0
  87. package/dist/cjs/util/type-utils.d.ts +4 -15
  88. package/dist/esm/dialect/dialect-adapter.d.ts +3 -2
  89. package/dist/esm/dialect/mysql/mysql-adapter.js +1 -1
  90. package/dist/esm/dialect/mysql/mysql-dialect.d.ts +3 -3
  91. package/dist/esm/dialect/mysql/mysql-driver.js +26 -33
  92. package/dist/esm/dialect/postgres/postgres-dialect.d.ts +2 -2
  93. package/dist/esm/dialect/postgres/postgres-driver.js +8 -19
  94. package/dist/esm/dialect/sqlite/sqlite-adapter.d.ts +7 -0
  95. package/dist/esm/dialect/sqlite/sqlite-adapter.js +14 -0
  96. package/dist/esm/dialect/sqlite/sqlite-dialect.d.ts +64 -0
  97. package/dist/esm/dialect/sqlite/sqlite-dialect.js +29 -0
  98. package/dist/esm/dialect/sqlite/sqlite-driver.d.ts +14 -0
  99. package/dist/esm/dialect/sqlite/sqlite-driver.js +112 -0
  100. package/dist/esm/dialect/sqlite/sqlite-introspector.d.ts +7 -0
  101. package/dist/esm/dialect/sqlite/sqlite-introspector.js +40 -0
  102. package/dist/esm/dialect/sqlite/sqlite-query-compiler.d.ts +7 -0
  103. package/dist/esm/dialect/sqlite/sqlite-query-compiler.js +15 -0
  104. package/dist/esm/driver/database-connection.d.ts +2 -2
  105. package/dist/esm/driver/runtime-driver.js +3 -4
  106. package/dist/esm/index.d.ts +45 -30
  107. package/dist/esm/index.js +44 -29
  108. package/dist/esm/kysely.d.ts +6 -4
  109. package/dist/esm/kysely.js +6 -4
  110. package/dist/esm/migration/migration.d.ts +1 -1
  111. package/dist/esm/migration/migration.js +3 -3
  112. package/dist/esm/operation-node/alias-node.d.ts +1 -1
  113. package/dist/esm/operation-node/column-definition-node.d.ts +4 -2
  114. package/dist/esm/operation-node/create-view-node.d.ts +1 -0
  115. package/dist/esm/operation-node/default-value-node.d.ts +14 -0
  116. package/dist/esm/operation-node/default-value-node.js +15 -0
  117. package/dist/esm/operation-node/generated-always-as-node.d.ts +16 -0
  118. package/dist/esm/operation-node/generated-always-as-node.js +22 -0
  119. package/dist/esm/operation-node/having-node.d.ts +4 -8
  120. package/dist/esm/operation-node/having-node.js +3 -3
  121. package/dist/esm/operation-node/join-node.d.ts +6 -9
  122. package/dist/esm/operation-node/join-node.js +10 -7
  123. package/dist/esm/operation-node/on-node.d.ts +14 -0
  124. package/dist/esm/operation-node/on-node.js +25 -0
  125. package/dist/esm/operation-node/operation-node-transformer.d.ts +6 -0
  126. package/dist/esm/operation-node/operation-node-transformer.js +26 -2
  127. package/dist/esm/operation-node/operation-node-utils.d.ts +1 -1
  128. package/dist/esm/operation-node/operation-node-visitor.d.ts +7 -0
  129. package/dist/esm/operation-node/operation-node-visitor.js +9 -2
  130. package/dist/esm/operation-node/operation-node.d.ts +1 -1
  131. package/dist/esm/operation-node/query-node.d.ts +3 -3
  132. package/dist/esm/operation-node/raw-node.d.ts +1 -1
  133. package/dist/esm/operation-node/select-query-node.d.ts +4 -4
  134. package/dist/esm/operation-node/where-node.d.ts +4 -8
  135. package/dist/esm/operation-node/where-node.js +3 -3
  136. package/dist/esm/parser/filter-parser.d.ts +1 -0
  137. package/dist/esm/parser/filter-parser.js +48 -52
  138. package/dist/esm/parser/returning-parser.d.ts +4 -2
  139. package/dist/esm/parser/select-parser.d.ts +2 -2
  140. package/dist/esm/plugin/immediate-value.ts/immediate-value-plugin.d.ts +1 -1
  141. package/dist/esm/query-builder/delete-result.d.ts +5 -0
  142. package/dist/esm/query-builder/delete-result.js +9 -0
  143. package/dist/esm/query-builder/expression-builder.d.ts +2 -2
  144. package/dist/esm/query-builder/expression-builder.js +1 -1
  145. package/dist/esm/query-builder/function-builder.d.ts +5 -5
  146. package/dist/esm/query-builder/function-builder.js +3 -3
  147. package/dist/esm/query-builder/insert-result.d.ts +27 -0
  148. package/dist/esm/query-builder/insert-result.js +31 -0
  149. package/dist/esm/query-builder/join-builder.d.ts +3 -0
  150. package/dist/esm/query-builder/query-builder.d.ts +95 -81
  151. package/dist/esm/query-builder/query-builder.js +38 -41
  152. package/dist/esm/query-builder/update-result.d.ts +5 -0
  153. package/dist/esm/query-builder/update-result.js +9 -0
  154. package/dist/esm/query-compiler/compiled-query.d.ts +5 -0
  155. package/dist/esm/query-compiler/compiled-query.js +11 -1
  156. package/dist/esm/query-compiler/default-query-compiler.d.ts +6 -0
  157. package/dist/esm/query-compiler/default-query-compiler.js +41 -14
  158. package/dist/esm/query-creator.d.ts +36 -26
  159. package/dist/esm/query-creator.js +25 -17
  160. package/dist/esm/raw-builder/raw-builder.d.ts +1 -1
  161. package/dist/esm/schema/alter-table-builder.d.ts +4 -0
  162. package/dist/esm/schema/alter-table-builder.js +24 -0
  163. package/dist/esm/schema/column-definition-builder.d.ts +41 -0
  164. package/dist/esm/schema/column-definition-builder.js +18 -1
  165. package/dist/esm/schema/create-table-builder.d.ts +6 -7
  166. package/dist/esm/schema/create-table-builder.js +6 -7
  167. package/dist/esm/schema/create-view-builder.d.ts +4 -0
  168. package/dist/esm/schema/create-view-builder.js +11 -0
  169. package/dist/esm/util/dynamic-import.d.ts +2 -0
  170. package/dist/esm/util/dynamic-import.js +27 -0
  171. package/dist/esm/util/performance-now.d.ts +1 -0
  172. package/dist/esm/util/performance-now.js +9 -0
  173. package/dist/esm/util/type-utils.d.ts +4 -15
  174. package/package.json +5 -3
@@ -1,4 +1,5 @@
1
- import { isFunction } from '../../util/object-utils.js';
1
+ import { CompiledQuery } from '../../query-compiler/compiled-query.js';
2
+ import { importNamedFunction } from '../../util/dynamic-import.js';
2
3
  const PRIVATE_RELEASE_METHOD = Symbol();
3
4
  export class PostgresDriver {
4
5
  #config;
@@ -35,20 +36,17 @@ export class PostgresDriver {
35
36
  }
36
37
  async beginTransaction(connection, settings) {
37
38
  if (settings.isolationLevel) {
38
- await connection.executeQuery({
39
- sql: `start transaction isolation level ${settings.isolationLevel}`,
40
- parameters: [],
41
- });
39
+ await connection.executeQuery(CompiledQuery.raw(`start transaction isolation level ${settings.isolationLevel}`));
42
40
  }
43
41
  else {
44
- await connection.executeQuery({ sql: 'begin', parameters: [] });
42
+ await connection.executeQuery(CompiledQuery.raw('begin'));
45
43
  }
46
44
  }
47
45
  async commitTransaction(connection) {
48
- await connection.executeQuery({ sql: 'commit', parameters: [] });
46
+ await connection.executeQuery(CompiledQuery.raw('commit'));
49
47
  }
50
48
  async rollbackTransaction(connection) {
51
- await connection.executeQuery({ sql: 'rollback', parameters: [] });
49
+ await connection.executeQuery(CompiledQuery.raw('rollback'));
52
50
  }
53
51
  async releaseConnection(connection) {
54
52
  const pgConnection = connection;
@@ -64,16 +62,7 @@ export class PostgresDriver {
64
62
  }
65
63
  async function importPgPool() {
66
64
  try {
67
- // For this to work with both esm and cjs modules we need
68
- // this hacky crap here.
69
- const pg = (await import('pg'));
70
- if (isFunction(pg.Pool)) {
71
- return pg.Pool;
72
- }
73
- else {
74
- // With esm the imported module doesn't match the typings.
75
- return pg.default.Pool;
76
- }
65
+ return await importNamedFunction('pg', 'Pool');
77
66
  }
78
67
  catch (error) {
79
68
  throw new Error('Postgres client not installed. Please run `npm install pg`');
@@ -90,7 +79,7 @@ class PostgresConnection {
90
79
  ]);
91
80
  if (result.command === 'UPDATE' || result.command === 'DELETE') {
92
81
  return {
93
- numUpdatedOrDeletedRows: result.rowCount,
82
+ numUpdatedOrDeletedRows: BigInt(result.rowCount),
94
83
  rows: result.rows ?? [],
95
84
  };
96
85
  }
@@ -0,0 +1,7 @@
1
+ import { DialectAdapter } from '../dialect-adapter.js';
2
+ export declare class SqliteAdapter implements DialectAdapter {
3
+ get supportsTransactionalDdl(): boolean;
4
+ get supportsReturning(): boolean;
5
+ acquireMigrationLock(): Promise<void>;
6
+ releaseMigrationLock(): Promise<void>;
7
+ }
@@ -0,0 +1,14 @@
1
+ export class SqliteAdapter {
2
+ get supportsTransactionalDdl() {
3
+ return false;
4
+ }
5
+ get supportsReturning() {
6
+ return false;
7
+ }
8
+ async acquireMigrationLock() {
9
+ // Nothing to do here.
10
+ }
11
+ async releaseMigrationLock() {
12
+ // Nothing to do here.
13
+ }
14
+ }
@@ -0,0 +1,64 @@
1
+ import { Driver } from '../../driver/driver.js';
2
+ import { Kysely } from '../../kysely.js';
3
+ import { QueryCompiler } from '../../query-compiler/query-compiler.js';
4
+ import { Dialect } from '../dialect.js';
5
+ import { DatabaseIntrospector } from '../../introspection/database-introspector.js';
6
+ import { DialectAdapter } from '../dialect-adapter.js';
7
+ import { DatabaseConnection } from '../../driver/database-connection.js';
8
+ /**
9
+ * SQLite dialect that uses the [better-sqlite3](https://github.com/JoshuaWise/better-sqlite3) library.
10
+ *
11
+ * The {@link SqliteDialectConfig | configuration} is used to construct an instance of
12
+ * [Database](https://github.com/JoshuaWise/better-sqlite3/blob/master/docs/api.md#new-databasepath-options)
13
+ * class. The configuration values are passed directly to the `Database` constructor.
14
+ */
15
+ export declare class SqliteDialect implements Dialect {
16
+ #private;
17
+ constructor(config: SqliteDialectConfig);
18
+ createDriver(): Driver;
19
+ createQueryCompiler(): QueryCompiler;
20
+ createAdapter(): DialectAdapter;
21
+ createIntrospector(db: Kysely<any>): DatabaseIntrospector;
22
+ }
23
+ /**
24
+ * Config for the SQLite dialect.
25
+ *
26
+ * This interface is equal to `better-sqlite3` library's `Databse` class's constructor parameters.
27
+ *
28
+ * https://github.com/JoshuaWise/better-sqlite3/blob/master/docs/api.md#new-databasepath-options
29
+ */
30
+ export interface SqliteDialectConfig {
31
+ /**
32
+ * The database file path.
33
+ *
34
+ * This is passed as the first argument for the [Database](https://github.com/JoshuaWise/better-sqlite3/blob/master/docs/api.md#new-databasepath-options)
35
+ * class constructor.
36
+ */
37
+ databasePath: string;
38
+ /**
39
+ * Open the database connection in readonly mode (default: false)
40
+ */
41
+ readonly?: boolean;
42
+ /**
43
+ * If the database does not exist, an Error will be thrown instead of creating a new file.
44
+ * This option is ignored for in-memory, temporary, or readonly database connections
45
+ * (default: false)
46
+ */
47
+ fileMustExist?: boolean;
48
+ /**
49
+ * The number of milliseconds to wait when executing queries on a locked database,
50
+ * before throwing a SQLITE_BUSY error (default: 5000)
51
+ */
52
+ timeout?: number;
53
+ /**
54
+ * Provide a function that gets called with every SQL string executed by the database connection
55
+ * (default: null)
56
+ */
57
+ verbose?: (sql: string) => void;
58
+ /**
59
+ * Called once when the first query is executed.
60
+ *
61
+ * This is a Kysely specific feature and does not come from the `better-sqlite3` module.
62
+ */
63
+ onCreateConnection?: (connection: DatabaseConnection) => Promise<void>;
64
+ }
@@ -0,0 +1,29 @@
1
+ import { SqliteDriver } from './sqlite-driver.js';
2
+ import { SqliteQueryCompiler } from './sqlite-query-compiler.js';
3
+ import { SqliteIntrospector } from './sqlite-introspector.js';
4
+ import { SqliteAdapter } from './sqlite-adapter.js';
5
+ /**
6
+ * SQLite dialect that uses the [better-sqlite3](https://github.com/JoshuaWise/better-sqlite3) library.
7
+ *
8
+ * The {@link SqliteDialectConfig | configuration} is used to construct an instance of
9
+ * [Database](https://github.com/JoshuaWise/better-sqlite3/blob/master/docs/api.md#new-databasepath-options)
10
+ * class. The configuration values are passed directly to the `Database` constructor.
11
+ */
12
+ export class SqliteDialect {
13
+ #config;
14
+ constructor(config) {
15
+ this.#config = config;
16
+ }
17
+ createDriver() {
18
+ return new SqliteDriver(this.#config);
19
+ }
20
+ createQueryCompiler() {
21
+ return new SqliteQueryCompiler();
22
+ }
23
+ createAdapter() {
24
+ return new SqliteAdapter();
25
+ }
26
+ createIntrospector(db) {
27
+ return new SqliteIntrospector(db);
28
+ }
29
+ }
@@ -0,0 +1,14 @@
1
+ import { DatabaseConnection } from '../../driver/database-connection.js';
2
+ import { Driver } from '../../driver/driver.js';
3
+ import { SqliteDialectConfig } from './sqlite-dialect.js';
4
+ export declare class SqliteDriver implements Driver {
5
+ #private;
6
+ constructor(config: SqliteDialectConfig);
7
+ init(): Promise<void>;
8
+ acquireConnection(): Promise<DatabaseConnection>;
9
+ beginTransaction(connection: DatabaseConnection): Promise<void>;
10
+ commitTransaction(connection: DatabaseConnection): Promise<void>;
11
+ rollbackTransaction(connection: DatabaseConnection): Promise<void>;
12
+ releaseConnection(): Promise<void>;
13
+ destroy(): Promise<void>;
14
+ }
@@ -0,0 +1,112 @@
1
+ import { CompiledQuery } from '../../query-compiler/compiled-query.js';
2
+ import { importFunction } from '../../util/dynamic-import.js';
3
+ import { isBoolean, isFunction, isNumber } from '../../util/object-utils.js';
4
+ export class SqliteDriver {
5
+ #config;
6
+ #connectionMutex = new ConnectionMutex();
7
+ #db;
8
+ #connection;
9
+ constructor(config) {
10
+ this.#config = config;
11
+ }
12
+ async init() {
13
+ // Import the `better-sqlite3` module here instead at the top of the file
14
+ // so that this file can be loaded by node without `better-sqlite3` driver
15
+ // installed. As you can see, there IS an import from `better-sqlite3` at
16
+ // the top level too, but that's only for types. It doesn't get compiled
17
+ // into javascript. You can check the built javascript code.
18
+ const DatabaseConstructor = await importBetterSqlite3Database();
19
+ const options = {};
20
+ if (isBoolean(this.#config.readonly)) {
21
+ options.readonly = this.#config.readonly;
22
+ }
23
+ if (isBoolean(this.#config.fileMustExist)) {
24
+ options.fileMustExist = this.#config.fileMustExist;
25
+ }
26
+ if (isNumber(this.#config.timeout)) {
27
+ options.timeout = this.#config.timeout;
28
+ }
29
+ if (isFunction(this.#config.verbose)) {
30
+ options.verbose = this.#config.verbose;
31
+ }
32
+ this.#db = new DatabaseConstructor(this.#config.databasePath, options);
33
+ this.#connection = new SqliteConnection(this.#db);
34
+ if (this.#config.onCreateConnection) {
35
+ await this.#config.onCreateConnection(this.#connection);
36
+ }
37
+ }
38
+ async acquireConnection() {
39
+ // SQLite only has one single connection. We use a mutex here to wait
40
+ // until the single connection has been released.
41
+ await this.#connectionMutex.lock();
42
+ return this.#connection;
43
+ }
44
+ async beginTransaction(connection) {
45
+ await connection.executeQuery(CompiledQuery.raw('begin'));
46
+ }
47
+ async commitTransaction(connection) {
48
+ await connection.executeQuery(CompiledQuery.raw('commit'));
49
+ }
50
+ async rollbackTransaction(connection) {
51
+ await connection.executeQuery(CompiledQuery.raw('rollback'));
52
+ }
53
+ async releaseConnection() {
54
+ this.#connectionMutex.unlock();
55
+ }
56
+ async destroy() {
57
+ this.#db?.close();
58
+ }
59
+ }
60
+ async function importBetterSqlite3Database() {
61
+ try {
62
+ return await importFunction('better-sqlite3');
63
+ }
64
+ catch (error) {
65
+ throw new Error('SQLite client not installed. Please run `npm install better-sqlite3`');
66
+ }
67
+ }
68
+ class SqliteConnection {
69
+ #db;
70
+ constructor(db) {
71
+ this.#db = db;
72
+ }
73
+ executeQuery(compiledQuery) {
74
+ const { sql, parameters } = compiledQuery;
75
+ const stmt = this.#db.prepare(sql);
76
+ if (stmt.reader) {
77
+ return Promise.resolve({
78
+ rows: stmt.all(parameters),
79
+ });
80
+ }
81
+ else {
82
+ const { changes, lastInsertRowid } = stmt.run(parameters);
83
+ return Promise.resolve({
84
+ numUpdatedOrDeletedRows: changes !== undefined && changes !== null
85
+ ? BigInt(changes)
86
+ : undefined,
87
+ insertId: lastInsertRowid !== undefined && lastInsertRowid !== null
88
+ ? BigInt(lastInsertRowid)
89
+ : undefined,
90
+ rows: [],
91
+ });
92
+ }
93
+ }
94
+ }
95
+ class ConnectionMutex {
96
+ #promise;
97
+ #resolve;
98
+ async lock() {
99
+ while (this.#promise) {
100
+ await this.#promise;
101
+ }
102
+ this.#promise = new Promise((resolve) => {
103
+ this.#resolve = resolve;
104
+ });
105
+ }
106
+ unlock() {
107
+ const resolve = this.#resolve;
108
+ this.#promise = undefined;
109
+ this.#resolve = undefined;
110
+ resolve?.();
111
+ }
112
+ }
@@ -0,0 +1,7 @@
1
+ import { DatabaseIntrospector, DatabaseMetadata, DatabaseMetadataOptions } from '../../introspection/database-introspector.js';
2
+ import { Kysely } from '../../kysely.js';
3
+ export declare class SqliteIntrospector implements DatabaseIntrospector {
4
+ #private;
5
+ constructor(db: Kysely<any>);
6
+ getMetadata(options?: DatabaseMetadataOptions): Promise<DatabaseMetadata>;
7
+ }
@@ -0,0 +1,40 @@
1
+ import { MIGRATION_LOCK_TABLE, MIGRATION_TABLE, } from '../../migration/migration.js';
2
+ export class SqliteIntrospector {
3
+ #db;
4
+ constructor(db) {
5
+ this.#db = db;
6
+ }
7
+ async getMetadata(options = { withInternalKyselyTables: false }) {
8
+ let query = this.#db
9
+ .selectFrom('sqlite_schema')
10
+ .where('type', '=', 'table')
11
+ .where('name', 'not like', 'sqlite_%')
12
+ .select('name')
13
+ .castTo();
14
+ if (!options.withInternalKyselyTables) {
15
+ query = query
16
+ .where('name', '!=', MIGRATION_TABLE)
17
+ .where('name', '!=', MIGRATION_LOCK_TABLE);
18
+ }
19
+ const tables = await query.execute();
20
+ return {
21
+ tables: await Promise.all(tables.map(({ name }) => this.#getTableMetadata(name))),
22
+ };
23
+ }
24
+ async #getTableMetadata(table) {
25
+ const db = this.#db;
26
+ const columns = await db
27
+ .selectFrom(db.raw(`PRAGMA_TABLE_INFO(?)`, [table]).as('table_info'))
28
+ .select(['name', 'type', 'notnull'])
29
+ .castTo()
30
+ .execute();
31
+ return {
32
+ name: table,
33
+ columns: columns.map((col) => ({
34
+ name: col.name,
35
+ dataType: col.type,
36
+ isNullable: !col.notnull,
37
+ })),
38
+ };
39
+ }
40
+ }
@@ -0,0 +1,7 @@
1
+ import { DefaultQueryCompiler } from '../../query-compiler/default-query-compiler.js';
2
+ export declare class SqliteQueryCompiler extends DefaultQueryCompiler {
3
+ protected visitReturning(): void;
4
+ protected getSql(): string;
5
+ protected getCurrentParameterPlaceholder(): string;
6
+ protected getAutoIncrement(): string;
7
+ }
@@ -0,0 +1,15 @@
1
+ import { DefaultQueryCompiler } from '../../query-compiler/default-query-compiler.js';
2
+ export class SqliteQueryCompiler extends DefaultQueryCompiler {
3
+ visitReturning() {
4
+ // Do nothing.
5
+ }
6
+ getSql() {
7
+ return super.getSql().trimEnd();
8
+ }
9
+ getCurrentParameterPlaceholder() {
10
+ return '?';
11
+ }
12
+ getAutoIncrement() {
13
+ return 'autoincrement';
14
+ }
15
+ }
@@ -12,12 +12,12 @@ export interface QueryResult<O> {
12
12
  * This is defined for update and delete queries and contains
13
13
  * the number of rows the query updated/deleted.
14
14
  */
15
- readonly numUpdatedOrDeletedRows?: number;
15
+ readonly numUpdatedOrDeletedRows?: bigint;
16
16
  /**
17
17
  * This is defined for insert queries on dialects that return
18
18
  * the auto incrementing primary key from an insert.
19
19
  */
20
- readonly insertedPrimaryKey?: number;
20
+ readonly insertId?: bigint;
21
21
  /**
22
22
  * The rows returned by the query. This is always defined and is
23
23
  * empty if the query returned no rows.
@@ -1,3 +1,4 @@
1
+ import { performanceNow } from '../util/performance-now.js';
1
2
  /**
2
3
  * A small wrapper around {@link Driver} that makes sure the driver is
3
4
  * initialized before it is used, only initialized and destroyed
@@ -71,7 +72,7 @@ class RuntimeConnection {
71
72
  this.#log = log;
72
73
  }
73
74
  async executeQuery(compiledQuery) {
74
- const startTime = process.hrtime.bigint();
75
+ const startTime = performanceNow();
75
76
  try {
76
77
  return await this.#connection.executeQuery(compiledQuery);
77
78
  }
@@ -97,8 +98,6 @@ class RuntimeConnection {
97
98
  }));
98
99
  }
99
100
  #calculateDurationMillis(startTime) {
100
- const endTime = process.hrtime.bigint();
101
- const durationNanos = Number(endTime - startTime);
102
- return durationNanos / 1_000_000;
101
+ return performanceNow() - startTime;
103
102
  }
104
103
  }
@@ -3,6 +3,9 @@ export * from './query-creator.js';
3
3
  export * from './query-builder/query-builder.js';
4
4
  export * from './query-builder/join-builder.js';
5
5
  export * from './query-builder/expression-builder.js';
6
+ export * from './query-builder/insert-result.js';
7
+ export * from './query-builder/delete-result.js';
8
+ export * from './query-builder/update-result.js';
6
9
  export * from './raw-builder/raw-builder.js';
7
10
  export * from './query-executor/query-executor.js';
8
11
  export * from './query-executor/default-query-executor.js';
@@ -37,41 +40,19 @@ export * from './dialect/mysql/mysql-query-compiler.js';
37
40
  export * from './dialect/mysql/mysql-driver.js';
38
41
  export * from './dialect/mysql/mysql-introspector.js';
39
42
  export * from './dialect/mysql/mysql-adapter.js';
43
+ export * from './dialect/sqlite/sqlite-dialect.js';
44
+ export * from './dialect/sqlite/sqlite-query-compiler.js';
45
+ export * from './dialect/sqlite/sqlite-driver.js';
46
+ export * from './dialect/sqlite/sqlite-introspector.js';
47
+ export * from './dialect/sqlite/sqlite-adapter.js';
40
48
  export * from './query-compiler/default-query-compiler.js';
41
49
  export * from './query-compiler/query-compiler.js';
42
50
  export * from './migration/migration.js';
43
51
  export * from './dialect/dialect.js';
44
52
  export * from './dialect/dialect-adapter.js';
45
53
  export * from './dialect/dialect-adapter-base.js';
46
- export * from './operation-node/operation-node-transformer.js';
47
- export * from './operation-node/operation-node-visitor.js';
48
54
  export * from './plugin/kysely-plugin.js';
49
55
  export * from './plugin/camel-case/camel-case-plugin.js';
50
- export * from './operation-node/operation-node-transformer.js';
51
- export * from './operation-node/operation-node-visitor.js';
52
- export * from './operation-node/operator-node.js';
53
- export * from './operation-node/or-node.js';
54
- export * from './operation-node/order-by-item-node.js';
55
- export * from './operation-node/order-by-node.js';
56
- export * from './operation-node/parens-node.js';
57
- export * from './operation-node/primary-constraint-node.js';
58
- export * from './operation-node/primitive-value-list-node.js';
59
- export * from './operation-node/query-node.js';
60
- export * from './operation-node/raw-node.js';
61
- export * from './operation-node/reference-node.js';
62
- export * from './operation-node/references-node.js';
63
- export * from './operation-node/rename-column-node.js';
64
- export * from './operation-node/returning-node.js';
65
- export * from './operation-node/select-all-node.js';
66
- export * from './operation-node/select-query-node.js';
67
- export * from './operation-node/selection-node.js';
68
- export * from './operation-node/table-node.js';
69
- export * from './operation-node/unique-constraint-node.js';
70
- export * from './operation-node/update-query-node.js';
71
- export * from './operation-node/value-list-node.js';
72
- export * from './operation-node/value-node.js';
73
- export * from './operation-node/where-node.js';
74
- export * from './operation-node/with-node.js';
75
56
  export * from './operation-node/add-column-node.js';
76
57
  export * from './operation-node/add-constraint-node.js';
77
58
  export * from './operation-node/alias-node.js';
@@ -87,16 +68,20 @@ export * from './operation-node/constraint-node.js';
87
68
  export * from './operation-node/create-index-node.js';
88
69
  export * from './operation-node/create-schema-node.js';
89
70
  export * from './operation-node/create-table-node.js';
71
+ export * from './operation-node/create-view-node.js';
90
72
  export * from './operation-node/data-type-node.js';
73
+ export * from './operation-node/default-value-node.js';
91
74
  export * from './operation-node/delete-query-node.js';
92
75
  export * from './operation-node/drop-column-node.js';
93
76
  export * from './operation-node/drop-constraint-node.js';
94
77
  export * from './operation-node/drop-index-node.js';
95
78
  export * from './operation-node/drop-schema-node.js';
96
79
  export * from './operation-node/drop-table-node.js';
80
+ export * from './operation-node/drop-view-node.js';
97
81
  export * from './operation-node/filter-node.js';
98
82
  export * from './operation-node/foreign-key-constraint-node.js';
99
83
  export * from './operation-node/from-node.js';
84
+ export * from './operation-node/generated-always-as-node.js';
100
85
  export * from './operation-node/group-by-item-node.js';
101
86
  export * from './operation-node/group-by-node.js';
102
87
  export * from './operation-node/having-node.js';
@@ -105,11 +90,41 @@ export * from './operation-node/insert-query-node.js';
105
90
  export * from './operation-node/join-node.js';
106
91
  export * from './operation-node/limit-node.js';
107
92
  export * from './operation-node/list-node.js';
93
+ export * from './operation-node/modify-column-node.js';
108
94
  export * from './operation-node/offset-node.js';
109
- export * from './operation-node//on-conflict-node.js';
110
- export * from './operation-node/operation-node.js';
95
+ export * from './operation-node/on-conflict-node.js';
96
+ export * from './operation-node/on-duplicate-key-node.js';
97
+ export * from './operation-node/on-node.js';
111
98
  export * from './operation-node/operation-node-source.js';
99
+ export * from './operation-node/operation-node-transformer.js';
100
+ export * from './operation-node/operation-node-utils.js';
101
+ export * from './operation-node/operation-node-visitor.js';
102
+ export * from './operation-node/operation-node.js';
103
+ export * from './operation-node/operator-node.js';
104
+ export * from './operation-node/or-node.js';
105
+ export * from './operation-node/order-by-item-node.js';
112
106
  export * from './operation-node/order-by-node.js';
107
+ export * from './operation-node/parens-node.js';
108
+ export * from './operation-node/primary-constraint-node.js';
109
+ export * from './operation-node/primitive-value-list-node.js';
110
+ export * from './operation-node/query-node.js';
111
+ export * from './operation-node/raw-node.js';
112
+ export * from './operation-node/reference-node.js';
113
+ export * from './operation-node/references-node.js';
114
+ export * from './operation-node/rename-column-node.js';
115
+ export * from './operation-node/returning-node.js';
116
+ export * from './operation-node/select-all-node.js';
117
+ export * from './operation-node/select-query-node.js';
118
+ export * from './operation-node/select-query-node.js';
119
+ export * from './operation-node/selection-node.js';
120
+ export * from './operation-node/table-node.js';
121
+ export * from './operation-node/union-node.js';
122
+ export * from './operation-node/unique-constraint-node.js';
123
+ export * from './operation-node/update-query-node.js';
124
+ export * from './operation-node/value-list-node.js';
125
+ export * from './operation-node/value-node.js';
126
+ export * from './operation-node/where-node.js';
127
+ export * from './operation-node/with-node.js';
113
128
  export * from './introspection/database-introspector.js';
114
129
  export * from './util/compilable.js';
115
130
  export { AnyColumn, UnknownRow, AnyQueryBuilder } from './util/type-utils.js';
@@ -117,7 +132,7 @@ export { SelectExpression, SelectExpressionOrList, } from './parser/select-parse
117
132
  export { ReferenceExpression, ReferenceExpressionOrList, } from './parser/reference-parser.js';
118
133
  export { ValueExpression, ValueExpressionOrList, } from './parser/value-parser.js';
119
134
  export { ExistsExpression, FilterOperator } from './parser/filter-parser.js';
120
- export { TableExpression } from './parser/table-parser.js';
135
+ export { TableExpression, TableExpressionOrList, } from './parser/table-parser.js';
121
136
  export { JoinReferenceExpression, JoinCallbackExpression, } from './parser/join-parser.js';
122
137
  export { InsertObject } from './parser/insert-values-parser.js';
123
138
  export { MutationObject } from './parser/update-set-parser.js';