tspace-mysql 1.5.0 → 1.5.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 (53) hide show
  1. package/README.md +1856 -701
  2. package/build/cli/dump/db.js +3 -2
  3. package/build/cli/generate/make.js +17 -15
  4. package/build/cli/generate/modelDecorator.d.ts +1 -1
  5. package/build/cli/generate/modelDecorator.js +2 -3
  6. package/build/cli/index.js +45 -27
  7. package/build/cli/migrate/make.d.ts +1 -1
  8. package/build/cli/migrate/make.js +2 -2
  9. package/build/cli/migrations/make-db.d.ts +4 -0
  10. package/build/cli/migrations/make-db.js +58 -0
  11. package/build/cli/migrations/make.d.ts +2 -0
  12. package/build/cli/migrations/make.js +201 -0
  13. package/build/lib/Interface.d.ts +24 -5
  14. package/build/lib/connection/index.d.ts +5 -1
  15. package/build/lib/connection/index.js +65 -8
  16. package/build/lib/connection/options.js +2 -2
  17. package/build/lib/constants/index.js +13 -3
  18. package/build/lib/{tspace → core}/Abstracts/AbstractBuilder.d.ts +1 -1
  19. package/build/lib/{tspace → core}/Abstracts/AbstractModel.d.ts +15 -13
  20. package/build/lib/{tspace → core}/Blueprint.d.ts +14 -3
  21. package/build/lib/{tspace → core}/Blueprint.js +30 -4
  22. package/build/lib/{tspace → core}/Builder.d.ts +140 -44
  23. package/build/lib/{tspace → core}/Builder.js +772 -459
  24. package/build/lib/{tspace → core}/DB.d.ts +20 -4
  25. package/build/lib/{tspace → core}/DB.js +73 -39
  26. package/build/lib/{tspace → core}/Decorator.js +2 -2
  27. package/build/lib/{tspace → core/Handlers}/Logger.d.ts +3 -3
  28. package/build/lib/{tspace → core/Handlers}/Logger.js +4 -4
  29. package/build/lib/{tspace → core}/Handlers/Proxy.js +2 -2
  30. package/build/lib/{tspace → core}/Handlers/Relation.d.ts +2 -4
  31. package/build/lib/{tspace → core}/Handlers/Relation.js +69 -48
  32. package/build/lib/{tspace → core}/Handlers/State.d.ts +1 -1
  33. package/build/lib/{tspace → core}/Handlers/State.js +3 -3
  34. package/build/lib/{tspace → core}/Model.d.ts +358 -133
  35. package/build/lib/{tspace → core}/Model.js +1316 -558
  36. package/build/lib/core/Schema.d.ts +137 -0
  37. package/build/lib/{tspace → core}/Schema.js +147 -52
  38. package/build/lib/core/Type.d.ts +6 -0
  39. package/build/lib/core/Type.js +2 -0
  40. package/build/lib/{tspace → core}/index.d.ts +2 -1
  41. package/build/lib/{tspace → core}/index.js +3 -2
  42. package/build/lib/index.d.ts +2 -2
  43. package/build/lib/index.js +2 -2
  44. package/build/lib/utils/index.d.ts +1 -0
  45. package/build/lib/utils/index.js +17 -7
  46. package/package.json +6 -4
  47. package/build/lib/tspace/Schema.d.ts +0 -70
  48. /package/build/lib/{tspace → core}/Abstracts/AbstractBuilder.js +0 -0
  49. /package/build/lib/{tspace → core}/Abstracts/AbstractDB.d.ts +0 -0
  50. /package/build/lib/{tspace → core}/Abstracts/AbstractDB.js +0 -0
  51. /package/build/lib/{tspace → core}/Abstracts/AbstractModel.js +0 -0
  52. /package/build/lib/{tspace → core}/Decorator.d.ts +0 -0
  53. /package/build/lib/{tspace → core}/Handlers/Proxy.d.ts +0 -0
@@ -5,11 +5,27 @@ import { Relation, Pagination, RelationQuery, ValidateSchema, GlobalSetting } fr
5
5
  *
6
6
  * 'Model' class is a representation of a database table
7
7
  * @example
8
- * class User extends Model {}
9
- * new User().findMany().then(users => console.log(users))
8
+ * class User extends Model {
9
+ * ...........
10
+ * }
11
+ * const users = await new User().findMany()
12
+ * console.log(users)
10
13
  */
11
- declare class Model extends AbstractModel {
14
+ declare class Model<TSchemaModel extends Record<string, Blueprint | string | number | Date> = any, TRelationModel = any> extends AbstractModel<TSchemaModel, TRelationModel> {
12
15
  constructor();
16
+ /**
17
+ * The 'global' method is used setting global variables in models.
18
+ * @static
19
+ * @param {GlobalSetting} settings
20
+ * @example
21
+ * Model.global({
22
+ * softDelete : true,
23
+ * uuid : true,
24
+ * timestamp : true,
25
+ * logger : true,
26
+ * })
27
+ * @return {void} void
28
+ */
13
29
  static global(settings: GlobalSetting): void;
14
30
  /**
15
31
  * The 'define' method is a special method that you can define within a model.
@@ -40,7 +56,7 @@ declare class Model extends AbstractModel {
40
56
  */
41
57
  protected boot(): void;
42
58
  /**
43
- * The "useObserve" pattern refers to a way of handling model events using observer classes.
59
+ * The "useObserve" method is used to pattern refers to a way of handling model events using observer classes.
44
60
  * Model events are triggered when certain actions occur on models,
45
61
  * such as creating, updating, deleting, or saving a record.
46
62
  *
@@ -81,6 +97,34 @@ declare class Model extends AbstractModel {
81
97
  updated: Function;
82
98
  deleted: Function;
83
99
  }): this;
100
+ /**
101
+ * The "useLogger" method is used to keeping query data and changed in models.
102
+ *
103
+ * @type {object} options
104
+ * @property {boolean} options.selected - default is false
105
+ * @property {boolean} options.inserted - default is true
106
+ * @property {boolean} options.updated - default is true
107
+ * @property {boolean} options.deleted - default is true
108
+ * @example
109
+ * class User extends Model {
110
+ * constructor() {
111
+ * super()
112
+ * this.useLogger({
113
+ * selected : true,
114
+ * inserted : true,
115
+ * updated : true,
116
+ * deleted : true,
117
+ * })
118
+ * }
119
+ * }
120
+ * @return {this} this
121
+ */
122
+ protected useLogger({ selected, inserted, updated, deleted }?: {
123
+ selected?: boolean | undefined;
124
+ inserted?: boolean | undefined;
125
+ updated?: boolean | undefined;
126
+ deleted?: boolean | undefined;
127
+ }): this;
84
128
  /**
85
129
  * The "useSchema" method is used to define the schema.
86
130
  *
@@ -90,6 +134,7 @@ declare class Model extends AbstractModel {
90
134
  * import { Blueprint } from 'tspace-mysql'
91
135
  * class User extends Model {
92
136
  * constructor() {
137
+ * super()
93
138
  * this.useSchema ({
94
139
  * id : new Blueprint().int().notNull().primary().autoIncrement(),
95
140
  * uuid : new Blueprint().varchar(50).null(),
@@ -112,6 +157,7 @@ declare class Model extends AbstractModel {
112
157
  * @example
113
158
  * class User extends Model {
114
159
  * constructor() {
160
+ * super()
115
161
  * this.useRegistry()
116
162
  * }
117
163
  * }
@@ -123,6 +169,7 @@ declare class Model extends AbstractModel {
123
169
  * @example
124
170
  * class User extends Model {
125
171
  * constructor() {
172
+ * super()
126
173
  * this.useLoadRelationInRegistry()
127
174
  * }
128
175
  * }
@@ -136,6 +183,7 @@ declare class Model extends AbstractModel {
136
183
  * @example
137
184
  * class User extends Model {
138
185
  * constructor() {
186
+ * super()
139
187
  * this.useBuiltInRelationsFunction()
140
188
  * }
141
189
  * }
@@ -149,6 +197,7 @@ declare class Model extends AbstractModel {
149
197
  * @example
150
198
  * class User extends Model {
151
199
  * constructor() {
200
+ * super()
152
201
  * this.usePrimaryKey()
153
202
  * }
154
203
  * }
@@ -163,6 +212,7 @@ declare class Model extends AbstractModel {
163
212
  * @example
164
213
  * class User extends Model {
165
214
  * constructor() {
215
+ * super()
166
216
  * this.useUUID()
167
217
  * }
168
218
  * }
@@ -180,6 +230,7 @@ declare class Model extends AbstractModel {
180
230
  * @example
181
231
  * class User extends Model {
182
232
  * constructor() {
233
+ * super()
183
234
  * this.usePattern('camelCase')
184
235
  * }
185
236
  * }
@@ -191,6 +242,7 @@ declare class Model extends AbstractModel {
191
242
  * @example
192
243
  * class User extends Model {
193
244
  * constructor() {
245
+ * super()
194
246
  * this.useCamelCase()
195
247
  * }
196
248
  * }
@@ -202,6 +254,7 @@ declare class Model extends AbstractModel {
202
254
  * @example
203
255
  * class User extends Model {
204
256
  * constructor() {
257
+ * super()
205
258
  * this.SnakeCase()
206
259
  * }
207
260
  * }
@@ -355,6 +408,30 @@ declare class Model extends AbstractModel {
355
408
  * }
356
409
  */
357
410
  protected useHooks(arrayFunctions: Function[]): this;
411
+ /**
412
+ * The "column" method is used get column from your schema.
413
+ * @param {string} column
414
+ * @return {string}
415
+ */
416
+ column<K extends keyof TSchemaModel>(column: K): K;
417
+ /**
418
+ * The "beforeCreatingTable" method is used exection function when creating the table.
419
+ * @param {Function} fn functions for executing before creating the table
420
+ * @return {this} this
421
+ * @example
422
+ * class User extends Model {
423
+ * constructor() {
424
+ * this.beforeCreatingTable(async () => {
425
+ * await new User()
426
+ * .create({
427
+ * ...columns
428
+ * })
429
+ * .save()
430
+ * })
431
+ * }
432
+ * }
433
+ */
434
+ protected beforeCreatingTable(fn: () => Promise<any>): this;
358
435
  /**
359
436
  * exceptColumns for method except
360
437
  * @override
@@ -367,37 +444,97 @@ declare class Model extends AbstractModel {
367
444
  * @param {Function} callback query callback
368
445
  * @return {this} this
369
446
  */
370
- protected buildMethodRelation(name: string, callback?: Function): this;
447
+ protected buildMethodRelation<K extends keyof TRelationModel>(name: K, callback?: Function): this;
371
448
  /**
372
449
  *
450
+ * @override
451
+ * @param {string[]} ...columns
452
+ * @return {this} this
453
+ */
454
+ select<K extends Extract<keyof TSchemaModel, string> | `${string}.${string}` | '*'>(...columns: K[]): this;
455
+ /**
456
+ *
457
+ * @override
458
+ * @param {...string} columns
459
+ * @return {this} this
460
+ */
461
+ except<K extends Extract<keyof TSchemaModel, string> | `${string}.${string}`>(...columns: K[]): this;
462
+ /**
463
+ *
464
+ * @override
465
+ * @return {this} this
466
+ */
467
+ exceptTimestamp(): this;
468
+ /**
469
+ *
470
+ * @override
471
+ * @param {string} column
472
+ * @param {string?} order by default order = 'asc' but you can used 'asc' or 'desc'
473
+ * @return {this}
474
+ */
475
+ orderBy<K extends Extract<keyof TSchemaModel, string> | `${string}.${string}`>(column: K, order?: 'ASC' | 'DESC'): this;
476
+ /**
477
+ *
478
+ * @override
479
+ * @param {string?} columns [column=id]
480
+ * @return {this}
481
+ */
482
+ latest<K extends Extract<keyof TSchemaModel, string> | `${string}.${string}`>(...columns: K[]): this;
483
+ /**
484
+ *
485
+ * @override
486
+ * @param {string?} columns [column=id]
487
+ * @return {this}
488
+ */
489
+ oldest<K extends Extract<keyof TSchemaModel, string> | `${string}.${string}`>(...columns: K[]): this;
490
+ /**
491
+ *
492
+ * @override
493
+ * @param {string?} columns [column=id]
494
+ * @return {this}
495
+ */
496
+ groupBy<K extends Extract<keyof TSchemaModel, string> | `${string}.${string}`>(...columns: K[]): this;
497
+ /**
498
+ * @override
499
+ * @param {string} column
500
+ * @return {string} return table.column
501
+ */
502
+ bindColumn(column: string, pattern?: boolean): string;
503
+ /**
504
+ *
505
+ * @override
373
506
  * The 'makeSelectStatement' method is used to make select statement.
374
507
  * @return {Promise<string>} string
375
508
  */
376
509
  makeSelectStatement(): Promise<string>;
377
510
  /**
378
511
  *
512
+ * @override
379
513
  * The 'makeInsertStatement' method is used to make insert table statement.
380
514
  * @return {Promise<string>} string
381
515
  */
382
516
  makeInsertStatement(): Promise<string>;
383
517
  /**
384
518
  *
519
+ * @override
385
520
  * The 'makeUpdateStatement' method is used to make update table statement.
386
521
  * @return {Promise<string>} string
387
522
  */
388
523
  makeUpdateStatement(): Promise<string>;
389
524
  /**
390
525
  *
526
+ * @override
391
527
  * The 'makeDeleteStatement' method is used to make delete statement.
392
528
  * @return {Promise<string>} string
393
529
  */
394
530
  makeDeleteStatement(): Promise<string>;
395
531
  /**
396
532
  *
397
- * The 'makeCreateStatement' method is used to make create table statement.
533
+ * @override
534
+ * The 'makeCreateTableStatement' method is used to make create table statement.
398
535
  * @return {Promise<string>} string
399
536
  */
400
- makeCreateStatement(): Promise<string>;
537
+ makeCreateTableStatement(): Promise<string>;
401
538
  /**
402
539
  *
403
540
  * Clone instance of model
@@ -423,11 +560,12 @@ declare class Model extends AbstractModel {
423
560
  offset?: boolean;
424
561
  groupBy?: boolean;
425
562
  select?: boolean;
563
+ having?: boolean;
426
564
  }): Model;
427
565
  /**
428
566
  *
429
567
  * execute the query using raw sql syntax
430
- * @override method
568
+ * @override
431
569
  * @param {string} sql
432
570
  * @return {this} this
433
571
  */
@@ -435,7 +573,7 @@ declare class Model extends AbstractModel {
435
573
  /**
436
574
  *
437
575
  * execute the query using raw sql syntax actions for insert update and delete
438
- * @override method
576
+ * @override
439
577
  * @param {Object} actions
440
578
  * @property {Function} actions.sqlresult
441
579
  * @property {Function} actions.returnId
@@ -457,6 +595,12 @@ declare class Model extends AbstractModel {
457
595
  * @return {this} this
458
596
  */
459
597
  disableSoftDelete(condition?: boolean): this;
598
+ /**
599
+ * The 'disableVoid' method is used to ignore void.
600
+ *
601
+ * @return {this} this
602
+ */
603
+ disableVoid(): this;
460
604
  /**
461
605
  * Assign ignore delete_at in model
462
606
  * @param {boolean} condition
@@ -495,7 +639,7 @@ declare class Model extends AbstractModel {
495
639
  * await new User().relations('posts').findMany()
496
640
  *
497
641
  */
498
- with(...nameRelations: string[]): this;
642
+ with<K extends keyof TRelationModel>(...nameRelations: K[]): this;
499
643
  /**
500
644
  * The 'withAll' method is used to eager load related (relations) data when retrieving records from a database.
501
645
  *
@@ -504,7 +648,7 @@ declare class Model extends AbstractModel {
504
648
  * @param {...string} nameRelations if data exists return blank
505
649
  * @return {this} this
506
650
  */
507
- withAll(...nameRelations: string[]): this;
651
+ withAll<K extends keyof TRelationModel>(...nameRelations: K[]): this;
508
652
  /**
509
653
  * The 'withAll' method is used to eager load related (relations) data when retrieving records from a database.
510
654
  *
@@ -513,7 +657,7 @@ declare class Model extends AbstractModel {
513
657
  * @param {...string} nameRelations if data exists return blank
514
658
  * @return {this} this
515
659
  */
516
- withCount(...nameRelations: string[]): this;
660
+ withCount<K extends keyof TRelationModel>(...nameRelations: K[]): this;
517
661
  /**
518
662
  * The 'withTrashed' method is used to eager load related (relations) data when retrieving records from a database.
519
663
  *
@@ -522,7 +666,7 @@ declare class Model extends AbstractModel {
522
666
  * @param {...string} nameRelations if data exists return blank
523
667
  * @return {this} this
524
668
  */
525
- withTrashed(...nameRelations: string[]): this;
669
+ withTrashed<K extends keyof TRelationModel>(...nameRelations: K[]): this;
526
670
  /**
527
671
  * The 'withExists' method is used to eager load related (relations) data when retrieving records from a database.
528
672
  *
@@ -549,7 +693,7 @@ declare class Model extends AbstractModel {
549
693
  * // use with for results of relationship if relations is exists
550
694
  * await new User().relationsExists('posts').findMany()
551
695
  */
552
- withExists(...nameRelations: string[]): this;
696
+ withExists<K extends keyof TRelationModel>(...nameRelations: K[]): this;
553
697
  /**
554
698
  *
555
699
  * Use relations in registry of model return only exists result of relation query
@@ -574,7 +718,7 @@ declare class Model extends AbstractModel {
574
718
  * await new User().has('posts').findMany()
575
719
  * @return {this} this
576
720
  */
577
- has(...nameRelations: string[]): this;
721
+ has<K extends keyof TRelationModel>(...nameRelations: K[]): this;
578
722
  /**
579
723
  *
580
724
  * The 'withQuery' method is particularly useful when you want to filter or add conditions records based on related data.
@@ -623,7 +767,7 @@ declare class Model extends AbstractModel {
623
767
  * .findMany()
624
768
  * @return {this} this
625
769
  */
626
- withQuery(nameRelation: string, callback: Function): this;
770
+ withQuery<K extends keyof TRelationModel, TModel extends Model>(nameRelation: K, callback: (query: TModel) => TModel): this;
627
771
  /**
628
772
  *
629
773
  * Use relations in registry of model return result of relation query
@@ -648,7 +792,7 @@ declare class Model extends AbstractModel {
648
792
  * await new User().relations('posts').findMany()
649
793
  * @return {this} this
650
794
  */
651
- relations(...nameRelations: string[]): this;
795
+ relations(...nameRelations: any[]): this;
652
796
  /**
653
797
  *
654
798
  * Use relations in registry of model return only exists result of relation query
@@ -673,7 +817,7 @@ declare class Model extends AbstractModel {
673
817
  * await new User().relationsExists('posts').findMany()
674
818
  * @return {this} this
675
819
  */
676
- relationsExists(...nameRelations: string[]): this;
820
+ relationsExists<K extends keyof TRelationModel>(...nameRelations: K[]): this;
677
821
  /**
678
822
  *
679
823
  * Use relation '${name}' registry of model return callback this query model
@@ -720,21 +864,21 @@ declare class Model extends AbstractModel {
720
864
  * .findMany()
721
865
  * @return {this} this
722
866
  */
723
- relationQuery(nameRelation: string, callback: Function): this;
867
+ relationQuery<K extends keyof TRelationModel, T extends Model>(nameRelation: K, callback: (query: T) => T): this;
724
868
  /**
725
869
  *
726
870
  * Use relations in registry of model return ignore soft deleted
727
871
  * @param {...string} nameRelations if data exists return blank
728
872
  * @return {this} this
729
873
  */
730
- relationsAll(...nameRelations: string[]): this;
874
+ relationsAll<K extends keyof TRelationModel>(...nameRelations: K[]): this;
731
875
  /**
732
876
  *
733
877
  * Use relations in registry of model return only in trash (soft delete)
734
878
  * @param {...string} nameRelations if data exists return blank
735
879
  * @return {this} this
736
880
  */
737
- relationsTrashed(...nameRelations: string[]): this;
881
+ relationsTrashed<K extends keyof TRelationModel>(...nameRelations: K[]): this;
738
882
  /**
739
883
  * The 'hasOne' relationship defines a one-to-one relationship between two database tables.
740
884
  *
@@ -751,7 +895,7 @@ declare class Model extends AbstractModel {
751
895
  * @property {string} relation.freezeTable
752
896
  * @return {this} this
753
897
  */
754
- protected hasOne({ name, as, model, localKey, foreignKey, freezeTable }: Relation): this;
898
+ protected hasOne<K extends keyof TRelationModel>({ name, as, model, localKey, foreignKey, freezeTable }: Relation<K>): this;
755
899
  /**
756
900
  * The 'hasMany' relationship defines a one-to-many relationship between two database tables.
757
901
  *
@@ -768,7 +912,7 @@ declare class Model extends AbstractModel {
768
912
  * @property {string} relation.freezeTable
769
913
  * @return {this} this
770
914
  */
771
- protected hasMany({ name, as, model, localKey, foreignKey, freezeTable }: Relation): this;
915
+ protected hasMany<K extends keyof TRelationModel>({ name, as, model, localKey, foreignKey, freezeTable }: Relation<K>): this;
772
916
  /**
773
917
  * The 'belongsTo' relationship defines a one-to-one or many-to-one relationship between two database tables.
774
918
  *
@@ -785,7 +929,7 @@ declare class Model extends AbstractModel {
785
929
  * @property {string} relation.freezeTable
786
930
  * @return {this} this
787
931
  */
788
- protected belongsTo({ name, as, model, localKey, foreignKey, freezeTable }: Relation): this;
932
+ protected belongsTo<K extends keyof TRelationModel>({ name, as, model, localKey, foreignKey, freezeTable }: Relation<K>): this;
789
933
  /**
790
934
  * The 'belongsToMany' relationship defines a many-to-many relationship between two database tables.
791
935
  *
@@ -805,7 +949,7 @@ declare class Model extends AbstractModel {
805
949
  * @property {class?} relation.modelPivot model for pivot
806
950
  * @return {this} this
807
951
  */
808
- protected belongsToMany({ name, as, model, localKey, foreignKey, freezeTable, pivot, oldVersion, modelPivot }: Relation): this;
952
+ protected belongsToMany<K extends keyof TRelationModel>({ name, as, model, localKey, foreignKey, freezeTable, pivot, oldVersion, modelPivot }: Relation<K>): this;
809
953
  /**
810
954
  * The 'hasOneBuilder' method is useful for creating 'hasOne' relationship to function
811
955
  *
@@ -896,31 +1040,30 @@ declare class Model extends AbstractModel {
896
1040
  * @return {string} string
897
1041
  */
898
1042
  toTableNameAndColumn(column: string): string;
899
- private _columnPattern;
900
1043
  /**
901
- * @override Method
902
- * @param {string} column if arguments is object
1044
+ * @override
1045
+ * @param {string | K} column if arguments is object
903
1046
  * @param {string?} operator ['=', '<', '>' ,'!=', '!<', '!>' ,'LIKE']
904
1047
  * @param {any?} value
905
1048
  * @return {this} this
906
1049
  */
907
- where(column: string | Record<string, any>, operator?: any, value?: any): this;
1050
+ where<K extends Extract<keyof TSchemaModel, string> | `${string}.${string}`>(column: K | Record<string, any>, operator?: any, value?: any): this;
908
1051
  /**
909
- * @override Method
1052
+ * @override
910
1053
  * @param {string} column
911
1054
  * @param {string?} operator ['=', '<', '>' ,'!=', '!<', '!>' ,'LIKE']
912
1055
  * @param {any?} value
913
1056
  * @return {this}
914
1057
  */
915
- orWhere(column: string, operator?: any, value?: any): this;
1058
+ orWhere<K extends Extract<keyof TSchemaModel, string> | `${string}.${string}`>(column: K, operator?: any, value?: any): this;
916
1059
  /**
917
- * @override Method
1060
+ * @override
918
1061
  * @param {Object} columns
919
1062
  * @return {this}
920
1063
  */
921
1064
  whereObject(columns: Record<string, any>): this;
922
1065
  /**
923
- * @override Method
1066
+ * @override
924
1067
  * @param {string} column
925
1068
  * @param {object} property object { key , value , operator }
926
1069
  * @property {string} property.key
@@ -928,201 +1071,236 @@ declare class Model extends AbstractModel {
928
1071
  * @property {string?} property.operator
929
1072
  * @return {this}
930
1073
  */
931
- whereJSON(column: string, { key, value, operator }: {
1074
+ whereJSON<K extends Extract<keyof TSchemaModel, string> | `${string}.${string}`>(column: K, { key, value, operator }: {
932
1075
  key: string;
933
1076
  value: string;
934
1077
  operator?: string;
935
1078
  }): this;
936
1079
  /**
937
- * @override Method
1080
+ * @override
938
1081
  * @param {number} userId
939
1082
  * @param {string?} column custom it *if column is not user_id
940
1083
  * @return {this}
941
1084
  */
942
1085
  whereUser(userId: number, column?: string): this;
943
1086
  /**
944
- * @override Method
1087
+ * @override
945
1088
  * @param {string} column
946
1089
  * @param {array} array
947
1090
  * @return {this}
948
1091
  */
949
- whereIn(column: string, array: any[]): this;
1092
+ whereIn<K extends Extract<keyof TSchemaModel, string> | `${string}.${string}`>(column: K, array: any[]): this;
950
1093
  /**
951
- * @override Method
1094
+ * @override
952
1095
  * @param {string} column
953
1096
  * @param {array} array
954
1097
  * @return {this}
955
1098
  */
956
- orWhereIn(column: string, array: any[]): this;
1099
+ orWhereIn<K extends Extract<keyof TSchemaModel, string> | `${string}.${string}`>(column: K, array: any[]): this;
957
1100
  /**
958
- * @override Method
1101
+ * @override
959
1102
  * @param {string} column
960
1103
  * @param {array} array
961
1104
  * @return {this}
962
1105
  */
963
- whereNotIn(column: string, array: any[]): this;
1106
+ whereNotIn<K extends Extract<keyof TSchemaModel, string> | `${string}.${string}`>(column: K, array: any[]): this;
964
1107
  /**
965
- * @override Method
1108
+ * @override
966
1109
  * @param {string} column
967
1110
  * @param {array} array
968
1111
  * @return {this}
969
1112
  */
970
- orWhereNotIn(column: string, array: any[]): this;
1113
+ orWhereNotIn<K extends Extract<keyof TSchemaModel, string> | `${string}.${string}`>(column: K, array: any[]): this;
971
1114
  /**
972
- * @override Method
1115
+ * @override
973
1116
  * @param {string} column
974
1117
  * @param {string} subQuery
975
1118
  * @return {this}
976
1119
  */
977
- whereSubQuery(column: string, subQuery: string): this;
1120
+ whereSubQuery<K extends Extract<keyof TSchemaModel, string> | `${string}.${string}`>(column: K, subQuery: string): this;
978
1121
  /**
979
- * @override Method
1122
+ * @override
980
1123
  * @param {string} column
981
1124
  * @param {string} subQuery
982
1125
  * @return {this}
983
1126
  */
984
- whereNotSubQuery(column: string, subQuery: string): this;
1127
+ whereNotSubQuery<K extends Extract<keyof TSchemaModel, string> | `${string}.${string}`>(column: K, subQuery: string): this;
985
1128
  /**
986
- * @override Method
1129
+ * @override
987
1130
  * @param {string} column
988
1131
  * @param {string} subQuery
989
1132
  * @return {this}
990
1133
  */
991
- orWhereSubQuery(column: string, subQuery: string): this;
1134
+ orWhereSubQuery<K extends Extract<keyof TSchemaModel, string> | `${string}.${string}`>(column: K, subQuery: string): this;
992
1135
  /**
993
- * @override Method
1136
+ * @override
994
1137
  * @param {string} column
995
1138
  * @param {string} subQuery
996
1139
  * @return {this}
997
1140
  */
998
- orWhereNotSubQuery(column: string, subQuery: string): this;
1141
+ orWhereNotSubQuery<K extends Extract<keyof TSchemaModel, string> | `${string}.${string}`>(column: K, subQuery: string): this;
999
1142
  /**
1000
- * @override Method
1143
+ * @override
1001
1144
  * @param {string} column
1002
1145
  * @param {array} array
1003
1146
  * @return {this}
1004
1147
  */
1005
- whereBetween(column: string, array: any[]): this;
1148
+ whereBetween<K extends Extract<keyof TSchemaModel, string> | `${string}.${string}`>(column: K, array: any[]): this;
1006
1149
  /**
1007
- * @override Method
1150
+ * @override
1008
1151
  * @param {string} column
1009
1152
  * @param {array} array
1010
1153
  * @return {this}
1011
1154
  */
1012
- orWhereBetween(column: string, array: any[]): this;
1155
+ orWhereBetween<K extends Extract<keyof TSchemaModel, string> | `${string}.${string}`>(column: K, array: any[]): this;
1013
1156
  /**
1014
- * @override Method
1157
+ * @override
1015
1158
  * @param {string} column
1016
1159
  * @param {array} array
1017
1160
  * @return {this}
1018
1161
  */
1019
- whereNotBetween(column: string, array: any[]): this;
1162
+ whereNotBetween<K extends Extract<keyof TSchemaModel, string> | `${string}.${string}`>(column: K, array: any[]): this;
1020
1163
  /**
1021
- * @override Method
1164
+ * @override
1022
1165
  * @param {string} column
1023
1166
  * @param {array} array
1024
1167
  * @return {this}
1025
1168
  */
1026
- orWhereNotBetween(column: string, array: any[]): this;
1169
+ orWhereNotBetween<K extends Extract<keyof TSchemaModel, string> | `${string}.${string}`>(column: K, array: any[]): this;
1027
1170
  /**
1028
- * @override Method
1171
+ * @override
1029
1172
  * @param {string} column
1030
1173
  * @return {this}
1031
1174
  */
1032
- whereNull(column: string): this;
1175
+ whereNull<K extends Extract<keyof TSchemaModel, string> | `${string}.${string}`>(column: K): this;
1033
1176
  /**
1034
- * @override Method
1177
+ * @override
1035
1178
  * @param {string} column
1036
1179
  * @return {this}
1037
1180
  */
1038
- orWhereNull(column: string): this;
1181
+ orWhereNull<K extends Extract<keyof TSchemaModel, string> | `${string}.${string}`>(column: K): this;
1039
1182
  /**
1040
- * @override Method
1183
+ * @override
1041
1184
  * @param {string} column
1042
1185
  * @return {this}
1043
1186
  */
1044
- whereNotNull(column: string): this;
1187
+ whereNotNull<K extends Extract<keyof TSchemaModel, string> | `${string}.${string}`>(column: K): this;
1045
1188
  /**
1046
- * @override Method
1189
+ * @override
1047
1190
  * @param {string} column
1048
1191
  * @return {this}
1049
1192
  */
1050
- orWhereNotNull(column: string): this;
1193
+ orWhereNotNull<K extends Extract<keyof TSchemaModel, string> | `${string}.${string}`>(column: K): this;
1051
1194
  /**
1052
- * @override Method
1195
+ * @override
1053
1196
  * @param {string} column
1054
1197
  * @param {string?} operator = < > != !< !>
1055
1198
  * @param {any?} value
1056
1199
  * @return {this}
1057
1200
  */
1058
- whereSensitive(column: string, operator?: any, value?: any): this;
1201
+ whereSensitive<K extends Extract<keyof TSchemaModel, string> | `${string}.${string}`>(column: K, operator?: any, value?: any): this;
1059
1202
  /**
1060
- * @override Method
1203
+ * @override
1061
1204
  * @param {string} column
1062
1205
  * @param {string?} operator = < > != !< !>
1063
1206
  * @param {any?} value
1064
1207
  * @return {this}
1065
1208
  */
1066
- whereStrict(column: string, operator?: any, value?: any): this;
1209
+ whereStrict<K extends Extract<keyof TSchemaModel, string> | `${string}.${string}`>(column: K, operator?: any, value?: any): this;
1067
1210
  /**
1068
- * @override Method
1211
+ * @override
1069
1212
  * @param {string} column
1070
1213
  * @param {string?} operator = < > != !< !>
1071
1214
  * @param {any?} value
1072
1215
  * @return {this}
1073
1216
  */
1074
- orWhereSensitive(column: string, operator?: any, value?: any): this;
1217
+ orWhereSensitive<K extends Extract<keyof TSchemaModel, string> | `${string}.${string}`>(column: K, operator?: any, value?: any): this;
1075
1218
  /**
1076
- * @override Method
1219
+ * @override
1077
1220
  * @param {Function} callback callback query
1078
1221
  * @return {this}
1079
1222
  */
1080
- whereQuery(callback: Function): this;
1223
+ whereQuery<T extends Model>(callback: (query: T) => T): this;
1081
1224
  /**
1082
- * @override Method
1225
+ * @override
1226
+ * @param {string[]} columns
1227
+ * @param {string?} operator ['=', '<', '>' ,'!=', '!<', '!>' ,'LIKE']
1228
+ * @param {any?} value
1229
+ * @return {this}
1230
+ */
1231
+ whereAny<K extends Extract<keyof TSchemaModel, string> | `${string}.${string}`>(columns: K[], operator?: any, value?: any): this;
1232
+ /**
1233
+ * The 'whereAll' method is used to clause to a database query.
1234
+ *
1235
+ * This method allows you to specify conditions that the retrieved records must meet.
1236
+ *
1237
+ * If has only 2 arguments default operator '='
1238
+ * @param {string[]} columns
1239
+ * @param {string?} operator ['=', '<', '>' ,'!=', '!<', '!>' ,'LIKE']
1240
+ * @param {any?} value
1241
+ * @return {this}
1242
+ */
1243
+ whereAll<K extends Extract<keyof TSchemaModel, string> | `${string}.${string}`>(columns: K[], operator?: any, value?: any): this;
1244
+ /**
1245
+ * @override
1083
1246
  * @return {promise<boolean>} promise boolean
1084
1247
  */
1085
1248
  delete(): Promise<boolean>;
1086
1249
  /**
1087
- * @override Method
1250
+ * @override
1088
1251
  * @return {promise<boolean>} promise boolean
1089
1252
  */
1090
1253
  deleteMany(): Promise<boolean>;
1091
1254
  /**
1092
- * @override Method
1255
+ *
1256
+ * The 'delete' method is used to delete records from a database table based on the specified query conditions.
1257
+ *
1258
+ * It allows you to remove one or more records that match certain criteria.
1259
+ *
1260
+ * This method should be ignore the soft delete
1261
+ * @return {promise<boolean>}
1262
+ */
1263
+ forceDelete(): Promise<boolean>;
1264
+ /**
1265
+ *
1266
+ * @override
1267
+ * @param {Function?} cb callback function return query sql
1093
1268
  * @return {promise<Record<string,any> | null>} Record | null
1094
1269
  */
1095
- first(cb?: Function): Promise<Record<string, any> | null>;
1270
+ first<K>(cb?: Function): Promise<Partial<TSchemaModel> & K & TRelationModel | null>;
1096
1271
  /**
1097
- * @override Method
1272
+ * @override
1273
+ * @param {Function?} cb callback function return query sql
1098
1274
  * @return {promise<Record<string,any> | null>} Record | null
1099
1275
  */
1100
- findOne(): Promise<Record<string, any> | null>;
1276
+ findOne<K>(cb?: Function): Promise<Partial<TSchemaModel> & K | null>;
1101
1277
  /**
1102
- * @override Method
1278
+ * @override
1103
1279
  * @return {promise<object | Error>} Record | throw error
1104
1280
  */
1105
- firstOrError(message: string, options?: Record<string, any>): Promise<Record<string, any>>;
1281
+ firstOrError<K>(message: string, options?: Record<string, any>): Promise<Partial<TSchemaModel> & K>;
1106
1282
  /**
1107
1283
  *
1108
- * @override Method
1284
+ * @override
1109
1285
  * @return {promise<any>} Record | throw error
1110
1286
  */
1111
- findOneOrError(message: string, options?: Record<string, any>): Promise<Record<string, any>>;
1287
+ findOneOrError<K>(message: string, options?: Record<string, any>): Promise<Partial<TSchemaModel> & K>;
1112
1288
  /**
1113
1289
  *
1114
- * @override Method
1290
+ * @override
1291
+ * @param {Function?} cb callback function return query sql
1115
1292
  * @return {promise<array>} Array
1116
1293
  */
1117
- get(cb?: Function): Promise<any[]>;
1294
+ get<K = Partial<TSchemaModel>>(cb?: Function): Promise<Partial<TSchemaModel[]> & K[]>;
1118
1295
  /**
1119
1296
  *
1120
- * @override Method
1297
+ * @override
1298
+ * @param {Function?} cb callback function return query sql
1121
1299
  * @return {promise<array>} Array
1122
1300
  */
1123
- findMany(): Promise<any[]>;
1301
+ findMany<K = Partial<TSchemaModel>>(cb?: Function): Promise<Partial<TSchemaModel[]> & K[]>;
1124
1302
  /**
1125
- * @override Method
1303
+ * @override
1126
1304
  * @param {object?} paginationOptions by default page = 1 , limit = 15
1127
1305
  * @property {number} paginationOptions.limit
1128
1306
  * @property {number} paginationOptions.page
@@ -1134,7 +1312,7 @@ declare class Model extends AbstractModel {
1134
1312
  }): Promise<Pagination>;
1135
1313
  /**
1136
1314
  *
1137
- * @override Method
1315
+ * @override
1138
1316
  * @param {?object} paginationOptions by default page = 1 , limit = 15
1139
1317
  * @property {number} paginationOptions.limit
1140
1318
  * @property {number} paginationOptions.page
@@ -1145,106 +1323,144 @@ declare class Model extends AbstractModel {
1145
1323
  page?: number;
1146
1324
  }): Promise<Pagination>;
1147
1325
  /**
1148
- * @override Method
1326
+ * @override
1149
1327
  * @param {string} column
1150
1328
  * @return {Promise<array>} Array
1151
1329
  */
1152
1330
  getGroupBy(column: string): Promise<any[]>;
1153
1331
  /**
1154
- * @override Method
1332
+ * @override
1155
1333
  * @param {object} data for insert
1156
1334
  * @return {this} this
1157
1335
  */
1158
- insert(data: Record<string, string | number | boolean | null | undefined>): this;
1336
+ insert<K extends keyof TSchemaModel>(data: K extends keyof TSchemaModel ? {
1337
+ [P in K]: string | number | boolean | null | undefined;
1338
+ } : never): this;
1159
1339
  /**
1160
- * @override Method
1340
+ * @override
1161
1341
  * @param {object} data for insert
1162
1342
  * @return {this} this
1163
1343
  */
1164
- create(data: Record<string, string | number | boolean | null | undefined>): this;
1344
+ create<K extends keyof TSchemaModel>(data: K extends keyof TSchemaModel ? {
1345
+ [P in K]: string | number | boolean | null | undefined;
1346
+ } : never): this;
1165
1347
  /**
1166
- * @override Method
1348
+ * @override
1167
1349
  * @param {object} data
1168
1350
  * @param {array?} updateNotExists options for except update some records in your ${data}
1169
1351
  * @return {this} this
1170
1352
  */
1171
- update(data: Record<string, string | number | boolean | null | undefined>, updateNotExists?: string[]): this;
1353
+ update<K extends keyof TSchemaModel>(data: K extends keyof TSchemaModel ? {
1354
+ [P in K]: string | number | boolean | null | undefined;
1355
+ } : never, updateNotExists?: string[]): this;
1172
1356
  /**
1173
- * @override Method
1357
+ * @override
1174
1358
  * @param {object} data
1175
1359
  * @param {array?} updateNotExists options for except update some records in your ${data}
1176
1360
  * @return {this} this
1177
1361
  */
1178
- updateMany(data: Record<string, string | number | boolean | null | undefined>, updateNotExists?: string[]): this;
1362
+ updateMany<K extends keyof TSchemaModel>(data: K extends keyof TSchemaModel ? {
1363
+ [P in K]: string | number | boolean | null | undefined;
1364
+ } : never, updateNotExists?: string[]): this;
1179
1365
  /**
1180
- * @override Method
1366
+ * @override
1181
1367
  * @param {object} data
1182
1368
  * @return {this} this
1183
1369
  */
1184
- updateNotExists(data: Record<string, string | number | boolean | null | undefined> & {
1185
- length?: unknown;
1186
- }): this;
1370
+ updateNotExists<K extends keyof TSchemaModel>(data: K extends keyof TSchemaModel ? {
1371
+ [P in K]: string | number | boolean | null | undefined;
1372
+ } : never): this;
1187
1373
  /**
1188
- * @override Method
1374
+ * @override
1189
1375
  * @param {object} data for update or create
1190
1376
  * @return {this} this
1191
1377
  */
1192
- updateOrCreate(data: Record<string, string | number | boolean | null | undefined>): this;
1378
+ updateOrCreate<K extends keyof TSchemaModel>(data: K extends keyof TSchemaModel ? {
1379
+ [P in K]: string | number | boolean | null | undefined;
1380
+ } : never): this;
1193
1381
  /**
1194
- * @override Method
1382
+ * @override
1195
1383
  * @param {object} data for update or create
1196
1384
  * @return {this} this
1197
1385
  */
1198
- updateOrInsert(data: Record<string, string | number | boolean | null | undefined>): this;
1386
+ updateOrInsert<K extends keyof TSchemaModel>(data: K extends keyof TSchemaModel ? {
1387
+ [P in K]: string | number | boolean | null | undefined;
1388
+ } : never): this;
1199
1389
  /**
1200
- * @override Method
1390
+ * @override
1201
1391
  * @param {object} data for update or create
1202
1392
  * @return {this} this
1203
1393
  */
1204
- insertOrUpdate(data: Record<string, string | number | boolean | null | undefined>): this;
1394
+ insertOrUpdate<K extends keyof TSchemaModel>(data: K extends keyof TSchemaModel ? {
1395
+ [P in K]: string | number | boolean | null | undefined;
1396
+ } : never): this;
1205
1397
  /**
1206
- * @override Method
1398
+ * @override
1207
1399
  * @param {object} data for update or create
1208
1400
  * @return {this} this
1209
1401
  */
1210
- createOrUpdate(data: Record<string, string | number | boolean | null | undefined>): this;
1402
+ createOrUpdate<K extends keyof TSchemaModel>(data: K extends keyof TSchemaModel ? {
1403
+ [P in K]: string | number | boolean | null | undefined;
1404
+ } : never): this;
1211
1405
  /**
1212
- * @override Method
1406
+ * @override
1213
1407
  * @param {object} data for create
1214
1408
  * @return {this} this
1215
1409
  */
1216
- createOrSelect(data: Record<string, string | number | boolean | null | undefined>): this;
1410
+ createOrSelect<K extends keyof TSchemaModel>(data: K extends keyof TSchemaModel ? {
1411
+ [P in K]: string | number | boolean | null | undefined;
1412
+ } : never): this;
1217
1413
  /**
1218
- * @override Method
1414
+ * @override
1219
1415
  * @param {object} data for update or create
1220
1416
  * @return {this} this
1221
1417
  */
1222
- insertOrSelect(data: Record<string, string | number | boolean | null | undefined>): this;
1418
+ insertOrSelect<K extends keyof TSchemaModel>(data: K extends keyof TSchemaModel ? {
1419
+ [P in K]: string | number | boolean | null | undefined;
1420
+ } : never): this;
1223
1421
  /**
1224
- * @override Method
1422
+ * @override
1225
1423
  * @param {Record<string,any>[]} data create multiple data
1226
1424
  * @return {this} this this
1227
1425
  */
1228
- createMultiple(data: Record<string, string | number | boolean | null | undefined>[]): this;
1426
+ createMultiple<K extends keyof TSchemaModel>(data: Record<K, string | number | boolean | null | undefined>[]): this;
1229
1427
  /**
1230
1428
  *
1231
- * @override Method
1429
+ * @override
1232
1430
  * @param {Record<string,any>[]} data create multiple data
1233
1431
  * @return {this} this
1234
1432
  */
1235
- insertMultiple(data: Record<string, string | number | boolean | null | undefined>[]): this;
1433
+ insertMultiple<K extends keyof TSchemaModel>(data: Record<K, string | number | boolean | null | undefined>[]): this;
1236
1434
  /**
1237
- * @override Method
1435
+ *
1436
+ * @override
1238
1437
  * @param {object} data create not exists data
1239
1438
  * @return {this} this
1240
1439
  */
1241
- createNotExists(data: Record<string, string | number | boolean | null | undefined>): this;
1440
+ createNotExists<K extends keyof TSchemaModel>(data: K extends keyof TSchemaModel ? {
1441
+ [P in K]: string | number | boolean | null | undefined;
1442
+ } : never): this;
1242
1443
  /**
1243
- * @override Method
1444
+ *
1445
+ * @override
1244
1446
  * @param {object} data create not exists data
1245
1447
  * @return {this} this this
1246
1448
  */
1247
- insertNotExists(data: Record<string, string | number | boolean | null | undefined>): this;
1449
+ insertNotExists<K extends keyof TSchemaModel>(data: K extends keyof TSchemaModel ? {
1450
+ [P in K]: string | number | boolean | null | undefined;
1451
+ } : never): this;
1452
+ /**
1453
+ *
1454
+ * @override
1455
+ * @param {{when : Object , columns : Object}[]} cases update multiple data specific columns by cases update
1456
+ * @property {Record<string,string | number | boolean | null | undefined>} cases.when
1457
+ * @property {Record<string,string | number | boolean | null | undefined>} cases.columns
1458
+ * @return {this} this
1459
+ */
1460
+ updateMultiple(cases: {
1461
+ when: Record<string, any>;
1462
+ columns: Record<string, string | number | boolean | null | undefined>;
1463
+ }[]): this;
1248
1464
  getSchemaModel(): Record<string, Blueprint> | null;
1249
1465
  validation(schema?: ValidateSchema): this;
1250
1466
  /**
@@ -1254,33 +1470,42 @@ declare class Model extends AbstractModel {
1254
1470
  */
1255
1471
  bindPattern(column: string): string;
1256
1472
  /**
1257
- * @override Method
1473
+ * @override
1258
1474
  * @return {Promise<Record<string,any> | any[] | null | undefined>}
1259
1475
  */
1260
1476
  save(): Promise<Record<string, any> | any[] | null | undefined>;
1261
1477
  /**
1262
1478
  *
1263
- * @override Method
1479
+ * @override
1264
1480
  * @param {number} rows number of rows
1265
- * @return {promise<any>}
1481
+ * @param {Function} callback function will be called data and index
1482
+ * @return {promise<any[]>}
1266
1483
  */
1267
1484
  faker(rows: number, callback?: Function): Promise<Record<string, any>[]>;
1268
1485
  /**
1269
1486
  * The 'Sync' method is used to check for create or update table or columns with your schema in your model.
1270
- *
1271
- * @property {boolean} force - forec always check all columns if not exists will be created
1272
- * @property {boolean} foreign - foreign key for constraint
1273
- * @return {promise<void>}
1274
- */
1275
- sync({ force, foreign }?: {
1487
+ * @type {object} options
1488
+ * @property {boolean} options.force - forec always check all columns if not exists will be created
1489
+ * @property {boolean} options.log - show log execution with sql statements
1490
+ * @property {boolean} options.foreign - check when has a foreign keys will be created
1491
+ * @property {boolean} options.changed - check when column is changed attribute will be change attribute
1492
+ * @return {Promise<void>}
1493
+ */
1494
+ sync({ force, foreign, changed }?: {
1276
1495
  force?: boolean | undefined;
1277
1496
  foreign?: boolean | undefined;
1497
+ changed?: boolean | undefined;
1278
1498
  }): Promise<void>;
1499
+ covertColumnSchemaToFixColumn(column: string): string;
1500
+ covertFixColumnToColumnSchema(column: string): string;
1279
1501
  private _valuePattern;
1502
+ private _checkTableLoggerIsExists;
1503
+ private _columnPattern;
1280
1504
  private _isPatternSnakeCase;
1281
1505
  private _classToTableName;
1282
1506
  private _makeTableName;
1283
1507
  private _handleSoftDelete;
1508
+ private _handleSelect;
1284
1509
  /**
1285
1510
  *
1286
1511
  * generate sql statements