tspace-mysql 1.6.2 → 1.6.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,18 +1,33 @@
1
1
  import { AbstractModel } from './Abstracts/AbstractModel';
2
2
  import { Blueprint } from './Blueprint';
3
3
  import { TSchemaModel } from './UtilityTypes';
4
- import { TRelationOptions, TPagination, TRelationQueryOptions, TValidateSchema, TGlobalSetting, TRawStringQuery } from '../types';
4
+ import { TRelationOptions, TPagination, TRelationQueryOptions, TValidateSchema, TGlobalSetting, TRawStringQuery, TRegistry } from '../types';
5
5
  /**
6
6
  *
7
7
  * 'Model' class is a representation of a database table
8
+ * @generic {Type} TS
9
+ * @generic {Type} TR
8
10
  * @example
9
- * class User extends Model {
10
- * ...........
11
+ * import { Model, Blueprint , TSchema , TRelation } from 'tspace-mysql'
12
+ *
13
+ * const schema = {
14
+ * id : new Blueprint().int().primary().autoIncrement(),
15
+ * uuid : new Blueprint().varchar(50).null(),
16
+ * email : new Blueprint().varchar(50).null(),
17
+ * name : new Blueprint().varchar(255).null(),
18
+ * }
19
+ *
20
+ * type TS = TSchema<typeof schema>
21
+ * type TR = TRelation<{}>
22
+ *
23
+ * class User extends Model<TS,TR> {
24
+ * ...........configration
11
25
  * }
26
+ *
12
27
  * const users = await new User().findMany()
13
28
  * console.log(users)
14
29
  */
15
- declare class Model<TypeSchemaModel extends Record<string, any> = any, TypeRelationModel = unknown> extends AbstractModel<TypeSchemaModel, TypeRelationModel> {
30
+ declare class Model<TS extends Record<string, any> = any, TR = unknown> extends AbstractModel<TS, TR> {
16
31
  constructor();
17
32
  /**
18
33
  * The 'global' method is used setting global variables in models.
@@ -154,7 +169,7 @@ declare class Model<TypeSchemaModel extends Record<string, any> = any, TypeRelat
154
169
  * It's automatically create, called when not exists table or columns.
155
170
  * @param {object} schema using Blueprint for schema
156
171
  * @example
157
- * import { Blueprint, TypeRelationModel } from 'tspace-mysql';
172
+ * import { Blueprint, TR } from 'tspace-mysql';
158
173
  * class User extends Model {
159
174
  * constructor() {
160
175
  * super()
@@ -461,31 +476,31 @@ declare class Model<TypeSchemaModel extends Record<string, any> = any, TypeRelat
461
476
  * @param {Function} callback query callback
462
477
  * @returns {this} this
463
478
  */
464
- protected buildMethodRelation<K extends TypeRelationModel extends object ? keyof TypeRelationModel : string>(name: K, callback?: Function): this;
479
+ protected buildMethodRelation<K extends TR extends object ? keyof TR : string>(name: K, callback?: Function): this;
465
480
  /**
466
481
  * The 'typeOfSchema' method is used get type of schema.
467
- * @returns {TypeSchemaModel} type of schema
482
+ * @returns {TS} type of schema
468
483
  */
469
- typeOfSchema(): TypeSchemaModel;
484
+ typeOfSchema(): TS;
470
485
  /**
471
486
  * The 'typeOfRelation' method is used get type of relation.
472
- * @returns {TypeRelationModel} type of Relation
487
+ * @returns {TR} type of Relation
473
488
  */
474
- typeOfRelation(): TypeRelationModel;
489
+ typeOfRelation(): TR;
475
490
  /**
476
491
  *
477
492
  * @override
478
493
  * @param {string[]} ...columns
479
494
  * @returns {this} this
480
495
  */
481
- select<K extends Extract<keyof TypeSchemaModel, string> | `${string}.${string}` | TRawStringQuery | '*'>(...columns: K[]): this;
496
+ select<K extends Extract<keyof TS, string> | `${string}.${string}` | TRawStringQuery | '*'>(...columns: K[]): this;
482
497
  /**
483
498
  *
484
499
  * @override
485
500
  * @param {...string} columns
486
501
  * @returns {this} this
487
502
  */
488
- except<K extends Extract<keyof TypeSchemaModel, string> | `${string}.${string}`>(...columns: K[]): this;
503
+ except<K extends Extract<keyof TS, string> | `${string}.${string}`>(...columns: K[]): this;
489
504
  /**
490
505
  *
491
506
  * @override
@@ -499,28 +514,28 @@ declare class Model<TypeSchemaModel extends Record<string, any> = any, TypeRelat
499
514
  * @param {string?} order by default order = 'asc' but you can used 'asc' or 'desc'
500
515
  * @returns {this}
501
516
  */
502
- orderBy<K extends Extract<keyof TypeSchemaModel, string> | `${string}.${string}`>(column: K, order?: 'ASC' | 'DESC'): this;
517
+ orderBy<K extends Extract<keyof TS, string> | `${string}.${string}`>(column: K, order?: 'ASC' | 'DESC'): this;
503
518
  /**
504
519
  *
505
520
  * @override
506
521
  * @param {string?} columns [column=id]
507
522
  * @returns {this}
508
523
  */
509
- latest<K extends Extract<keyof TypeSchemaModel, string> | `${string}.${string}`>(...columns: K[]): this;
524
+ latest<K extends Extract<keyof TS, string> | `${string}.${string}`>(...columns: K[]): this;
510
525
  /**
511
526
  *
512
527
  * @override
513
528
  * @param {string?} columns [column=id]
514
529
  * @returns {this}
515
530
  */
516
- oldest<K extends Extract<keyof TypeSchemaModel, string> | `${string}.${string}`>(...columns: K[]): this;
531
+ oldest<K extends Extract<keyof TS, string> | `${string}.${string}`>(...columns: K[]): this;
517
532
  /**
518
533
  *
519
534
  * @override
520
535
  * @param {string?} columns [column=id]
521
536
  * @returns {this}
522
537
  */
523
- groupBy<K extends Extract<keyof TypeSchemaModel, string> | `${string}.${string}`>(...columns: K[]): this;
538
+ groupBy<K extends Extract<keyof TS, string> | `${string}.${string}`>(...columns: K[]): this;
524
539
  /**
525
540
  * @override
526
541
  * @param {string} column
@@ -648,7 +663,7 @@ declare class Model<TypeSchemaModel extends Record<string, any> = any, TypeRelat
648
663
  * @param {...string} nameRelations ...name registry in models using (hasOne , hasMany , belongsTo , belongsToMany)
649
664
  * @returns {this} this
650
665
  * @example
651
- * import { Model , TypeRelationModel } from 'tspace-mysql'
666
+ * import { Model , TR } from 'tspace-mysql'
652
667
  *
653
668
  * class User extends Model {
654
669
  * constructor(){
@@ -668,7 +683,7 @@ declare class Model<TypeSchemaModel extends Record<string, any> = any, TypeRelat
668
683
  * await new User().relations('posts').findMany()
669
684
  *
670
685
  */
671
- with<K extends TypeRelationModel extends object ? keyof TypeRelationModel : string>(...nameRelations: K[]): this;
686
+ with<K extends TR extends object ? keyof TR : string>(...nameRelations: K[]): this;
672
687
  /**
673
688
  * The 'relations' method is used to eager load related (relations) data when retrieving records from a database.
674
689
  *
@@ -677,7 +692,7 @@ declare class Model<TypeSchemaModel extends Record<string, any> = any, TypeRelat
677
692
  * @param {...string} nameRelations ...name registry in models using (hasOne , hasMany , belongsTo , belongsToMany)
678
693
  * @returns {this} this
679
694
  * @example
680
- * import { Model , TypeRelationModel } from 'tspace-mysql'
695
+ * import { Model , TR } from 'tspace-mysql'
681
696
  *
682
697
  * class User extends Model {
683
698
  * constructor(){
@@ -697,7 +712,7 @@ declare class Model<TypeSchemaModel extends Record<string, any> = any, TypeRelat
697
712
  * await new User().relations('posts').findMany()
698
713
  *
699
714
  */
700
- relations<K extends TypeRelationModel extends object ? keyof TypeRelationModel : string>(...nameRelations: K[]): this;
715
+ relations<K extends TR extends object ? keyof TR : string>(...nameRelations: K[]): this;
701
716
  /**
702
717
  * The 'withAll' method is used to eager load related (relations) data when retrieving records from a database.
703
718
  *
@@ -706,7 +721,7 @@ declare class Model<TypeSchemaModel extends Record<string, any> = any, TypeRelat
706
721
  * @param {...string} nameRelations if data exists return empty
707
722
  * @returns {this} this
708
723
  */
709
- withAll<K extends TypeRelationModel extends object ? keyof TypeRelationModel : string>(...nameRelations: K[]): this;
724
+ withAll<K extends TR extends object ? keyof TR : string>(...nameRelations: K[]): this;
710
725
  /**
711
726
  * The 'relationsAll' method is used to eager load related (relations) data when retrieving records from a database.
712
727
  *
@@ -716,21 +731,21 @@ declare class Model<TypeSchemaModel extends Record<string, any> = any, TypeRelat
716
731
  * @param {...string} nameRelations if data exists return empty
717
732
  * @returns {this} this
718
733
  */
719
- relationsAll<K extends TypeRelationModel extends object ? keyof TypeRelationModel : string>(...nameRelations: K[]): this;
734
+ relationsAll<K extends TR extends object ? keyof TR : string>(...nameRelations: K[]): this;
720
735
  /**
721
736
  * The 'withCount' method is used to eager load related (relations) data and count data in the relation.
722
737
  *
723
738
  * @param {...string} nameRelations if data exists return 0
724
739
  * @returns {this} this
725
740
  */
726
- withCount<K extends TypeRelationModel extends object ? keyof TypeRelationModel : string>(...nameRelations: K[]): this;
741
+ withCount<K extends TR extends object ? keyof TR : string>(...nameRelations: K[]): this;
727
742
  /**
728
743
  * The 'relationsCount' method is used to eager load related (relations) data and count data in the relation.
729
744
  *
730
745
  * @param {...string} nameRelations if data exists return 0
731
746
  * @returns {this} this
732
747
  */
733
- relationsCount<K extends TypeRelationModel extends object ? keyof TypeRelationModel : string>(...nameRelations: K[]): this;
748
+ relationsCount<K extends TR extends object ? keyof TR : string>(...nameRelations: K[]): this;
734
749
  /**
735
750
  * The 'withTrashed' method is used to eager load related (relations) data when retrieving records from a database.
736
751
  *
@@ -740,7 +755,7 @@ declare class Model<TypeSchemaModel extends Record<string, any> = any, TypeRelat
740
755
  * @param {...string} nameRelations if data exists return blank
741
756
  * @returns {this} this
742
757
  */
743
- withTrashed<K extends TypeRelationModel extends object ? keyof TypeRelationModel : string>(...nameRelations: K[]): this;
758
+ withTrashed<K extends TR extends object ? keyof TR : string>(...nameRelations: K[]): this;
744
759
  /**
745
760
  * The 'relationsTrashed' method is used to eager load related (relations) data when retrieving records from a database.
746
761
  *
@@ -750,7 +765,7 @@ declare class Model<TypeSchemaModel extends Record<string, any> = any, TypeRelat
750
765
  * @param {...string} nameRelations if data exists return blank
751
766
  * @returns {this} this
752
767
  */
753
- relationsTrashed<K extends TypeRelationModel extends object ? keyof TypeRelationModel : string>(...nameRelations: K[]): this;
768
+ relationsTrashed<K extends TR extends object ? keyof TR : string>(...nameRelations: K[]): this;
754
769
  /**
755
770
  * The 'withExists' method is used to eager load related (relations) data when retrieving records from a database.
756
771
  *
@@ -778,7 +793,7 @@ declare class Model<TypeSchemaModel extends Record<string, any> = any, TypeRelat
778
793
  * // use with for results of relationship if relations is exists
779
794
  * await new User().withExists('posts').findMany()
780
795
  */
781
- withExists<K extends TypeRelationModel extends object ? keyof TypeRelationModel : string>(...nameRelations: K[]): this;
796
+ withExists<K extends TR extends object ? keyof TR : string>(...nameRelations: K[]): this;
782
797
  /**
783
798
  * The 'relationsExists' method is used to eager load related (relations) data when retrieving records from a database.
784
799
  *
@@ -806,7 +821,7 @@ declare class Model<TypeSchemaModel extends Record<string, any> = any, TypeRelat
806
821
  * // use with for results of relationship if relations is exists
807
822
  * await new User().relationsExists('posts').findMany()
808
823
  */
809
- relationsExists<K extends TypeRelationModel extends object ? keyof TypeRelationModel : string>(...nameRelations: K[]): this;
824
+ relationsExists<K extends TR extends object ? keyof TR : string>(...nameRelations: K[]): this;
810
825
  /**
811
826
  * The 'has' method is used to eager load related (relations) data when retrieving records from a database.
812
827
  *
@@ -834,7 +849,7 @@ declare class Model<TypeSchemaModel extends Record<string, any> = any, TypeRelat
834
849
  * // use with for results of relationship if relations is exists
835
850
  * await new User().has('posts').findMany()
836
851
  */
837
- has<K extends TypeRelationModel extends object ? keyof TypeRelationModel : string>(...nameRelations: K[]): this;
852
+ has<K extends TR extends object ? keyof TR : string>(...nameRelations: K[]): this;
838
853
  /**
839
854
  *
840
855
  * The 'withQuery' method is particularly useful when you want to filter or add conditions records based on related data.
@@ -842,6 +857,7 @@ declare class Model<TypeSchemaModel extends Record<string, any> = any, TypeRelat
842
857
  * Use relation '${name}' registry models then return callback queries
843
858
  * @param {string} nameRelation name relation in registry in your model
844
859
  * @param {function} callback query callback
860
+ * @param {object} options pivot the query
845
861
  * @example
846
862
  * import { Model } from 'tspace-mysql'
847
863
  * class User extends Model {
@@ -883,7 +899,9 @@ declare class Model<TypeSchemaModel extends Record<string, any> = any, TypeRelat
883
899
  * .findMany()
884
900
  * @returns {this} this
885
901
  */
886
- withQuery<K extends TypeRelationModel extends object ? keyof TypeRelationModel : string, TModel extends Model>(nameRelation: K, callback: (query: TModel) => TModel): this;
902
+ withQuery<K extends TR extends object ? keyof TR : string, M extends Model>(nameRelation: K, callback: (query: M) => M, options?: {
903
+ pivot: boolean;
904
+ }): this;
887
905
  /**
888
906
  *
889
907
  * The 'relationQuery' method is particularly useful when you want to filter or add conditions records based on related data.
@@ -891,6 +909,7 @@ declare class Model<TypeSchemaModel extends Record<string, any> = any, TypeRelat
891
909
  * Use relation '${name}' registry models then return callback queries
892
910
  * @param {string} nameRelation name relation in registry in your model
893
911
  * @param {function} callback query callback
912
+ * @param {object} options pivot the query
894
913
  * @example
895
914
  * import { Model } from 'tspace-mysql'
896
915
  * class User extends Model {
@@ -932,7 +951,9 @@ declare class Model<TypeSchemaModel extends Record<string, any> = any, TypeRelat
932
951
  * .findMany()
933
952
  * @returns {this} this
934
953
  */
935
- relationQuery<K extends TypeRelationModel extends object ? keyof TypeRelationModel : string, T extends Model>(nameRelation: K, callback: (query: T) => T): this;
954
+ relationQuery<K extends TR extends object ? keyof TR : string, T extends Model>(nameRelation: K, callback: (query: T) => T, options?: {
955
+ pivot: boolean;
956
+ }): this;
936
957
  /**
937
958
  *
938
959
  * The 'findWithQuery' method is particularly useful when you want to filter or add conditions records based on related data.
@@ -941,7 +962,7 @@ declare class Model<TypeSchemaModel extends Record<string, any> = any, TypeRelat
941
962
  * @param {string} nameRelation name relation in registry in your model
942
963
  * @returns {Model} model instance
943
964
  */
944
- findWithQuery<K extends TypeRelationModel extends object ? keyof TypeRelationModel : string, TModel extends Model>(nameRelation: K): Model | null;
965
+ findWithQuery<K extends TR extends object ? keyof TR : string>(nameRelation: K): Model | null;
945
966
  /**
946
967
  * The 'hasOne' relationship defines a one-to-one relationship between two database tables.
947
968
  *
@@ -958,7 +979,7 @@ declare class Model<TypeSchemaModel extends Record<string, any> = any, TypeRelat
958
979
  * @property {string} relation.freezeTable
959
980
  * @returns {this} this
960
981
  */
961
- protected hasOne<K extends TypeRelationModel extends object ? keyof TypeRelationModel : string>({ name, as, model, localKey, foreignKey, freezeTable }: TRelationOptions<K>): this;
982
+ protected hasOne<K extends TR extends object ? keyof TR : string>({ name, as, model, localKey, foreignKey, freezeTable }: TRelationOptions<K>): this;
962
983
  /**
963
984
  * The 'hasMany' relationship defines a one-to-many relationship between two database tables.
964
985
  *
@@ -975,7 +996,7 @@ declare class Model<TypeSchemaModel extends Record<string, any> = any, TypeRelat
975
996
  * @property {string} relation.freezeTable
976
997
  * @returns {this} this
977
998
  */
978
- protected hasMany<K extends TypeRelationModel extends object ? keyof TypeRelationModel : string>({ name, as, model, localKey, foreignKey, freezeTable }: TRelationOptions<K>): this;
999
+ protected hasMany<K extends TR extends object ? keyof TR : string>({ name, as, model, localKey, foreignKey, freezeTable }: TRelationOptions<K>): this;
979
1000
  /**
980
1001
  * The 'belongsTo' relationship defines a one-to-one or many-to-one relationship between two database tables.
981
1002
  *
@@ -992,7 +1013,7 @@ declare class Model<TypeSchemaModel extends Record<string, any> = any, TypeRelat
992
1013
  * @property {string} relation.freezeTable
993
1014
  * @returns {this} this
994
1015
  */
995
- protected belongsTo<K extends TypeRelationModel extends object ? keyof TypeRelationModel : string>({ name, as, model, localKey, foreignKey, freezeTable }: TRelationOptions<K>): this;
1016
+ protected belongsTo<K extends TR extends object ? keyof TR : string>({ name, as, model, localKey, foreignKey, freezeTable }: TRelationOptions<K>): this;
996
1017
  /**
997
1018
  * The 'belongsToMany' relationship defines a many-to-many relationship between two database tables.
998
1019
  *
@@ -1012,7 +1033,7 @@ declare class Model<TypeSchemaModel extends Record<string, any> = any, TypeRelat
1012
1033
  * @property {class?} relation.modelPivot model for pivot
1013
1034
  * @returns {this} this
1014
1035
  */
1015
- protected belongsToMany<K extends TypeRelationModel extends object ? keyof TypeRelationModel : string>({ name, as, model, localKey, foreignKey, freezeTable, pivot, oldVersion, modelPivot }: TRelationOptions<K>): this;
1036
+ protected belongsToMany<K extends TR extends object ? keyof TR : string>({ name, as, model, localKey, foreignKey, freezeTable, pivot, oldVersion, modelPivot }: TRelationOptions<K>): this;
1016
1037
  /**
1017
1038
  * The 'hasOneBuilder' method is useful for creating 'hasOne' relationship to function
1018
1039
  *
@@ -1092,7 +1113,7 @@ declare class Model<TypeSchemaModel extends Record<string, any> = any, TypeRelat
1092
1113
  * restore data in trashed
1093
1114
  * @returns {promise}
1094
1115
  */
1095
- restore(): Promise<TypeSchemaModel[]>;
1116
+ restore(): Promise<TS[]>;
1096
1117
  /**
1097
1118
  *
1098
1119
  * @returns {string} string
@@ -1111,7 +1132,7 @@ declare class Model<TypeSchemaModel extends Record<string, any> = any, TypeRelat
1111
1132
  * @param {any?} value
1112
1133
  * @returns {this} this
1113
1134
  */
1114
- where<K extends keyof TypeSchemaModel | `${string}.${string}` | TRawStringQuery>(column: K | Record<string, any>, operator?: any, value?: any): this;
1135
+ where<K extends keyof TS | `${string}.${string}` | TRawStringQuery>(column: K | Record<string, any>, operator?: any, value?: any): this;
1115
1136
  /**
1116
1137
  * @override
1117
1138
  * @param {string} column
@@ -1119,13 +1140,13 @@ declare class Model<TypeSchemaModel extends Record<string, any> = any, TypeRelat
1119
1140
  * @param {any?} value
1120
1141
  * @returns {this}
1121
1142
  */
1122
- orWhere<K extends Extract<keyof TypeSchemaModel, string> | `${string}.${string}`>(column: K, operator?: any, value?: any): this;
1143
+ orWhere<K extends Extract<keyof TS, string> | `${string}.${string}`>(column: K, operator?: any, value?: any): this;
1123
1144
  /**
1124
1145
  * @override
1125
1146
  * @param {Object} columns
1126
1147
  * @returns {this}
1127
1148
  */
1128
- whereObject<K extends keyof TypeSchemaModel>(columns: Record<K, string | number | boolean | null | any[]>): this;
1149
+ whereObject<K extends keyof TS>(columns: Record<K, string | number | boolean | null | any[]>): this;
1129
1150
  /**
1130
1151
  * @override
1131
1152
  * @param {string} column
@@ -1135,7 +1156,7 @@ declare class Model<TypeSchemaModel extends Record<string, any> = any, TypeRelat
1135
1156
  * @property {string?} property.operator
1136
1157
  * @returns {this}
1137
1158
  */
1138
- whereJSON<K extends Extract<keyof TypeSchemaModel, string> | `${string}.${string}`>(column: K, { key, value, operator }: {
1159
+ whereJSON<K extends Extract<keyof TS, string> | `${string}.${string}`>(column: K, { key, value, operator }: {
1139
1160
  key: string;
1140
1161
  value: string;
1141
1162
  operator?: string;
@@ -1153,108 +1174,108 @@ declare class Model<TypeSchemaModel extends Record<string, any> = any, TypeRelat
1153
1174
  * @param {array} array
1154
1175
  * @returns {this}
1155
1176
  */
1156
- whereIn<K extends keyof TypeSchemaModel | `${string}.${string}`>(column: K, array: any[]): this;
1177
+ whereIn<K extends keyof TS | `${string}.${string}`>(column: K, array: any[]): this;
1157
1178
  /**
1158
1179
  * @override
1159
1180
  * @param {string} column
1160
1181
  * @param {array} array
1161
1182
  * @returns {this}
1162
1183
  */
1163
- orWhereIn<K extends keyof TypeSchemaModel | `${string}.${string}`>(column: K, array: any[]): this;
1184
+ orWhereIn<K extends keyof TS | `${string}.${string}`>(column: K, array: any[]): this;
1164
1185
  /**
1165
1186
  * @override
1166
1187
  * @param {string} column
1167
1188
  * @param {array} array
1168
1189
  * @returns {this}
1169
1190
  */
1170
- whereNotIn<K extends keyof TypeSchemaModel | `${string}.${string}`>(column: K, array: any[]): this;
1191
+ whereNotIn<K extends keyof TS | `${string}.${string}`>(column: K, array: any[]): this;
1171
1192
  /**
1172
1193
  * @override
1173
1194
  * @param {string} column
1174
1195
  * @param {array} array
1175
1196
  * @returns {this}
1176
1197
  */
1177
- orWhereNotIn<K extends keyof TypeSchemaModel | `${string}.${string}`>(column: K, array: any[]): this;
1198
+ orWhereNotIn<K extends keyof TS | `${string}.${string}`>(column: K, array: any[]): this;
1178
1199
  /**
1179
1200
  * @override
1180
1201
  * @param {string} column
1181
1202
  * @param {string} subQuery
1182
1203
  * @returns {this}
1183
1204
  */
1184
- whereSubQuery<K extends keyof TypeSchemaModel | `${string}.${string}`>(column: K, subQuery: string): this;
1205
+ whereSubQuery<K extends keyof TS | `${string}.${string}`>(column: K, subQuery: string): this;
1185
1206
  /**
1186
1207
  * @override
1187
1208
  * @param {string} column
1188
1209
  * @param {string} subQuery
1189
1210
  * @returns {this}
1190
1211
  */
1191
- whereNotSubQuery<K extends keyof TypeSchemaModel | `${string}.${string}`>(column: K, subQuery: string): this;
1212
+ whereNotSubQuery<K extends keyof TS | `${string}.${string}`>(column: K, subQuery: string): this;
1192
1213
  /**
1193
1214
  * @override
1194
1215
  * @param {string} column
1195
1216
  * @param {string} subQuery
1196
1217
  * @returns {this}
1197
1218
  */
1198
- orWhereSubQuery<K extends keyof TypeSchemaModel | `${string}.${string}`>(column: K, subQuery: string): this;
1219
+ orWhereSubQuery<K extends keyof TS | `${string}.${string}`>(column: K, subQuery: string): this;
1199
1220
  /**
1200
1221
  * @override
1201
1222
  * @param {string} column
1202
1223
  * @param {string} subQuery
1203
1224
  * @returns {this}
1204
1225
  */
1205
- orWhereNotSubQuery<K extends keyof TypeSchemaModel | `${string}.${string}`>(column: K, subQuery: string): this;
1226
+ orWhereNotSubQuery<K extends keyof TS | `${string}.${string}`>(column: K, subQuery: string): this;
1206
1227
  /**
1207
1228
  * @override
1208
1229
  * @param {string} column
1209
1230
  * @param {array} array
1210
1231
  * @returns {this}
1211
1232
  */
1212
- whereBetween<K extends keyof TypeSchemaModel | `${string}.${string}`>(column: K, array: any[]): this;
1233
+ whereBetween<K extends keyof TS | `${string}.${string}`>(column: K, array: any[]): this;
1213
1234
  /**
1214
1235
  * @override
1215
1236
  * @param {string} column
1216
1237
  * @param {array} array
1217
1238
  * @returns {this}
1218
1239
  */
1219
- orWhereBetween<K extends keyof TypeSchemaModel | `${string}.${string}`>(column: K, array: any[]): this;
1240
+ orWhereBetween<K extends keyof TS | `${string}.${string}`>(column: K, array: any[]): this;
1220
1241
  /**
1221
1242
  * @override
1222
1243
  * @param {string} column
1223
1244
  * @param {array} array
1224
1245
  * @returns {this}
1225
1246
  */
1226
- whereNotBetween<K extends keyof TypeSchemaModel | `${string}.${string}`>(column: K, array: any[]): this;
1247
+ whereNotBetween<K extends keyof TS | `${string}.${string}`>(column: K, array: any[]): this;
1227
1248
  /**
1228
1249
  * @override
1229
1250
  * @param {string} column
1230
1251
  * @param {array} array
1231
1252
  * @returns {this}
1232
1253
  */
1233
- orWhereNotBetween<K extends keyof TypeSchemaModel | `${string}.${string}`>(column: K, array: any[]): this;
1254
+ orWhereNotBetween<K extends keyof TS | `${string}.${string}`>(column: K, array: any[]): this;
1234
1255
  /**
1235
1256
  * @override
1236
1257
  * @param {string} column
1237
1258
  * @returns {this}
1238
1259
  */
1239
- whereNull<K extends keyof TypeSchemaModel | `${string}.${string}`>(column: K): this;
1260
+ whereNull<K extends keyof TS | `${string}.${string}`>(column: K): this;
1240
1261
  /**
1241
1262
  * @override
1242
1263
  * @param {string} column
1243
1264
  * @returns {this}
1244
1265
  */
1245
- orWhereNull<K extends keyof TypeSchemaModel | `${string}.${string}`>(column: K): this;
1266
+ orWhereNull<K extends keyof TS | `${string}.${string}`>(column: K): this;
1246
1267
  /**
1247
1268
  * @override
1248
1269
  * @param {string} column
1249
1270
  * @returns {this}
1250
1271
  */
1251
- whereNotNull<K extends keyof TypeSchemaModel | `${string}.${string}`>(column: K): this;
1272
+ whereNotNull<K extends keyof TS | `${string}.${string}`>(column: K): this;
1252
1273
  /**
1253
1274
  * @override
1254
1275
  * @param {string} column
1255
1276
  * @returns {this}
1256
1277
  */
1257
- orWhereNotNull<K extends keyof TypeSchemaModel | `${string}.${string}`>(column: K): this;
1278
+ orWhereNotNull<K extends keyof TS | `${string}.${string}`>(column: K): this;
1258
1279
  /**
1259
1280
  * @override
1260
1281
  * @param {string} column
@@ -1262,7 +1283,7 @@ declare class Model<TypeSchemaModel extends Record<string, any> = any, TypeRelat
1262
1283
  * @param {any?} value
1263
1284
  * @returns {this}
1264
1285
  */
1265
- whereSensitive<K extends keyof TypeSchemaModel | `${string}.${string}`>(column: K, operator?: any, value?: any): this;
1286
+ whereSensitive<K extends keyof TS | `${string}.${string}`>(column: K, operator?: any, value?: any): this;
1266
1287
  /**
1267
1288
  * @override
1268
1289
  * @param {string} column
@@ -1270,7 +1291,7 @@ declare class Model<TypeSchemaModel extends Record<string, any> = any, TypeRelat
1270
1291
  * @param {any?} value
1271
1292
  * @returns {this}
1272
1293
  */
1273
- whereStrict<K extends keyof TypeSchemaModel | `${string}.${string}`>(column: K, operator?: any, value?: any): this;
1294
+ whereStrict<K extends keyof TS | `${string}.${string}`>(column: K, operator?: any, value?: any): this;
1274
1295
  /**
1275
1296
  * @override
1276
1297
  * @param {string} column
@@ -1278,7 +1299,7 @@ declare class Model<TypeSchemaModel extends Record<string, any> = any, TypeRelat
1278
1299
  * @param {any?} value
1279
1300
  * @returns {this}
1280
1301
  */
1281
- orWhereSensitive<K extends keyof TypeSchemaModel | `${string}.${string}`>(column: K, operator?: any, value?: any): this;
1302
+ orWhereSensitive<K extends keyof TS | `${string}.${string}`>(column: K, operator?: any, value?: any): this;
1282
1303
  /**
1283
1304
  * @override
1284
1305
  * @param {Function} callback callback query
@@ -1292,7 +1313,7 @@ declare class Model<TypeSchemaModel extends Record<string, any> = any, TypeRelat
1292
1313
  * @param {any?} value
1293
1314
  * @returns {this}
1294
1315
  */
1295
- whereAny<K extends keyof TypeSchemaModel | `${string}.${string}`>(columns: K[], operator?: any, value?: any): this;
1316
+ whereAny<K extends keyof TS | `${string}.${string}`>(columns: K[], operator?: any, value?: any): this;
1296
1317
  /**
1297
1318
  * The 'whereAll' method is used to clause to a database query.
1298
1319
  *
@@ -1304,7 +1325,7 @@ declare class Model<TypeSchemaModel extends Record<string, any> = any, TypeRelat
1304
1325
  * @param {any?} value
1305
1326
  * @returns {this}
1306
1327
  */
1307
- whereAll<K extends keyof TypeSchemaModel | `${string}.${string}`>(columns: K[], operator?: any, value?: any): this;
1328
+ whereAll<K extends keyof TS | `${string}.${string}`>(columns: K[], operator?: any, value?: any): this;
1308
1329
  /**
1309
1330
  * @override
1310
1331
  * @returns {promise<boolean>} promise boolean
@@ -1330,45 +1351,45 @@ declare class Model<TypeSchemaModel extends Record<string, any> = any, TypeRelat
1330
1351
  * @param {string=} column [column=id]
1331
1352
  * @returns {promise<Array>}
1332
1353
  */
1333
- toArray<K extends Extract<keyof TypeSchemaModel, string> | 'id'>(column?: K): Promise<any[]>;
1354
+ toArray<K extends Extract<keyof TS, string> | 'id'>(column?: K): Promise<any[]>;
1334
1355
  /**
1335
1356
  *
1336
1357
  * @override
1337
1358
  * @param {Function?} cb callback function return query sql
1338
1359
  * @returns {promise<Record<string,any> | null>} Record | null
1339
1360
  */
1340
- first<K>(cb?: Function): Promise<TypeSchemaModel & K & Partial<TypeRelationModel extends any ? TypeSchemaModel & TypeRelationModel : TypeRelationModel> | null>;
1361
+ first<K>(cb?: Function): Promise<TS & K & Partial<TR extends any ? TS & Partial<TR> & Partial<TRegistry> : TR> | null>;
1341
1362
  /**
1342
1363
  * @override
1343
1364
  * @param {Function?} cb callback function return query sql
1344
1365
  * @returns {promise<Record<string,any> | null>} Record | null
1345
1366
  */
1346
- findOne<K>(cb?: Function): Promise<Partial<TypeSchemaModel> & K & Partial<TypeRelationModel> | null>;
1367
+ findOne<K>(cb?: Function): Promise<Partial<TS> & K & Partial<TR> & Partial<TRegistry> | null>;
1347
1368
  /**
1348
1369
  * @override
1349
1370
  * @returns {promise<object | Error>} Record | throw error
1350
1371
  */
1351
- firstOrError<K>(message: string, options?: Record<string, any>): Promise<TypeSchemaModel & K & Partial<TypeRelationModel>>;
1372
+ firstOrError<K>(message: string, options?: Record<string, any>): Promise<TS & K & Partial<TR> & Partial<TRegistry>>;
1352
1373
  /**
1353
1374
  *
1354
1375
  * @override
1355
1376
  * @returns {promise<any>} Record | throw error
1356
1377
  */
1357
- findOneOrError<K>(message: string, options?: Record<string, any>): Promise<Partial<TypeSchemaModel> & K & Partial<TypeRelationModel>>;
1378
+ findOneOrError<K>(message: string, options?: Record<string, any>): Promise<Partial<TS> & K & Partial<TR>>;
1358
1379
  /**
1359
1380
  *
1360
1381
  * @override
1361
1382
  * @param {Function?} cb callback function return query sql
1362
1383
  * @returns {promise<array>} Array
1363
1384
  */
1364
- get<K>(cb?: Function): Promise<(TypeSchemaModel & K & Partial<TypeRelationModel>)[]>;
1385
+ get<K>(cb?: Function): Promise<(TS & K & Partial<TR> & Partial<TRegistry>)[]>;
1365
1386
  /**
1366
1387
  *
1367
1388
  * @override
1368
1389
  * @param {Function?} cb callback function return query sql
1369
1390
  * @returns {promise<array>} Array
1370
1391
  */
1371
- findMany<K>(cb?: Function): Promise<Partial<(TypeSchemaModel & K & Partial<TypeRelationModel>)>[]>;
1392
+ findMany<K>(cb?: Function): Promise<Partial<(TS & K & Partial<TR> & Partial<TRegistry>)>[]>;
1372
1393
  /**
1373
1394
  * @override
1374
1395
  * @param {object?} paginationOptions by default page = 1 , limit = 15
@@ -1379,7 +1400,7 @@ declare class Model<TypeSchemaModel extends Record<string, any> = any, TypeRelat
1379
1400
  pagination<K>(paginationOptions?: {
1380
1401
  limit?: number;
1381
1402
  page?: number;
1382
- }): Promise<TPagination<Partial<(TypeSchemaModel & K & Partial<TypeRelationModel>)>[]>>;
1403
+ }): Promise<TPagination<Partial<(TS & K & Partial<TR> & Partial<TRegistry>)>[]>>;
1383
1404
  /**
1384
1405
  *
1385
1406
  * @override
@@ -1391,26 +1412,26 @@ declare class Model<TypeSchemaModel extends Record<string, any> = any, TypeRelat
1391
1412
  paginate<K>(paginationOptions?: {
1392
1413
  limit?: number;
1393
1414
  page?: number;
1394
- }): Promise<TPagination<Partial<(TypeSchemaModel & K & Partial<TypeRelationModel>)>[]>>;
1415
+ }): Promise<TPagination<Partial<(TS & K & Partial<TR> & Partial<TRegistry>)>[]>>;
1395
1416
  /**
1396
1417
  * @override
1397
1418
  * @param {string} column
1398
1419
  * @returns {Promise<array>} Array
1399
1420
  */
1400
- getGroupBy<K extends Extract<keyof TypeSchemaModel, string> | `${string}.${string}`>(column: K): Promise<any[]>;
1421
+ getGroupBy<K extends Extract<keyof TS, string> | `${string}.${string}`>(column: K): Promise<any[]>;
1401
1422
  /**
1402
1423
  * @override
1403
1424
  * @param {string} column
1404
1425
  * @returns {Promise<array>} Array
1405
1426
  */
1406
- findGroupBy<K extends Extract<keyof TypeSchemaModel, string> | `${string}.${string}`>(column: K): Promise<any[]>;
1427
+ findGroupBy<K extends Extract<keyof TS, string> | `${string}.${string}`>(column: K): Promise<any[]>;
1407
1428
  /**
1408
1429
  * @override
1409
1430
  * @param {object} data for insert
1410
1431
  * @returns {this} this
1411
1432
  */
1412
- insert<K extends keyof TypeSchemaModel>(data: K extends keyof TypeSchemaModel ? {
1413
- [P in K]: TypeSchemaModel[K] | TRawStringQuery;
1433
+ insert<K extends keyof TS>(data: K extends keyof TS ? {
1434
+ [P in K]: TS[K] | TRawStringQuery;
1414
1435
  } : {
1415
1436
  [P in K]: any;
1416
1437
  }): this;
@@ -1419,8 +1440,8 @@ declare class Model<TypeSchemaModel extends Record<string, any> = any, TypeRelat
1419
1440
  * @param {object} data for insert
1420
1441
  * @returns {this} this
1421
1442
  */
1422
- create<K extends keyof TypeSchemaModel>(data: K extends keyof TypeSchemaModel ? {
1423
- [P in K]: TypeSchemaModel[K] | TRawStringQuery;
1443
+ create<K extends keyof TS>(data: K extends keyof TS ? {
1444
+ [P in K]: TS[K] | TRawStringQuery;
1424
1445
  } : {
1425
1446
  [P in K]: any;
1426
1447
  }): this;
@@ -1430,8 +1451,8 @@ declare class Model<TypeSchemaModel extends Record<string, any> = any, TypeRelat
1430
1451
  * @param {array?} updateNotExists options for except update some records in your ${data}
1431
1452
  * @returns {this} this
1432
1453
  */
1433
- update<K extends keyof TypeSchemaModel>(data: K extends keyof TypeSchemaModel ? {
1434
- [P in K]: TypeSchemaModel[K] | TRawStringQuery;
1454
+ update<K extends keyof TS>(data: K extends keyof TS ? {
1455
+ [P in K]: TS[K] | TRawStringQuery;
1435
1456
  } : {
1436
1457
  [P in K]: any;
1437
1458
  }, updateNotExists?: string[]): this;
@@ -1441,8 +1462,8 @@ declare class Model<TypeSchemaModel extends Record<string, any> = any, TypeRelat
1441
1462
  * @param {array?} updateNotExists options for except update some records in your ${data}
1442
1463
  * @returns {this} this
1443
1464
  */
1444
- updateMany<K extends keyof TypeSchemaModel>(data: K extends keyof TypeSchemaModel ? {
1445
- [P in K]: TypeSchemaModel[K] | TRawStringQuery;
1465
+ updateMany<K extends keyof TS>(data: K extends keyof TS ? {
1466
+ [P in K]: TS[K] | TRawStringQuery;
1446
1467
  } : {
1447
1468
  [P in K]: any;
1448
1469
  }, updateNotExists?: string[]): this;
@@ -1451,8 +1472,8 @@ declare class Model<TypeSchemaModel extends Record<string, any> = any, TypeRelat
1451
1472
  * @param {object} data
1452
1473
  * @returns {this} this
1453
1474
  */
1454
- updateNotExists<K extends keyof TypeSchemaModel>(data: K extends keyof TypeSchemaModel ? {
1455
- [P in K]: TypeSchemaModel[K] | TRawStringQuery;
1475
+ updateNotExists<K extends keyof TS>(data: K extends keyof TS ? {
1476
+ [P in K]: TS[K] | TRawStringQuery;
1456
1477
  } : {
1457
1478
  [P in K]: any;
1458
1479
  }): this;
@@ -1461,8 +1482,8 @@ declare class Model<TypeSchemaModel extends Record<string, any> = any, TypeRelat
1461
1482
  * @param {object} data for update or create
1462
1483
  * @returns {this} this
1463
1484
  */
1464
- updateOrCreate<K extends keyof TypeSchemaModel>(data: K extends keyof TypeSchemaModel ? {
1465
- [P in K]: TypeSchemaModel[K] | TRawStringQuery;
1485
+ updateOrCreate<K extends keyof TS>(data: K extends keyof TS ? {
1486
+ [P in K]: TS[K] | TRawStringQuery;
1466
1487
  } : {
1467
1488
  [P in K]: any;
1468
1489
  }): this;
@@ -1471,8 +1492,8 @@ declare class Model<TypeSchemaModel extends Record<string, any> = any, TypeRelat
1471
1492
  * @param {object} data for update or create
1472
1493
  * @returns {this} this
1473
1494
  */
1474
- updateOrInsert<K extends keyof TypeSchemaModel>(data: K extends keyof TypeSchemaModel ? {
1475
- [P in K]: TypeSchemaModel[K] | TRawStringQuery;
1495
+ updateOrInsert<K extends keyof TS>(data: K extends keyof TS ? {
1496
+ [P in K]: TS[K] | TRawStringQuery;
1476
1497
  } : {
1477
1498
  [P in K]: any;
1478
1499
  }): this;
@@ -1481,8 +1502,8 @@ declare class Model<TypeSchemaModel extends Record<string, any> = any, TypeRelat
1481
1502
  * @param {object} data for update or create
1482
1503
  * @returns {this} this
1483
1504
  */
1484
- insertOrUpdate<K extends keyof TypeSchemaModel>(data: K extends keyof TypeSchemaModel ? {
1485
- [P in K]: TypeSchemaModel[K] | TRawStringQuery;
1505
+ insertOrUpdate<K extends keyof TS>(data: K extends keyof TS ? {
1506
+ [P in K]: TS[K] | TRawStringQuery;
1486
1507
  } : {
1487
1508
  [P in K]: any;
1488
1509
  }): this;
@@ -1491,8 +1512,8 @@ declare class Model<TypeSchemaModel extends Record<string, any> = any, TypeRelat
1491
1512
  * @param {object} data for update or create
1492
1513
  * @returns {this} this
1493
1514
  */
1494
- createOrUpdate<K extends keyof TypeSchemaModel>(data: K extends keyof TypeSchemaModel ? {
1495
- [P in K]: TypeSchemaModel[K] | TRawStringQuery;
1515
+ createOrUpdate<K extends keyof TS>(data: K extends keyof TS ? {
1516
+ [P in K]: TS[K] | TRawStringQuery;
1496
1517
  } : {
1497
1518
  [P in K]: any;
1498
1519
  }): this;
@@ -1501,8 +1522,8 @@ declare class Model<TypeSchemaModel extends Record<string, any> = any, TypeRelat
1501
1522
  * @param {object} data for create
1502
1523
  * @returns {this} this
1503
1524
  */
1504
- createOrSelect<K extends keyof TypeSchemaModel>(data: K extends keyof TypeSchemaModel ? {
1505
- [P in K]: TypeSchemaModel[K] | TRawStringQuery;
1525
+ createOrSelect<K extends keyof TS>(data: K extends keyof TS ? {
1526
+ [P in K]: TS[K] | TRawStringQuery;
1506
1527
  } : {
1507
1528
  [P in K]: any;
1508
1529
  }): this;
@@ -1511,8 +1532,8 @@ declare class Model<TypeSchemaModel extends Record<string, any> = any, TypeRelat
1511
1532
  * @param {object} data for update or create
1512
1533
  * @returns {this} this
1513
1534
  */
1514
- insertOrSelect<K extends keyof TypeSchemaModel>(data: K extends keyof TypeSchemaModel ? {
1515
- [P in K]: TypeSchemaModel[K] | TRawStringQuery;
1535
+ insertOrSelect<K extends keyof TS>(data: K extends keyof TS ? {
1536
+ [P in K]: TS[K] | TRawStringQuery;
1516
1537
  } : {
1517
1538
  [P in K]: any;
1518
1539
  }): this;
@@ -1522,8 +1543,8 @@ declare class Model<TypeSchemaModel extends Record<string, any> = any, TypeRelat
1522
1543
  * @param {object} data create not exists data
1523
1544
  * @returns {this} this
1524
1545
  */
1525
- createNotExists<K extends keyof TypeSchemaModel>(data: K extends keyof TypeSchemaModel ? {
1526
- [P in K]: TypeSchemaModel[K] | TRawStringQuery;
1546
+ createNotExists<K extends keyof TS>(data: K extends keyof TS ? {
1547
+ [P in K]: TS[K] | TRawStringQuery;
1527
1548
  } : {
1528
1549
  [P in K]: any;
1529
1550
  }): this;
@@ -1533,8 +1554,8 @@ declare class Model<TypeSchemaModel extends Record<string, any> = any, TypeRelat
1533
1554
  * @param {object} data create not exists data
1534
1555
  * @returns {this} this this
1535
1556
  */
1536
- insertNotExists<K extends keyof TypeSchemaModel>(data: K extends keyof TypeSchemaModel ? {
1537
- [P in K]: TypeSchemaModel[K] | TRawStringQuery;
1557
+ insertNotExists<K extends keyof TS>(data: K extends keyof TS ? {
1558
+ [P in K]: TS[K] | TRawStringQuery;
1538
1559
  } : {
1539
1560
  [P in K]: any;
1540
1561
  }): this;
@@ -1543,8 +1564,8 @@ declare class Model<TypeSchemaModel extends Record<string, any> = any, TypeRelat
1543
1564
  * @param {Record<string,any>[]} data create multiple data
1544
1565
  * @returns {this} this this
1545
1566
  */
1546
- createMultiple<K extends keyof TypeSchemaModel>(data: (K extends keyof TypeSchemaModel ? Partial<{
1547
- [K in keyof TypeSchemaModel]: TypeSchemaModel[K];
1567
+ createMultiple<K extends keyof TS>(data: (K extends keyof TS ? Partial<{
1568
+ [K in keyof TS]: TS[K];
1548
1569
  }> : Record<string, any>)[]): this;
1549
1570
  /**
1550
1571
  *
@@ -1552,8 +1573,8 @@ declare class Model<TypeSchemaModel extends Record<string, any> = any, TypeRelat
1552
1573
  * @param {Record<string,any>[]} data create multiple data
1553
1574
  * @returns {this} this
1554
1575
  */
1555
- insertMultiple<K extends keyof TypeSchemaModel>(data: (K extends keyof TypeSchemaModel ? Partial<{
1556
- [K in keyof TypeSchemaModel]: TypeSchemaModel[K];
1576
+ insertMultiple<K extends keyof TS>(data: (K extends keyof TS ? Partial<{
1577
+ [K in keyof TS]: TS[K];
1557
1578
  }> : Record<string, any>)[]): this;
1558
1579
  /**
1559
1580
  *
@@ -1563,12 +1584,12 @@ declare class Model<TypeSchemaModel extends Record<string, any> = any, TypeRelat
1563
1584
  * @property {Record<string,string | number | boolean | null | undefined>} cases.columns
1564
1585
  * @returns {this} this
1565
1586
  */
1566
- updateMultiple<K extends keyof TypeSchemaModel>(cases: {
1567
- when: (K extends keyof TypeSchemaModel ? Partial<{
1568
- [K in keyof TypeSchemaModel]: TypeSchemaModel[K];
1587
+ updateMultiple<K extends keyof TS>(cases: {
1588
+ when: (K extends keyof TS ? Partial<{
1589
+ [K in keyof TS]: TS[K];
1569
1590
  }> : Record<string, any>);
1570
- columns: (K extends keyof TypeSchemaModel ? Partial<{
1571
- [K in keyof TypeSchemaModel]: TypeSchemaModel[K];
1591
+ columns: (K extends keyof TS ? Partial<{
1592
+ [K in keyof TS]: TS[K];
1572
1593
  }> : Record<string, any>);
1573
1594
  }[]): this;
1574
1595
  /**
@@ -1646,6 +1667,7 @@ declare class Model<TypeSchemaModel extends Record<string, any> = any, TypeRelat
1646
1667
  private _returnEmpty;
1647
1668
  private _returnResult;
1648
1669
  private _hiddenColumnModel;
1670
+ private _save;
1649
1671
  private _attach;
1650
1672
  private _detach;
1651
1673
  private _queryUpdateModel;