tspace-mysql 1.4.7 → 1.4.9

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 (39) hide show
  1. package/README.md +128 -49
  2. package/dist/lib/{tspace/Interface.d.ts → Interface.d.ts} +18 -2
  3. package/dist/lib/connection/index.d.ts +1 -1
  4. package/dist/lib/constants/index.js +3 -3
  5. package/dist/lib/tspace/{Abstract → Abstracts}/AbstractBuilder.d.ts +3 -3
  6. package/dist/lib/tspace/{Abstract → Abstracts}/AbstractBuilder.js +2 -2
  7. package/dist/lib/tspace/{Abstract → Abstracts}/AbstractDB.d.ts +8 -2
  8. package/dist/lib/tspace/{Abstract → Abstracts}/AbstractModel.d.ts +22 -2
  9. package/dist/lib/tspace/Blueprint.d.ts +19 -5
  10. package/dist/lib/tspace/Blueprint.js +41 -19
  11. package/dist/lib/tspace/Builder.d.ts +26 -11
  12. package/dist/lib/tspace/Builder.js +378 -330
  13. package/dist/lib/tspace/DB.d.ts +42 -2
  14. package/dist/lib/tspace/DB.js +61 -5
  15. package/dist/lib/tspace/Decorator.d.ts +20 -0
  16. package/dist/lib/tspace/Decorator.js +166 -0
  17. package/dist/lib/tspace/{ProxyHandler.js → Handlers/Proxy.js} +1 -1
  18. package/dist/lib/tspace/{RelationHandler.d.ts → Handlers/Relation.d.ts} +4 -4
  19. package/dist/lib/tspace/{RelationHandler.js → Handlers/Relation.js} +103 -28
  20. package/dist/lib/tspace/{StateHandler.js → Handlers/State.js} +3 -2
  21. package/dist/lib/tspace/Model.d.ts +275 -11
  22. package/dist/lib/tspace/Model.js +989 -99
  23. package/dist/lib/tspace/Schema.js +5 -8
  24. package/dist/lib/tspace/index.d.ts +4 -0
  25. package/dist/lib/tspace/index.js +20 -2
  26. package/dist/lib/utils/index.d.ts +1 -0
  27. package/dist/lib/utils/index.js +9 -0
  28. package/dist/tests/01-Pool.test.d.ts +1 -0
  29. package/dist/tests/01-Pool.test.js +45 -0
  30. package/dist/tests/02-DB.test.d.ts +1 -0
  31. package/dist/tests/02-DB.test.js +109 -0
  32. package/dist/tests/03-Model.test.d.ts +1 -0
  33. package/dist/tests/03-Model.test.js +73 -0
  34. package/package.json +14 -3
  35. /package/dist/lib/{tspace/Interface.js → Interface.js} +0 -0
  36. /package/dist/lib/tspace/{Abstract → Abstracts}/AbstractDB.js +0 -0
  37. /package/dist/lib/tspace/{Abstract → Abstracts}/AbstractModel.js +0 -0
  38. /package/dist/lib/tspace/{ProxyHandler.d.ts → Handlers/Proxy.d.ts} +0 -0
  39. /package/dist/lib/tspace/{StateHandler.d.ts → Handlers/State.d.ts} +0 -0
@@ -36,14 +36,15 @@ class StateHandler {
36
36
  this.STATE.currentState.set('INSERT', '');
37
37
  this.STATE.currentState.set('UPDATE', '');
38
38
  this.STATE.currentState.set('DELETE', '');
39
- this.STATE.currentState.set('WHERE', '');
39
+ this.STATE.currentState.set('WHERE', []);
40
40
  this.STATE.currentState.set('LIMIT', '');
41
41
  this.STATE.currentState.set('OFFSET', '');
42
42
  this.STATE.currentState.set('SELECT', []);
43
43
  this.STATE.currentState.set('GROUP_BY', '');
44
44
  this.STATE.currentState.set('HAVING', '');
45
- this.STATE.currentState.set('JOIN', '');
45
+ this.STATE.currentState.set('JOIN', []);
46
46
  this.STATE.currentState.set('SAVE', '');
47
+ this.STATE.currentState.set('RELATIONS', []);
47
48
  return;
48
49
  }
49
50
  _assertError(condition = true, message = 'error') {
@@ -1,5 +1,6 @@
1
- import { AbstractModel } from './Abstract/AbstractModel';
2
- import { Relation, Pagination, RelationQuery, ValidateSchema } from './Interface';
1
+ import { AbstractModel } from './Abstracts/AbstractModel';
2
+ import { Blueprint } from './Blueprint';
3
+ import { Relation, Pagination, RelationQuery, ValidateSchema } from '../Interface';
3
4
  /**
4
5
  *
5
6
  * 'Model' class is a representation of a database table
@@ -92,7 +93,7 @@ declare class Model extends AbstractModel {
92
93
  * }
93
94
  * @return {this} this
94
95
  */
95
- protected useSchema(schema: Record<string, any>): this;
96
+ protected useSchema(schema: Record<string, Blueprint>): this;
96
97
  /**
97
98
  *
98
99
  * The "useRegistry" method is used to define Function to results.
@@ -105,7 +106,6 @@ declare class Model extends AbstractModel {
105
106
  * this.useRegistry()
106
107
  * }
107
108
  * }
108
-
109
109
  */
110
110
  protected useRegistry(): this;
111
111
  /**
@@ -176,7 +176,27 @@ declare class Model extends AbstractModel {
176
176
  * }
177
177
  */
178
178
  protected usePattern(pattern: "snake_case" | "camelCase"): this;
179
+ /**
180
+ * The "useCamelCase" method is used to assign pattern camelCase.
181
+ * @return {this} this
182
+ * @example
183
+ * class User extends Model {
184
+ * constructor() {
185
+ * this.useCamelCase()
186
+ * }
187
+ * }
188
+ */
179
189
  protected useCamelCase(): this;
190
+ /**
191
+ * The "SnakeCase" method is used to assign pattern snake_case.
192
+ * @return {this} this
193
+ * @example
194
+ * class User extends Model {
195
+ * constructor() {
196
+ * this.SnakeCase()
197
+ * }
198
+ * }
199
+ */
180
200
  protected useSnakeCase(): this;
181
201
  /**
182
202
  * The "useSoftDelete" refer to a feature that allows you to "soft delete" records from a database table instead of permanently deleting them.
@@ -331,7 +351,7 @@ declare class Model extends AbstractModel {
331
351
  * @override
332
352
  * @return {promise<string>} string
333
353
  */
334
- protected _exceptColumns(): Promise<string[]>;
354
+ protected exceptColumns(): Promise<string[]>;
335
355
  /**
336
356
  * Build method for relation in model
337
357
  * @param {string} name name relation registry in your model
@@ -339,6 +359,36 @@ declare class Model extends AbstractModel {
339
359
  * @return {this} this
340
360
  */
341
361
  protected buildMethodRelation(name: string, callback?: Function): this;
362
+ /**
363
+ *
364
+ * The 'makeSelectStatement' method is used to make select statement.
365
+ * @return {Promise<string>} string
366
+ */
367
+ makeSelectStatement(): Promise<string>;
368
+ /**
369
+ *
370
+ * The 'makeInsertStatement' method is used to make insert table statement.
371
+ * @return {Promise<string>} string
372
+ */
373
+ makeInsertStatement(): Promise<string>;
374
+ /**
375
+ *
376
+ * The 'makeUpdateStatement' method is used to make update table statement.
377
+ * @return {Promise<string>} string
378
+ */
379
+ makeUpdateStatement(): Promise<string>;
380
+ /**
381
+ *
382
+ * The 'makeDeleteStatement' method is used to make delete statement.
383
+ * @return {Promise<string>} string
384
+ */
385
+ makeDeleteStatement(): Promise<string>;
386
+ /**
387
+ *
388
+ * The 'makeCreateStatement' method is used to make create table statement.
389
+ * @return {Promise<string>} string
390
+ */
391
+ makeCreateStatement(): Promise<string>;
342
392
  /**
343
393
  *
344
394
  * Clone instance of model
@@ -446,6 +496,15 @@ declare class Model extends AbstractModel {
446
496
  * @return {this} this
447
497
  */
448
498
  withAll(...nameRelations: string[]): this;
499
+ /**
500
+ * The 'withAll' method is used to eager load related (relations) data when retrieving records from a database.
501
+ *
502
+ * Eager loading allows you to retrieve a primary model and its related models in a more efficient
503
+ * It's method ignore soft delete
504
+ * @param {...string} nameRelations if data exists return blank
505
+ * @return {this} this
506
+ */
507
+ withCount(...nameRelations: string[]): this;
449
508
  /**
450
509
  * The 'withTrashed' method is used to eager load related (relations) data when retrieving records from a database.
451
510
  *
@@ -817,8 +876,199 @@ declare class Model extends AbstractModel {
817
876
  * @return {promise}
818
877
  */
819
878
  restore(): Promise<any[]>;
879
+ /**
880
+ *
881
+ * @return {string} string
882
+ */
820
883
  toTableName(): string;
884
+ /**
885
+ *
886
+ * @param {string} column
887
+ * @return {string} string
888
+ */
821
889
  toTableNameAndColumn(column: string): string;
890
+ private _columnPattern;
891
+ /**
892
+ * @override Method
893
+ * @param {string} column if arguments is object
894
+ * @param {string?} operator ['=', '<', '>' ,'!=', '!<', '!>' ,'LIKE']
895
+ * @param {any?} value
896
+ * @return {this} this
897
+ */
898
+ where(column: string | Record<string, any>, operator?: any, value?: any): this;
899
+ /**
900
+ * @override Method
901
+ * @param {string} column
902
+ * @param {string?} operator ['=', '<', '>' ,'!=', '!<', '!>' ,'LIKE']
903
+ * @param {any?} value
904
+ * @return {this}
905
+ */
906
+ orWhere(column: string, operator?: any, value?: any): this;
907
+ /**
908
+ * @override Method
909
+ * @param {Object} columns
910
+ * @return {this}
911
+ */
912
+ whereObject(columns: Record<string, any>): this;
913
+ /**
914
+ * @override Method
915
+ * @param {string} column
916
+ * @param {object} property object { key , value , operator }
917
+ * @property {string} property.key
918
+ * @property {string} property.value
919
+ * @property {string?} property.operator
920
+ * @return {this}
921
+ */
922
+ whereJSON(column: string, { key, value, operator }: {
923
+ key: string;
924
+ value: string;
925
+ operator?: string;
926
+ }): this;
927
+ /**
928
+ * @override Method
929
+ * @param {number} userId
930
+ * @param {string?} column custom it *if column is not user_id
931
+ * @return {this}
932
+ */
933
+ whereUser(userId: number, column?: string): this;
934
+ /**
935
+ * @override Method
936
+ * @param {string} column
937
+ * @param {array} array
938
+ * @return {this}
939
+ */
940
+ whereIn(column: string, array: any[]): this;
941
+ /**
942
+ * @override Method
943
+ * @param {string} column
944
+ * @param {array} array
945
+ * @return {this}
946
+ */
947
+ orWhereIn(column: string, array: any[]): this;
948
+ /**
949
+ * @override Method
950
+ * @param {string} column
951
+ * @param {array} array
952
+ * @return {this}
953
+ */
954
+ whereNotIn(column: string, array: any[]): this;
955
+ /**
956
+ * @override Method
957
+ * @param {string} column
958
+ * @param {array} array
959
+ * @return {this}
960
+ */
961
+ orWhereNotIn(column: string, array: any[]): this;
962
+ /**
963
+ * @override Method
964
+ * @param {string} column
965
+ * @param {string} subQuery
966
+ * @return {this}
967
+ */
968
+ whereSubQuery(column: string, subQuery: string): this;
969
+ /**
970
+ * @override Method
971
+ * @param {string} column
972
+ * @param {string} subQuery
973
+ * @return {this}
974
+ */
975
+ whereNotSubQuery(column: string, subQuery: string): this;
976
+ /**
977
+ * @override Method
978
+ * @param {string} column
979
+ * @param {string} subQuery
980
+ * @return {this}
981
+ */
982
+ orWhereSubQuery(column: string, subQuery: string): this;
983
+ /**
984
+ * @override Method
985
+ * @param {string} column
986
+ * @param {string} subQuery
987
+ * @return {this}
988
+ */
989
+ orWhereNotSubQuery(column: string, subQuery: string): this;
990
+ /**
991
+ * @override Method
992
+ * @param {string} column
993
+ * @param {array} array
994
+ * @return {this}
995
+ */
996
+ whereBetween(column: string, array: any[]): this;
997
+ /**
998
+ * @override Method
999
+ * @param {string} column
1000
+ * @param {array} array
1001
+ * @return {this}
1002
+ */
1003
+ orWhereBetween(column: string, array: any[]): this;
1004
+ /**
1005
+ * @override Method
1006
+ * @param {string} column
1007
+ * @param {array} array
1008
+ * @return {this}
1009
+ */
1010
+ whereNotBetween(column: string, array: any[]): this;
1011
+ /**
1012
+ * @override Method
1013
+ * @param {string} column
1014
+ * @param {array} array
1015
+ * @return {this}
1016
+ */
1017
+ orWhereNotBetween(column: string, array: any[]): this;
1018
+ /**
1019
+ * @override Method
1020
+ * @param {string} column
1021
+ * @return {this}
1022
+ */
1023
+ whereNull(column: string): this;
1024
+ /**
1025
+ * @override Method
1026
+ * @param {string} column
1027
+ * @return {this}
1028
+ */
1029
+ orWhereNull(column: string): this;
1030
+ /**
1031
+ * @override Method
1032
+ * @param {string} column
1033
+ * @return {this}
1034
+ */
1035
+ whereNotNull(column: string): this;
1036
+ /**
1037
+ * @override Method
1038
+ * @param {string} column
1039
+ * @return {this}
1040
+ */
1041
+ orWhereNotNull(column: string): this;
1042
+ /**
1043
+ * @override Method
1044
+ * @param {string} column
1045
+ * @param {string?} operator = < > != !< !>
1046
+ * @param {any?} value
1047
+ * @return {this}
1048
+ */
1049
+ whereSensitive(column: string, operator?: any, value?: any): this;
1050
+ /**
1051
+ * @override Method
1052
+ * @param {string} column
1053
+ * @param {string?} operator = < > != !< !>
1054
+ * @param {any?} value
1055
+ * @return {this}
1056
+ */
1057
+ whereStrict(column: string, operator?: any, value?: any): this;
1058
+ /**
1059
+ * @override Method
1060
+ * @param {string} column
1061
+ * @param {string?} operator = < > != !< !>
1062
+ * @param {any?} value
1063
+ * @return {this}
1064
+ */
1065
+ orWhereSensitive(column: string, operator?: any, value?: any): this;
1066
+ /**
1067
+ * @override Method
1068
+ * @param {Function} callback callback query
1069
+ * @return {this}
1070
+ */
1071
+ whereQuery(callback: Function): this;
822
1072
  /**
823
1073
  * @override Method
824
1074
  * @return {promise<boolean>} promise boolean
@@ -986,13 +1236,14 @@ declare class Model extends AbstractModel {
986
1236
  * @return {this} this this
987
1237
  */
988
1238
  insertNotExists(data: Record<string, string | number | boolean | null | undefined>): this;
1239
+ getSchemaModel(): Record<string, Blueprint> | null;
1240
+ validation(schema?: ValidateSchema): this;
989
1241
  /**
990
- *
991
- * get schema from table
992
- * @return {this} this this
1242
+ * The 'bindPattern' method is used to covert column relate with pattern
1243
+ * @param {string} column
1244
+ * @return {string} return table.column
993
1245
  */
994
- getSchema(): Promise<any>;
995
- getSchemaModel(): Record<string, any> | null;
1246
+ bindPattern(column: string): string;
996
1247
  /**
997
1248
  * @override Method
998
1249
  * @return {Promise<Record<string,any> | any[] | null | undefined>}
@@ -1004,7 +1255,18 @@ declare class Model extends AbstractModel {
1004
1255
  * @param {number} rows number of rows
1005
1256
  * @return {promise<any>}
1006
1257
  */
1007
- faker(rows?: number): Promise<Record<string, any>[]>;
1258
+ faker(rows: number, callback?: Function): Promise<Record<string, any>[]>;
1259
+ /**
1260
+ * The 'Sync' method is used to check for create or update table or columns with your schema in your model.
1261
+ *
1262
+ * @property {boolean} force - forec always check all columns if not exists will be created
1263
+ * @property {boolean} foreign - foreign key for constraint
1264
+ * @return {promise<void>}
1265
+ */
1266
+ sync({ force, foreign }?: {
1267
+ force?: boolean | undefined;
1268
+ foreign?: boolean | undefined;
1269
+ }): Promise<void>;
1008
1270
  private _valuePattern;
1009
1271
  private _isPatternSnakeCase;
1010
1272
  private _classToTableName;
@@ -1020,6 +1282,7 @@ declare class Model extends AbstractModel {
1020
1282
  insert: () => string;
1021
1283
  update: () => string;
1022
1284
  delete: () => string;
1285
+ where: () => string | null;
1023
1286
  any: () => string;
1024
1287
  };
1025
1288
  private _showOnly;
@@ -1046,6 +1309,7 @@ declare class Model extends AbstractModel {
1046
1309
  private _checkSchemaOrNextError;
1047
1310
  private _stoppedRetry;
1048
1311
  private _observer;
1312
+ private _makeRelations;
1049
1313
  private _initialModel;
1050
1314
  }
1051
1315
  export { Model };