tspace-mysql 1.3.0 → 1.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/README.md +72 -14
  2. package/dist/cli/dump/db.d.ts +4 -4
  3. package/dist/cli/dump/db.js +25 -25
  4. package/dist/cli/generate/make.d.ts +4 -4
  5. package/dist/cli/generate/make.js +45 -45
  6. package/dist/cli/generate/model.d.ts +2 -2
  7. package/dist/cli/generate/model.js +6 -6
  8. package/dist/cli/index.d.ts +2 -2
  9. package/dist/cli/index.js +58 -58
  10. package/dist/cli/migrate/make.d.ts +4 -4
  11. package/dist/cli/migrate/make.js +30 -30
  12. package/dist/cli/models/make.d.ts +4 -4
  13. package/dist/cli/models/make.js +51 -51
  14. package/dist/cli/models/model.d.ts +2 -2
  15. package/dist/cli/models/model.js +20 -11
  16. package/dist/cli/query/index.d.ts +4 -4
  17. package/dist/cli/query/index.js +7 -7
  18. package/dist/cli/tables/make.d.ts +4 -4
  19. package/dist/cli/tables/make.js +26 -26
  20. package/dist/cli/tables/table.d.ts +2 -2
  21. package/dist/cli/tables/table.js +6 -6
  22. package/dist/lib/connection/index.d.ts +30 -30
  23. package/dist/lib/connection/index.js +144 -143
  24. package/dist/lib/connection/options.d.ts +15 -4
  25. package/dist/lib/connection/options.js +43 -42
  26. package/dist/lib/constants/index.d.ts +5 -8
  27. package/dist/lib/constants/index.js +162 -158
  28. package/dist/lib/index.d.ts +8 -8
  29. package/dist/lib/index.js +36 -36
  30. package/dist/lib/tspace/{AbstractDatabase.d.ts → AbstractBuilder.d.ts} +124 -116
  31. package/dist/lib/tspace/{AbstractDatabase.js → AbstractBuilder.js} +36 -34
  32. package/dist/lib/tspace/AbstractDB.d.ts +18 -18
  33. package/dist/lib/tspace/AbstractDB.js +11 -11
  34. package/dist/lib/tspace/AbstractModel.d.ts +43 -41
  35. package/dist/lib/tspace/AbstractModel.js +11 -11
  36. package/dist/lib/tspace/Blueprint.d.ts +136 -136
  37. package/dist/lib/tspace/Blueprint.js +228 -228
  38. package/dist/lib/tspace/{Database.d.ts → Builder.d.ts} +825 -706
  39. package/dist/lib/tspace/{Database.js → Builder.js} +2548 -2363
  40. package/dist/lib/tspace/DB.d.ts +152 -126
  41. package/dist/lib/tspace/DB.js +373 -264
  42. package/dist/lib/tspace/Interface.d.ts +110 -109
  43. package/dist/lib/tspace/Interface.js +2 -2
  44. package/dist/lib/tspace/Logger.d.ts +8 -8
  45. package/dist/lib/tspace/Logger.js +49 -49
  46. package/dist/lib/tspace/Model.d.ts +708 -609
  47. package/dist/lib/tspace/Model.js +2519 -2477
  48. package/dist/lib/tspace/ProxyHandler.d.ts +14 -14
  49. package/dist/lib/tspace/ProxyHandler.js +31 -31
  50. package/dist/lib/tspace/Schema.d.ts +8 -8
  51. package/dist/lib/tspace/Schema.js +45 -44
  52. package/dist/lib/tspace/index.d.ts +15 -15
  53. package/dist/lib/tspace/index.js +20 -20
  54. package/dist/lib/utils/index.d.ts +15 -15
  55. package/dist/lib/utils/index.js +155 -165
  56. package/package.json +2 -4
@@ -1,706 +1,825 @@
1
- import AbstractDatabase from './AbstractDatabase';
2
- import { Pagination, Backup, ConnectionOptions, BackupToFile, Connection, ConnectionTransaction } from './Interface';
3
- declare class Database extends AbstractDatabase {
4
- constructor();
5
- /**
6
- *
7
- * @param {string} column
8
- * @return {this}
9
- */
10
- pluck(column: string): this;
11
- /**
12
- *
13
- * @param {...string} columns
14
- * @return {this} this
15
- */
16
- except(...columns: Array<string>): this;
17
- /**
18
- * data alaways will return void
19
- * @return {this} this
20
- */
21
- void(): this;
22
- /**
23
- *
24
- * @param {...string} columns show only colums selected
25
- * @return {this} this
26
- */
27
- only(...columns: Array<string>): this;
28
- /**
29
- *
30
- * @param {string=} column [column=id]
31
- * @return {this} this
32
- */
33
- distinct(column?: string): this;
34
- /**
35
- * select data form table
36
- * @param {Array<string>} ...columns
37
- * @return {this} this
38
- */
39
- select(...columns: Array<string>): this;
40
- /**
41
- * chunks data from array
42
- * @param {number} chunk
43
- * @return {this} this
44
- */
45
- chunk(chunk: number): this;
46
- /**
47
- *
48
- * @param {string | number | undefined | null | Boolean} condition when condition true will return query callback
49
- * @return {this} this
50
- */
51
- when(condition: string | number | undefined | null | Boolean, callback: Function): this;
52
- /**
53
- * if has 2 arguments default operator '='
54
- * @param {string} column
55
- * @param {string?} operator ['=', '<', '>' ,'!=', '!<', '!>' ,'LIKE']
56
- * @param {any?} value
57
- * @return {this}
58
- */
59
- resetWhere(): this;
60
- /**
61
- * if has 2 arguments default operator '='
62
- * @param {string} column
63
- * @param {string?} operator ['=', '<', '>' ,'!=', '!<', '!>' ,'LIKE']
64
- * @param {any?} value
65
- * @return {this}
66
- */
67
- where(column: string, operator?: any, value?: any): this;
68
- /**
69
- * where using object operator only '='
70
- * @param {Object} columns
71
- * @return {this}
72
- */
73
- whereObject(columns: {
74
- [key: string]: any;
75
- }): this;
76
- /**
77
- * if has 2 arguments default operator '='
78
- * @param {string} column
79
- * @param {string?} operator ['=', '<', '>' ,'!=', '!<', '!>' ,'LIKE']
80
- * @param {any?} value
81
- * @return {this}
82
- */
83
- orWhere(column: string, operator?: any, value?: any): this;
84
- /**
85
- *
86
- * @param {string} sql where column with raw sql
87
- * @return {this} this
88
- */
89
- whereRaw(sql: string): this;
90
- /**
91
- *
92
- * @param {string} query where column with raw sql
93
- * @return {this} this
94
- */
95
- orWhereRaw(sql: string): this;
96
- /**
97
- *
98
- * @param {string} tableAndLocalKey
99
- * @param {string?} tableAndForeignKey
100
- * @return {this}
101
- */
102
- protected whereReference(tableAndLocalKey: string, tableAndForeignKey?: any): this;
103
- /**
104
- *
105
- * where exists
106
- * @param {string} sql
107
- * @return {this}
108
- */
109
- whereExists(sql: string): this;
110
- /**
111
- *
112
- * @param {number} id
113
- * @param {string?} column custom it *if column is not id
114
- * @return {this} this
115
- */
116
- whereId(id: number, column?: string): this;
117
- /**
118
- *
119
- * @param {string} email where using email
120
- * @return {this}
121
- */
122
- whereEmail(email: string): this;
123
- /**
124
- *
125
- * @param {number} id
126
- * @param {string?} column custom it *if column is not user_id
127
- * @return {this}
128
- */
129
- whereUser(id: number, column?: string): this;
130
- /**
131
- * using array value where in value in array
132
- * @param {string} column
133
- * @param {array} array
134
- * @return {this}
135
- */
136
- whereIn(column: string, array: Array<any>): this;
137
- /**
138
- * or where in data using array values
139
- * @param {string} column
140
- * @param {array} array
141
- * @return {this}
142
- */
143
- orWhereIn(column: string, array: Array<any>): this;
144
- /**
145
- * where not in data using array values
146
- * @param {string} column
147
- * @param {array} array
148
- * @return {this}
149
- */
150
- whereNotIn(column: string, array: Array<any>): this;
151
- /**
152
- * where sub query using sub query sql
153
- * @param {string} column
154
- * @param {string} subQuery
155
- * @return {this}
156
- */
157
- whereSubQuery(column: string, subQuery: string): this;
158
- /**
159
- * where not sub query using sub query sql
160
- * @param {string} column
161
- * @param {string} subQuery
162
- * @return {this}
163
- */
164
- whereNotSubQuery(column: string, subQuery: string): this;
165
- /**
166
- * or where not sub query using query sql
167
- * @param {string} column
168
- * @param {string} subQuery
169
- * @return {this}
170
- */
171
- orWhereSubQuery(column: string, subQuery: string): this;
172
- /**
173
- * where between using [value1, value2]
174
- * @param {string} column
175
- * @param {array} array
176
- * @return {this}
177
- */
178
- whereBetween(column: string, array: Array<any>): this;
179
- /**
180
- * where null using NULL
181
- * @param {string} column
182
- * @return {this}
183
- */
184
- whereNull(column: string): this;
185
- /**
186
- * where not null using NULL
187
- * @param {string} column
188
- * @return {this}
189
- */
190
- whereNotNull(column: string): this;
191
- /**
192
- * where sensitive (uppercase, lowercase)
193
- * @param {string} column
194
- * @param {string?} operator = < > != !< !>
195
- * @param {any?} value
196
- * @return {this}
197
- */
198
- whereSensitive(column: string, operator?: any, value?: any): this;
199
- /**
200
- * where group query
201
- * @param {function} callback callback query
202
- * @return {this}
203
- */
204
- whereQuery(callback: Function): this;
205
- /**
206
- * select by cases
207
- * @param {array} cases array object [{ when : 'id < 7' , then : 'id is than under 7'}]
208
- * @param {string} as
209
- * @return {this}
210
- */
211
- case(cases: string | any[], as: string): this;
212
- /**
213
- *
214
- * @param {string} condition
215
- * @return {this}
216
- */
217
- having(condition: string): this;
218
- /**
219
- *
220
- * @param {string} pk talbe.pk
221
- * @param {string} fk talbe.fk
222
- * @return {this}
223
- */
224
- join(pk: string, fk: string): this;
225
- /**
226
- *
227
- * @param {string} pk talbe.pk
228
- * @param {string} fk talbe.fk
229
- * @return {this}
230
- */
231
- rightJoin(pk: string, fk: string): this;
232
- /**
233
- *
234
- * @param {string} pk talbe.pk
235
- * @param {string} fk talbe.fk
236
- * @return {this}
237
- */
238
- leftJoin(pk: string, fk: string): this;
239
- /**
240
- *
241
- * @param {string} pk talbe.pk
242
- * @param {string} fk talbe.fk
243
- * @return {this}
244
- */
245
- crossJoin(pk: string, fk: string): this;
246
- /**
247
- *
248
- * @param {string} column
249
- * @param {string?} order [order=asc] asc, desc
250
- * @return {this}
251
- */
252
- orderBy(column: string, order?: string | undefined): this;
253
- /**
254
- *
255
- * @param {string?} column [column=id]
256
- * @return {this}
257
- */
258
- latest(...columns: Array<string>): this;
259
- /**
260
- *
261
- * @param {string?} column [column=id]
262
- * @return {this}
263
- */
264
- oldest(...columns: Array<string>): this;
265
- /**
266
- *
267
- * @param {string?} column [column=id]
268
- * @return {this}
269
- */
270
- groupBy(...columns: Array<string>): this;
271
- /**
272
- *
273
- * @param {number=} number [number=1]
274
- * @return {this}
275
- */
276
- limit(number?: number): this;
277
- /**
278
- *
279
- * @param {number=} number [number=1]
280
- * @return {this}
281
- */
282
- offset(number?: number | undefined): this;
283
- /**
284
- *
285
- * @param {...string} columns
286
- * @return {this} this
287
- */
288
- hidden(...columns: Array<string>): this;
289
- /**
290
- *
291
- * update data in the database
292
- * @param {object} data
293
- * @return {this} this
294
- */
295
- update(data: object): this;
296
- /**
297
- *
298
- * insert data into the database
299
- * @param {object} data
300
- * @return {this} this
301
- */
302
- insert(data: object): this;
303
- /**
304
- *
305
- * insert data into the database
306
- * @param {object} data
307
- * @return {this} this
308
- */
309
- create(data: object): this;
310
- /**
311
- *
312
- * insert muliple data into the database
313
- * @param {array} data create multiple data
314
- * @return {this} this this
315
- */
316
- createMultiple(data: Array<any>): this;
317
- /**
318
- *
319
- * insert muliple data into the database
320
- * @param {array} data create multiple data
321
- * @return {this} this this
322
- */
323
- insertMultiple(data: Array<any>): this;
324
- /**
325
- *
326
- * @return {string} return sql query
327
- */
328
- toString(): string;
329
- /**
330
- *
331
- * @return {string} return sql query
332
- */
333
- toSQL(): string;
334
- /**
335
- *
336
- * @param {boolean} debug debug sql statements
337
- * @return {this} this this
338
- */
339
- debug(debug?: boolean): this;
340
- /**
341
- *
342
- * @param {boolean} debug debug sql statements
343
- * @return {this} this this
344
- */
345
- dd(debug?: boolean): this;
346
- /**
347
- * hook function when execute returned result to callback function
348
- * @param {Function} func function for callback result
349
- * @return {this}
350
- */
351
- hook(func: Function): this;
352
- /**
353
- *
354
- * @param {object} data create not exists data
355
- * @return {this} this this
356
- */
357
- createNotExists(data: object): this;
358
- /**
359
- *
360
- * @param {object} data insert not exists data
361
- * @return {this} this this
362
- */
363
- insertNotExists(data: object): this;
364
- /**
365
- *
366
- * check data if exists if exists then update. if not exists insert
367
- * @param {object} data insert or update data
368
- * @return {this} this this
369
- */
370
- updateOrCreate(data: object): this;
371
- /**
372
- *
373
- * check data if exists if exists then update. if not exists insert
374
- * @param {object} data insert or update data
375
- * @return {this} this this
376
- */
377
- updateOrInsert(data: object): this;
378
- /**
379
- *
380
- * check data if exists if exists then update. if not exists insert
381
- * @param {object} data insert or update data
382
- * @return {this} this this
383
- */
384
- insertOrUpdate(data: object): this;
385
- /**
386
- *
387
- * check data if exists if exists then update. if not exists insert
388
- * @param {object} data create or update data
389
- * @return {this} this this
390
- */
391
- createOrUpdate(data: object): this;
392
- /**
393
- *
394
- * @param {Object} options options for connection database with credentials
395
- * @param {string} option.host
396
- * @param {number} option.port
397
- * @param {string} option.database
398
- * @param {string} option.user
399
- * @param {string} option.password
400
- * @return {this} this
401
- */
402
- connection(options: ConnectionOptions): this;
403
- /**
404
- *
405
- * @param {Function} pool pool connection database
406
- * @return {this} this
407
- */
408
- pool(pool: Connection): this;
409
- /**
410
- * make sure this connection has same transaction in pool connection
411
- * @param {object} connection pool database
412
- * @return {this} this
413
- */
414
- bind(connection: Connection | ConnectionTransaction): this;
415
- /**
416
- * exceptColumns for method except
417
- * @return {promise<string>} string
418
- */
419
- exceptColumns(): Promise<string>;
420
- /**
421
- * execute sql statements with raw sql query
422
- * @param {string} sql sql execute return data
423
- * @return {promise<any>}
424
- */
425
- rawQuery(sql: string): Promise<any>;
426
- /**
427
- *
428
- * plus value then update
429
- * @param {string} column
430
- * @param {number} value
431
- * @return {promise<any>}
432
- */
433
- increment(column?: string, value?: number): Promise<any>;
434
- /**
435
- *
436
- * minus value then update
437
- * @param {string} column
438
- * @param {number} value
439
- * @return {promise<any>}
440
- */
441
- decrement(column?: string, value?: number): Promise<any>;
442
- /**
443
- * execute data without condition
444
- * @return {promise<any>}
445
- */
446
- all(): Promise<any>;
447
- /**
448
- *
449
- * execute data with where by id
450
- * @param {number} id
451
- * @return {promise<any>}
452
- */
453
- find(id: number): Promise<any>;
454
- /**
455
- *
456
- * execute data page & limit
457
- * @param {?object} paginationOptions
458
- * @param {number} paginationOptions.limit default 15
459
- * @param {number} paginationOptions.page default 1
460
- * @return {promise<Pagination>}
461
- */
462
- pagination(paginationOptions?: {
463
- limit?: number;
464
- page?: number;
465
- }): Promise<Pagination>;
466
- /**
467
- *
468
- * execute data useing page & limit
469
- * @param {?object} paginationOptions
470
- * @param {number} paginationOptions.limit
471
- * @param {number} paginationOptions.page
472
- * @return {promise<Pagination>}
473
- */
474
- paginate(paginationOptions?: {
475
- limit?: number;
476
- page?: number;
477
- }): Promise<Pagination>;
478
- /**
479
- *
480
- * execute data return object | null
481
- * @return {promise<object | null>}
482
- */
483
- first(): Promise<{
484
- [key: string]: any;
485
- } | null>;
486
- /**
487
- *
488
- * execute data return object | throw rror
489
- * @return {promise<object | null>}
490
- */
491
- findOne(): Promise<{
492
- [key: string]: any;
493
- } | null>;
494
- /**
495
- *
496
- * execute data return object | throw Error
497
- * @return {promise<object | Error>}
498
- */
499
- firstOrError(message: string, options?: {
500
- [key: string]: any;
501
- }): Promise<{
502
- [key: string]: any;
503
- }>;
504
- /**
505
- *
506
- * execute data return object | null
507
- * @return {promise<object | null>}
508
- */
509
- findOneOrError(message: string, options?: {
510
- [key: string]: any;
511
- }): Promise<{
512
- [key: string]: any;
513
- }>;
514
- /**
515
- *
516
- * execute data return Array
517
- * @return {promise<Array<any>>}
518
- */
519
- get(): Promise<Array<any>>;
520
- /**
521
- *
522
- * execute data return Array
523
- * @return {promise<Array<any>>}
524
- */
525
- findMany(): Promise<Array<any>>;
526
- /**
527
- *
528
- * execute data return json of result
529
- * @return {promise<string>}
530
- */
531
- toJSON(): Promise<string>;
532
- /**
533
- *
534
- * execute data return array of results
535
- * @param {string=} column [column=id]
536
- * @return {promise<Array>}
537
- */
538
- toArray(column?: string): Promise<Array<any>>;
539
- /**
540
- *
541
- * execute data return number of results
542
- * @param {string=} column [column=id]
543
- * @return {promise<number>}
544
- */
545
- count(column?: string): Promise<number>;
546
- /**
547
- *
548
- * execute data return result is exists
549
- * @return {promise<boolean>}
550
- */
551
- exists(): Promise<boolean>;
552
- /**
553
- *
554
- * execute data return average of results
555
- * @param {string=} column [column=id]
556
- * @return {promise<number>}
557
- */
558
- avg(column?: string): Promise<number>;
559
- /**
560
- *
561
- * execute data return summary of results
562
- * @param {string=} column [column=id]
563
- * @return {promise<number>}
564
- */
565
- sum(column?: string): Promise<number>;
566
- /**
567
- *
568
- * execute data return maximum of results
569
- * @param {string=} column [column=id]
570
- * @return {promise<number>}
571
- */
572
- max(column?: string): Promise<number>;
573
- /**
574
- *
575
- * execute data return minimum of results
576
- * @param {string=} column [column=id]
577
- * @return {promise<number>}
578
- */
579
- min(column?: string): Promise<number>;
580
- /**
581
- *
582
- * delete data from database
583
- * @return {promise<boolean>}
584
- */
585
- delete(): Promise<boolean>;
586
- /**
587
- *
588
- * delete data from database ignore where condition
589
- * @return {promise<boolean>}
590
- */
591
- forceDelete(): Promise<boolean>;
592
- /**
593
- *
594
- * execute data return Array *grouping results in column
595
- * @param {string} column
596
- * @return {promise<Array>}
597
- */
598
- getGroupBy(column: string): Promise<Array<any>>;
599
- /**
600
- *
601
- * execute data return grouping results by index
602
- * @param {string} column
603
- * @return {promise<Array>}
604
- */
605
- findManyGroupBy(column: string): Promise<Array<any>>;
606
- /**
607
- * execute data when save *action [insert , update]
608
- * @return {Promise<any>} promise
609
- */
610
- save(): Promise<{
611
- [key: string]: any;
612
- } | Array<any> | null | undefined>;
613
- /**
614
- *
615
- * show columns in table
616
- * @param {string=} table table name
617
- * @return {Promise<Array>}
618
- */
619
- showColumns(table?: string): Promise<Array<string>>;
620
- /**
621
- *
622
- * show schemas in table
623
- * @param {string=} table [table= current table name]
624
- * @return {Promise<Array>}
625
- */
626
- showSchemas(table?: string): Promise<Array<string>>;
627
- /**
628
- *
629
- * show values in table
630
- * @param {string=} table table name
631
- * @return {Promise<Array>}
632
- */
633
- showValues(table?: string): Promise<Array<string>>;
634
- /**
635
- *
636
- * backup this database intro new database same server or to another server
637
- * @param {Object} backupOptions
638
- * @param {string} backup.database
639
- * @param {object?} backup.to
640
- * @param {string} backup.to.host
641
- * @param {number} backup.to.port
642
- * @param {string} backup.to.database
643
- * @param {string} backup.to.username
644
- * @param {string} backup.to.password
645
-
646
- * @return {Promise<boolean>}
647
- */
648
- backup({ database, to }: Backup): Promise<boolean>;
649
- /**
650
- *
651
- * backup database intro file
652
- * @param {Object} backupOptions
653
- * @param {string} backup.database
654
- * @param {object?} backup.filePath
655
- * @param {object?} backup.connection
656
- * @param {string} backup.connection.host
657
- * @param {number} backup.connection.port
658
- * @param {string} backup.connection.database
659
- * @param {string} backup.connection.username
660
- * @param {string} backup.connection.password
661
-
662
- * @return {Promise<boolean>}
663
- */
664
- backupToFile({ filePath, database, connection }: BackupToFile): Promise<void>;
665
- /**
666
- *
667
- * fake data
668
- * @param {number} rows number of rows
669
- * @return {promise<any>}
670
- */
671
- faker(rows?: number): Promise<any>;
672
- /**
673
- *
674
- * truncate of table
675
- * @return {promise<boolean>}
676
- */
677
- truncate(): Promise<boolean>;
678
- /**
679
- *
680
- * drop of table
681
- * @return {promise<boolean>}
682
- */
683
- drop(): Promise<boolean>;
684
- private _queryWhereIsExists;
685
- private _bindTableAndColumnInQueryWhere;
686
- private _insertNotExists;
687
- protected queryStatement(sql: string): Promise<Array<any>>;
688
- protected actionStatement({ sql, returnId }: {
689
- sql: string;
690
- returnId?: boolean;
691
- }): Promise<any>;
692
- private _create;
693
- private _createMultiple;
694
- private _updateOrInsert;
695
- private _update;
696
- private _hiddenColumn;
697
- private _queryUpdate;
698
- private _queryInsert;
699
- private _queryInsertMultiple;
700
- private _valueAndOperator;
701
- private _valueTrueFalse;
702
- private _buildQuery;
703
- private _initialConnection;
704
- }
705
- export { Database };
706
- export default Database;
1
+ import { AbstractBuilder } from './AbstractBuilder';
2
+ import { Pagination, Backup, ConnectionOptions, BackupToFile, Connection, ConnectionTransaction } from './Interface';
3
+ declare class Builder extends AbstractBuilder {
4
+ constructor();
5
+ /**
6
+ *
7
+ * @param {string} column
8
+ * @return {this}
9
+ */
10
+ pluck(column: string): this;
11
+ /**
12
+ *
13
+ * @param {...string} columns
14
+ * @return {this} this
15
+ */
16
+ except(...columns: Array<string>): this;
17
+ /**
18
+ * data alaways will return void
19
+ * @return {this} this
20
+ */
21
+ void(): this;
22
+ /**
23
+ *
24
+ * @param {...string} columns show only colums selected
25
+ * @return {this} this
26
+ */
27
+ only(...columns: Array<string>): this;
28
+ /**
29
+ *
30
+ * @param {string=} column [column=id]
31
+ * @return {this} this
32
+ */
33
+ distinct(column?: string): this;
34
+ /**
35
+ * select data form table
36
+ * @param {Array<string>} ...columns
37
+ * @return {this} this
38
+ */
39
+ select(...columns: Array<string>): this;
40
+ selectRaw(...columns: Array<string>): this;
41
+ /**
42
+ * chunks data from array
43
+ * @param {number} chunk
44
+ * @return {this} this
45
+ */
46
+ chunk(chunk: number): this;
47
+ /**
48
+ *
49
+ * @param {string | number | undefined | null | Boolean} condition when condition true will return query callback
50
+ * @return {this} this
51
+ */
52
+ when(condition: string | number | undefined | null | Boolean, callback: Function): this;
53
+ /**
54
+ * if has 2 arguments default operator '='
55
+ * @param {string} column if arguments is object
56
+ * @param {string?} operator ['=', '<', '>' ,'!=', '!<', '!>' ,'LIKE']
57
+ * @param {any?} value
58
+ * @return {this}
59
+ */
60
+ where(column: string | any, operator?: any, value?: any): this;
61
+ /**
62
+ * where using object operator only '='
63
+ * @param {Object} columns
64
+ * @return {this}
65
+ */
66
+ whereObject(columns: {
67
+ [key: string]: any;
68
+ }): this;
69
+ /**
70
+ * if has 2 arguments default operator '='
71
+ * @param {string} column
72
+ * @param {string?} operator ['=', '<', '>' ,'!=', '!<', '!>' ,'LIKE']
73
+ * @param {any?} value
74
+ * @return {this}
75
+ */
76
+ orWhere(column: string, operator?: any, value?: any): this;
77
+ /**
78
+ *
79
+ * @param {string} sql where column with raw sql
80
+ * @return {this} this
81
+ */
82
+ whereRaw(sql: string): this;
83
+ /**
84
+ *
85
+ * @param {string} query where column with raw sql
86
+ * @return {this} this
87
+ */
88
+ orWhereRaw(sql: string): this;
89
+ /**
90
+ *
91
+ * @param {string} tableAndLocalKey
92
+ * @param {string?} tableAndForeignKey
93
+ * @return {this}
94
+ */
95
+ protected whereReference(tableAndLocalKey: string, tableAndForeignKey?: any): this;
96
+ /**
97
+ *
98
+ * where exists
99
+ * @param {string} sql
100
+ * @return {this}
101
+ */
102
+ whereExists(sql: string): this;
103
+ /**
104
+ *
105
+ * @param {number} id
106
+ * @return {this} this
107
+ */
108
+ whereId(id: number, column?: string): this;
109
+ /**
110
+ *
111
+ * @param {string} email where using email
112
+ * @return {this}
113
+ */
114
+ whereEmail(email: string): this;
115
+ /**
116
+ *
117
+ * @param {number} userId
118
+ * @param {string?} column custom it *if column is not user_id
119
+ * @return {this}
120
+ */
121
+ whereUser(userId: number, column?: string): this;
122
+ /**
123
+ * using array value where in value in array
124
+ * @param {string} column
125
+ * @param {array} array
126
+ * @return {this}
127
+ */
128
+ whereIn(column: string, array: Array<any>): this;
129
+ /**
130
+ * or where in data using array values
131
+ * @param {string} column
132
+ * @param {array} array
133
+ * @return {this}
134
+ */
135
+ orWhereIn(column: string, array: Array<any>): this;
136
+ /**
137
+ * where not in data using array values
138
+ * @param {string} column
139
+ * @param {array} array
140
+ * @return {this}
141
+ */
142
+ whereNotIn(column: string, array: Array<any>): this;
143
+ /**
144
+ * where not in data using array values
145
+ * @param {string} column
146
+ * @param {array} array
147
+ * @return {this}
148
+ */
149
+ orWhereNotIn(column: string, array: Array<any>): this;
150
+ /**
151
+ * where sub query using sub query sql
152
+ * @param {string} column
153
+ * @param {string} subQuery
154
+ * @return {this}
155
+ */
156
+ whereSubQuery(column: string, subQuery: string): this;
157
+ /**
158
+ * where not sub query using sub query sql
159
+ * @param {string} column
160
+ * @param {string} subQuery
161
+ * @return {this}
162
+ */
163
+ whereNotSubQuery(column: string, subQuery: string): this;
164
+ /**
165
+ * or where not sub query using query sql
166
+ * @param {string} column
167
+ * @param {string} subQuery
168
+ * @return {this}
169
+ */
170
+ orWhereSubQuery(column: string, subQuery: string): this;
171
+ /**
172
+ * or where not sub query using query sql
173
+ * @param {string} column
174
+ * @param {string} subQuery
175
+ * @return {this}
176
+ */
177
+ orWhereNotSubQuery(column: string, subQuery: string): this;
178
+ /**
179
+ * where between using [value1, value2]
180
+ * @param {string} column
181
+ * @param {array} array
182
+ * @return {this}
183
+ */
184
+ whereBetween(column: string, array: Array<any>): this;
185
+ /**
186
+ * where null using NULL
187
+ * @param {string} column
188
+ * @return {this}
189
+ */
190
+ whereNull(column: string): this;
191
+ /**
192
+ * where not null using NULL
193
+ * @param {string} column
194
+ * @return {this}
195
+ */
196
+ whereNotNull(column: string): this;
197
+ /**
198
+ * where sensitive (uppercase, lowercase)
199
+ * @param {string} column
200
+ * @param {string?} operator = < > != !< !>
201
+ * @param {any?} value
202
+ * @return {this}
203
+ */
204
+ whereSensitive(column: string, operator?: any, value?: any): this;
205
+ /**
206
+ * where Strict (uppercase, lowercase)
207
+ * @param {string} column
208
+ * @param {string?} operator = < > != !< !>
209
+ * @param {any?} value
210
+ * @return {this}
211
+ */
212
+ whereStrict(column: string, operator?: any, value?: any): this;
213
+ /**
214
+ * where group query
215
+ * @param {function} callback callback query
216
+ * @return {this}
217
+ */
218
+ whereQuery(callback: Function): this;
219
+ /**
220
+ * select by cases
221
+ * @param {array} cases array object [{ when : 'id < 7' , then : 'id is than under 7'}]
222
+ * @param {string} as
223
+ * @return {this}
224
+ */
225
+ case(cases: string | any[], as: string): this;
226
+ /**
227
+ *
228
+ * @param {string} pk talbe.pk
229
+ * @param {string} fk talbe.fk
230
+ * @return {this}
231
+ */
232
+ join(pk: string, fk: string): this;
233
+ /**
234
+ *
235
+ * @param {string} pk talbe.pk
236
+ * @param {string} fk talbe.fk
237
+ * @return {this}
238
+ */
239
+ rightJoin(pk: string, fk: string): this;
240
+ /**
241
+ *
242
+ * @param {string} pk talbe.pk
243
+ * @param {string} fk talbe.fk
244
+ * @return {this}
245
+ */
246
+ leftJoin(pk: string, fk: string): this;
247
+ /**
248
+ *
249
+ * @param {string} pk talbe.pk
250
+ * @param {string} fk talbe.fk
251
+ * @return {this}
252
+ */
253
+ crossJoin(pk: string, fk: string): this;
254
+ /**
255
+ * sort the result in ASC or DESC order.
256
+ * @param {string} column
257
+ * @param {string?} order [order=asc] asc, desc
258
+ * @return {this}
259
+ */
260
+ orderBy(column: string, order?: string | undefined): this;
261
+ /**
262
+ * sort the result in ASC or DESC order. can using with raw query
263
+ * @param {string} column
264
+ * @param {string?} order [order=asc] asc, desc
265
+ * @return {this}
266
+ */
267
+ orderByRaw(column: string, order?: string | undefined): this;
268
+ /**
269
+ * sort the result in using DESC for order by.
270
+ * @param {string?} columns [column=id]
271
+ * @return {this}
272
+ */
273
+ latest(...columns: Array<string>): this;
274
+ /**
275
+ * sort the result in using DESC for order by. can using with raw query
276
+ * @param {string?} columns [column=id]
277
+ * @return {this}
278
+ */
279
+ latestRaw(...columns: Array<string>): this;
280
+ /**
281
+ * sort the result in using ASC for order by.
282
+ * @param {string?} columns [column=id]
283
+ * @return {this}
284
+ */
285
+ oldest(...columns: Array<string>): this;
286
+ /**
287
+ * sort the result in using ASC for order by. can using with raw query
288
+ * @param {string?} columns [column=id]
289
+ * @return {this}
290
+ */
291
+ oldestRaw(...columns: Array<string>): this;
292
+ /**
293
+ *
294
+ * @param {string?} columns [column=id]
295
+ * @return {this}
296
+ */
297
+ groupBy(...columns: Array<string>): this;
298
+ /**
299
+ *
300
+ * @param {string?} columns [column=id]
301
+ * @return {this}
302
+ */
303
+ groupByRaw(...columns: Array<string>): this;
304
+ /**
305
+ *
306
+ * @param {string} condition
307
+ * @return {this}
308
+ */
309
+ having(condition: string): this;
310
+ /**
311
+ *
312
+ * @param {string} condition
313
+ * @return {this}
314
+ */
315
+ havingRaw(condition: string): this;
316
+ /**
317
+ * sort the result in random order.
318
+ * @return {this}
319
+ */
320
+ random(): this;
321
+ /**
322
+ * sort the result in random order.
323
+ * @return {this}
324
+ */
325
+ inRandom(): this;
326
+ /**
327
+ * limit data
328
+ * @param {number=} number [number=1]
329
+ * @return {this}
330
+ */
331
+ limit(number?: number): this;
332
+ /**
333
+ * limit data
334
+ * @param {number=} number [number=1]
335
+ * @return {this}
336
+ */
337
+ take(number?: number): this;
338
+ /**
339
+ *
340
+ * @param {number=} number [number=1]
341
+ * @return {this}
342
+ */
343
+ offset(number?: number): this;
344
+ /**
345
+ *
346
+ * @param {number=} number [number=1]
347
+ * @return {this}
348
+ */
349
+ skip(number?: number): this;
350
+ /**
351
+ *
352
+ * @param {...string} columns
353
+ * @return {this} this
354
+ */
355
+ hidden(...columns: Array<string>): this;
356
+ /**
357
+ *
358
+ * update data in the database
359
+ * @param {object} data
360
+ * @return {this} this
361
+ */
362
+ update(data: {
363
+ [key: string]: any;
364
+ } & {
365
+ length?: unknown;
366
+ }): this;
367
+ /**
368
+ *
369
+ * insert data into the database
370
+ * @param {object} data
371
+ * @return {this} this
372
+ */
373
+ insert(data: {
374
+ [key: string]: any;
375
+ } & {
376
+ length?: unknown;
377
+ }): this;
378
+ /**
379
+ *
380
+ * insert data into the database
381
+ * @param {object} data
382
+ * @return {this} this
383
+ */
384
+ create(data: {
385
+ [key: string]: any;
386
+ } & {
387
+ length?: unknown;
388
+ }): this;
389
+ /**
390
+ *
391
+ * insert muliple data into the database
392
+ * @param {array} data create multiple data
393
+ * @return {this} this this
394
+ */
395
+ createMultiple(data: Array<any>): this;
396
+ /**
397
+ *
398
+ * insert muliple data into the database
399
+ * @param {array} data create multiple data
400
+ * @return {this} this this
401
+ */
402
+ insertMultiple(data: Array<any>): this;
403
+ /**
404
+ *
405
+ * @return {string} return sql query
406
+ */
407
+ toString(): string;
408
+ /**
409
+ *
410
+ * @return {string} return sql query
411
+ */
412
+ toSQL(): string;
413
+ /**
414
+ *
415
+ * @param {boolean} debug debug sql statements
416
+ * @return {this} this this
417
+ */
418
+ debug(debug?: boolean): this;
419
+ /**
420
+ *
421
+ * @param {boolean} debug debug sql statements
422
+ * @return {this} this this
423
+ */
424
+ dd(debug?: boolean): this;
425
+ /**
426
+ * hook function when execute returned result to callback function
427
+ * @param {Function} func function for callback result
428
+ * @return {this}
429
+ */
430
+ hook(func: Function): this;
431
+ /**
432
+ * hook function when execute returned result to callback function
433
+ * @param {Function} func function for callback result
434
+ * @return {this}
435
+ */
436
+ before(func: Function): this;
437
+ /**
438
+ *
439
+ * @param {object} data create not exists data
440
+ * @return {this} this this
441
+ */
442
+ createNotExists(data: {
443
+ [key: string]: any;
444
+ } & {
445
+ length?: unknown;
446
+ }): this;
447
+ /**
448
+ *
449
+ * @param {object} data insert not exists data
450
+ * @return {this} this this
451
+ */
452
+ insertNotExists(data: Record<string, any> & {
453
+ length?: never;
454
+ }): this;
455
+ /**
456
+ *
457
+ * check data if exists if exists then return result. if not exists insert data
458
+ * @param {object} data insert data
459
+ * @return {this} this this
460
+ */
461
+ createOrSelect(data: Record<string, any> & {
462
+ length?: never;
463
+ }): this;
464
+ /**
465
+ *
466
+ * check data if exists if exists then update. if not exists insert
467
+ * @param {object} data insert or update data
468
+ * @return {this} this this
469
+ */
470
+ insertOrSelect(data: Record<string, any> & {
471
+ length?: never;
472
+ }): this;
473
+ /**
474
+ *
475
+ * check data if exists if exists then update. if not exists insert
476
+ * @param {object} data insert or update data
477
+ * @return {this} this this
478
+ */
479
+ updateOrCreate(data: Record<string, any> & {
480
+ length?: never;
481
+ }): this;
482
+ /**
483
+ *
484
+ * check data if exists if exists then update. if not exists insert
485
+ * @param {object} data insert or update data
486
+ * @return {this} this this
487
+ */
488
+ updateOrInsert(data: Record<string, any> & {
489
+ length?: never;
490
+ }): this;
491
+ /**
492
+ *
493
+ * check data if exists if exists then update. if not exists insert
494
+ * @param {object} data insert or update data
495
+ * @return {this} this this
496
+ */
497
+ insertOrUpdate(data: Record<string, any> & {
498
+ length?: never;
499
+ }): this;
500
+ /**
501
+ *
502
+ * check data if exists if exists then update. if not exists insert
503
+ * @param {object} data create or update data
504
+ * @return {this} this this
505
+ */
506
+ createOrUpdate(data: Record<string, any> & {
507
+ length?: never;
508
+ }): this;
509
+ /**
510
+ *
511
+ * @param {Object} options options for connection database with credentials
512
+ * @param {string} option.host
513
+ * @param {number} option.port
514
+ * @param {string} option.database
515
+ * @param {string} option.user
516
+ * @param {string} option.password
517
+ * @return {this} this
518
+ */
519
+ connection(options: ConnectionOptions): this;
520
+ /**
521
+ *
522
+ * @param {Function} pool pool connection database
523
+ * @return {this} this
524
+ */
525
+ pool(pool: Connection): this;
526
+ /**
527
+ * make sure this connection has same transaction in pool connection
528
+ * @param {object} connection pool database
529
+ * @return {this} this
530
+ */
531
+ bind(connection: Connection | ConnectionTransaction): this;
532
+ /**
533
+ * exceptColumns for method except
534
+ * @return {promise<string>} string
535
+ */
536
+ protected exceptColumns(): Promise<string>;
537
+ /**
538
+ * execute sql statements with raw sql query
539
+ * @param {string} sql sql execute return data
540
+ * @return {promise<any>}
541
+ */
542
+ rawQuery(sql: string): Promise<any>;
543
+ /**
544
+ *
545
+ * plus value then update
546
+ * @param {string} column
547
+ * @param {number} value
548
+ * @return {promise<any>}
549
+ */
550
+ increment(column?: string, value?: number): Promise<any>;
551
+ /**
552
+ *
553
+ * minus value then update
554
+ * @param {string} column
555
+ * @param {number} value
556
+ * @return {promise<any>}
557
+ */
558
+ decrement(column?: string, value?: number): Promise<any>;
559
+ /**
560
+ * execute data without condition
561
+ * @return {promise<any>}
562
+ */
563
+ all(): Promise<any>;
564
+ /**
565
+ *
566
+ * execute data with where by primary key default = id
567
+ * @param {number} id
568
+ * @return {promise<any>}
569
+ */
570
+ find(id: number): Promise<Record<string, any> | null>;
571
+ /**
572
+ *
573
+ * execute data page & limit
574
+ * @param {?object} paginationOptions
575
+ * @param {number} paginationOptions.limit default 15
576
+ * @param {number} paginationOptions.page default 1
577
+ * @return {promise<Pagination>}
578
+ */
579
+ pagination(paginationOptions?: {
580
+ limit?: number;
581
+ page?: number;
582
+ }): Promise<Pagination>;
583
+ /**
584
+ *
585
+ * execute data useing page & limit
586
+ * @param {?object} paginationOptions
587
+ * @param {number} paginationOptions.limit
588
+ * @param {number} paginationOptions.page
589
+ * @return {promise<Pagination>}
590
+ */
591
+ paginate(paginationOptions?: {
592
+ limit?: number;
593
+ page?: number;
594
+ }): Promise<Pagination>;
595
+ /**
596
+ *
597
+ * execute data return object | null
598
+ * @return {promise<object | null>}
599
+ */
600
+ first(): Promise<{
601
+ [key: string]: any;
602
+ } | null>;
603
+ /**
604
+ *
605
+ * execute data return object | throw rror
606
+ * @return {promise<object | null>}
607
+ */
608
+ findOne(): Promise<{
609
+ [key: string]: any;
610
+ } | null>;
611
+ /**
612
+ *
613
+ * execute data return object | throw Error
614
+ * @return {promise<object | Error>}
615
+ */
616
+ firstOrError(message: string, options?: {
617
+ [key: string]: any;
618
+ }): Promise<{
619
+ [key: string]: any;
620
+ }>;
621
+ /**
622
+ *
623
+ * execute data return object | null
624
+ * @return {promise<object | null>}
625
+ */
626
+ findOneOrError(message: string, options?: {
627
+ [key: string]: any;
628
+ }): Promise<{
629
+ [key: string]: any;
630
+ }>;
631
+ /**
632
+ *
633
+ * execute data return Array
634
+ * @return {promise<Array<any>>}
635
+ */
636
+ get(): Promise<Array<any>>;
637
+ /**
638
+ *
639
+ * execute data return Array
640
+ * @return {promise<Array<any>>}
641
+ */
642
+ findMany(): Promise<Array<any>>;
643
+ /**
644
+ *
645
+ * execute data return json of result
646
+ * @return {promise<string>}
647
+ */
648
+ toJSON(): Promise<string>;
649
+ /**
650
+ *
651
+ * execute data return array of results
652
+ * @param {string=} column [column=id]
653
+ * @return {promise<Array>}
654
+ */
655
+ toArray(column?: string): Promise<Array<any>>;
656
+ /**
657
+ *
658
+ * execute data return number of results
659
+ * @param {string=} column [column=id]
660
+ * @return {promise<number>}
661
+ */
662
+ count(column?: string): Promise<number>;
663
+ /**
664
+ *
665
+ * execute data return result is exists
666
+ * @return {promise<boolean>}
667
+ */
668
+ exists(): Promise<boolean>;
669
+ /**
670
+ *
671
+ * execute data return average of results
672
+ * @param {string=} column [column=id]
673
+ * @return {promise<number>}
674
+ */
675
+ avg(column?: string): Promise<number>;
676
+ /**
677
+ *
678
+ * execute data return summary of results
679
+ * @param {string=} column [column=id]
680
+ * @return {promise<number>}
681
+ */
682
+ sum(column?: string): Promise<number>;
683
+ /**
684
+ *
685
+ * execute data return maximum of results
686
+ * @param {string=} column [column=id]
687
+ * @return {promise<number>}
688
+ */
689
+ max(column?: string): Promise<number>;
690
+ /**
691
+ *
692
+ * execute data return minimum of results
693
+ * @param {string=} column [column=id]
694
+ * @return {promise<number>}
695
+ */
696
+ min(column?: string): Promise<number>;
697
+ /**
698
+ *
699
+ * delete data from database
700
+ * @return {promise<boolean>}
701
+ */
702
+ delete(): Promise<boolean>;
703
+ /**
704
+ *
705
+ * delete data from database ignore where condition
706
+ * @return {promise<boolean>}
707
+ */
708
+ forceDelete(): Promise<boolean>;
709
+ /**
710
+ *
711
+ * execute data return Array *grouping results in column
712
+ * @param {string} column
713
+ * @return {promise<Array>}
714
+ */
715
+ getGroupBy(column: string): Promise<Array<any>>;
716
+ /**
717
+ *
718
+ * execute data return grouping results by index
719
+ * @param {string} column
720
+ * @return {promise<Array>}
721
+ */
722
+ findManyGroupBy(column: string): Promise<Array<any>>;
723
+ /**
724
+ * execute data when save *action [insert , update]
725
+ * @return {Promise<any>} promise
726
+ */
727
+ save(): Promise<{
728
+ [key: string]: any;
729
+ } | Array<any> | null | undefined>;
730
+ /**
731
+ *
732
+ * show columns in table
733
+ * @param {string=} table table name
734
+ * @return {Promise<Array>}
735
+ */
736
+ showColumns(table?: string): Promise<Array<string>>;
737
+ /**
738
+ *
739
+ * show schemas in table
740
+ * @param {string=} table [table= current table name]
741
+ * @return {Promise<Array>}
742
+ */
743
+ showSchemas(table?: string): Promise<Array<string>>;
744
+ /**
745
+ *
746
+ * show values in table
747
+ * @param {string=} table table name
748
+ * @return {Promise<Array>}
749
+ */
750
+ showValues(table?: string): Promise<Array<string>>;
751
+ /**
752
+ *
753
+ * backup this database intro new database same server or to another server
754
+ * @param {Object} backupOptions
755
+ * @param {string} backup.database
756
+ * @param {object?} backup.to
757
+ * @param {string} backup.to.host
758
+ * @param {number} backup.to.port
759
+ * @param {string} backup.to.database
760
+ * @param {string} backup.to.username
761
+ * @param {string} backup.to.password
762
+
763
+ * @return {Promise<boolean>}
764
+ */
765
+ backup({ database, to }: Backup): Promise<boolean>;
766
+ /**
767
+ *
768
+ * backup database intro file
769
+ * @param {Object} backupOptions
770
+ * @param {string} backup.database
771
+ * @param {object?} backup.filePath
772
+ * @param {object?} backup.connection
773
+ * @param {string} backup.connection.host
774
+ * @param {number} backup.connection.port
775
+ * @param {string} backup.connection.database
776
+ * @param {string} backup.connection.username
777
+ * @param {string} backup.connection.password
778
+
779
+ * @return {Promise<boolean>}
780
+ */
781
+ backupToFile({ filePath, database, connection }: BackupToFile): Promise<void>;
782
+ /**
783
+ *
784
+ * fake data
785
+ * @param {number} rows number of rows
786
+ * @return {promise<any>}
787
+ */
788
+ faker(rows?: number): Promise<any>;
789
+ /**
790
+ *
791
+ * truncate of table
792
+ * @return {promise<boolean>}
793
+ */
794
+ truncate(): Promise<boolean>;
795
+ /**
796
+ *
797
+ * drop of table
798
+ * @return {promise<boolean>}
799
+ */
800
+ drop(): Promise<boolean>;
801
+ private _queryWhereIsExists;
802
+ private _bindTableAndColumnInQueryWhere;
803
+ private _insertNotExists;
804
+ protected queryStatement(sql: string): Promise<Array<any>>;
805
+ protected actionStatement({ sql, returnId }: {
806
+ sql: string;
807
+ returnId?: boolean;
808
+ }): Promise<any>;
809
+ private _insert;
810
+ private _checkValueHasRaw;
811
+ private _insertMultiple;
812
+ private _insertOrSelect;
813
+ private _updateOrInsert;
814
+ private _update;
815
+ private _hiddenColumn;
816
+ private _queryUpdate;
817
+ private _queryInsert;
818
+ private _queryInsertMultiple;
819
+ private _valueAndOperator;
820
+ private _valueTrueFalse;
821
+ private _buildQuery;
822
+ private _initialConnection;
823
+ }
824
+ export { Builder };
825
+ export default Builder;