@devbro/neko-sql 0.1.37 → 0.1.39

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