tspace-mysql 1.4.6 → 1.4.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/README.md +185 -76
  2. package/dist/cli/generate/model.js +1 -1
  3. package/dist/lib/{tspace/Interface.d.ts → Interface.d.ts} +25 -4
  4. package/dist/lib/connection/index.d.ts +2 -2
  5. package/dist/lib/connection/index.js +1 -1
  6. package/dist/lib/constants/index.js +15 -13
  7. package/dist/lib/tspace/{Abstract → Abstracts}/AbstractBuilder.d.ts +6 -4
  8. package/dist/lib/tspace/{Abstract → Abstracts}/AbstractBuilder.js +6 -2
  9. package/dist/lib/tspace/{Abstract → Abstracts}/AbstractDB.d.ts +8 -4
  10. package/dist/lib/tspace/{Abstract → Abstracts}/AbstractModel.d.ts +9 -5
  11. package/dist/lib/tspace/Abstracts/AbstractModel.js +8 -0
  12. package/dist/lib/tspace/Blueprint.d.ts +21 -3
  13. package/dist/lib/tspace/Blueprint.js +22 -2
  14. package/dist/lib/tspace/Builder.d.ts +574 -192
  15. package/dist/lib/tspace/Builder.js +1631 -1104
  16. package/dist/lib/tspace/DB.d.ts +140 -88
  17. package/dist/lib/tspace/DB.js +195 -217
  18. package/dist/lib/tspace/{ProxyHandler.js → Handlers/Proxy.js} +1 -1
  19. package/dist/lib/tspace/Handlers/Relation.d.ts +32 -0
  20. package/dist/lib/tspace/Handlers/Relation.js +605 -0
  21. package/dist/lib/tspace/{StateHandler.js → Handlers/State.js} +4 -0
  22. package/dist/lib/tspace/Model.d.ts +378 -210
  23. package/dist/lib/tspace/Model.js +1105 -1093
  24. package/dist/lib/tspace/Schema.d.ts +9 -4
  25. package/dist/lib/tspace/Schema.js +122 -49
  26. package/dist/lib/tspace/index.d.ts +2 -0
  27. package/dist/lib/tspace/index.js +3 -1
  28. package/dist/lib/utils/index.d.ts +5 -1
  29. package/dist/lib/utils/index.js +37 -3
  30. package/package.json +1 -1
  31. package/dist/lib/tspace/Abstract/AbstractModel.js +0 -11
  32. /package/dist/lib/{tspace/Interface.js → Interface.js} +0 -0
  33. /package/dist/lib/tspace/{Abstract → Abstracts}/AbstractDB.js +0 -0
  34. /package/dist/lib/tspace/{ProxyHandler.d.ts → Handlers/Proxy.d.ts} +0 -0
  35. /package/dist/lib/tspace/{StateHandler.d.ts → Handlers/State.d.ts} +0 -0
package/README.md CHANGED
@@ -21,15 +21,17 @@ npm install tspace-mysql --save
21
21
  - [Backup](#backup)
22
22
  - [Generating Model Classes](#generating-model-classes)
23
23
  - [Model Conventions](#model-conventions)
24
- - [Relationships](#relationships)
25
- - [One To One](#one-to-one)
26
- - [One To Many](#one-to-many)
27
- - [Belongs To](#belongs-to)
28
- - [Many To Many](#many-to-many)
29
- - [Deeply Nested Relations](#deeply-nested-relations)
30
- - [Relation Exists](#relation-exists)
31
- - [Built in Relation Functions](#built-in-relation-functions)
32
- - [Schema Sync](#schema-sync)
24
+ - [Relationships](#relationships)
25
+ - [One To One](#one-to-one)
26
+ - [One To Many](#one-to-many)
27
+ - [Belongs To](#belongs-to)
28
+ - [Many To Many](#many-to-many)
29
+ - [Deeply Nested Relations](#deeply-nested-relations)
30
+ - [Relation Exists](#relation-exists)
31
+ - [Built in Relation Functions](#built-in-relation-functions)
32
+ - [Schema Model](#schema-model)
33
+ - [Validation](#validation)
34
+ - [Sync](#sync)
33
35
  - [Query Builder](#query-builder)
34
36
  - [Cli](#cli)
35
37
  - [Make Model](#make-model)
@@ -101,15 +103,24 @@ import { DB } from 'tspace-mysql'
101
103
  await new DB('users').findMany() // SELECT * FROM users => Array
102
104
  await new DB('users').findOne() // SELECT * FROM users LIMIT 1 => Object
103
105
  })()
106
+
107
+ ```
108
+ Running A Raw Query
109
+ ```js
110
+ const rawQuery = await new DB().query('SELECT * FROM users')
111
+
104
112
  ```
105
113
  Running A Select Query
106
114
  ```js
107
- const selectQuery = await new DB('users').select('id','username').findOne()
108
- // selectQuery => { id : 1, username : 'tspace'}
109
- const selectQueries = await new DB('users').select('id','username').findMany()
110
- // selectQueries => [{ id : 1, username : 'tspace' } , { id : 2, username : 'tspace2'}]
115
+ const select = await new DB('users').select('id','username').findOne()
111
116
 
112
- const selectQueryRaw = await new DB('users').selectRaw('COUNT(id)').findMany()
117
+ const selectRaw = await new DB('users').selectRaw('COUNT(id)').findMany()
118
+
119
+ const selectObject = await new DB('posts')
120
+ .join('posts.user_id', 'users.id')
121
+ .select('posts.*')
122
+ .selectObject({ id : 'users.id', name : 'users.name' , email : 'users.email'},'user')
123
+ .findOne()
113
124
 
114
125
  /**
115
126
  * @example except
@@ -137,10 +148,10 @@ await new DB('posts').rightJoin('posts.user_id' , 'users.id').findMany()
137
148
 
138
149
  Running A Where Query
139
150
  ```js
140
- const user = await new DB('users').where('id',1).findOne()
151
+ const whereEqual = await new DB('users').where('id',1).findOne()
141
152
  // SELECT * FROM `users` WHERE `users`.`id` = '1' LIMIT 1;
142
153
 
143
- const users = await new DB('users').where('id','!=',1).findMany()
154
+ const whereNotEqual = await new DB('users').where('id','!=',1).findMany()
144
155
  // SELECT * FROM `users` WHERE `users`.`id` != '1';
145
156
 
146
157
  const whereIn = await new DB('users').whereIn('id',[1,2]).findMany()
@@ -165,8 +176,14 @@ const whereQuery = await new DB('users').whereQuery(query => query.where('id',1)
165
176
  const whereExists = await new DB('users').whereExists(new DB('users').select('id').where('id',1).toString()).findOne()
166
177
  // SELECT * FROM `users` WHERE EXISTS (SELECT `id` FROM `users` WHERE id = 1) LIMIT 1;
167
178
 
168
- const whereJson= await new DB('users').whereJSON('json', { targetKey : 'id', value : '1234' }).findOne()
179
+ const whereJSON = await new DB('users').whereJSON('json', { key : 'id', value : '1234' }).findOne()
169
180
  // SELECT * FROM `users` WHERE `users`.`json`->>'$.id' = '1234' LIMIT 1;
181
+
182
+ const whereWhenIsTrue = await new DB('users').where('id',1).when(true, (query) => query.where('username','when is actived')).findOne()
183
+ // SELECT * FROM `users` WHERE `users`.`id` = '1' AND `users`.`username` = 'when is actived' LIMIT 1;
184
+
185
+ const whereWhenIsFalse = await new DB('users').where('id',1).when(false, (query) => query.where('username','when is actived')).findOne()
186
+ // SELECT * FROM `users` WHERE `users`.`id` = '1' LIMIT 1;
170
187
  ```
171
188
 
172
189
  Running A Hook Query
@@ -239,10 +256,21 @@ Running A Update Query
239
256
  const user = await new DB('users')
240
257
  .where('id',1)
241
258
  .update({
242
- name : 'tspace1**',
243
- email : 'tspace1@gmail.com'
244
- }).save()
245
- // user => { id : 1 , username : 'tspace1**', email : 'tspace1@gmail.com'}
259
+ name : 'tspace1**',
260
+ email : 'tspace1@gmail.com'
261
+ })
262
+ .save()
263
+ // UPDATE `users` SET `name` = 'tspace1**',`email` = 'tspace1@gmail.com' WHERE `users`.`id` = '1' LIMIT 1;
264
+
265
+ const user = await new DB('users')
266
+ .where('id',1)
267
+ .update({
268
+ name : 'tspace1**',
269
+ email : 'tspace1@gmail.com'
270
+ },['name'])
271
+ .save()
272
+ // UPDATE `users` SET `name` = CASE WHEN (`name` = "" OR `name` IS NULL) THEN "tspace1**" ELSE `name` END,`email` = 'tspace1@gmail.com' WHERE `users`.`id` = '1' LIMIT 1;
273
+
246
274
 
247
275
  +--------------------------------------------------------------------------+
248
276
 
@@ -251,26 +279,28 @@ reposity.name = 'tspace1++'
251
279
  reposity.email = 'tspace1++@gmail.com'
252
280
 
253
281
  await reposity.save()
254
-
282
+ // UPDATE `users` SET `name` = 'tspace1**',`email` = 'tspace1@gmail.com' WHERE `users`.`id` = '1' LIMIT 1;
255
283
  const { result } = reposity
256
284
  // result => { id : 1 , username : 'tspace1++', email : 'tspace1++@gmail.com'}
257
285
 
258
286
  ```
259
- Running A Update Or Created Query
287
+ Running A Update Or Created Query
260
288
  ```js
261
289
  const user = await new DB('users')
262
290
  .where('id',1)
263
291
  .updateOrCreate({
264
- name : 'tspace1**',
265
- email : 'tspace1@gmail.com'
292
+ name : 'tspace1**',
293
+ email : 'tspace1@gmail.com'
266
294
  }).save()
267
- // user => { username : 'tspace1**', email : 'tspace1@gmail.com' }
295
+ // INSERT INTO `users` (`name`,`email`) VALUES ('tspace1**','tspace1@gmail.com');
296
+
297
+ // UPDATE `users` SET `name` = 'tspace1**',`email` = 'tspace1@gmail.com' WHERE `users`.`id` = '1' LIMIT 1;
268
298
  ```
269
299
 
270
300
  Running A Delete Query
271
301
  ```js
272
302
  const deleted = await new DB('users').where('id',1).delete()
273
- // deleted => Boolean
303
+ // DELETE FROM `users` WHERE `users`.`id` = '1' LIMIT 1;
274
304
  ```
275
305
  ## Database Transactions
276
306
 
@@ -420,7 +450,7 @@ class User extends Model {
420
450
  *
421
451
  * Assign setting global in your model
422
452
  * @useMethod
423
- *
453
+ * this.usePattern('camelCase') // => default 'snake_case'
424
454
  * this.useDebug()
425
455
  * this.usePrimaryKey('id')
426
456
  * this.useTimestamp({
@@ -430,8 +460,7 @@ class User extends Model {
430
460
  * this.useSoftDelete('deletedAt') // => default target to colmun deleted_at
431
461
  * this.useTable('users')
432
462
  * this.useTableSingular() // => 'user'
433
- * this.useTablePlural() // => 'users'
434
- * this.usePattern('camelCase') // => default 'snake_case'
463
+ * this.useTablePlural() // => 'users'
435
464
  * this.useUUID('uuid') // => runing a uuid (universally unique identifier) when insert new data
436
465
  * this.useRegistry() // => build-in functions registry
437
466
  * this.useLoadRelationsInRegistry() // => auto generated result from relationship to results
@@ -440,14 +469,34 @@ class User extends Model {
440
469
  * this.useSchema ({
441
470
  * id : new Blueprint().int().notNull().primary().autoIncrement(),
442
471
  * uuid : new Blueprint().varchar(50).null(),
443
- * user_id : new Blueprint().int().notNull(),
444
- * title : new Blueprint().varchar(255).null(),
472
+ * name : new Blueprint().varchar(191).notNull(),
473
+ * email : new Blueprint().varchar(191).notNull(),
445
474
  * created_at : new Blueprint().timestamp().null(),
446
475
  * updated_at : new Blueprint().timestamp().null(),
447
476
  * deleted_at : new Blueprint().timestamp().null()
448
477
  * }) // auto-generated table when table is not exists and auto-create column when column not exists
449
478
  *
450
- * this.useValidateSchema() // => validate type of value when return results reference to the schema in 'this.useSchema'
479
+ * // validate input when create or update reference to the schema in 'this.useSchema'
480
+ * this.useValidateSchema({
481
+ * id : Number,
482
+ * uuid : Number,
483
+ * name : {
484
+ * type : String,
485
+ * length : 191
486
+ * require : true
487
+ * },
488
+ * email : {
489
+ * type : String,
490
+ * require : true,
491
+ * length : 191,
492
+ * match: /^[a-zA-Z0-9._]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/,
493
+ * unique : true,
494
+ * fn : (email : string) => !/^[a-zA-Z0-9._]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/.test(email)
495
+ * },
496
+ * created_at : Date,
497
+ * updated_at : Date,
498
+ * deleted_at : Date
499
+ * })
451
500
  */
452
501
 
453
502
 
@@ -686,7 +735,7 @@ await new User()
686
735
 
687
736
  ```
688
737
  ## Relation Exists
689
- Relationships can return only result is not empty in relations.
738
+ Relationships can return only result is not empty in relations (soft delete).
690
739
  let's example a exists in relations :
691
740
  ```js
692
741
  +-------------+--------------+----------------------------+--------------------+
@@ -823,10 +872,59 @@ for (const post of posts) {
823
872
  }
824
873
 
825
874
  ```
875
+ ## Schema Model
876
+ Define the schema of Model
877
+ let's example a validator model:
826
878
 
827
- ## Schema Sync
828
- Sync schema to Models in your directory,
829
- Sync will check for create or update table or columns with useSchema in your models.
879
+ ## Validation
880
+ Validate the schema of Model
881
+ let's example a validator model:
882
+ ```js
883
+
884
+ class User extends Model {
885
+ constructor(){
886
+ super()
887
+ this.useCamelCase()
888
+ this.useSchema ({
889
+ id : new Blueprint().int().notNull().primary().autoIncrement(),
890
+ uuid : new Blueprint().varchar(50).null(),
891
+ name : new Blueprint().varchar(191).notNull(),
892
+ email : new Blueprint().varchar(191).notNull(),
893
+ createdAt : new Blueprint().timestamp().null(),
894
+ updatedAt : new Blueprint().timestamp().null(),
895
+ deletedAt : new Blueprint().timestamp().null()
896
+ })
897
+ // validate input when create or update reference to the schema in 'this.useSchema'
898
+ this.useValidateSchema({
899
+ id : Number,
900
+ uuid : Number,
901
+ name : {
902
+ type : String,
903
+ length : 191
904
+ require : true,
905
+ json : true
906
+ },
907
+ email : {
908
+ type : String,
909
+ require : true,
910
+ length : 191,
911
+ match: /^[a-zA-Z0-9._]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/,
912
+ unique : true,
913
+ fn : (email : string) => !/^[a-zA-Z0-9._]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/.test(email)
914
+ },
915
+ createdAt : Date,
916
+ updatedAt : Date,
917
+ deletedAt : Date
918
+ })
919
+ }
920
+ }
921
+
922
+ ```
923
+
924
+ ## Sync
925
+ Sync schema with Models setting in your directory,
926
+ Sync will check for create or update table columns and foreign keys,
927
+ Related by method 'useSchema' in your models.
830
928
  Let's examine a basic model sync class:
831
929
 
832
930
  ```js
@@ -840,43 +938,44 @@ Let's examine a basic model sync class:
840
938
  * - Models
841
939
  * - User.ts
842
940
  * - Post.ts
843
- *
844
- * // file User.ts
845
- * class User extends Model {
846
- * constructor(){
847
- * super()
848
- * this.hasMany({ name : 'posts' , model : Post })
849
- * this.useSchema ({
850
- * id : new Blueprint().int().notNull().primary().autoIncrement(),
851
- * uuid : new Blueprint().varchar(50).null(),
852
- * email : new Blueprint().int().notNull().unique(),
853
- * name : new Blueprint().varchar(255).null(),
854
- * created_at : new Blueprint().timestamp().null(),
855
- * updated_at : new Blueprint().timestamp().null(),
856
- * deleted_at : new Blueprint().timestamp().null()
857
- * })
858
- * }
859
- * }
860
- *
861
- * // file Post.ts
862
- * class Post extends Model {
863
- * constructor(){
864
- * super()
865
- * this.hasMany({ name : 'comments' , model : Comment })
866
- * this.belongsTo({ name : 'user' , model : User })
867
- * this.useSchema ({
868
- * id : new Blueprint().int().notNull().primary().autoIncrement(),
869
- * uuid : new Blueprint().varchar(50).null(),
870
- * user_id : new Blueprint().int().notNull(),
871
- * title : new Blueprint().varchar(255).null(),
872
- * created_at : new Blueprint().timestamp().null(),
873
- * updated_at : new Blueprint().timestamp().null(),
874
- * deleted_at : new Blueprint().timestamp().null()
875
- * })
876
- * }
877
- * }
878
- *
879
941
  */
942
+
943
+ // file User
944
+ class User extends Model {
945
+ constructor(){
946
+ super()
947
+ this.hasMany({ name : 'posts' , model : Post })
948
+ this.useSchema ({
949
+ id : new Blueprint().int().notNull().primary().autoIncrement(),
950
+ uuid : new Blueprint().varchar(50).null(),
951
+ email : new Blueprint().int().notNull().unique(),
952
+ name : new Blueprint().varchar(255).null(),
953
+ created_at : new Blueprint().timestamp().null(),
954
+ updated_at : new Blueprint().timestamp().null(),
955
+ deleted_at : new Blueprint().timestamp().null()
956
+ })
957
+ }
958
+ }
959
+
960
+ // file Post
961
+ import User from './User'
962
+ class Post extends Model {
963
+ constructor(){
964
+ super()
965
+ this.hasMany({ name : 'comments' , model : Comment })
966
+ this.belongsTo({ name : 'user' , model : User })
967
+ this.useSchema ({
968
+ id : new Blueprint().int().notNull().primary().autoIncrement(),
969
+ uuid : new Blueprint().varchar(50).null(),
970
+ user_id : new Blueprint().int().notNull()
971
+ .foreign({ references : 'id' , on : User ,onDelete : 'CASCADE' , onUpdate : 'CASCADE' }),
972
+ title : new Blueprint().varchar(255).null(),
973
+ created_at : new Blueprint().timestamp().null(),
974
+ updated_at : new Blueprint().timestamp().null(),
975
+ deleted_at : new Blueprint().timestamp().null()
976
+ })
977
+ }
978
+ }
880
979
  await Schema.sync(`src/Models` , { force : true })
881
980
 
882
981
  ```
@@ -903,6 +1002,8 @@ orWhere(column , operator , value)
903
1002
  orWhereRaw(sql)
904
1003
  orWhereIn(column , [])
905
1004
  orWhereSubQuery(colmn , rawSQL)
1005
+ when(contition , callback)
1006
+ if(contition , callback)
906
1007
  select(column1 ,column2 ,...N)
907
1008
  distinct()
908
1009
  selectRaw(column1 ,column2 ,...N)
@@ -926,8 +1027,10 @@ groupByRaw (column)
926
1027
  create(objects)
927
1028
  createMultiple(array objects)
928
1029
  update (objects)
1030
+ updateMany (objects)
929
1031
  createNotExists(objects)
930
1032
  updateOrCreate (objects)
1033
+ onlyTrashed()
931
1034
  connection(options)
932
1035
  backup({ database , connection })
933
1036
  backupToFile({ filePath, database , connection })
@@ -971,8 +1074,8 @@ findMany()
971
1074
  findOne()
972
1075
  find(id)
973
1076
  delelte()
974
- exists ()
975
- onlyTrashed()
1077
+ delelteMany()
1078
+ exists()
976
1079
  toString()
977
1080
  toJSON()
978
1081
  toArray(column)
@@ -982,7 +1085,12 @@ avg(column)
982
1085
  max(column)
983
1086
  min(column)
984
1087
  pagination({ limit , page })
985
- save() /*for action statements insert update or delete */
1088
+ save() /* for actions statements insert or update */
1089
+ makeSelectStatement()
1090
+ makeInsertStatement()
1091
+ makeUpdateStatement()
1092
+ makeDeleteStatement()
1093
+ makeCreateStatement()
986
1094
  ```
987
1095
 
988
1096
  ## Cli
@@ -1152,4 +1260,5 @@ primary()
1152
1260
  default(string)
1153
1261
  defaultTimestamp()
1154
1262
  autoIncrement()
1263
+ foreign({ references : <column> , on : <table or model>}),
1155
1264
  ```
@@ -14,7 +14,7 @@ class ${model} extends Model {
14
14
  * createdAt : 'created_at',
15
15
  * updatedAt : 'updated_at'
16
16
  * }) // runing a timestamp when insert or update
17
- * this.useSoftDelete('deletedAt') // => default target to colmun deleted_at
17
+ * this.useSoftDelete('deletedAt') // => default target to column deleted_at
18
18
  * this.usePattern('snake_case') // => default 'snake_case'
19
19
  * this.useUUID('uuid') // => runing a uuid (universally unique identifier) when insert new data
20
20
  * this.useRegistry() // => build-in functions registry
@@ -1,7 +1,8 @@
1
+ import Model from "./tspace/Model";
1
2
  export interface Relation {
2
3
  name: string;
3
- model: any;
4
- as?: string;
4
+ model: new () => Model;
5
+ as?: string | undefined;
5
6
  localKey?: string | undefined;
6
7
  foreignKey?: string | undefined;
7
8
  freezeTable?: string | undefined;
@@ -11,11 +12,13 @@ export interface Relation {
11
12
  exists?: boolean | undefined;
12
13
  all?: boolean | undefined;
13
14
  trashed?: boolean | undefined;
15
+ count?: boolean | undefined;
14
16
  oldVersion?: boolean | undefined;
17
+ modelPivot?: new () => Model | undefined;
15
18
  }
16
19
  export interface RelationQuery {
17
20
  name?: string;
18
- model: any;
21
+ model: new () => Model;
19
22
  as?: string;
20
23
  localKey?: string | undefined;
21
24
  foreignKey?: string | undefined;
@@ -23,6 +26,11 @@ export interface RelationQuery {
23
26
  pivot?: string | undefined;
24
27
  query?: any | undefined;
25
28
  relation?: Object | undefined;
29
+ exists?: boolean | undefined;
30
+ all?: boolean | undefined;
31
+ trashed?: boolean | undefined;
32
+ oldVersion?: boolean | undefined;
33
+ modelPivot?: new () => Model | undefined;
26
34
  }
27
35
  export interface RelationShip {
28
36
  hasOne: string;
@@ -47,7 +55,6 @@ export interface Backup {
47
55
  to?: {
48
56
  host: string;
49
57
  port: number;
50
- database: string;
51
58
  username: string;
52
59
  password: string;
53
60
  };
@@ -121,3 +128,17 @@ export interface Execute {
121
128
  };
122
129
  }
123
130
  export type Pattern = 'snake_case' | 'camelCase';
131
+ export type ValidateSchema = null | Record<string, NumberConstructor | StringConstructor | DateConstructor | BooleanConstructor | {
132
+ type: NumberConstructor | StringConstructor | DateConstructor | BooleanConstructor;
133
+ require?: boolean;
134
+ match?: RegExp;
135
+ length?: number;
136
+ minLength?: number;
137
+ maxLength?: number;
138
+ min?: number;
139
+ max?: number;
140
+ enum?: string[] | number[] | boolean[];
141
+ unique?: boolean;
142
+ json?: boolean;
143
+ fn?: Function;
144
+ }>;
@@ -1,5 +1,5 @@
1
1
  import { loadOptionsEnvironment } from './options';
2
- import { Connection, Options } from '../tspace/Interface';
2
+ import { Connection, Options } from '../Interface';
3
3
  export declare class PoolConnection {
4
4
  private OPTIONS;
5
5
  /**
@@ -29,6 +29,6 @@ export declare class PoolConnection {
29
29
  * @property {Function} Connection.connection
30
30
  */
31
31
  declare const pool: Connection;
32
- export { pool as Pool };
33
32
  export { loadOptionsEnvironment };
33
+ export { pool as Pool };
34
34
  export default pool;
@@ -26,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
26
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.loadOptionsEnvironment = exports.Pool = exports.PoolConnection = void 0;
29
+ exports.Pool = exports.loadOptionsEnvironment = exports.PoolConnection = void 0;
30
30
  const fs_1 = __importDefault(require("fs"));
31
31
  const path_1 = __importDefault(require("path"));
32
32
  const options_1 = __importStar(require("./options"));
@@ -5,9 +5,9 @@ const CONSTANTS = Object.freeze({
5
5
  ID: 'ID',
6
6
  SHOW: 'SHOW',
7
7
  BINARY: 'BINARY',
8
- SHOW_TABLES: 'SHOW TABLES',
9
8
  FIELDS: 'FIELDS',
10
9
  COLUMNS: 'COLUMNS',
10
+ TABLES: 'TABLES',
11
11
  WHERE: 'WHERE',
12
12
  BETWEEN: 'BETWEEN',
13
13
  NOT_BETWEEN: 'NOT BETWEEN',
@@ -18,7 +18,6 @@ const CONSTANTS = Object.freeze({
18
18
  OR: 'OR',
19
19
  LIKE: 'LIKE',
20
20
  SELECT: 'SELECT',
21
- SELECTED: '*',
22
21
  DISTINCT: 'DISTINCT',
23
22
  FROM: 'FROM',
24
23
  OFFSET: 'OFFSET',
@@ -66,11 +65,12 @@ const CONSTANTS = Object.freeze({
66
65
  CREATE_DATABASE_NOT_EXISTS: 'CREATE DATABASE IF NOT EXISTS',
67
66
  CREATE_TABLE: 'CREATE TABLE',
68
67
  CREATE_TABLE_NOT_EXISTS: 'CREATE TABLE IF NOT EXISTS',
69
- ENGINE: 'ENGINE=INNODB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8',
68
+ ENGINE: 'ENGINE=INNODB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4',
70
69
  RAND: 'RAND()',
71
70
  ALTER_TABLE: 'ALTER TABLE',
72
71
  ADD: 'ADD',
73
72
  AFTER: 'AFTER',
73
+ JSON_OBJECT: 'JSON_OBJECT',
74
74
  RELATIONSHIP: {
75
75
  hasOne: 'hasOne',
76
76
  hasMany: 'hasMany',
@@ -94,14 +94,14 @@ const CONSTANTS = Object.freeze({
94
94
  DELETE: '',
95
95
  UPDATE: '',
96
96
  INSERT: '',
97
- SELECT: '',
97
+ SELECT: [],
98
98
  ONLY: [],
99
99
  EXCEPTS: [],
100
100
  CHUNK: 0,
101
101
  COUNT: '',
102
- FROM: '',
103
- JOIN: '',
104
- WHERE: '',
102
+ FROM: 'FROM',
103
+ JOIN: [],
104
+ WHERE: [],
105
105
  GROUP_BY: '',
106
106
  ORDER_BY: '',
107
107
  LIMIT: '',
@@ -119,7 +119,7 @@ const CONSTANTS = Object.freeze({
119
119
  MODEL: {
120
120
  PRIMARY_KEY: 'id',
121
121
  VOID: false,
122
- SELECT: '',
122
+ SELECT: [],
123
123
  DELETE: '',
124
124
  UPDATE: '',
125
125
  INSERT: '',
@@ -127,9 +127,9 @@ const CONSTANTS = Object.freeze({
127
127
  EXCEPTS: [],
128
128
  CHUNK: 0,
129
129
  COUNT: '',
130
- FROM: '',
131
- JOIN: '',
132
- WHERE: '',
130
+ FROM: 'FROM',
131
+ JOIN: [],
132
+ WHERE: [],
133
133
  GROUP_BY: '',
134
134
  ORDER_BY: '',
135
135
  LIMIT: '',
@@ -143,7 +143,6 @@ const CONSTANTS = Object.freeze({
143
143
  SOFT_DELETE: false,
144
144
  SOFT_DELETE_FORMAT: 'deleted_at',
145
145
  SOFT_DELETE_RELATIONS: false,
146
- RELATION: [],
147
146
  PAGE: 1,
148
147
  PER_PAGE: 1,
149
148
  REGISTRY: {},
@@ -153,6 +152,7 @@ const CONSTANTS = Object.freeze({
153
152
  PLUCK: '',
154
153
  SAVE: '',
155
154
  HOOKS: [],
155
+ RELATION: [],
156
156
  RELATIONS: [],
157
157
  RELATIONS_TRASHED: false,
158
158
  RELATIONS_EXISTS: false,
@@ -166,7 +166,9 @@ const CONSTANTS = Object.freeze({
166
166
  VALIDATE_SCHEMA_DEFINED: null,
167
167
  FUNCTION_RELATION: false,
168
168
  SCHEMA_TABLE: null,
169
- RETRY_QUERIES: 0
169
+ RETRY: 0,
170
+ OBSERVER: null,
171
+ DATA: null
170
172
  }
171
173
  });
172
174
  exports.CONSTANTS = CONSTANTS;
@@ -1,5 +1,5 @@
1
- import { Pagination } from '../Interface';
2
- import { StateHandler } from '../StateHandler';
1
+ import { Pagination } from '../../Interface';
2
+ import { StateHandler } from '../Handlers/State';
3
3
  declare abstract class AbstractBuilder {
4
4
  protected $setters: string[];
5
5
  protected $utils: {
@@ -35,8 +35,8 @@ declare abstract class AbstractBuilder {
35
35
  abstract whereUser(id: number): this;
36
36
  abstract whereEmail(value: string): this;
37
37
  abstract whereQuery(callback: Function): this;
38
- abstract whereJSON(column: string, { targetKey, value, operator }: {
39
- targetKey: string;
38
+ abstract whereJSON(column: string, { key, value, operator }: {
39
+ key: string;
40
40
  value: string;
41
41
  operator: string;
42
42
  }): this;
@@ -70,6 +70,7 @@ declare abstract class AbstractBuilder {
70
70
  abstract insert(data: Record<string, any>): this;
71
71
  abstract create(data: Record<string, any>): this;
72
72
  abstract update(data: Record<string, any>, updateNotExists?: string[]): this;
73
+ abstract updateMany(data: Record<string, any>, updateNotExists?: string[]): this;
73
74
  abstract insertNotExists(data: Record<string, any>): this;
74
75
  abstract createNotExists(data: Record<string, any>): this;
75
76
  abstract insertOrUpdate(data: Record<string, any>): this;
@@ -111,6 +112,7 @@ declare abstract class AbstractBuilder {
111
112
  abstract min(column: string): Promise<number>;
112
113
  abstract rawQuery(sql: string): Promise<any[]>;
113
114
  abstract delete(): Promise<boolean>;
115
+ abstract deleteMany(): Promise<boolean>;
114
116
  abstract exists(): Promise<boolean>;
115
117
  abstract save(): Promise<Record<string, any> | any[] | null | undefined>;
116
118
  abstract increment(column: string, value: number): Promise<number>;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.AbstractBuilder = void 0;
4
- const StateHandler_1 = require("../StateHandler");
4
+ const State_1 = require("../Handlers/State");
5
5
  class AbstractBuilder {
6
6
  constructor() {
7
7
  this.$setters = [
@@ -11,10 +11,14 @@ class AbstractBuilder {
11
11
  '$constants',
12
12
  '$pool',
13
13
  '$state',
14
+ '$relation'
14
15
  ];
15
16
  this.$utils = {};
16
17
  this.$constants = (name) => { };
17
- this.$state = new StateHandler_1.StateHandler({});
18
+ this.$state = new State_1.StateHandler({
19
+ state: {},
20
+ constants: {}
21
+ });
18
22
  this.$pool = {
19
23
  query: (sql) => { },
20
24
  set: (pool) => { },
@@ -1,12 +1,16 @@
1
1
  import Builder from '../Builder';
2
- import { Connection, ConnectionOptions } from '../Interface';
2
+ import { Connection, ConnectionOptions } from '../../Interface';
3
3
  declare abstract class AbstractDB extends Builder {
4
- abstract table(name: string): void;
4
+ abstract table(name: string): this;
5
5
  abstract beginTransaction(): Promise<any>;
6
- abstract makeObject(value: any): Record<string, any> | null;
7
- abstract makeArray(value: any): Array<any>;
8
6
  abstract generateUUID(): string;
9
7
  abstract raw(sql: string): string;
8
+ abstract escape(sql: string): string;
9
+ abstract escapeXSS(sql: string): string;
10
+ abstract snakeCase(sql: string): string;
11
+ abstract camelCase(sql: string): string;
12
+ abstract JSONObject(object: Record<string, string>, alias: string): string;
13
+ abstract jsonObject(object: Record<string, string>, alias: string): string;
10
14
  abstract constants(constants?: string): string | Record<string, any>;
11
15
  abstract caseUpdate(cases: {
12
16
  when: string;