@devbro/neko-sql 0.1.37 → 0.1.38

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 (97) hide show
  1. package/dist/cjs/index.d.ts +610 -0
  2. package/dist/cjs/index.js.map +1 -0
  3. package/dist/esm/Blueprint.mjs.map +1 -0
  4. package/dist/esm/Connection.mjs.map +1 -0
  5. package/dist/esm/Expression.mjs.map +1 -0
  6. package/dist/esm/Migration.mjs.map +1 -0
  7. package/dist/esm/Query.mjs.map +1 -0
  8. package/dist/esm/QueryGrammar.mjs.map +1 -0
  9. package/dist/esm/Schema.mjs.map +1 -0
  10. package/dist/esm/SchemaGrammar.mjs.map +1 -0
  11. package/dist/esm/databases/index.mjs.map +1 -0
  12. package/dist/esm/databases/mysql/MysqlConnection.mjs.map +1 -0
  13. package/dist/esm/databases/mysql/MysqlQueryGrammar.mjs.map +1 -0
  14. package/dist/esm/databases/mysql/MysqlSchemaGrammar.mjs.map +1 -0
  15. package/dist/esm/databases/mysql/index.mjs.map +1 -0
  16. package/dist/esm/databases/postgresql/PostgresqlConnection.mjs.map +1 -0
  17. package/dist/esm/databases/postgresql/PostgresqlQueryGrammar.mjs.map +1 -0
  18. package/dist/esm/databases/postgresql/PostgresqlSchemaGrammar.mjs.map +1 -0
  19. package/dist/esm/databases/postgresql/index.mjs.map +1 -0
  20. package/dist/esm/databases/sqlite/SqliteConnection.mjs.map +1 -0
  21. package/dist/esm/databases/sqlite/SqliteQueryGrammar.mjs.map +1 -0
  22. package/dist/esm/databases/sqlite/SqliteSchemaGrammar.mjs.map +1 -0
  23. package/dist/esm/databases/sqlite/index.mjs.map +1 -0
  24. package/dist/esm/index.mjs.map +1 -0
  25. package/package.json +7 -7
  26. package/dist/Blueprint.mjs.map +0 -1
  27. package/dist/Connection.mjs.map +0 -1
  28. package/dist/Expression.mjs.map +0 -1
  29. package/dist/Migration.mjs.map +0 -1
  30. package/dist/Query.mjs.map +0 -1
  31. package/dist/QueryGrammar.mjs.map +0 -1
  32. package/dist/Schema.mjs.map +0 -1
  33. package/dist/SchemaGrammar.mjs.map +0 -1
  34. package/dist/databases/index.mjs.map +0 -1
  35. package/dist/databases/mysql/MysqlConnection.mjs.map +0 -1
  36. package/dist/databases/mysql/MysqlQueryGrammar.mjs.map +0 -1
  37. package/dist/databases/mysql/MysqlSchemaGrammar.mjs.map +0 -1
  38. package/dist/databases/mysql/index.mjs.map +0 -1
  39. package/dist/databases/postgresql/PostgresqlConnection.mjs.map +0 -1
  40. package/dist/databases/postgresql/PostgresqlQueryGrammar.mjs.map +0 -1
  41. package/dist/databases/postgresql/PostgresqlSchemaGrammar.mjs.map +0 -1
  42. package/dist/databases/postgresql/index.mjs.map +0 -1
  43. package/dist/databases/sqlite/SqliteConnection.mjs.map +0 -1
  44. package/dist/databases/sqlite/SqliteQueryGrammar.mjs.map +0 -1
  45. package/dist/databases/sqlite/SqliteSchemaGrammar.mjs.map +0 -1
  46. package/dist/databases/sqlite/index.mjs.map +0 -1
  47. package/dist/index.js.map +0 -1
  48. package/dist/index.mjs.map +0 -1
  49. /package/dist/{index.js → cjs/index.js} +0 -0
  50. /package/dist/{Blueprint-DjP_Sfrr.d.mts → esm/Blueprint-DjP_Sfrr.d.mts} +0 -0
  51. /package/dist/{Blueprint.d.mts → esm/Blueprint.d.mts} +0 -0
  52. /package/dist/{Blueprint.mjs → esm/Blueprint.mjs} +0 -0
  53. /package/dist/{Connection.d.mts → esm/Connection.d.mts} +0 -0
  54. /package/dist/{Connection.mjs → esm/Connection.mjs} +0 -0
  55. /package/dist/{Expression.d.mts → esm/Expression.d.mts} +0 -0
  56. /package/dist/{Expression.mjs → esm/Expression.mjs} +0 -0
  57. /package/dist/{Migration.d.mts → esm/Migration.d.mts} +0 -0
  58. /package/dist/{Migration.mjs → esm/Migration.mjs} +0 -0
  59. /package/dist/{Query.d.mts → esm/Query.d.mts} +0 -0
  60. /package/dist/{Query.mjs → esm/Query.mjs} +0 -0
  61. /package/dist/{QueryGrammar.d.mts → esm/QueryGrammar.d.mts} +0 -0
  62. /package/dist/{QueryGrammar.mjs → esm/QueryGrammar.mjs} +0 -0
  63. /package/dist/{Schema.d.mts → esm/Schema.d.mts} +0 -0
  64. /package/dist/{Schema.mjs → esm/Schema.mjs} +0 -0
  65. /package/dist/{SchemaGrammar.d.mts → esm/SchemaGrammar.d.mts} +0 -0
  66. /package/dist/{SchemaGrammar.mjs → esm/SchemaGrammar.mjs} +0 -0
  67. /package/dist/{databases → esm/databases}/index.d.mts +0 -0
  68. /package/dist/{databases → esm/databases}/index.mjs +0 -0
  69. /package/dist/{databases → esm/databases}/mysql/MysqlConnection.d.mts +0 -0
  70. /package/dist/{databases → esm/databases}/mysql/MysqlConnection.mjs +0 -0
  71. /package/dist/{databases → esm/databases}/mysql/MysqlQueryGrammar.d.mts +0 -0
  72. /package/dist/{databases → esm/databases}/mysql/MysqlQueryGrammar.mjs +0 -0
  73. /package/dist/{databases → esm/databases}/mysql/MysqlSchemaGrammar.d.mts +0 -0
  74. /package/dist/{databases → esm/databases}/mysql/MysqlSchemaGrammar.mjs +0 -0
  75. /package/dist/{databases → esm/databases}/mysql/index.d.mts +0 -0
  76. /package/dist/{databases → esm/databases}/mysql/index.mjs +0 -0
  77. /package/dist/{databases → esm/databases}/postgresql/PostgresqlConnection.d.mts +0 -0
  78. /package/dist/{databases → esm/databases}/postgresql/PostgresqlConnection.mjs +0 -0
  79. /package/dist/{databases → esm/databases}/postgresql/PostgresqlQueryGrammar.d.mts +0 -0
  80. /package/dist/{databases → esm/databases}/postgresql/PostgresqlQueryGrammar.mjs +0 -0
  81. /package/dist/{databases → esm/databases}/postgresql/PostgresqlSchemaGrammar.d.mts +0 -0
  82. /package/dist/{databases → esm/databases}/postgresql/PostgresqlSchemaGrammar.mjs +0 -0
  83. /package/dist/{databases → esm/databases}/postgresql/index.d.mts +0 -0
  84. /package/dist/{databases → esm/databases}/postgresql/index.mjs +0 -0
  85. /package/dist/{databases → esm/databases}/sqlite/SqliteConnection.d.mts +0 -0
  86. /package/dist/{databases → esm/databases}/sqlite/SqliteConnection.mjs +0 -0
  87. /package/dist/{databases → esm/databases}/sqlite/SqliteQueryGrammar.d.mts +0 -0
  88. /package/dist/{databases → esm/databases}/sqlite/SqliteQueryGrammar.mjs +0 -0
  89. /package/dist/{databases → esm/databases}/sqlite/SqliteSchemaGrammar.d.mts +0 -0
  90. /package/dist/{databases → esm/databases}/sqlite/SqliteSchemaGrammar.mjs +0 -0
  91. /package/dist/{databases → esm/databases}/sqlite/index.d.mts +0 -0
  92. /package/dist/{databases → esm/databases}/sqlite/index.mjs +0 -0
  93. /package/dist/{index.d.mts → esm/index.d.mts} +0 -0
  94. /package/dist/{index.mjs → esm/index.mjs} +0 -0
  95. /package/dist/{types.d.mts → esm/types.d.mts} +0 -0
  96. /package/dist/{types.mjs → esm/types.mjs} +0 -0
  97. /package/dist/{types.mjs.map → esm/types.mjs.map} +0 -0
@@ -0,0 +1,610 @@
1
+ import { EventEmittor } from '@devbro/neko-helper';
2
+ import { PoolClient, Pool, PoolConfig } from 'pg';
3
+ import Database from 'better-sqlite3';
4
+ import mysql from 'mysql2/promise';
5
+
6
+ declare class Expression {
7
+ private sql;
8
+ private bindings;
9
+ constructor(sql?: string, bindings?: never[]);
10
+ toCompiledSql(): CompiledSql;
11
+ }
12
+
13
+ declare abstract class QueryGrammar {
14
+ sqlParts: string[];
15
+ toSql(query: Query): CompiledSql;
16
+ toSqlParts(query: Query): CompiledSql;
17
+ compileCount(query: Query): CompiledSql;
18
+ compileSelect(selects: selectType[]): CompiledSql;
19
+ joinArray(arr: (string | number)[]): string;
20
+ compileTable(tableName: string): CompiledSql;
21
+ compileJoin(joins: joinType[]): CompiledSql;
22
+ compileWhere(wheres: whereType[]): CompiledSql;
23
+ compileWhereNested(w: whereNested): CompiledSql;
24
+ compileWhereOperation(w: whereOp): CompiledSql;
25
+ compileWhereOperationColumn(w: whereOpColumn): CompiledSql;
26
+ compileWhereRaw(w: whereRaw): CompiledSql;
27
+ compileOrderBy(orderBy: string[]): CompiledSql;
28
+ compileLimit(limit: number | null): CompiledSql;
29
+ compileOffset(offset: number | null): CompiledSql;
30
+ compileWhereNull(w: whereNull): CompiledSql;
31
+ compileInsert(query: Query, data: Record<string, Parameter> | Record<string, Parameter>[]): CompiledSql;
32
+ abstract compileInsertGetId(query: Query, data: Record<string, Parameter> | Record<string, Parameter>[], options: {
33
+ primaryKey: string[];
34
+ }): CompiledSql;
35
+ compileUpdate(query: Query, data: Record<string, Parameter>): CompiledSql;
36
+ compileDelete(query: Query): CompiledSql;
37
+ compileUpsert(query: Query, data: Record<string, Parameter>, conflictFields: string[], updateFields: string[]): CompiledSql;
38
+ compileGroupBy(groupBy: string[]): CompiledSql;
39
+ compileHaving(having: havingType[]): CompiledSql;
40
+ compileHavingOperation(w: whereOp): CompiledSql;
41
+ compileHavingRaw(w: whereRaw): CompiledSql;
42
+ /**
43
+ * post process result from database
44
+ * @param result result from database
45
+ * @returns post processed result
46
+ */
47
+ postProcessGetInsertId(result: any): any;
48
+ }
49
+
50
+ type QueryParts = {
51
+ select: selectType[];
52
+ table: string;
53
+ join: joinType[];
54
+ where: whereType[];
55
+ groupBy: string[];
56
+ having: havingType[];
57
+ orderBy: string[];
58
+ limit: number | null;
59
+ offset: number | null;
60
+ alias: string | null;
61
+ };
62
+ declare class Query {
63
+ readonly connection: Connection | null;
64
+ readonly grammar: QueryGrammar;
65
+ allowedOperations: string[];
66
+ parts: QueryParts;
67
+ constructor(connection: Connection | null, grammar: QueryGrammar);
68
+ table(tableName: string): this;
69
+ whereNested(func: (q: Query) => void, joinCondition?: JoinCondition, negateCondition?: boolean): this;
70
+ whereOp(column: string, operation: (typeof this.allowedOperations)[number], value: Parameter, joinCondition?: JoinCondition, negateCondition?: boolean): this;
71
+ whereRaw(sql: string, bindings: Parameter[], joinCondition?: JoinCondition, negateCondition?: boolean): this;
72
+ whereColumn(column1: string, operation: (typeof this.allowedOperations)[number], column2: string, joinCondition?: JoinCondition, negateCondition?: boolean): this;
73
+ whereNull(column: string, joinCondition?: JoinCondition, negateCondition?: boolean): this;
74
+ clearWhere(): this;
75
+ select(selects: selectType[]): this;
76
+ groupBy(columns: string[]): this;
77
+ havingOp(column: string, operation: (typeof this.allowedOperations)[number], value: Parameter, joinCondition?: JoinCondition, negateCondition?: boolean): this;
78
+ havingRaw(sql: string, bindings: Parameter[], joinCondition?: JoinCondition, negateCondition?: boolean): this;
79
+ orderBy(column: string, direction?: 'asc' | 'desc'): this;
80
+ limit(limit: number): this;
81
+ offset(offset: number): this;
82
+ toSql(): CompiledSql;
83
+ get(): Promise<any>;
84
+ first(): Promise<any>;
85
+ count(): Promise<number>;
86
+ getCursor(): Promise<any>;
87
+ getConnection(): Connection | null;
88
+ insert(data: Record<string, Parameter> | Record<string, Parameter>[]): Promise<any>;
89
+ insertGetId(data: Record<string, Parameter> | Record<string, Parameter>[], options?: {
90
+ primaryKey: string[];
91
+ }): Promise<any>;
92
+ update(data: Record<string, Parameter>): Promise<any>;
93
+ upsert(data: Record<string, Parameter>, uniqueColumns: string[], updateColumns: string[]): Promise<any>;
94
+ delete(): Promise<any>;
95
+ join(table: string | Query, type: joinType['type'], conditions: (whereType | {
96
+ column1: string;
97
+ column2: string;
98
+ })[]): this;
99
+ innerJoin(table: Parameters<typeof this.join>[0], conditions: (whereType | {
100
+ column1: string;
101
+ column2: string;
102
+ })[]): this;
103
+ leftJoin(table: Parameters<typeof this.join>[0], conditions: (whereType | {
104
+ column1: string;
105
+ column2: string;
106
+ })[]): this;
107
+ rightJoin(table: Parameters<typeof this.join>[0], conditions: (whereType | {
108
+ column1: string;
109
+ column2: string;
110
+ })[]): this;
111
+ fullJoin(table: Parameters<typeof this.join>[0], conditions: (whereType | {
112
+ column1: string;
113
+ column2: string;
114
+ })[]): this;
115
+ crossJoin(table: Parameters<typeof this.join>[0], conditions: (whereType | {
116
+ column1: string;
117
+ column2: string;
118
+ })[]): this;
119
+ alias(alias: string): this;
120
+ }
121
+
122
+ type selectType = string;
123
+ type whereBasic = {
124
+ joinCondition: JoinCondition;
125
+ negateCondition: boolean;
126
+ };
127
+ type whereOp = {
128
+ type: 'operation';
129
+ column: string;
130
+ operation: string;
131
+ value: Parameter;
132
+ };
133
+ type whereOpColumn = {
134
+ type: 'operationColumn';
135
+ column1: string;
136
+ operation: string;
137
+ column2: string;
138
+ };
139
+ type whereNested = {
140
+ type: 'nested';
141
+ query: Query;
142
+ };
143
+ type whereRaw = {
144
+ type: 'raw';
145
+ sql: string;
146
+ bindings: Parameter[];
147
+ };
148
+ type whereNull = {
149
+ type: 'null';
150
+ column: string;
151
+ };
152
+ type whereType = whereBasic & (whereOp | whereOpColumn | whereNested | whereNull | whereRaw);
153
+ type Parameter = string | number | Date | boolean | null | Expression | undefined | number[] | string[];
154
+ type JoinCondition = 'and' | 'or';
155
+ type CompiledSql = {
156
+ sql: string;
157
+ parts: (string | number)[];
158
+ bindings: Parameter[];
159
+ };
160
+ type havingType = whereBasic & (whereOp | whereRaw);
161
+ type joinType = {
162
+ type: 'inner' | 'left' | 'right' | 'full' | 'cross';
163
+ table: string | Query;
164
+ conditions: whereType[];
165
+ };
166
+
167
+ type ColumnPropertiesType = {
168
+ type: 'string' | 'integer' | 'float' | 'double' | 'boolean' | 'char' | 'text' | 'date' | 'timestamp' | 'timestampz' | 'serial' | 'json' | 'jsonb' | 'raw';
169
+ length: number;
170
+ nullable: boolean;
171
+ unique: boolean;
172
+ default: Parameter;
173
+ };
174
+ declare class Column {
175
+ columnName: string;
176
+ properties: ColumnPropertiesType;
177
+ constructor(columnName: string, type: ColumnPropertiesType['type']);
178
+ length(length: number): this;
179
+ nullable(nullable?: boolean): this;
180
+ unique(unique?: boolean): this;
181
+ default(value: ColumnPropertiesType['default']): this;
182
+ }
183
+ declare class IndexConstraint {
184
+ columns: string[];
185
+ indexName: string | undefined;
186
+ unique: boolean;
187
+ _type: 'gin' | 'btree' | 'hash' | 'gist' | 'spgist' | 'brin' | undefined;
188
+ constructor(columns: string | string[]);
189
+ name(indexName: string): this;
190
+ setUnique(unique?: boolean): this;
191
+ type(type: typeof this._type): this;
192
+ }
193
+ declare class ForeignKeyConstraint {
194
+ column: string;
195
+ reference_table: {
196
+ table: string;
197
+ column: string;
198
+ };
199
+ onUpdateAction: 'cascade' | 'set null' | 'restrict' | 'no action';
200
+ onDeleteAction: 'cascade' | 'set null' | 'restrict' | 'no action';
201
+ constructor(column: string);
202
+ on(table: string): this;
203
+ references(column: string): this;
204
+ onDelete(action: typeof this.onDeleteAction): this;
205
+ onUpdate(action: typeof this.onUpdateAction): this;
206
+ }
207
+ declare class Blueprint {
208
+ tableName: string;
209
+ columns: Column[];
210
+ drop_coumns: string[];
211
+ foreignKeys: ForeignKeyConstraint[];
212
+ indexes: IndexConstraint[];
213
+ existingTable: boolean;
214
+ primaryKeys: string[];
215
+ constructor();
216
+ setTableName(tableName: string, existingTable?: boolean): void;
217
+ boolean(columnName: string): Column;
218
+ char(columnName: string): Column;
219
+ string(columnName: string, length?: number): Column;
220
+ raw(sql: string): Column;
221
+ text(columnName: string): Column;
222
+ json(columnName: string): Column;
223
+ jsonb(columnName: string): Column;
224
+ integer(columnName: string): Column;
225
+ float(columnName: string): Column;
226
+ double(columnName: string): Column;
227
+ id(): Column;
228
+ timestamps(): void;
229
+ date(columnName: string): Column;
230
+ timestamp(columnName: string): Column;
231
+ timestampTz(columnName: string): Column;
232
+ datetime(columnName: string): Column;
233
+ datetimeTz(columnName: string): Column;
234
+ primary(keys: string[]): void;
235
+ foreign(columnName: string): ForeignKeyConstraint;
236
+ dropColumn(columnName: string): void;
237
+ index(columns: string | string[], indexName?: string): IndexConstraint;
238
+ unique(columns: string | string[], indexName?: string): IndexConstraint;
239
+ }
240
+
241
+ declare class SchemaGrammar {
242
+ toSql(blueprint: Blueprint): string;
243
+ compileCreateTable(blueprint: Blueprint): CompiledSql;
244
+ compileAlterTable(blueprint: Blueprint): CompiledSql;
245
+ compileColumn(column: Column): string;
246
+ escape(value: Parameter): string;
247
+ compilePrimaryKeys(primaryKeys: string[]): string;
248
+ compileTables(schema?: string | string[] | undefined): CompiledSql;
249
+ compileTableExists(tableName: string, schema?: string): CompiledSql;
250
+ compileDropTable(tableName: string): CompiledSql;
251
+ compileDropTableIfExists(tableName: string): CompiledSql;
252
+ protected compileSchemaWhereClause(schema: string | string[] | undefined, column: string): string;
253
+ protected quoteString(value: string | string[]): string;
254
+ protected doubleQuoteString(value: string | string[]): string;
255
+ protected compileForeignKey(foreignKey: ForeignKeyConstraint): string;
256
+ protected compileIndex(tableName: string, index: IndexConstraint): CompiledSql;
257
+ }
258
+
259
+ /**
260
+ * Schema builder for creating and managing database tables.
261
+ * Provides methods for table creation, alteration, and inspection.
262
+ */
263
+ declare class Schema {
264
+ private readonly connection;
265
+ private readonly grammar;
266
+ /**
267
+ * Creates a new Schema instance.
268
+ *
269
+ * @param connection - The database connection to use for schema operations
270
+ * @param grammar - The schema grammar for generating SQL statements
271
+ */
272
+ constructor(connection: Connection | null, grammar: SchemaGrammar);
273
+ /**
274
+ * Creates a new table in the database.
275
+ *
276
+ * @param tableName - The name of the table to create
277
+ * @param structMethod - A callback function that receives a Blueprint to define table structure
278
+ *
279
+ * @example
280
+ * await schema.createTable('users', (table) => {
281
+ * table.increments('id');
282
+ * table.string('name');
283
+ * table.string('email').unique();
284
+ * table.timestamps();
285
+ * });
286
+ */
287
+ createTable(tableName: string, structMethod: (blueprint: Blueprint) => void): Promise<void>;
288
+ /**
289
+ * Modifies an existing table structure.
290
+ *
291
+ * @param tableName - The name of the table to alter
292
+ * @param structMethod - A callback function that receives a Blueprint to define modifications
293
+ *
294
+ * @example
295
+ * await schema.alterTable('users', (table) => {
296
+ * table.string('phone').nullable();
297
+ * table.dropColumn('old_field');
298
+ * });
299
+ */
300
+ alterTable(tableName: string, structMethod: (blueprint: Blueprint) => void): Promise<void>;
301
+ /**
302
+ * Drops (deletes) a table from the database.
303
+ *
304
+ * @param tableName - The name of the table to drop
305
+ *
306
+ * @example
307
+ * await schema.dropTable('old_users');
308
+ */
309
+ dropTable(tableName: string): Promise<void>;
310
+ /**
311
+ * Drops a table from the database if it exists.
312
+ * Safe to call even if the table doesn't exist.
313
+ *
314
+ * @param tableName - The name of the table to drop
315
+ *
316
+ * @example
317
+ * await schema.dropTableIfExists('temp_table');
318
+ */
319
+ dropTableIfExists(tableName: string): Promise<void>;
320
+ /**
321
+ * Retrieves a list of all tables in the database.
322
+ *
323
+ * @returns A promise that resolves to an array of table information
324
+ *
325
+ * @example
326
+ * const allTables = await schema.tables();
327
+ * console.log(allTables);
328
+ */
329
+ tables(): Promise<any>;
330
+ /**
331
+ * Checks if a table exists in the database.
332
+ *
333
+ * @param table_name - The name of the table to check
334
+ * @returns A promise that resolves to true if the table exists, false otherwise
335
+ *
336
+ * @example
337
+ * if (await schema.tableExists('users')) {
338
+ * console.log('Users table exists');
339
+ * }
340
+ */
341
+ tableExists(table_name: string): Promise<boolean>;
342
+ }
343
+
344
+ type connection_events = 'connect' | 'disconnect' | 'query' | 'error';
345
+ declare abstract class Connection implements EventEmittor<connection_events[]> {
346
+ abstract on(event: connection_events, listener: (...args: any[]) => void): this;
347
+ abstract off(event: connection_events, listener: (...args: any[]) => void): this;
348
+ abstract emit(event: connection_events, ...args: any[]): Promise<boolean>;
349
+ abstract isConnected(): boolean;
350
+ abstract connect(): Promise<boolean>;
351
+ abstract runQuery(sql: CompiledSql | string): Promise<any>;
352
+ abstract runCursor(sql: CompiledSql): Promise<any>;
353
+ abstract disconnect(): Promise<boolean>;
354
+ abstract getQuery(): Query;
355
+ abstract getSchema(): Schema;
356
+ abstract beginTransaction(): Promise<void>;
357
+ abstract commit(): Promise<void>;
358
+ abstract rollback(): Promise<void>;
359
+ abstract getQueryGrammar(): QueryGrammar;
360
+ abstract getSchemaGrammar(): SchemaGrammar;
361
+ abstract createDatabase(name: string): Promise<void>;
362
+ abstract dropDatabase(name: string): Promise<void>;
363
+ abstract listDatabases(): Promise<string[]>;
364
+ abstract existsDatabase(name: string): Promise<boolean>;
365
+ }
366
+
367
+ declare class PostgresqlQueryGrammar extends QueryGrammar {
368
+ constructor();
369
+ toSql(query: Query): CompiledSql;
370
+ compileInsert(query: Query, data: Record<string, any> | Record<string, any>[]): CompiledSql;
371
+ compileInsertGetId(query: Query, data: Record<string, any> | Record<string, any>[], options?: {
372
+ primaryKey: string[];
373
+ }): CompiledSql;
374
+ compileUpdate(query: Query, data: Record<string, any>): CompiledSql;
375
+ compileDelete(query: Query): CompiledSql;
376
+ compileUpsert(query: Query, data: Record<string, Parameter>, conflictFields: string[], updateFields: string[]): CompiledSql;
377
+ compileCount(query: Query): CompiledSql;
378
+ }
379
+
380
+ declare class PostgresqlSchemaGrammar extends SchemaGrammar {
381
+ }
382
+
383
+ declare class PostgresqlConnection extends Connection {
384
+ private eventManager;
385
+ on(event: connection_events, listener: (...args: any[]) => void): this;
386
+ off(event: connection_events, listener: (...args: any[]) => void): this;
387
+ emit(event: connection_events, ...args: any[]): Promise<boolean>;
388
+ connection: PoolClient | undefined;
389
+ static pool: Pool;
390
+ static defaults: PoolConfig;
391
+ constructor(params: PoolConfig);
392
+ connect(): Promise<boolean>;
393
+ runQuery(sql: CompiledSql | string): Promise<any>;
394
+ runCursor(sql: CompiledSql): Promise<any>;
395
+ disconnect(): Promise<boolean>;
396
+ getQuery(): Query;
397
+ getSchema(): Schema;
398
+ getQueryGrammar(): PostgresqlQueryGrammar;
399
+ getSchemaGrammar(): PostgresqlSchemaGrammar;
400
+ beginTransaction(): Promise<void>;
401
+ commit(): Promise<void>;
402
+ rollback(): Promise<void>;
403
+ static destroy(): Promise<void>;
404
+ isConnected(): boolean;
405
+ /**
406
+ * Validates and escapes a PostgreSQL identifier (database name, table name, etc.)
407
+ * Uses a whitelist approach to ensure only safe characters are allowed
408
+ */
409
+ private validateAndEscapeIdentifier;
410
+ createDatabase(name: string): Promise<void>;
411
+ dropDatabase(name: string): Promise<void>;
412
+ listDatabases(): Promise<string[]>;
413
+ existsDatabase(name: string): Promise<boolean>;
414
+ }
415
+
416
+ declare class SqliteQueryGrammar extends QueryGrammar {
417
+ constructor();
418
+ toSql(query: Query): CompiledSql;
419
+ compileInsert(query: Query, data: Record<string, any> | Record<string, any>[]): CompiledSql;
420
+ compileInsertGetId(query: Query, data: Record<string, any> | Record<string, any>[], options?: {
421
+ primaryKey: string[];
422
+ }): CompiledSql;
423
+ compileUpdate(query: Query, data: Record<string, any>): CompiledSql;
424
+ compileDelete(query: Query): CompiledSql;
425
+ compileUpsert(query: Query, data: Record<string, Parameter>, conflictFields: string[], updateFields: string[]): CompiledSql;
426
+ compileCount(query: Query): CompiledSql;
427
+ }
428
+
429
+ declare class SqliteSchemaGrammar extends SchemaGrammar {
430
+ compileColumn(column: Column): string;
431
+ }
432
+
433
+ /**
434
+ * Configuration options for SQLite database connection
435
+ */
436
+ interface SqliteConfig {
437
+ /** Path to the SQLite database file */
438
+ filename: string;
439
+ /** Open the database in read-only mode (default: false) */
440
+ readonly?: boolean;
441
+ /** Throw an error if the database file doesn't exist (default: false) */
442
+ fileMustExist?: boolean;
443
+ /** Timeout in milliseconds for database operations (default: 5000) */
444
+ timeout?: number;
445
+ /** Optional verbose logging function for debugging SQL statements */
446
+ verbose?: (message?: unknown, ...additionalArgs: unknown[]) => void;
447
+ }
448
+ /**
449
+ * SQLite database connection implementation
450
+ *
451
+ * Provides a connection to SQLite databases using better-sqlite3.
452
+ * Supports transactions, queries, schema operations, and database management.
453
+ */
454
+ declare class SqliteConnection extends Connection {
455
+ private eventManager;
456
+ on(event: connection_events, listener: (...args: any[]) => void): this;
457
+ off(event: connection_events, listener: (...args: any[]) => void): this;
458
+ emit(event: connection_events, ...args: any[]): Promise<boolean>;
459
+ connection: Database.Database | undefined;
460
+ private config;
461
+ /** Default configuration values for SQLite connections */
462
+ static defaults: Partial<SqliteConfig>;
463
+ constructor(params: SqliteConfig);
464
+ /**
465
+ * Establishes a connection to the SQLite database
466
+ * Creates or opens the database file specified in the configuration
467
+ */
468
+ connect(): Promise<boolean>;
469
+ /**
470
+ * Executes a SQL query against the database
471
+ * Automatically detects SELECT queries and queries with RETURNING clauses
472
+ *
473
+ * @param sql - Compiled SQL or raw SQL string to execute
474
+ * @returns Query results (rows for SELECT, run info for INSERT/UPDATE/DELETE)
475
+ */
476
+ runQuery(sql: CompiledSql | string): Promise<any>;
477
+ /**
478
+ * Executes a query and returns an iterator for streaming results
479
+ * Useful for large result sets to avoid loading all rows into memory
480
+ *
481
+ * @param sql - Compiled SQL to execute
482
+ * @returns Iterator over query results
483
+ */
484
+ runCursor(sql: CompiledSql): Promise<any>;
485
+ /**
486
+ * Closes the database connection
487
+ */
488
+ disconnect(): Promise<boolean>;
489
+ /**
490
+ * Creates a new query builder instance for this connection
491
+ */
492
+ getQuery(): Query;
493
+ /**
494
+ * Creates a new schema builder instance for this connection
495
+ */
496
+ getSchema(): Schema;
497
+ /**
498
+ * Gets the query grammar for building SQL statements
499
+ */
500
+ getQueryGrammar(): SqliteQueryGrammar;
501
+ /**
502
+ * Gets the schema grammar for building DDL statements
503
+ */
504
+ getSchemaGrammar(): SqliteSchemaGrammar;
505
+ /**
506
+ * Starts a new database transaction
507
+ */
508
+ beginTransaction(): Promise<void>;
509
+ /**
510
+ * Commits the current transaction
511
+ */
512
+ commit(): Promise<void>;
513
+ /**
514
+ * Rolls back the current transaction
515
+ */
516
+ rollback(): Promise<void>;
517
+ /**
518
+ * Checks if the database connection is active
519
+ */
520
+ isConnected(): boolean;
521
+ /**
522
+ * Validates and escapes a SQLite identifier (database name, table name, etc.)
523
+ * Uses a whitelist approach to ensure only safe characters are allowed
524
+ *
525
+ * @param name - The identifier to validate and escape
526
+ * @returns The escaped identifier, quoted if it's a reserved keyword
527
+ * @throws Error if the identifier contains invalid characters
528
+ */
529
+ private validateAndEscapeIdentifier;
530
+ /**
531
+ * Creates a new SQLite database file
532
+ *
533
+ * @param name - Name or path of the database file to create
534
+ */
535
+ createDatabase(name: string): Promise<void>;
536
+ /**
537
+ * Deletes a SQLite database file
538
+ *
539
+ * @param name - Name or path of the database file to delete
540
+ */
541
+ dropDatabase(name: string): Promise<void>;
542
+ /**
543
+ * Lists available databases
544
+ * For SQLite, this returns the current database filename
545
+ *
546
+ * @returns Array containing the current database filename
547
+ */
548
+ listDatabases(): Promise<string[]>;
549
+ /**
550
+ * Checks if a database file exists
551
+ *
552
+ * @param name - Name or path of the database file to check
553
+ * @returns True if the database file exists, false otherwise
554
+ */
555
+ existsDatabase(name: string): Promise<boolean>;
556
+ }
557
+
558
+ declare class MysqlQueryGrammar extends QueryGrammar {
559
+ compileInsertGetId(query: Query, data: Record<string, any> | Record<string, any>[], options?: {
560
+ primaryKey: string[];
561
+ }): CompiledSql;
562
+ postProcessGetInsertId(result: any): {
563
+ id: any;
564
+ }[];
565
+ }
566
+
567
+ declare class MysqlSchemaGrammar extends SchemaGrammar {
568
+ compileColumn(column: Column): string;
569
+ }
570
+
571
+ declare class MysqlConnection extends Connection {
572
+ private eventManager;
573
+ on(event: connection_events, listener: (...args: any[]) => void): this;
574
+ off(event: connection_events, listener: (...args: any[]) => void): this;
575
+ emit(event: connection_events, ...args: any[]): Promise<boolean>;
576
+ connection: mysql.PoolConnection | undefined;
577
+ static pool: mysql.Pool;
578
+ static poolConfig: mysql.PoolOptions;
579
+ static defaults: mysql.PoolOptions;
580
+ constructor(params: mysql.PoolOptions);
581
+ connect(): Promise<boolean>;
582
+ runQuery(sql: CompiledSql | string): Promise<any>;
583
+ runCursor(sql: CompiledSql): Promise<any>;
584
+ disconnect(): Promise<boolean>;
585
+ getQuery(): Query;
586
+ getSchema(): Schema;
587
+ getQueryGrammar(): MysqlQueryGrammar;
588
+ getSchemaGrammar(): MysqlSchemaGrammar;
589
+ beginTransaction(): Promise<void>;
590
+ commit(): Promise<void>;
591
+ rollback(): Promise<void>;
592
+ static destroy(): Promise<void>;
593
+ isConnected(): boolean;
594
+ /**
595
+ * Validates and escapes a MySQL identifier (database name, table name, etc.)
596
+ * Uses a whitelist approach to ensure only safe characters are allowed
597
+ */
598
+ private validateAndEscapeIdentifier;
599
+ createDatabase(name: string): Promise<void>;
600
+ dropDatabase(name: string): Promise<void>;
601
+ listDatabases(): Promise<string[]>;
602
+ existsDatabase(name: string): Promise<boolean>;
603
+ }
604
+
605
+ declare abstract class Migration {
606
+ abstract up(schema: Schema): Promise<void>;
607
+ abstract down(schema: Schema): Promise<void>;
608
+ }
609
+
610
+ export { Blueprint, Column, type ColumnPropertiesType, type CompiledSql, Connection, ForeignKeyConstraint, IndexConstraint, type JoinCondition, Migration, MysqlConnection, MysqlQueryGrammar, MysqlSchemaGrammar, type Parameter, PostgresqlConnection, PostgresqlQueryGrammar, PostgresqlSchemaGrammar, Query, QueryGrammar, type QueryParts, Schema, SchemaGrammar, type SqliteConfig, SqliteConnection, SqliteQueryGrammar, SqliteSchemaGrammar, type connection_events, type havingType, type joinType, type selectType, type whereBasic, type whereNested, type whereNull, type whereOp, type whereOpColumn, type whereRaw, type whereType };