tspace-mysql 1.1.2 → 1.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.
@@ -1,5 +1,6 @@
1
1
  import AbstractDatabase from './AbstractDatabase';
2
- import { Pagination, Backup, Transaction, ConnectionOptions, BackupToFile } from './Interface';
2
+ import { Connection, ConnectionTransaction } from '../connection';
3
+ import { Pagination, Backup, ConnectionOptions, BackupToFile } from './Interface';
3
4
  declare class Database extends AbstractDatabase {
4
5
  constructor();
5
6
  /**
@@ -13,13 +14,13 @@ declare class Database extends AbstractDatabase {
13
14
  * @param {...string} columns
14
15
  * @return {this} this
15
16
  */
16
- except(...columns: string[]): this;
17
+ except(...columns: Array<string>): this;
17
18
  /**
18
19
  *
19
20
  * @param {...string} columns show only colums selected
20
21
  * @return {this} this
21
22
  */
22
- only(...columns: string[]): this;
23
+ only(...columns: Array<string>): this;
23
24
  /**
24
25
  *
25
26
  * @param {string=} column [column=id]
@@ -28,10 +29,10 @@ declare class Database extends AbstractDatabase {
28
29
  distinct(column?: string): this;
29
30
  /**
30
31
  *
31
- * @param {string[]} ...columns
32
+ * @param {Array<string>} ...columns
32
33
  * @return {this} this
33
34
  */
34
- select(...columns: string[]): this;
35
+ select(...columns: Array<string>): this;
35
36
  /**
36
37
  *
37
38
  * @param {number} chunk
@@ -62,10 +63,30 @@ declare class Database extends AbstractDatabase {
62
63
  orWhere(column: string, operator?: any, value?: any): this;
63
64
  /**
64
65
  *
65
- * @param {string} query where column with raw sql
66
+ * @param {string} sql where column with raw sql
66
67
  * @return {this} this
67
68
  */
68
69
  whereRaw(sql: string): this;
70
+ /**
71
+ *
72
+ * @param {string} query where column with raw sql
73
+ * @return {this} this
74
+ */
75
+ orWhereRaw(sql: string): this;
76
+ /**
77
+ *
78
+ * @param {string} tableAndLocalKey
79
+ * @param {string?} tableAndForeignKey
80
+ * @return {this}
81
+ */
82
+ whereReference(tableAndLocalKey: string, tableAndForeignKey?: any): this;
83
+ /**
84
+ *
85
+ * where exists
86
+ * @param {string} sql
87
+ * @return {this}
88
+ */
89
+ whereExists(sql: string): this;
69
90
  /**
70
91
  *
71
92
  * @param {number} id
@@ -156,37 +177,18 @@ declare class Database extends AbstractDatabase {
156
177
  */
157
178
  whereSensitive(column: string, operator?: any, value?: any): this;
158
179
  /**
159
- * where grouping of start statements
160
- * @param {string} column
161
- * @param {string?} operator = < > != !< !>
162
- * @param {any?} value
163
- * @return {this}
164
- */
165
- whereGroupStart(column: string, operator?: any, value?: any): this;
166
- /**
167
- * or where grouping of start statements
168
- * @param {string} column
169
- * @param {string?} operator = < > != !< !>
170
- * @param {any?} value
180
+ * where group query
181
+ * @param {function} callback callback query
171
182
  * @return {this}
172
183
  */
173
- orWhereGroupStart(column: string, operator?: any, value?: any): this;
184
+ whereQuery(callback: Function): this;
174
185
  /**
175
- * where grouping of end statements
176
- * @param {string} column
177
- * @param {string?} operator = < > != !< !>
178
- * @param {any?} value
179
- * @return {this}
180
- */
181
- whereGroupEnd(column: string, operator?: any, value?: any): this;
182
- /**
183
- * where grouping of end statements
184
- * @param {string} column
185
- * @param {string?} operator = < > != !< !>
186
- * @param {any?} value
186
+ * select by cases
187
+ * @param {array} cases array object [{ when : 'id < 7' , then : 'id is than under 7'}]
188
+ * @param {string} as
187
189
  * @return {this}
188
190
  */
189
- orWhereGroupEnd(column: string, operator?: any, value?: any): this;
191
+ case(cases: string | any[], as: string): this;
190
192
  /**
191
193
  *
192
194
  * @param {string} condition
@@ -224,25 +226,25 @@ declare class Database extends AbstractDatabase {
224
226
  /**
225
227
  *
226
228
  * @param {string} column
227
- * @param {string=} order [order=asc] asc, desc
229
+ * @param {string?} order [order=asc] asc, desc
228
230
  * @return {this}
229
231
  */
230
232
  orderBy(column: string, order?: string | undefined): this;
231
233
  /**
232
234
  *
233
- * @param {string=} column [column=id]
235
+ * @param {string?} column [column=id]
234
236
  * @return {this}
235
237
  */
236
238
  latest(column?: string): this;
237
239
  /**
238
240
  *
239
- * @param {string=} column [column=id]
241
+ * @param {string?} column [column=id]
240
242
  * @return {this}
241
243
  */
242
244
  oldest(column?: string): this;
243
245
  /**
244
246
  *
245
- * @param {string=} column [column=id]
247
+ * @param {string?} column [column=id]
246
248
  * @return {this}
247
249
  */
248
250
  groupBy(column?: string): this;
@@ -257,13 +259,13 @@ declare class Database extends AbstractDatabase {
257
259
  * @param {number=} number [number=1]
258
260
  * @return {this}
259
261
  */
260
- offset(number?: number): this;
262
+ offset(number?: number | undefined): this;
261
263
  /**
262
264
  *
263
265
  * @param {...string} columns
264
266
  * @return {this} this
265
267
  */
266
- hidden(...columns: string[]): this;
268
+ hidden(...columns: Array<string>): this;
267
269
  /**
268
270
  *
269
271
  * update data in the database
@@ -372,6 +374,18 @@ declare class Database extends AbstractDatabase {
372
374
  * @return {this} this
373
375
  */
374
376
  connection(options: ConnectionOptions): this;
377
+ /**
378
+ *
379
+ * @param {Function} pool pool connection database
380
+ * @return {this} this
381
+ */
382
+ pool(pool: Connection): this;
383
+ /**
384
+ *
385
+ * @param {object} connection pool database
386
+ * @return {this} this
387
+ */
388
+ bind(connection: Connection | ConnectionTransaction): this;
375
389
  /**
376
390
  * execute sql statements with raw sql query
377
391
  * @param {string} sql sql execute return data
@@ -440,12 +454,32 @@ declare class Database extends AbstractDatabase {
440
454
  } | null>;
441
455
  /**
442
456
  *
443
- * execute data return object | null
457
+ * execute data return object | throw rror
444
458
  * @return {promise<object | null>}
445
459
  */
446
460
  findOne(): Promise<{
447
461
  [key: string]: any;
448
462
  } | null>;
463
+ /**
464
+ *
465
+ * execute data return object | throw Error
466
+ * @return {promise<object | Error>}
467
+ */
468
+ firstOrError(message: string, options?: {
469
+ [key: string]: any;
470
+ }): Promise<{
471
+ [key: string]: any;
472
+ }>;
473
+ /**
474
+ *
475
+ * execute data return object | null
476
+ * @return {promise<object | null>}
477
+ */
478
+ findOneOrError(message: string, options?: {
479
+ [key: string]: any;
480
+ }): Promise<{
481
+ [key: string]: any;
482
+ }>;
449
483
  /**
450
484
  *
451
485
  * execute data return Array
@@ -540,10 +574,9 @@ declare class Database extends AbstractDatabase {
540
574
  findManyGroupBy(column: string): Promise<Array<any>>;
541
575
  /**
542
576
  * execute data when save *action [insert , update]
543
- * @param {object} transaction | DB.beginTransaction()
544
577
  * @return {Promise<any>}
545
578
  */
546
- save(transaction?: Transaction): Promise<any>;
579
+ save(): Promise<any>;
547
580
  /**
548
581
  *
549
582
  * show columns in table
@@ -554,7 +587,7 @@ declare class Database extends AbstractDatabase {
554
587
  /**
555
588
  *
556
589
  * show schemas in table
557
- * @param {string=} table table name
590
+ * @param {string=} table [table= current table name]
558
591
  * @return {Promise<Array>}
559
592
  */
560
593
  showSchemas(table?: string): Promise<Array<string>>;
@@ -567,20 +600,35 @@ declare class Database extends AbstractDatabase {
567
600
  showValues(table?: string): Promise<Array<string>>;
568
601
  /**
569
602
  *
570
- * backup database intro new database same server or to another server
603
+ * backup this database intro new database same server or to another server
571
604
  * @param {Object} backupOptions
572
605
  * @param {string} backup.database
606
+ * @param {object?} backup.to
607
+ * @param {string} backup.to.host
608
+ * @param {number} backup.to.port
609
+ * @param {string} backup.to.database
610
+ * @param {string} backup.to.username
611
+ * @param {string} backup.to.password
612
+
613
+ * @return {Promise<boolean>}
614
+ */
615
+ backup({ database, to }: Backup): Promise<boolean>;
616
+ /**
617
+ *
618
+ * backup database intro file
619
+ * @param {Object} backupOptions
620
+ * @param {string} backup.database
621
+ * @param {object?} backup.filePath
573
622
  * @param {object?} backup.connection
574
- * @param {string} backup.connection.host
575
- * @param {number} backup.connection.port
576
- * @param {string} backup.connection.database
577
- * @param {string} backup.connection.username
578
- * @param {string} backup.connection.password
623
+ * @param {string} backup.connection.host
624
+ * @param {number} backup.connection.port
625
+ * @param {string} backup.connection.database
626
+ * @param {string} backup.connection.username
627
+ * @param {string} backup.connection.password
579
628
 
580
629
  * @return {Promise<boolean>}
581
630
  */
582
- backup({ database, connection }: Backup): Promise<boolean>;
583
- backupToFile({ filePath, database, connection }: BackupToFile): Promise<boolean>;
631
+ backupToFile({ filePath, database, connection }: BackupToFile): Promise<void>;
584
632
  /**
585
633
  *
586
634
  * fake data
@@ -601,6 +649,7 @@ declare class Database extends AbstractDatabase {
601
649
  */
602
650
  drop(): Promise<boolean>;
603
651
  private _queryWhereIsExists;
652
+ private _bindTableAndColumnInQueryWhere;
604
653
  private _insertNotExists;
605
654
  private _setupPool;
606
655
  private _queryStatement;
@@ -615,7 +664,7 @@ declare class Database extends AbstractDatabase {
615
664
  private _queryInsertMultiple;
616
665
  private _valueAndOperator;
617
666
  private _valueTrueFalse;
618
- private _queryGenrate;
667
+ private _buildQuery;
619
668
  private _setupLogger;
620
669
  private _initialConnection;
621
670
  }