tspace-mysql 1.3.7 → 1.3.8

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/README.md CHANGED
@@ -189,7 +189,8 @@ const users = await new DB('users')
189
189
  name :'tspace6',
190
190
  email : 'tspace6@gmail.com'
191
191
  },
192
- ]).save()
192
+ ])
193
+ .save()
193
194
 
194
195
  const users = await new DB('users')
195
196
  .where('name','tspace4')
@@ -275,7 +276,8 @@ try {
275
276
  .bind(connection)
276
277
  .save()
277
278
 
278
- const posts = await new Post().createMultiple([
279
+ const posts = await new Post()
280
+ .createMultiple([
279
281
  {
280
282
  user_id : user.id,
281
283
  title : `tspace-post1`
@@ -853,23 +855,32 @@ hook((result) => ...) // callback result to function
853
855
  /**
854
856
  * registry relation in your models
855
857
  * @relationship
856
- */
857
- hasOne({ name , model , localKey , foreignKey , freezeTable , as })
858
- hasMany({ name , model , localKey , foreignKey , freezeTable , as })
859
- belongsTo({ name , model , localKey , foreignKey , freezeTable , as })
860
- belongsToMany({ name , model , localKey , foreignKey , freezeTable , as , pivot })
858
+ */
859
+ hasOne({ name, model, localKey, foreignKey, freezeTable , as })
860
+ hasMany({ name, model, localKey, foreignKey, freezeTable , as })
861
+ belongsTo({ name, model, localKey, foreignKey, freezeTable , as })
862
+ belongsToMany({ name, model, localKey, foreignKey, freezeTable, as, pivot })
861
863
  /**
862
864
  * @relation using registry in your models
863
- */
865
+ */
864
866
  relations(name1 , name2,...nameN)
867
+ /**
868
+ * @relation using registry in your models ignore soft delete
869
+ */
870
+ relationsAll(name1 , name2,...nameN)
865
871
  /**
866
872
  * @relation using registry in your models. if exists child data remove this data
867
- */
873
+ */
868
874
  relationsExists(name1 , name2,...nameN)
869
875
  /**
870
876
  * @relation call a name of relation in registry, callback query of data
871
- */
877
+ */
872
878
  relationQuery(name, (callback) )
879
+ /**
880
+ * @relation using registry in your models return only in trash (soft delete)
881
+ */
882
+ relationsTrashed(name1 , name2,...nameN)
883
+
873
884
 
874
885
  /**
875
886
  * queries statements
@@ -11,6 +11,7 @@ const CONSTANTS = Object.freeze({
11
11
  BETWEEN: 'BETWEEN',
12
12
  NOT_BETWEEN: 'NOT BETWEEN',
13
13
  AND: 'AND',
14
+ NULL: 'NULL',
14
15
  IS_NULL: 'IS NULL',
15
16
  IS_NOT_NULL: 'IS NOT NULL',
16
17
  OR: 'OR',
@@ -34,12 +34,14 @@ declare abstract class AbstractModel extends Builder {
34
34
  abstract with(...nameRelations: string[]): this;
35
35
  abstract withQuery(nameRelations: string, callback: Function): this;
36
36
  abstract withExists(...nameRelations: string[]): this;
37
- abstract withAndTrashed(...nameRelations: string[]): this;
37
+ abstract withTrashed(...nameRelations: string[]): this;
38
+ abstract withAll(...nameRelations: string[]): this;
38
39
  abstract has(...nameRelations: string[]): this;
39
40
  abstract relations(...nameRelations: string[]): this;
40
41
  abstract relationQuery(nameRelations: string, callback: Function): this;
41
42
  abstract relationsExists(...nameRelations: string[]): this;
42
- abstract relationsAndTrashed(...nameRelations: string[]): this;
43
+ abstract relationsAll(...nameRelations: string[]): this;
44
+ abstract relationsTrashed(...nameRelations: string[]): this;
43
45
  }
44
46
  export { AbstractModel };
45
47
  export default AbstractModel;
@@ -189,6 +189,13 @@ declare class Builder extends AbstractBuilder {
189
189
  * @return {this}
190
190
  */
191
191
  whereNotBetween(column: string, array: Array<any>): this;
192
+ /**
193
+ * where not between using [value1, value2]
194
+ * @param {string} column
195
+ * @param {array} array
196
+ * @return {this}
197
+ */
198
+ orWhereNotBetween(column: string, array: Array<any>): this;
192
199
  /**
193
200
  * where null using NULL
194
201
  * @param {string} column
@@ -300,9 +300,9 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
300
300
  whereIn(column, array) {
301
301
  if (!Array.isArray(array))
302
302
  throw new Error(`[${array}] is't array`);
303
- if (!array.length)
304
- return this;
305
- const values = `${array.map((value) => this._checkValueHasRaw(this.$utils.escape(value))).join(',')}`;
303
+ const values = array.length
304
+ ? `${array.map((value) => this._checkValueHasRaw(this.$utils.escape(value))).join(',')}`
305
+ : this.$constants('NULL');
306
306
  this.$state.set('WHERE', [
307
307
  this._queryWhereIsExists()
308
308
  ? `${this.$state.get('WHERE')} ${this.$constants('AND')}`
@@ -322,9 +322,9 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
322
322
  orWhereIn(column, array) {
323
323
  if (!Array.isArray(array))
324
324
  throw new Error(`[${array}] is't array`);
325
- if (!array.length)
326
- return this;
327
- const values = `${array.map((value) => this._checkValueHasRaw(this.$utils.escape(value))).join(',')}`;
325
+ const values = array.length
326
+ ? `${array.map((value) => this._checkValueHasRaw(this.$utils.escape(value))).join(',')}`
327
+ : this.$constants('NULL');
328
328
  this.$state.set('WHERE', [
329
329
  this._queryWhereIsExists()
330
330
  ? `${this.$state.get('WHERE')} ${this.$constants('OR')}`
@@ -345,9 +345,9 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
345
345
  const sql = this.$state.get('WHERE');
346
346
  if (!Array.isArray(array))
347
347
  throw new Error(`[${array}] is't array`);
348
- if (!array.length)
349
- return this;
350
- const values = `${array.map((value) => this._checkValueHasRaw(this.$utils.escape(value))).join(',')}`;
348
+ const values = array.length
349
+ ? `${array.map((value) => this._checkValueHasRaw(this.$utils.escape(value))).join(',')}`
350
+ : this.$constants('NULL');
351
351
  this.$state.set('WHERE', [
352
352
  this._queryWhereIsExists()
353
353
  ? `${this.$state.get('WHERE')} ${this.$constants('AND')}`
@@ -367,9 +367,9 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
367
367
  orWhereNotIn(column, array) {
368
368
  if (!Array.isArray(array))
369
369
  throw new Error(`[${array}] is't array`);
370
- if (!array.length)
371
- return this;
372
- const values = `${array.map((value) => this._checkValueHasRaw(this.$utils.escape(value))).join(',')}`;
370
+ const values = array.length
371
+ ? `${array.map((value) => this._checkValueHasRaw(this.$utils.escape(value))).join(',')}`
372
+ : this.$constants('NULL');
373
373
  this.$state.set('WHERE', [
374
374
  this._queryWhereIsExists()
375
375
  ? `${this.$state.get('WHERE')} ${this.$constants('OR')}`
@@ -387,6 +387,8 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
387
387
  * @return {this}
388
388
  */
389
389
  whereSubQuery(column, subQuery) {
390
+ if (!this.$utils.isQuery(subQuery))
391
+ throw new Error(`This "${subQuery}" is invalid sub query`);
390
392
  this.$state.set('WHERE', [
391
393
  this._queryWhereIsExists()
392
394
  ? `${this.$state.get('WHERE')} ${this.$constants('AND')}`
@@ -404,6 +406,8 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
404
406
  * @return {this}
405
407
  */
406
408
  whereNotSubQuery(column, subQuery) {
409
+ if (!this.$utils.isQuery(subQuery))
410
+ throw new Error(`This "${subQuery}" is invalid sub query`);
407
411
  this.$state.set('WHERE', [
408
412
  this._queryWhereIsExists()
409
413
  ? `${this.$state.get('WHERE')} ${this.$constants('AND')}`
@@ -421,6 +425,8 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
421
425
  * @return {this}
422
426
  */
423
427
  orWhereSubQuery(column, subQuery) {
428
+ if (!this.$utils.isQuery(subQuery))
429
+ throw new Error(`This "${subQuery}" is invalid sub query`);
424
430
  this.$state.set('WHERE', [
425
431
  this._queryWhereIsExists()
426
432
  ? `${this.$state.get('WHERE')} ${this.$constants('OR')}`
@@ -438,6 +444,8 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
438
444
  * @return {this}
439
445
  */
440
446
  orWhereNotSubQuery(column, subQuery) {
447
+ if (!this.$utils.isQuery(subQuery))
448
+ throw new Error(`This "${subQuery}" is invalid sub query`);
441
449
  this.$state.set('WHERE', [
442
450
  this._queryWhereIsExists()
443
451
  ? `${this.$state.get('WHERE')} ${this.$constants('OR')}`
@@ -457,8 +465,16 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
457
465
  whereBetween(column, array) {
458
466
  if (!Array.isArray(array))
459
467
  throw new Error("Value is't array");
460
- if (!array.length)
468
+ if (!array.length) {
469
+ this.$state.set('WHERE', [
470
+ this._queryWhereIsExists()
471
+ ? `${this.$state.get('WHERE')} ${this.$constants('AND')}`
472
+ : `${this.$constants('WHERE')}`,
473
+ `${this._bindTableAndColumnInQueryWhere(column)} ${this.$constants('BETWEEN')}`,
474
+ `${this.$constants('NULL')} ${this.$constants('AND')} ${this.$constants('NULL')}`
475
+ ].join(' '));
461
476
  return this;
477
+ }
462
478
  const [value1, value2] = array;
463
479
  this.$state.set('WHERE', [
464
480
  this._queryWhereIsExists()
@@ -478,8 +494,16 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
478
494
  orWhereBetween(column, array) {
479
495
  if (!Array.isArray(array))
480
496
  throw new Error("Value is't array");
481
- if (!array.length)
497
+ if (!array.length) {
498
+ this.$state.set('WHERE', [
499
+ this._queryWhereIsExists()
500
+ ? `${this.$state.get('WHERE')} ${this.$constants('OR')}`
501
+ : `${this.$constants('WHERE')}`,
502
+ `${this._bindTableAndColumnInQueryWhere(column)} ${this.$constants('BETWEEN')}`,
503
+ `${this.$constants('NULL')} ${this.$constants('AND')} ${this.$constants('NULL')}`
504
+ ].join(' '));
482
505
  return this;
506
+ }
483
507
  const [value1, value2] = array;
484
508
  this.$state.set('WHERE', [
485
509
  this._queryWhereIsExists()
@@ -499,8 +523,16 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
499
523
  whereNotBetween(column, array) {
500
524
  if (!Array.isArray(array))
501
525
  throw new Error("Value is't array");
502
- if (!array.length)
526
+ if (!array.length) {
527
+ this.$state.set('WHERE', [
528
+ this._queryWhereIsExists()
529
+ ? `${this.$state.get('WHERE')} ${this.$constants('AND')}`
530
+ : `${this.$constants('WHERE')}`,
531
+ `${this._bindTableAndColumnInQueryWhere(column)} ${this.$constants('NOT_BETWEEN')}`,
532
+ `${this.$constants('NULL')} ${this.$constants('AND')} ${this.$constants('NULL')}`
533
+ ].join(' '));
503
534
  return this;
535
+ }
504
536
  const [value1, value2] = array;
505
537
  this.$state.set('WHERE', [
506
538
  this._queryWhereIsExists()
@@ -511,6 +543,35 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
511
543
  ].join(' '));
512
544
  return this;
513
545
  }
546
+ /**
547
+ * where not between using [value1, value2]
548
+ * @param {string} column
549
+ * @param {array} array
550
+ * @return {this}
551
+ */
552
+ orWhereNotBetween(column, array) {
553
+ if (!Array.isArray(array))
554
+ throw new Error("Value is't array");
555
+ if (!array.length) {
556
+ this.$state.set('WHERE', [
557
+ this._queryWhereIsExists()
558
+ ? `${this.$state.get('WHERE')} ${this.$constants('OR')}`
559
+ : `${this.$constants('WHERE')}`,
560
+ `${this._bindTableAndColumnInQueryWhere(column)} ${this.$constants('NOT_BETWEEN')}`,
561
+ `${this.$constants('NULL')} ${this.$constants('AND')} ${this.$constants('NULL')}`
562
+ ].join(' '));
563
+ return this;
564
+ }
565
+ const [value1, value2] = array;
566
+ this.$state.set('WHERE', [
567
+ this._queryWhereIsExists()
568
+ ? `${this.$state.get('WHERE')} ${this.$constants('OR')}`
569
+ : `${this.$constants('WHERE')}`,
570
+ `${this._bindTableAndColumnInQueryWhere(column)} ${this.$constants('NOT_BETWEEN')}`,
571
+ `${this._checkValueHasRaw(this.$utils.escape(value1))} ${this.$constants('AND')} ${this._checkValueHasRaw(this.$utils.escape(value2))}`
572
+ ].join(' '));
573
+ return this;
574
+ }
514
575
  /**
515
576
  * where null using NULL
516
577
  * @param {string} column
@@ -9,6 +9,7 @@ export interface Relation {
9
9
  query?: any | undefined;
10
10
  relation?: Object | undefined;
11
11
  exists?: boolean | undefined;
12
+ all?: boolean | undefined;
12
13
  trashed?: boolean | undefined;
13
14
  oldVersion?: boolean | undefined;
14
15
  }
@@ -342,11 +342,18 @@ declare class Model extends AbstractModel {
342
342
  with(...nameRelations: Array<string>): this;
343
343
  /**
344
344
  *
345
- * Use relations in registry of model return normal and in trash
345
+ * Use relations in registry of model return ignore soft delete
346
346
  * @param {...string} nameRelations if data exists return blank
347
347
  * @return {this} this
348
348
  */
349
- withAndTrashed(...nameRelations: Array<string>): this;
349
+ withAll(...nameRelations: Array<string>): this;
350
+ /**
351
+ *
352
+ * Use relations in registry of model return only in trash (soft delete)
353
+ * @param {...string} nameRelations if data exists return blank
354
+ * @return {this} this
355
+ */
356
+ withTrashed(...nameRelations: Array<string>): this;
350
357
  /**
351
358
  *
352
359
  * Use relations in registry of model return only exists result of relation query
@@ -547,7 +554,14 @@ declare class Model extends AbstractModel {
547
554
  * @param {...string} nameRelations if data exists return blank
548
555
  * @return {this} this
549
556
  */
550
- relationsAndTrashed(...nameRelations: Array<string>): this;
557
+ relationsAll(...nameRelations: Array<string>): this;
558
+ /**
559
+ *
560
+ * Use relations in registry of model return only in trash (soft delete)
561
+ * @param {...string} nameRelations if data exists return blank
562
+ * @return {this} this
563
+ */
564
+ relationsTrashed(...nameRelations: Array<string>): this;
551
565
  /**
552
566
  * Assign the relation in model Objects
553
567
  * @param {object} relations registry relation in your model
@@ -654,6 +668,12 @@ declare class Model extends AbstractModel {
654
668
  * @return {this} this
655
669
  */
656
670
  protected belongsToManyBuilder({ name, as, model, localKey, foreignKey, freezeTable, pivot }: RelationQuery, callback?: Function): this;
671
+ /**
672
+ * where not null using NULL
673
+ * @override
674
+ * @return {this}
675
+ */
676
+ whereTrashed(): this;
657
677
  /**
658
678
  * return only in trashed (data has been remove)
659
679
  * @return {promise}
@@ -194,7 +194,7 @@ class Model extends AbstractModel_1.AbstractModel {
194
194
  this.$constants('PATTERN').snake_case,
195
195
  this.$constants('PATTERN').camelCase
196
196
  ];
197
- this._assertError(!allowPattern.includes(pattern), `tspace-mysql support only pattern [${allowPattern}]`);
197
+ this._assertError(!allowPattern.includes(pattern), `tspace-mysql support only pattern ["${this.$constants('PATTERN').snake_case}","${this.$constants('PATTERN').camelCase}"]`);
198
198
  this.$state.set('PATTERN', pattern);
199
199
  return this;
200
200
  }
@@ -549,11 +549,32 @@ class Model extends AbstractModel_1.AbstractModel {
549
549
  }
550
550
  /**
551
551
  *
552
- * Use relations in registry of model return normal and in trash
552
+ * Use relations in registry of model return ignore soft delete
553
553
  * @param {...string} nameRelations if data exists return blank
554
554
  * @return {this} this
555
555
  */
556
- withAndTrashed(...nameRelations) {
556
+ withAll(...nameRelations) {
557
+ const relations = this._handleRelations(nameRelations);
558
+ relations.forEach(relation => relation.all = true);
559
+ const setRelations = this.$state.get('RELATIONS').length
560
+ ? [...relations.map((w) => {
561
+ const exists = this.$state.get('RELATIONS').find((r) => r.name === w.name);
562
+ if (exists)
563
+ return null;
564
+ return w;
565
+ }).filter((d) => d != null),
566
+ ...this.$state.get('RELATIONS')]
567
+ : relations;
568
+ this.$state.set('RELATIONS', setRelations);
569
+ return this;
570
+ }
571
+ /**
572
+ *
573
+ * Use relations in registry of model return only in trash (soft delete)
574
+ * @param {...string} nameRelations if data exists return blank
575
+ * @return {this} this
576
+ */
577
+ withTrashed(...nameRelations) {
557
578
  const relations = this._handleRelations(nameRelations);
558
579
  relations.forEach(relation => relation.trashed = true);
559
580
  const setRelations = this.$state.get('RELATIONS').length
@@ -799,8 +820,17 @@ class Model extends AbstractModel_1.AbstractModel {
799
820
  * @param {...string} nameRelations if data exists return blank
800
821
  * @return {this} this
801
822
  */
802
- relationsAndTrashed(...nameRelations) {
803
- return this.withAndTrashed(...nameRelations);
823
+ relationsAll(...nameRelations) {
824
+ return this.withAll(...nameRelations);
825
+ }
826
+ /**
827
+ *
828
+ * Use relations in registry of model return only in trash (soft delete)
829
+ * @param {...string} nameRelations if data exists return blank
830
+ * @return {this} this
831
+ */
832
+ relationsTrashed(...nameRelations) {
833
+ return this.withTrashed(...nameRelations);
804
834
  }
805
835
  /**
806
836
  * Assign the relation in model Objects
@@ -1047,6 +1077,16 @@ class Model extends AbstractModel_1.AbstractModel {
1047
1077
  r.query = callback(new r.model());
1048
1078
  return this;
1049
1079
  }
1080
+ /**
1081
+ * where not null using NULL
1082
+ * @override
1083
+ * @return {this}
1084
+ */
1085
+ whereTrashed() {
1086
+ this.disableSoftDelete();
1087
+ this.whereNotNull(this._valuePattern(this.$state.get('SOFT_DELETE_FORMAT')));
1088
+ return this;
1089
+ }
1050
1090
  /**
1051
1091
  * return only in trashed (data has been remove)
1052
1092
  * @return {promise}
@@ -2152,7 +2192,8 @@ class Model extends AbstractModel_1.AbstractModel {
2152
2192
  .bind(this.$pool.get())
2153
2193
  .whereIn(foreignKey, dataPerentId)
2154
2194
  .debug(this.$state.get('DEBUG'))
2155
- .when(relation.trashed, (query) => query.disableSoftDelete())
2195
+ .when(relation.trashed, (query) => query.whereTrashed())
2196
+ .when(relation.all, (query) => query.disableSoftDelete())
2156
2197
  .get();
2157
2198
  return dataFromRelation;
2158
2199
  });
@@ -2185,7 +2226,8 @@ class Model extends AbstractModel_1.AbstractModel {
2185
2226
  const sqldataChilds = queryChildModel
2186
2227
  .whereIn(localKeyPivotTable, dataPerentId)
2187
2228
  .when(relation.exists, (query) => query.whereExists(sql))
2188
- .when(relation.trashed, (query) => query.disableSoftDelete())
2229
+ .when(relation.trashed, (query) => query.whereTrashed())
2230
+ .when(relation.all, (query) => query.disableSoftDelete())
2189
2231
  .toString();
2190
2232
  const dataChilds = yield this.queryStatement(sqldataChilds);
2191
2233
  const otherId = dataChilds.map((sub) => sub[otherforeignKey]).filter((data) => data != null);
@@ -5,6 +5,7 @@ declare const utils: {
5
5
  timestamp: () => string;
6
6
  date: () => string;
7
7
  escape: (str: any) => any;
8
+ isQuery: (str: string) => boolean;
8
9
  generateUUID: () => string;
9
10
  covertBooleanToNumber: (data: any) => any;
10
11
  snakeCase: (data: any) => any;
@@ -34,6 +34,7 @@ const escape = (str) => {
34
34
  return str;
35
35
  return str.replace(/[\0\b\t\n\r\x1a\'\\]/g, '');
36
36
  };
37
+ const isQuery = (str) => /\b(?:SELECT|FROM|WHERE|JOIN|INNER JOIN|LEFT JOIN|RIGHT JOIN|OUTER JOIN|AND|OR|ORDER BY|GROUP BY|LIMIT)\b/i.test(str);
37
38
  const columnRelation = (name) => {
38
39
  var _a;
39
40
  const matches = (_a = name === null || name === void 0 ? void 0 : name.match(/[A-Z]/g)) !== null && _a !== void 0 ? _a : [];
@@ -145,6 +146,7 @@ const utils = {
145
146
  timestamp,
146
147
  date,
147
148
  escape,
149
+ isQuery,
148
150
  generateUUID,
149
151
  covertBooleanToNumber,
150
152
  snakeCase,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tspace-mysql",
3
- "version": "1.3.7",
3
+ "version": "1.3.8",
4
4
  "description": "mysql query builder object relational mapping",
5
5
  "main": "dist/lib/index.js",
6
6
  "types": "dist/lib/index.d.ts",
@@ -1,122 +0,0 @@
1
- import { Pagination } from './Interface';
2
- import { StateHandler } from './StateHandler';
3
- declare abstract class AbstractBuilder {
4
- protected $setters: string[];
5
- protected $utils: {
6
- [key: string]: Function;
7
- };
8
- protected $constants: Function;
9
- protected $state: StateHandler;
10
- protected $pool: {
11
- query: Function;
12
- set: Function;
13
- get: Function;
14
- };
15
- protected $logger: {
16
- get: Function;
17
- set: (value: string) => void;
18
- reset: () => void;
19
- check: (value: string) => boolean;
20
- };
21
- protected $attributes: {
22
- [key: string]: any;
23
- } | null;
24
- abstract void(): this;
25
- abstract debug(): this;
26
- abstract dd(): this;
27
- abstract select(...columns: string[]): this;
28
- abstract distinct(...columns: string[]): this;
29
- abstract whereNull(column: string): this;
30
- abstract whereNotNull(column: string): this;
31
- abstract where(column: string, operator: string, value: string): this;
32
- abstract whereSensitive(column: string, operator: string, value: string): this;
33
- abstract whereRaw(sql: string): this;
34
- abstract whereId(id: number): this;
35
- abstract whereUser(id: number): this;
36
- abstract whereEmail(value: string): this;
37
- abstract whereQuery(callback: Function): this;
38
- abstract orWhere(column: string, operator: string, value: string): this;
39
- abstract whereIn(column: string, arrayValues: Array<any>): this;
40
- abstract orWhereIn(column: string, arrayValues: Array<any>): this;
41
- abstract whereNotIn(column: string, arrayValues: Array<any>): this;
42
- abstract whereSubQuery(column: string, subQuery: string): this;
43
- abstract whereNotSubQuery(column: string, subQuery: string): this;
44
- abstract orWhereSubQuery(column: string, subQuery: string): this;
45
- abstract whereBetween(column: string, arrayValue: Array<any>): this;
46
- abstract whereNotBetween(column: string, arrayValue: Array<any>): this;
47
- abstract having(condition: string): this;
48
- abstract havingRaw(condition: string): this;
49
- abstract join(pk: string, fk: string): this;
50
- abstract rightJoin(pk: string, fk: string): this;
51
- abstract leftJoin(pk: string, fk: string): this;
52
- abstract crossJoin(pk: string, fk: string): this;
53
- abstract orderBy(column: string, order: string): this;
54
- abstract orderByRaw(column: string, order: string): this;
55
- abstract latest(...columns: Array<string>): this;
56
- abstract latestRaw(...columns: Array<string>): this;
57
- abstract oldest(...columns: Array<string>): this;
58
- abstract oldestRaw(...columns: Array<string>): this;
59
- abstract groupBy(...columns: string[]): this;
60
- abstract groupByRaw(...columns: string[]): this;
61
- abstract random(): this;
62
- abstract inRandom(): this;
63
- abstract limit(number: number): this;
64
- abstract hidden(...columns: string[]): this;
65
- abstract insert(objects: object): this;
66
- abstract create(objects: object): this;
67
- abstract update(objects: object): this;
68
- abstract insertNotExists(objects: object): this;
69
- abstract createNotExists(objects: object): this;
70
- abstract insertOrUpdate(objects: object): this;
71
- abstract createOrUpdate(objects: object): this;
72
- abstract updateOrInsert(objects: object): this;
73
- abstract updateOrCreate(objects: object): this;
74
- abstract createMultiple(objects: object): this;
75
- abstract insertMultiple(objects: object): this;
76
- abstract except(...columns: string[]): this;
77
- abstract only(...columns: string[]): this;
78
- abstract drop(): Promise<any>;
79
- abstract truncate(): Promise<any>;
80
- abstract all(): Promise<Array<any>>;
81
- abstract find(id: number): Promise<any>;
82
- abstract pagination({ limit, page }: {
83
- limit: number;
84
- page: number;
85
- }): Promise<Pagination>;
86
- abstract paginate({ limit, page }: {
87
- limit: number;
88
- page: number;
89
- }): Promise<Pagination>;
90
- abstract first(): Promise<any>;
91
- abstract firstOrError(message: string, options?: {
92
- [key: string]: any;
93
- }): Promise<any>;
94
- abstract findOneOrError(message: string, options?: {
95
- [key: string]: any;
96
- }): Promise<any>;
97
- abstract get(): Promise<any>;
98
- abstract findOne(): Promise<any>;
99
- abstract findMany(): Promise<any>;
100
- abstract getGroupBy(column: string): Promise<any>;
101
- abstract findManyGroupBy(column: string): Promise<any>;
102
- abstract toArray(column: string): Promise<any>;
103
- abstract toJSON(): Promise<any>;
104
- abstract toSQL(): string;
105
- abstract toString(): string;
106
- abstract count(column: string): Promise<number>;
107
- abstract sum(column: string): Promise<number>;
108
- abstract avg(column: string): Promise<number>;
109
- abstract max(column: string): Promise<number>;
110
- abstract min(column: string): Promise<number>;
111
- abstract rawQuery(sql: string): Promise<Array<any>>;
112
- abstract delete(): Promise<boolean>;
113
- abstract exists(): Promise<boolean>;
114
- abstract save(): Promise<{
115
- [key: string]: any;
116
- } | Array<any> | null | undefined>;
117
- abstract increment(column: string, value: number): Promise<any>;
118
- abstract decrement(column: string, value: number): Promise<any>;
119
- abstract faker(round: number): Promise<any>;
120
- }
121
- export { AbstractBuilder };
122
- export default AbstractBuilder;
@@ -1,33 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AbstractBuilder = void 0;
4
- const StateHandler_1 = require("./StateHandler");
5
- class AbstractBuilder {
6
- constructor() {
7
- this.$setters = [
8
- '$attributes',
9
- '$logger',
10
- '$utils',
11
- '$constants',
12
- '$pool',
13
- '$state',
14
- ];
15
- this.$utils = {};
16
- this.$constants = (name) => { };
17
- this.$state = new StateHandler_1.StateHandler({});
18
- this.$pool = {
19
- query: (sql) => { },
20
- set: (pool) => { },
21
- get: () => { }
22
- };
23
- this.$logger = {
24
- get: () => { },
25
- set: (value) => { },
26
- reset: () => { },
27
- check: (value) => true || false
28
- };
29
- this.$attributes = null;
30
- }
31
- }
32
- exports.AbstractBuilder = AbstractBuilder;
33
- exports.default = AbstractBuilder;
@@ -1,20 +0,0 @@
1
- import Builder from './Builder';
2
- import { Connection, ConnectionOptions } from './Interface';
3
- declare abstract class AbstractDB extends Builder {
4
- abstract table(tableName: string): void;
5
- abstract beginTransaction(): Promise<any>;
6
- abstract makeObject(value: any): Record<string, any> | null;
7
- abstract makeArray(value: any): Array<any>;
8
- abstract generateUUID(): string;
9
- abstract raw(sql: string): string;
10
- abstract constants(constants?: string): string | {
11
- [key: string]: any;
12
- };
13
- abstract caseUpdate(cases: {
14
- when: string;
15
- then: string;
16
- }[], final?: string): string | [];
17
- abstract getConnection(options: ConnectionOptions): Connection;
18
- }
19
- export { AbstractDB };
20
- export default AbstractDB;
@@ -1,11 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.AbstractDB = void 0;
7
- const Builder_1 = __importDefault(require("./Builder"));
8
- class AbstractDB extends Builder_1.default {
9
- }
10
- exports.AbstractDB = AbstractDB;
11
- exports.default = AbstractDB;
@@ -1,45 +0,0 @@
1
- import { Relation, RelationQuery } from './Interface';
2
- import Builder from './Builder';
3
- declare abstract class AbstractModel extends Builder {
4
- protected abstract useUUID(): this;
5
- protected abstract usePrimaryKey(primaryKey: string): this;
6
- protected abstract useRegistry(): this;
7
- protected abstract useDebug(): this;
8
- protected abstract useTable(table: string): this;
9
- protected abstract useTablePlural(): this;
10
- protected abstract useTableSingular(): this;
11
- protected abstract useTimestamp(): this;
12
- protected abstract useSoftDelete(): this;
13
- protected abstract usePattern(pattern: string): this;
14
- protected abstract useLoadRelationsInRegistry(): this;
15
- protected abstract useBuiltInRelationFunctions(): this;
16
- protected abstract define(): void;
17
- protected abstract hasOne({ name, model, localKey, foreignKey, freezeTable, as }: Relation): this;
18
- protected abstract hasMany({ name, model, localKey, foreignKey, freezeTable, as }: Relation): this;
19
- protected abstract belongsTo({ name, model, localKey, foreignKey, freezeTable, as }: Relation): this;
20
- protected abstract belongsToMany({ name, model, localKey, foreignKey, freezeTable, as }: Relation): this;
21
- protected abstract buildMethodRelation(name: string, callback?: Function): this;
22
- protected abstract hasOneBuilder({ name, model, localKey, foreignKey, freezeTable, as }: RelationQuery, callback: Function): this;
23
- protected abstract hasManyBuilder({ name, model, localKey, foreignKey, freezeTable, as }: RelationQuery, callback: Function): this;
24
- protected abstract belongsToBuilder({ name, model, localKey, foreignKey, freezeTable, as }: RelationQuery, callback: Function): this;
25
- protected abstract belongsToManyBuilder({ name, model, localKey, foreignKey, freezeTable, as }: RelationQuery, callback: Function): this;
26
- abstract ignoreSoftDelete(): this;
27
- abstract disableSoftDelete(): this;
28
- abstract registry(func: {
29
- [key: string]: Function;
30
- }): this;
31
- abstract onlyTrashed(): Promise<any>;
32
- abstract trashed(): Promise<any>;
33
- abstract restore(): Promise<any>;
34
- abstract with(...nameRelations: string[]): this;
35
- abstract withQuery(nameRelations: string, callback: Function): this;
36
- abstract withExists(...nameRelations: string[]): this;
37
- abstract withAndTrashed(...nameRelations: string[]): this;
38
- abstract has(...nameRelations: string[]): this;
39
- abstract relations(...nameRelations: string[]): this;
40
- abstract relationQuery(nameRelations: string, callback: Function): this;
41
- abstract relationsExists(...nameRelations: string[]): this;
42
- abstract relationsAndTrashed(...nameRelations: string[]): this;
43
- }
44
- export { AbstractModel };
45
- export default AbstractModel;
@@ -1,11 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.AbstractModel = void 0;
7
- const Builder_1 = __importDefault(require("./Builder"));
8
- class AbstractModel extends Builder_1.default {
9
- }
10
- exports.AbstractModel = AbstractModel;
11
- exports.default = AbstractModel;