@dbcube/query-builder 5.1.1 → 5.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -1,426 +1,432 @@
1
- type WhereCallback = (query: Table) => void;
2
- type DatabaseRecord = Record<string, any>;
3
-
1
+ export type WhereCallback = (query: Table) => void;
2
+ export type DatabaseRecord = Record<string, any>;
4
3
  /**
5
4
  * Main class to handle MySQL database connections and queries.
6
5
  * Implements the Singleton pattern to ensure a single instance of the connection pool.
7
6
  */
8
- declare class Database {
9
- private name;
10
- private engine;
11
- private computedFields;
12
- private triggers;
13
- constructor(name: string);
14
- useComputes(): Promise<Database>;
15
- useTriggers(): Promise<Database>;
16
- connect(): Promise<void>;
17
- disconnect(): Promise<void>;
18
- /**
19
- * Creates and returns a new instance of `Table` for the specified table.
20
- * This method is used to start building queries for a specific table.
21
- * It provides a fluent interface for common database operations like select, insert, update, and delete.
22
- *
23
- * @param {string} tableName - The name of the table to query.
24
- * @returns {Table} - Returns a new instance of `Table` for the specified table.
25
- *
26
- * @example
27
- * // Select all records from a table
28
- * const users = await db.table('users').get();
29
- *
30
- * // Select records with conditions
31
- * const activeUsers = await db.table('users')
32
- * .where('status', '=', 'active')
33
- * .orderBy('created_at', 'DESC')
34
- * .limit(10)
35
- * .get();
36
- *
37
- * // Insert records
38
- * await db.table('users').insert([
39
- * { name: 'John', email: 'john@example.com', age: 30 }
40
- * ]);
41
- *
42
- * // Update records
43
- * await db.table('users')
44
- * .where('id', '=', 1)
45
- * .update({ status: 'inactive' });
46
- *
47
- * // Delete records
48
- * await db.table('users')
49
- * .where('status', '=', 'deleted')
50
- * .delete();
51
- *
52
- * // Access column management
53
- * const columns = await db.table('users').columns().get();
54
- */
55
- table(tableName: string): Table;
56
- private setComputedFields;
57
- private setTriggers;
7
+ export declare class Database {
8
+ private name;
9
+ private engine;
10
+ private computedFields;
11
+ private triggers;
12
+ constructor(name: string);
13
+ useComputes(): Promise<Database>;
14
+ useTriggers(): Promise<Database>;
15
+ connect(): Promise<void>;
16
+ disconnect(): Promise<void>;
17
+ /**
18
+ * Creates and returns a new instance of `Table` for the specified table.
19
+ * This method is used to start building queries for a specific table.
20
+ * It provides a fluent interface for common database operations like select, insert, update, and delete.
21
+ *
22
+ * @param {string} tableName - The name of the table to query.
23
+ * @returns {Table} - Returns a new instance of `Table` for the specified table.
24
+ *
25
+ * @example
26
+ * // Select all records from a table
27
+ * const users = await db.table('users').get();
28
+ *
29
+ * // Select records with conditions
30
+ * const activeUsers = await db.table('users')
31
+ * .where('status', '=', 'active')
32
+ * .orderBy('created_at', 'DESC')
33
+ * .limit(10)
34
+ * .get();
35
+ *
36
+ * // Insert records
37
+ * await db.table('users').insert([
38
+ * { name: 'John', email: 'john@example.com', age: 30 }
39
+ * ]);
40
+ *
41
+ * // Update records
42
+ * await db.table('users')
43
+ * .where('id', '=', 1)
44
+ * .update({ status: 'inactive' });
45
+ *
46
+ * // Delete records
47
+ * await db.table('users')
48
+ * .where('status', '=', 'deleted')
49
+ * .delete();
50
+ *
51
+ * // Access column management
52
+ * const columns = await db.table('users').columns().get();
53
+ */
54
+ table(tableName: string): Table;
55
+ private setComputedFields;
56
+ private setTriggers;
58
57
  }
59
58
  /**
60
59
  * Class to build and execute SQL queries for a specific table.
61
60
  * Supports operations like SELECT, INSERT, UPDATE, DELETE, and more.
62
61
  */
63
- declare class Table {
64
- private engine;
65
- private nextType;
66
- private dml;
67
- private computedFields;
68
- private trigger;
69
- private triggers;
70
- constructor(instance: any, databaseName: string, tableName: string, engine?: any, computedFields?: any[], triggers?: any[]);
71
- /**
72
- * Specifies the columns to select in a SELECT query.
73
- *
74
- * @param {string[]} fields - Array of column names to select. If empty, selects all columns.
75
- * @returns {Table} - Returns the current instance of Table for method chaining.
76
- *
77
- * @example
78
- * const users = await db.table('users').select(['id', 'name']).get();
79
- * console.log(users); // [{ id: 1, name: 'John' }, { id: 2, name: 'Jane' }]
80
- */
81
- select(fields?: string[]): Table;
82
- /**
83
- * Adds a WHERE condition to the query.
84
- *
85
- * @param {string} column - The column to filter by.
86
- * @param {string} operator - The comparison operator (e.g., '=', '>', '<', 'IS NULL', 'IS NOT NULL').
87
- * @param {any} value - The value to compare against (optional for IS NULL/IS NOT NULL).
88
- * @returns {Table} - Returns the current instance of Table for method chaining.
89
- *
90
- * @example
91
- * const users = await db.table('users').where('age', '>', 25).get();
92
- * const nullUsers = await db.table('users').where('email', 'IS NULL').get();
93
- * console.log(users); // [{ id: 1, name: 'John', age: 30 }]
94
- */
95
- where(column: string, operator: 'IS NULL' | 'IS NOT NULL'): Table;
96
- where(column: string, operator: '=' | '!=' | '<>' | '>' | '<' | '>=' | '<=' | 'LIKE' | 'NOT LIKE' | 'IN' | 'NOT IN' | 'BETWEEN' | 'NOT BETWEEN', value: any): Table;
97
- /**
98
- * Adds an OR WHERE condition to the query.
99
- *
100
- * @param {string} column - The column to filter by.
101
- * @param {string} operator - The comparison operator (e.g., '=', '>', '<', 'IS NULL', 'IS NOT NULL').
102
- * @param {any} value - The value to compare against (optional for IS NULL/IS NOT NULL).
103
- * @returns {Table} - Returns the current instance of Table for method chaining.
104
- *
105
- * @example
106
- * const users = await db.table('users').where('age', '>', 25).orWhere('name', '=', 'Jane').get();
107
- * const nullUsers = await db.table('users').where('active', '=', true).orWhere('email', 'IS NULL').get();
108
- * console.log(users); // [{ id: 1, name: 'John', age: 30 }, { id: 2, name: 'Jane', age: 25 }]
109
- */
110
- orWhere(column: string, operator: 'IS NULL' | 'IS NOT NULL'): Table;
111
- orWhere(column: string, operator: '=' | '!=' | '<>' | '>' | '<' | '>=' | '<=' | 'LIKE' | 'NOT LIKE' | 'IN' | 'NOT IN' | 'BETWEEN' | 'NOT BETWEEN', value: any): Table;
112
- /**
113
- * Adds a grouped WHERE condition to the query.
114
- *
115
- * @param {WhereCallback} callback - A callback function that receives a new Table instance to build the grouped conditions.
116
- * @returns {Table} - Returns the current instance of Table for method chaining.
117
- *
118
- * @example
119
- * const users = await db.table('users').whereGroup(query => {
120
- * query.where('age', '>', 25).orWhere('name', '=', 'Jane');
121
- * }).get();
122
- * console.log(users); // [{ id: 1, name: 'John', age: 30 }, { id: 2, name: 'Jane', age: 25 }]
123
- */
124
- whereGroup(callback: WhereCallback): Table;
125
- or(): Table;
126
- and(): Table;
127
- /**
128
- * Adds a WHERE BETWEEN condition to the query.
129
- *
130
- * @param {string} column - The column to filter by.
131
- * @param {[any, any]} values - A tuple with two values representing the range.
132
- * @returns {Table} - Returns the current instance of Table for method chaining.
133
- *
134
- * @example
135
- * const users = await db.table('users').whereBetween('age', [20, 30]).get();
136
- * console.log(users); // [{ id: 1, name: 'John', age: 30 }, { id: 2, name: 'Jane', age: 25 }]
137
- */
138
- whereBetween(column: string, values: [any, any]): Table;
139
- /**
140
- * Adds a WHERE IN condition to the query.
141
- *
142
- * @param {string} column - The column to filter by.
143
- * @param {any[]} values - An array of values to match.
144
- * @returns {Table} - Returns the current instance of Table for method chaining.
145
- *
146
- * @example
147
- * const users = await db.table('users').whereIn('id', [1, 2]).get();
148
- * console.log(users); // [{ id: 1, name: 'John' }, { id: 2, name: 'Jane' }]
149
- */
150
- whereIn(column: string, values: any[]): Table;
151
- /**
152
- * Adds a WHERE IS NULL condition to the query.
153
- *
154
- * @param {string} column - The column to filter by.
155
- * @returns {Table} - Returns the current instance of Table for method chaining.
156
- *
157
- * @example
158
- * const users = await db.table('users').whereNull('email').get();
159
- * console.log(users); // [{ id: 3, name: 'Alice', email: null }]
160
- */
161
- whereNull(column: string): Table;
162
- /**
163
- * Adds a WHERE IS NOT NULL condition to the query.
164
- *
165
- * @param {string} column - The column to filter by.
166
- * @returns {Table} - Returns the current instance of Table for method chaining.
167
- *
168
- * @example
169
- * const users = await db.table('users').whereNotNull('email').get();
170
- * console.log(users); // [{ id: 1, name: 'John', email: 'john@example.com' }]
171
- */
172
- whereNotNull(column: string): Table;
173
- /**
174
- * Adds a JOIN clause to the query.
175
- *
176
- * @param {string} table - The table to join.
177
- * @param {string} column1 - The column from the current table.
178
- * @param {string} operator - The comparison operator (e.g., '=', '>', '<').
179
- * @param {string} column2 - The column from the joined table.
180
- * @returns {Table} - Returns the current instance of Table for method chaining.
181
- *
182
- * @example
183
- * const users = await db.table('users').join('orders', 'users.id', '=', 'orders.user_id').get();
184
- * console.log(users); // [{ id: 1, name: 'John', order_id: 101 }]
185
- */
186
- join(table: string, column1: string, operator: string, column2: string): Table;
187
- /**
188
- * Adds a LEFT JOIN clause to the query.
189
- *
190
- * @param {string} table - The table to join.
191
- * @param {string} column1 - The column from the current table.
192
- * @param {string} operator - The comparison operator (e.g., '=', '>', '<').
193
- * @param {string} column2 - The column from the joined table.
194
- * @returns {Table} - Returns the current instance of Table for method chaining.
195
- *
196
- * @example
197
- * const users = await db.table('users').leftJoin('orders', 'users.id', '=', 'orders.user_id').get();
198
- * console.log(users); // [{ id: 1, name: 'John', order_id: 101 }, { id: 2, name: 'Jane', order_id: null }]
199
- */
200
- leftJoin(table: string, column1: string, operator: string, column2: string): Table;
201
- /**
202
- * Adds a RIGHT JOIN clause to the query.
203
- *
204
- * @param {string} table - The table to join.
205
- * @param {string} column1 - The column from the current table.
206
- * @param {string} operator - The comparison operator (e.g., '=', '>', '<').
207
- * @param {string} column2 - The column from the joined table.
208
- * @returns {Table} - Returns the current instance of Table for method chaining.
209
- *
210
- * @example
211
- * const users = await db.table('users').rightJoin('orders', 'users.id', '=', 'orders.user_id').get();
212
- * console.log(users); // [{ id: 1, name: 'John', order_id: 101 }, { id: null, name: null, order_id: 102 }]
213
- */
214
- rightJoin(table: string, column1: string, operator: string, column2: string): Table;
215
- /**
216
- * Adds an ORDER BY clause to the query.
217
- *
218
- * @param {string} column - The column to order by.
219
- * @param {'ASC' | 'DESC'} direction - The sorting direction ('ASC' or 'DESC').
220
- * @returns {Table} - Returns the current instance of Table for method chaining.
221
- *
222
- * @example
223
- * const users = await db.table('users').orderBy('name', 'ASC').get();
224
- * console.log(users); // [{ id: 2, name: 'Jane' }, { id: 1, name: 'John' }]
225
- */
226
- orderBy(column: string, direction?: 'ASC' | 'DESC'): Table;
227
- /**
228
- * Adds a GROUP BY clause to the query.
229
- *
230
- * @param {string} column - The column to group by.
231
- * @returns {Table} - Returns the current instance of Table for method chaining.
232
- *
233
- * @example
234
- * const users = await db.table('users').groupBy('age').get();
235
- * console.log(users); // [{ age: 30, count: 1 }, { age: 25, count: 1 }]
236
- */
237
- groupBy(column: string): Table;
238
- /**
239
- * Adds a DISTINCT clause to the query.
240
- *
241
- * @returns {Table} - Returns the current instance of Table for method chaining.
242
- *
243
- * @example
244
- * const users = await db.table('users').distinct().select(['name']).get();
245
- * console.log(users); // [{ name: 'John' }, { name: 'Jane' }]
246
- */
247
- distinct(): Table;
248
- /**
249
- * Adds a COUNT clause to the query.
250
- *
251
- * @param {string} column - The column to count (default is '*').
252
- * @returns {Table} - Returns the current instance of Table for method chaining.
253
- *
254
- * @example
255
- * const count = await db.table('users').count().first();
256
- * console.log(count); // { count: 2 }
257
- */
258
- count(column?: string): Promise<Number>;
259
- /**
260
- * Adds a SUM clause to the query.
261
- *
262
- * @param {string} column - The column to sum.
263
- * @returns {Table} - Returns the current instance of Table for method chaining.
264
- *
265
- * @example
266
- * const totalAge = await db.table('users').sum('age').first();
267
- * console.log(totalAge); // { sum: 55 }
268
- */
269
- sum(column: string): Promise<Number>;
270
- /**
271
- * Adds an AVG clause to the query.
272
- *
273
- * @param {string} column - The column to calculate the average.
274
- * @returns {Table} - Returns the current instance of Table for method chaining.
275
- *
276
- * @example
277
- * const avgAge = await db.table('users').avg('age').first();
278
- * console.log(avgAge); // { avg: 27.5 }
279
- */
280
- avg(column: string): Promise<Number>;
281
- /**
282
- * Adds a MAX clause to the query.
283
- *
284
- * @param {string} column - The column to find the maximum value.
285
- * @returns {Table} - Returns the current instance of Table for method chaining.
286
- *
287
- * @example
288
- * const maxAge = await db.table('users').max('age').first();
289
- * console.log(maxAge); // { max: 30 }
290
- */
291
- max(column: string): Promise<Number>;
292
- /**
293
- * Adds a MIN clause to the query.
294
- *
295
- * @param {string} column - The column to find the minimum value.
296
- * @returns {Table} - Returns the current instance of Table for method chaining.
297
- *
298
- * @example
299
- * const minAge = await db.table('users').min('age').first();
300
- * console.log(minAge); // { min: 25 }
301
- */
302
- min(column: string): Promise<Number>;
303
- /**
304
- * Gets the column names of the table.
305
- * For SQL databases (MySQL, PostgreSQL, SQLite), returns a simple array of column names.
306
- * For MongoDB, returns a hierarchical structure with nested documents.
307
- *
308
- * @returns {Promise<string[] | any>} - Returns an array of column names for SQL databases,
309
- * or a hierarchical structure for MongoDB.
310
- *
311
- * @example
312
- * // SQL databases (MySQL, PostgreSQL, SQLite)
313
- * const columns = await db.table('users').columns();
314
- * console.log(columns); // ['id', 'name', 'email', 'age', 'created_at']
315
- *
316
- * @example
317
- * // MongoDB
318
- * const structure = await db.table('users').columns();
319
- * console.log(structure);
320
- * // {
321
- * // columns: ['id', 'name', 'profile'],
322
- * // submenu: {
323
- * // profile: {
324
- * // columns: ['age', 'city'],
325
- * // submenu: {}
326
- * // }
327
- * // }
328
- * // }
329
- */
330
- columns(): Promise<string[] | any>;
331
- /**
332
- * Adds a LIMIT clause to the query.
333
- *
334
- * @param {number} number - The maximum number of rows to return.
335
- * @returns {Table} - Returns the current instance of Table for method chaining.
336
- *
337
- * @example
338
- * const users = await db.table('users').limit(1).get();
339
- * console.log(users); // [{ id: 1, name: 'John', age: 30 }]
340
- */
341
- limit(number: number): Table;
342
- /**
343
- * Adds pagination to the query using LIMIT and OFFSET.
344
- *
345
- * @param {number} number - The page number (starting from 1).
346
- * @returns {Table} - Returns the current instance of Table for method chaining.
347
- *
348
- * @example
349
- * const users = await db.table('users').limit(1).page(2).get();
350
- * console.log(users); // [{ id: 2, name: 'Jane', age: 25 }]
351
- */
352
- page(number: number): Table;
353
- /**
354
- * Executes the query and returns all matching rows.
355
- *
356
- * @returns {Promise<DatabaseRecord[]>} - Returns an array of rows.
357
- *
358
- * @example
359
- * const users = await db.table('users').get();
360
- * console.log(users); // [{ id: 1, name: 'John' }, { id: 2, name: 'Jane' }]
361
- */
362
- get(): Promise<DatabaseRecord[]>;
363
- /**
364
- * Executes the query and returns the first matching row.
365
- *
366
- * @returns {Promise<DatabaseRecord | null>} - Returns the first row or null if no rows match.
367
- *
368
- * @example
369
- * const user = await db.table('users').first();
370
- * console.log(user); // { id: 1, name: 'John' }
371
- */
372
- first(): Promise<DatabaseRecord | null>;
373
- /**
374
- * Finds a row by a specific column value.
375
- *
376
- * @param {any} value - The value to search for.
377
- * @param {string} column - The column to search in (default is 'id').
378
- * @returns {Promise<DatabaseRecord | null>} - Returns the first matching row or null if no rows match.
379
- *
380
- * @example
381
- * const user = await db.table('users').find(1);
382
- * console.log(user); // { id: 1, name: 'John' }
383
- */
384
- find(value: any, column?: string): Promise<DatabaseRecord | null>;
385
- /**
386
- * Inserts one or more rows into the table.
387
- *
388
- * @param {DatabaseRecord[]} data - An array of objects representing the rows to insert.
389
- * @returns {Promise<DatabaseRecord[]>} - Returns an array of the inserted rows.
390
- *
391
- * @example
392
- * const newUsers = await db.table('users').insert([
393
- * { name: 'Alice', age: 28 },
394
- * { name: 'Bob', age: 32 }
395
- * ]);
396
- * console.log(newUsers); // [{ id: 3, name: 'Alice', age: 28 }, { id: 4, name: 'Bob', age: 32 }]
397
- */
398
- insert(data: DatabaseRecord[]): Promise<DatabaseRecord[]>;
399
- /**
400
- * Updates rows in the table based on the defined conditions.
401
- *
402
- * @param {DatabaseRecord} data - An object with key-value pairs representing the fields to update.
403
- * @returns {Promise<any>} - Returns the result of the update operation.
404
- *
405
- * @example
406
- * const result = await db.table('users')
407
- * .where('id', '=', 1)
408
- * .update({ name: 'John Updated', age: 31 });
409
- * console.log(result); // { affectedRows: 1 }
410
- */
411
- update(data: DatabaseRecord): Promise<any>;
412
- /**
413
- * Deletes rows from the table based on the defined conditions.
414
- *
415
- * @returns {Promise<any>} - Returns the result of the delete operation.
416
- *
417
- * @example
418
- * const result = await db.table('users').where('id', '=', 1).delete();
419
- * console.log(result); // { affectedRows: 1 }
420
- */
421
- delete(): Promise<any>;
422
- private getResponse;
423
- private clone;
62
+ export declare class Table {
63
+ private engine;
64
+ private nextType;
65
+ private dml;
66
+ private computedFields;
67
+ private trigger;
68
+ private triggers;
69
+ constructor(instance: any, databaseName: string, tableName: string, engine?: any, computedFields?: any[], triggers?: any[]);
70
+ /**
71
+ * Specifies the columns to select in a SELECT query.
72
+ *
73
+ * @param {string[]} fields - Array of column names to select. If empty, selects all columns.
74
+ * @returns {Table} - Returns the current instance of Table for method chaining.
75
+ *
76
+ * @example
77
+ * const users = await db.table('users').select(['id', 'name']).get();
78
+ * console.log(users); // [{ id: 1, name: 'John' }, { id: 2, name: 'Jane' }]
79
+ */
80
+ select(fields?: string[]): Table;
81
+ /**
82
+ * Adds a WHERE condition to the query.
83
+ *
84
+ * @param {string} column - The column to filter by.
85
+ * @param {string} operator - The comparison operator (e.g., '=', '>', '<', 'IS NULL', 'IS NOT NULL').
86
+ * @param {any} value - The value to compare against (optional for IS NULL/IS NOT NULL).
87
+ * @returns {Table} - Returns the current instance of Table for method chaining.
88
+ *
89
+ * @example
90
+ * const users = await db.table('users').where('age', '>', 25).get();
91
+ * const nullUsers = await db.table('users').where('email', 'IS NULL').get();
92
+ * console.log(users); // [{ id: 1, name: 'John', age: 30 }]
93
+ */
94
+ where(column: string, operator: "IS NULL" | "IS NOT NULL"): Table;
95
+ where(column: string, operator: "=" | "!=" | "<>" | ">" | "<" | ">=" | "<=" | "LIKE" | "NOT LIKE" | "IN" | "NOT IN" | "BETWEEN" | "NOT BETWEEN", value: any): Table;
96
+ /**
97
+ * Adds an OR WHERE condition to the query.
98
+ *
99
+ * @param {string} column - The column to filter by.
100
+ * @param {string} operator - The comparison operator (e.g., '=', '>', '<', 'IS NULL', 'IS NOT NULL').
101
+ * @param {any} value - The value to compare against (optional for IS NULL/IS NOT NULL).
102
+ * @returns {Table} - Returns the current instance of Table for method chaining.
103
+ *
104
+ * @example
105
+ * const users = await db.table('users').where('age', '>', 25).orWhere('name', '=', 'Jane').get();
106
+ * const nullUsers = await db.table('users').where('active', '=', true).orWhere('email', 'IS NULL').get();
107
+ * console.log(users); // [{ id: 1, name: 'John', age: 30 }, { id: 2, name: 'Jane', age: 25 }]
108
+ */
109
+ orWhere(column: string, operator: "IS NULL" | "IS NOT NULL"): Table;
110
+ orWhere(column: string, operator: "=" | "!=" | "<>" | ">" | "<" | ">=" | "<=" | "LIKE" | "NOT LIKE" | "IN" | "NOT IN" | "BETWEEN" | "NOT BETWEEN", value: any): Table;
111
+ /**
112
+ * Adds a grouped WHERE condition to the query.
113
+ *
114
+ * @param {WhereCallback} callback - A callback function that receives a new Table instance to build the grouped conditions.
115
+ * @returns {Table} - Returns the current instance of Table for method chaining.
116
+ *
117
+ * @example
118
+ * const users = await db.table('users').whereGroup(query => {
119
+ * query.where('age', '>', 25).orWhere('name', '=', 'Jane');
120
+ * }).get();
121
+ * console.log(users); // [{ id: 1, name: 'John', age: 30 }, { id: 2, name: 'Jane', age: 25 }]
122
+ */
123
+ whereGroup(callback: WhereCallback): Table;
124
+ or(): Table;
125
+ and(): Table;
126
+ /**
127
+ * Adds a WHERE BETWEEN condition to the query.
128
+ *
129
+ * @param {string} column - The column to filter by.
130
+ * @param {[any, any]} values - A tuple with two values representing the range.
131
+ * @returns {Table} - Returns the current instance of Table for method chaining.
132
+ *
133
+ * @example
134
+ * const users = await db.table('users').whereBetween('age', [20, 30]).get();
135
+ * console.log(users); // [{ id: 1, name: 'John', age: 30 }, { id: 2, name: 'Jane', age: 25 }]
136
+ */
137
+ whereBetween(column: string, values: [
138
+ any,
139
+ any
140
+ ]): Table;
141
+ /**
142
+ * Adds a WHERE IN condition to the query.
143
+ *
144
+ * @param {string} column - The column to filter by.
145
+ * @param {any[]} values - An array of values to match.
146
+ * @returns {Table} - Returns the current instance of Table for method chaining.
147
+ *
148
+ * @example
149
+ * const users = await db.table('users').whereIn('id', [1, 2]).get();
150
+ * console.log(users); // [{ id: 1, name: 'John' }, { id: 2, name: 'Jane' }]
151
+ */
152
+ whereIn(column: string, values: any[]): Table;
153
+ /**
154
+ * Adds a WHERE IS NULL condition to the query.
155
+ *
156
+ * @param {string} column - The column to filter by.
157
+ * @returns {Table} - Returns the current instance of Table for method chaining.
158
+ *
159
+ * @example
160
+ * const users = await db.table('users').whereNull('email').get();
161
+ * console.log(users); // [{ id: 3, name: 'Alice', email: null }]
162
+ */
163
+ whereNull(column: string): Table;
164
+ /**
165
+ * Adds a WHERE IS NOT NULL condition to the query.
166
+ *
167
+ * @param {string} column - The column to filter by.
168
+ * @returns {Table} - Returns the current instance of Table for method chaining.
169
+ *
170
+ * @example
171
+ * const users = await db.table('users').whereNotNull('email').get();
172
+ * console.log(users); // [{ id: 1, name: 'John', email: 'john@example.com' }]
173
+ */
174
+ whereNotNull(column: string): Table;
175
+ /**
176
+ * Adds a JOIN clause to the query.
177
+ *
178
+ * @param {string} table - The table to join.
179
+ * @param {string} column1 - The column from the current table.
180
+ * @param {string} operator - The comparison operator (e.g., '=', '>', '<').
181
+ * @param {string} column2 - The column from the joined table.
182
+ * @returns {Table} - Returns the current instance of Table for method chaining.
183
+ *
184
+ * @example
185
+ * const users = await db.table('users').join('orders', 'users.id', '=', 'orders.user_id').get();
186
+ * console.log(users); // [{ id: 1, name: 'John', order_id: 101 }]
187
+ */
188
+ join(table: string, column1: string, operator: string, column2: string): Table;
189
+ /**
190
+ * Adds a LEFT JOIN clause to the query.
191
+ *
192
+ * @param {string} table - The table to join.
193
+ * @param {string} column1 - The column from the current table.
194
+ * @param {string} operator - The comparison operator (e.g., '=', '>', '<').
195
+ * @param {string} column2 - The column from the joined table.
196
+ * @returns {Table} - Returns the current instance of Table for method chaining.
197
+ *
198
+ * @example
199
+ * const users = await db.table('users').leftJoin('orders', 'users.id', '=', 'orders.user_id').get();
200
+ * console.log(users); // [{ id: 1, name: 'John', order_id: 101 }, { id: 2, name: 'Jane', order_id: null }]
201
+ */
202
+ leftJoin(table: string, column1: string, operator: string, column2: string): Table;
203
+ /**
204
+ * Adds a RIGHT JOIN clause to the query.
205
+ *
206
+ * @param {string} table - The table to join.
207
+ * @param {string} column1 - The column from the current table.
208
+ * @param {string} operator - The comparison operator (e.g., '=', '>', '<').
209
+ * @param {string} column2 - The column from the joined table.
210
+ * @returns {Table} - Returns the current instance of Table for method chaining.
211
+ *
212
+ * @example
213
+ * const users = await db.table('users').rightJoin('orders', 'users.id', '=', 'orders.user_id').get();
214
+ * console.log(users); // [{ id: 1, name: 'John', order_id: 101 }, { id: null, name: null, order_id: 102 }]
215
+ */
216
+ rightJoin(table: string, column1: string, operator: string, column2: string): Table;
217
+ /**
218
+ * Adds an ORDER BY clause to the query.
219
+ *
220
+ * @param {string} column - The column to order by.
221
+ * @param {'ASC' | 'DESC'} direction - The sorting direction ('ASC' or 'DESC').
222
+ * @returns {Table} - Returns the current instance of Table for method chaining.
223
+ *
224
+ * @example
225
+ * const users = await db.table('users').orderBy('name', 'ASC').get();
226
+ * console.log(users); // [{ id: 2, name: 'Jane' }, { id: 1, name: 'John' }]
227
+ */
228
+ orderBy(column: string, direction?: "ASC" | "DESC"): Table;
229
+ /**
230
+ * Adds a GROUP BY clause to the query.
231
+ *
232
+ * @param {string} column - The column to group by.
233
+ * @returns {Table} - Returns the current instance of Table for method chaining.
234
+ *
235
+ * @example
236
+ * const users = await db.table('users').groupBy('age').get();
237
+ * console.log(users); // [{ age: 30, count: 1 }, { age: 25, count: 1 }]
238
+ */
239
+ groupBy(column: string): Table;
240
+ /**
241
+ * Adds a DISTINCT clause to the query.
242
+ *
243
+ * @returns {Table} - Returns the current instance of Table for method chaining.
244
+ *
245
+ * @example
246
+ * const users = await db.table('users').distinct().select(['name']).get();
247
+ * console.log(users); // [{ name: 'John' }, { name: 'Jane' }]
248
+ */
249
+ distinct(): Table;
250
+ /**
251
+ * Adds a COUNT clause to the query.
252
+ *
253
+ * @param {string} column - The column to count (default is '*').
254
+ * @returns {Table} - Returns the current instance of Table for method chaining.
255
+ *
256
+ * @example
257
+ * const count = await db.table('users').count().first();
258
+ * console.log(count); // { count: 2 }
259
+ */
260
+ count(column?: string): Promise<Number>;
261
+ /**
262
+ * Adds a SUM clause to the query.
263
+ *
264
+ * @param {string} column - The column to sum.
265
+ * @returns {Table} - Returns the current instance of Table for method chaining.
266
+ *
267
+ * @example
268
+ * const totalAge = await db.table('users').sum('age').first();
269
+ * console.log(totalAge); // { sum: 55 }
270
+ */
271
+ sum(column: string): Promise<Number>;
272
+ /**
273
+ * Adds an AVG clause to the query.
274
+ *
275
+ * @param {string} column - The column to calculate the average.
276
+ * @returns {Table} - Returns the current instance of Table for method chaining.
277
+ *
278
+ * @example
279
+ * const avgAge = await db.table('users').avg('age').first();
280
+ * console.log(avgAge); // { avg: 27.5 }
281
+ */
282
+ avg(column: string): Promise<Number>;
283
+ /**
284
+ * Adds a MAX clause to the query.
285
+ *
286
+ * @param {string} column - The column to find the maximum value.
287
+ * @returns {Table} - Returns the current instance of Table for method chaining.
288
+ *
289
+ * @example
290
+ * const maxAge = await db.table('users').max('age').first();
291
+ * console.log(maxAge); // { max: 30 }
292
+ */
293
+ max(column: string): Promise<Number>;
294
+ /**
295
+ * Adds a MIN clause to the query.
296
+ *
297
+ * @param {string} column - The column to find the minimum value.
298
+ * @returns {Table} - Returns the current instance of Table for method chaining.
299
+ *
300
+ * @example
301
+ * const minAge = await db.table('users').min('age').first();
302
+ * console.log(minAge); // { min: 25 }
303
+ */
304
+ min(column: string): Promise<Number>;
305
+ /**
306
+ * Gets the column names of the table.
307
+ * For SQL databases (MySQL, PostgreSQL, SQLite), returns a simple array of column names.
308
+ * For MongoDB, returns a hierarchical structure with nested documents.
309
+ *
310
+ * @returns {Promise<string[] | any>} - Returns an array of column names for SQL databases,
311
+ * or a hierarchical structure for MongoDB.
312
+ *
313
+ * @example
314
+ * // SQL databases (MySQL, PostgreSQL, SQLite)
315
+ * const columns = await db.table('users').columns();
316
+ * console.log(columns); // ['id', 'name', 'email', 'age', 'created_at']
317
+ *
318
+ * @example
319
+ * // MongoDB
320
+ * const structure = await db.table('users').columns();
321
+ * console.log(structure);
322
+ * // {
323
+ * // columns: ['id', 'name', 'profile'],
324
+ * // submenu: {
325
+ * // profile: {
326
+ * // columns: ['age', 'city'],
327
+ * // submenu: {}
328
+ * // }
329
+ * // }
330
+ * // }
331
+ */
332
+ columns(): Promise<string[] | any>;
333
+ /**
334
+ * Adds a LIMIT clause to the query.
335
+ *
336
+ * @param {number} number - The maximum number of rows to return.
337
+ * @returns {Table} - Returns the current instance of Table for method chaining.
338
+ *
339
+ * @example
340
+ * const users = await db.table('users').limit(1).get();
341
+ * console.log(users); // [{ id: 1, name: 'John', age: 30 }]
342
+ */
343
+ limit(number: number): Table;
344
+ /**
345
+ * Adds pagination to the query using LIMIT and OFFSET.
346
+ *
347
+ * @param {number} number - The page number (starting from 1).
348
+ * @returns {Table} - Returns the current instance of Table for method chaining.
349
+ *
350
+ * @example
351
+ * const users = await db.table('users').limit(1).page(2).get();
352
+ * console.log(users); // [{ id: 2, name: 'Jane', age: 25 }]
353
+ */
354
+ page(number: number): Table;
355
+ /**
356
+ * Executes the query and returns all matching rows.
357
+ *
358
+ * @returns {Promise<DatabaseRecord[]>} - Returns an array of rows.
359
+ *
360
+ * @example
361
+ * const users = await db.table('users').get();
362
+ * console.log(users); // [{ id: 1, name: 'John' }, { id: 2, name: 'Jane' }]
363
+ */
364
+ get(): Promise<DatabaseRecord[]>;
365
+ /**
366
+ * Executes the query and returns the first matching row.
367
+ *
368
+ * @returns {Promise<DatabaseRecord | null>} - Returns the first row or null if no rows match.
369
+ *
370
+ * @example
371
+ * const user = await db.table('users').first();
372
+ * console.log(user); // { id: 1, name: 'John' }
373
+ */
374
+ first(): Promise<DatabaseRecord | null>;
375
+ /**
376
+ * Finds a row by a specific column value.
377
+ *
378
+ * @param {any} value - The value to search for.
379
+ * @param {string} column - The column to search in (default is 'id').
380
+ * @returns {Promise<DatabaseRecord | null>} - Returns the first matching row or null if no rows match.
381
+ *
382
+ * @example
383
+ * const user = await db.table('users').find(1);
384
+ * console.log(user); // { id: 1, name: 'John' }
385
+ */
386
+ find(value: any, column?: string): Promise<DatabaseRecord | null>;
387
+ /**
388
+ * Inserts one or more rows into the table.
389
+ *
390
+ * @param {DatabaseRecord[]} data - An array of objects representing the rows to insert.
391
+ * @returns {Promise<DatabaseRecord[]>} - Returns an array of the inserted rows.
392
+ *
393
+ * @example
394
+ * const newUsers = await db.table('users').insert([
395
+ * { name: 'Alice', age: 28 },
396
+ * { name: 'Bob', age: 32 }
397
+ * ]);
398
+ * console.log(newUsers); // [{ id: 3, name: 'Alice', age: 28 }, { id: 4, name: 'Bob', age: 32 }]
399
+ */
400
+ insert(data: DatabaseRecord[]): Promise<DatabaseRecord[]>;
401
+ /**
402
+ * Updates rows in the table based on the defined conditions.
403
+ *
404
+ * @param {DatabaseRecord} data - An object with key-value pairs representing the fields to update.
405
+ * @returns {Promise<any>} - Returns the result of the update operation.
406
+ *
407
+ * @example
408
+ * const result = await db.table('users')
409
+ * .where('id', '=', 1)
410
+ * .update({ name: 'John Updated', age: 31 });
411
+ * console.log(result); // { affectedRows: 1 }
412
+ */
413
+ update(data: DatabaseRecord): Promise<any>;
414
+ /**
415
+ * Deletes rows from the table based on the defined conditions.
416
+ *
417
+ * @returns {Promise<any>} - Returns the result of the delete operation.
418
+ *
419
+ * @example
420
+ * const result = await db.table('users').where('id', '=', 1).delete();
421
+ * console.log(result); // { affectedRows: 1 }
422
+ */
423
+ delete(): Promise<any>;
424
+ private getResponse;
425
+ private clone;
424
426
  }
425
427
 
426
- export { Database, type DatabaseRecord, Table, type WhereCallback, Database as default };
428
+ export {
429
+ Database as default,
430
+ };
431
+
432
+ export {};