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
@@ -1,5 +1,5 @@
1
1
  import { AbstractBuilder } from './Abstracts/AbstractBuilder';
2
- import { Pagination, ConnectionOptions, Connection, ConnectionTransaction } from '../Interface';
2
+ import { Pagination, ConnectionOptions, Connection, ConnectionTransaction, NonEmptyArray } from '../Interface';
3
3
  declare class Builder extends AbstractBuilder {
4
4
  constructor();
5
5
  /**
@@ -36,6 +36,20 @@ declare class Builder extends AbstractBuilder {
36
36
  * @return {this} this
37
37
  */
38
38
  selectObject(object: Record<string, string>, alias: string): this;
39
+ /**
40
+ * The 'sleep' method is used to delay the query.
41
+ *
42
+ * @param {number} second - The number of seconds to sleep
43
+ * @return {this} this
44
+ */
45
+ sleep(second: number): this;
46
+ /**
47
+ * The 'returnType' method is used covert the results to type 'object' or 'array'.
48
+ *
49
+ * @param {string} type - The types 'object' | 'array'
50
+ * @return {this} this
51
+ */
52
+ returnType(type: 'object' | 'array'): this;
39
53
  /**
40
54
  * The 'pluck' method is used to retrieve the value of a single column from the first result of a query.
41
55
  *
@@ -53,6 +67,12 @@ declare class Builder extends AbstractBuilder {
53
67
  * @return {this} this
54
68
  */
55
69
  except(...columns: string[]): this;
70
+ /**
71
+ * The 'exceptTimestamp' method is used to timestamp columns (created_at , updated_at) you don't want to retrieve from a database table.
72
+ *
73
+ * @return {this} this
74
+ */
75
+ exceptTimestamp(): this;
56
76
  /**
57
77
  * The 'void' method is used to specify which you don't want to return a result from database table.
58
78
  *
@@ -176,6 +196,15 @@ declare class Builder extends AbstractBuilder {
176
196
  * @return {this}
177
197
  */
178
198
  whereExists(sql: string): this;
199
+ /**
200
+ *
201
+ * The 'whereExists' method is used to add a conditional clause to a database query that checks for the existence of related records in a subquery or another table.
202
+ *
203
+ * It allows you to filter records based on whether a specified condition is true for related records.
204
+ * @param {string} sql
205
+ * @return {this}
206
+ */
207
+ whereNotExists(sql: string): this;
179
208
  /**
180
209
  *
181
210
  * @param {number} id
@@ -411,6 +440,29 @@ declare class Builder extends AbstractBuilder {
411
440
  * @return {this}
412
441
  */
413
442
  orWhereGroup(callback: Function): this;
443
+ /**
444
+ * The 'whereAny' method is used to add conditions to a database query,
445
+ * where either the original condition or the new condition must be true.
446
+ *
447
+ * If has only 2 arguments default operator '='
448
+ * @param {string[]} columns
449
+ * @param {string?} operator ['=', '<', '>' ,'!=', '!<', '!>' ,'LIKE']
450
+ * @param {any?} value
451
+ * @return {this}
452
+ */
453
+ whereAny(columns: string[], operator?: any, value?: any): this;
454
+ /**
455
+ * The 'whereAll' method is used to clause to a database query.
456
+ *
457
+ * This method allows you to specify conditions that the retrieved records must meet.
458
+ *
459
+ * If has only 2 arguments default operator '='
460
+ * @param {string[]} columns
461
+ * @param {string?} operator ['=', '<', '>' ,'!=', '!<', '!>' ,'LIKE']
462
+ * @param {any?} value
463
+ * @return {this}
464
+ */
465
+ whereAll(columns: string[], operator?: any, value?: any): this;
414
466
  /**
415
467
  * The 'whereCases' method is used to add conditions with cases to a database query.
416
468
  *
@@ -464,6 +516,25 @@ declare class Builder extends AbstractBuilder {
464
516
  * @return {this}
465
517
  */
466
518
  join(localKey: string, referenceKey: string): this;
519
+ /**
520
+ * The 'join' method is used to perform various types of SQL joins between two or more database tables.
521
+ *
522
+ * Joins are used to combine data from different tables based on a specified condition, allowing you to retrieve data from related tables in a single query.
523
+ * @param {object} property object { localKey , foreignKey , sqlr }
524
+ * @property {string} property.localKey local key in current table
525
+ * @property {string} property.foreignKey reference key in next table
526
+ * @property {string} property.sql sql string
527
+ * @example
528
+ * await new DB('users')
529
+ * .joinSubQuery({ localKey : 'id' , foreignKey : 'userId' , sql : '....sql'})
530
+ * .get()
531
+ * @return {this}
532
+ */
533
+ joinSubQuery({ localKey, foreignKey, sql }: {
534
+ localKey: string;
535
+ foreignKey: string;
536
+ sql: string;
537
+ }): this;
467
538
  /**
468
539
  * The 'rightJoin' method is used to perform a right join operation between two database tables.
469
540
  *
@@ -503,7 +574,7 @@ declare class Builder extends AbstractBuilder {
503
574
  * @param {string?} order by default order = 'asc' but you can used 'asc' or 'desc'
504
575
  * @return {this}
505
576
  */
506
- orderBy(column: string, order?: string): this;
577
+ orderBy(column: string, order?: 'ASC' | 'DESC'): this;
507
578
  /**
508
579
  * The 'orderByRaw' method is used to specify the order in which the results of a database query should be sorted.
509
580
  *
@@ -515,6 +586,18 @@ declare class Builder extends AbstractBuilder {
515
586
  * @return {this}
516
587
  */
517
588
  orderByRaw(column: string, order?: string): this;
589
+ /**
590
+ * The 'random' method is used to retrieve random records from a database table or to randomize the order in which records are returned in the query result set.
591
+ *
592
+ * @return {this}
593
+ */
594
+ random(): this;
595
+ /**
596
+ * The 'inRandom' method is used to retrieve random records from a database table or to randomize the order in which records are returned in the query result set.
597
+ *
598
+ * @return {this}
599
+ */
600
+ inRandom(): this;
518
601
  /**
519
602
  * The 'latest' method is used to specify the order in which the results of a database query should be sorted.
520
603
  *
@@ -595,20 +678,6 @@ declare class Builder extends AbstractBuilder {
595
678
  * @return {this}
596
679
  */
597
680
  havingRaw(condition: string): this;
598
- /**
599
- * The 'random' method is used to add a random ordering to a database query.
600
- *
601
- * This method is used to retrieve random records from a database table or to randomize the order in which records are returned in the query result set.
602
- * @return {this}
603
- */
604
- random(): this;
605
- /**
606
- * The 'inRandom' method is used to add a random ordering to a database query.
607
- *
608
- * This method is used to retrieve random records from a database table or to randomize the order in which records are returned in the query result set.
609
- * @return {this}
610
- */
611
- inRandom(): this;
612
681
  /**
613
682
  * The 'limit' method is used to limit the number of records returned by a database query.
614
683
  *
@@ -703,15 +772,7 @@ declare class Builder extends AbstractBuilder {
703
772
  * @param {array} data create multiple data
704
773
  * @return {this} this this
705
774
  */
706
- createMultiple(data: Array<Record<string, any>>): this;
707
- /**
708
- * The 'createMany' method is used to insert a new records into a database table associated.
709
- *
710
- * It simplifies the process of creating and inserting records with an array.
711
- * @param {array} data create multiple data
712
- * @return {this} this this
713
- */
714
- createMany(data: Array<Record<string, any>>): this;
775
+ createMultiple(data: any[]): this;
715
776
  /**
716
777
  * The 'insertMultiple' method is used to insert a new records into a database table associated.
717
778
  *
@@ -719,15 +780,7 @@ declare class Builder extends AbstractBuilder {
719
780
  * @param {array} data create multiple data
720
781
  * @return {this} this this
721
782
  */
722
- insertMultiple(data: Array<Record<string, any>>): this;
723
- /**
724
- * The 'insertMany' method is used to insert a new records into a database table associated.
725
- *
726
- * It simplifies the process of creating and inserting records with an array.
727
- * @param {array} data create multiple data
728
- * @return {this} this this
729
- */
730
- insertMany(data: Array<Record<string, any>>): this;
783
+ insertMultiple(data: NonEmptyArray<Record<string, any>>): this;
731
784
  /**
732
785
  * The 'createNotExists' method to insert data into a database table while ignoring any duplicate key constraint violations.
733
786
  *
@@ -815,6 +868,17 @@ declare class Builder extends AbstractBuilder {
815
868
  createOrUpdate(data: Record<string, any> & {
816
869
  length?: never;
817
870
  }): this;
871
+ /**
872
+ *
873
+ * @param {{when : Object , columns : Object}[]} cases update multiple data specific columns by cases update
874
+ * @property {Record<string,string | number | boolean | null | undefined>} cases.when
875
+ * @property {Record<string,string | number | boolean | null | undefined>} cases.columns
876
+ * @return {this} this
877
+ */
878
+ updateMultiple(cases: {
879
+ when: Record<string, any>;
880
+ columns: Record<string, any>;
881
+ }[]): this;
818
882
  /**
819
883
  * The 'toString' method is used to retrieve the raw SQL query that would be executed by a query builder instance without actually executing it.
820
884
  *
@@ -984,17 +1048,19 @@ declare class Builder extends AbstractBuilder {
984
1048
  * The 'first' method is used to retrieve the first record that matches the query conditions.
985
1049
  *
986
1050
  * It allows you to retrieve a single record from a database table that meets the specified criteria.
1051
+ * @param {Function?} cb callback function return query sql
987
1052
  * @return {promise<object | null>}
988
1053
  */
989
- first(): Promise<Record<string, any> | null>;
1054
+ first(cb?: Function): Promise<Record<string, any> | null>;
990
1055
  /**
991
1056
  *
992
1057
  * The 'findOne' method is used to retrieve the first record that matches the query conditions.
993
1058
  *
994
1059
  * It allows you to retrieve a single record from a database table that meets the specified criteria.
1060
+ * @param {Function?} cb callback function return query sql
995
1061
  * @return {promise<object | null>}
996
1062
  */
997
- findOne(): Promise<Record<string, any> | null>;
1063
+ findOne(cb?: Function): Promise<Record<string, any> | null>;
998
1064
  /**
999
1065
  * The 'firstOrError' method is used to retrieve the first record that matches the query conditions.
1000
1066
  *
@@ -1018,16 +1084,18 @@ declare class Builder extends AbstractBuilder {
1018
1084
  * The 'get' method is used to execute a database query and retrieve the result set that matches the query conditions.
1019
1085
  *
1020
1086
  * It retrieves multiple records from a database table based on the criteria specified in the query.
1087
+ * @param {Function?} cb callback function return query sql
1021
1088
  * @return {promise<any[]>}
1022
1089
  */
1023
- get(): Promise<any[]>;
1090
+ get(cb?: Function): Promise<any[]>;
1024
1091
  /**
1025
1092
  * The 'findMany' method is used to execute a database query and retrieve the result set that matches the query conditions.
1026
1093
  *
1027
1094
  * It retrieves multiple records from a database table based on the criteria specified in the query.
1095
+ * @param {Function?} cb callback function return query sql
1028
1096
  * @return {promise<any[]>}
1029
1097
  */
1030
- findMany(): Promise<any[]>;
1098
+ findMany(cb?: Function): Promise<any[]>;
1031
1099
  /**
1032
1100
  *
1033
1101
  * The 'toJSON' method is used to execute a database query and retrieve the result set that matches the query conditions.
@@ -1148,10 +1216,40 @@ declare class Builder extends AbstractBuilder {
1148
1216
  */
1149
1217
  save(): Promise<Record<string, any> | any[] | null | undefined>;
1150
1218
  /**
1151
- * The 'showTables' method is used to show schema table.
1152
- *
1153
- * @return {Promise<Array>}
1154
- */
1219
+ *
1220
+ * The 'makeSelectStatement' method is used to make select statement.
1221
+ * @return {Promise<string>} string
1222
+ */
1223
+ makeSelectStatement(): Promise<string>;
1224
+ /**
1225
+ *
1226
+ * The 'makeInsertStatement' method is used to make insert table statement.
1227
+ * @return {Promise<string>} string
1228
+ */
1229
+ makeInsertStatement(): Promise<string>;
1230
+ /**
1231
+ *
1232
+ * The 'makeUpdateStatement' method is used to make update table statement.
1233
+ * @return {Promise<string>} string
1234
+ */
1235
+ makeUpdateStatement(): Promise<string>;
1236
+ /**
1237
+ *
1238
+ * The 'makeDeleteStatement' method is used to make delete statement.
1239
+ * @return {Promise<string>} string
1240
+ */
1241
+ makeDeleteStatement(): Promise<string>;
1242
+ /**
1243
+ *
1244
+ * The 'makeCreateTableStatement' method is used to make create table statement.
1245
+ * @return {Promise<string>} string
1246
+ */
1247
+ makeCreateTableStatement(): Promise<string>;
1248
+ /**
1249
+ * The 'showTables' method is used to show schema table.
1250
+ *
1251
+ * @return {Promise<Array>}
1252
+ */
1155
1253
  showTables(): Promise<string[]>;
1156
1254
  /**
1157
1255
  *
@@ -1233,8 +1331,6 @@ declare class Builder extends AbstractBuilder {
1233
1331
  where: () => string | null;
1234
1332
  any: () => string;
1235
1333
  };
1236
- protected _getState(key: string): any;
1237
- protected _setState(key: string, value: any): void;
1238
1334
  protected _resultHandler(data: any): any;
1239
1335
  whereReference(tableAndLocalKey: string, tableAndForeignKey?: string): this;
1240
1336
  protected _queryStatement(sql: string): Promise<any[]>;