tspace-mysql 1.4.5 → 1.4.6
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.
- package/README.md +112 -90
- package/dist/lib/connection/index.d.ts +1 -1
- package/dist/lib/connection/index.js +9 -10
- package/dist/lib/connection/options.js +1 -1
- package/dist/lib/constants/index.js +3 -2
- package/dist/lib/tspace/Abstract/AbstractBuilder.d.ts +41 -42
- package/dist/lib/tspace/Abstract/AbstractDB.d.ts +2 -4
- package/dist/lib/tspace/Abstract/AbstractModel.d.ts +5 -7
- package/dist/lib/tspace/Blueprint.d.ts +9 -3
- package/dist/lib/tspace/Blueprint.js +15 -8
- package/dist/lib/tspace/Builder.d.ts +92 -96
- package/dist/lib/tspace/Builder.js +220 -142
- package/dist/lib/tspace/Model.d.ts +45 -139
- package/dist/lib/tspace/Model.js +78 -180
- package/dist/lib/tspace/Schema.js +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -52,7 +52,6 @@ DB_DATABASE = database
|
|
|
52
52
|
/**
|
|
53
53
|
* @default
|
|
54
54
|
* DB_CONNECTION_LIMIT = 10
|
|
55
|
-
* DB_CONNECTION_ERROR = true
|
|
56
55
|
* DB_QUEUE_LIMIT = 0
|
|
57
56
|
* DB_TIMEOUT = 60000
|
|
58
57
|
* DB_DATE_STRINGS = true
|
|
@@ -99,8 +98,8 @@ Once you have configured your database connection, you may run queries is this :
|
|
|
99
98
|
|
|
100
99
|
import { DB } from 'tspace-mysql'
|
|
101
100
|
(async () => {
|
|
102
|
-
await new DB('users').findMany() //
|
|
103
|
-
await new DB('users').findOne()
|
|
101
|
+
await new DB('users').findMany() // SELECT * FROM users => Array
|
|
102
|
+
await new DB('users').findOne() // SELECT * FROM users LIMIT 1 => Object
|
|
104
103
|
})()
|
|
105
104
|
```
|
|
106
105
|
Running A Select Query
|
|
@@ -139,118 +138,139 @@ await new DB('posts').rightJoin('posts.user_id' , 'users.id').findMany()
|
|
|
139
138
|
Running A Where Query
|
|
140
139
|
```js
|
|
141
140
|
const user = await new DB('users').where('id',1).findOne()
|
|
142
|
-
|
|
141
|
+
// SELECT * FROM `users` WHERE `users`.`id` = '1' LIMIT 1;
|
|
142
|
+
|
|
143
143
|
const users = await new DB('users').where('id','!=',1).findMany()
|
|
144
|
-
|
|
144
|
+
// SELECT * FROM `users` WHERE `users`.`id` != '1';
|
|
145
145
|
|
|
146
146
|
const whereIn = await new DB('users').whereIn('id',[1,2]).findMany()
|
|
147
|
+
// SELECT * FROM `users` WHERE `users`.`id` BETWEEN '1' AND '2';
|
|
148
|
+
|
|
147
149
|
const whereBetween = await new DB('users').whereBetween('id',[1,2]).findMany()
|
|
148
|
-
|
|
149
|
-
|
|
150
|
+
// SELECT * FROM `users` WHERE `users`.`id` BETWEEN '1' AND '2';
|
|
151
|
+
|
|
152
|
+
const whereSubQuery = await new DB('users').whereSubQuery('id','SELECT id FROM users').findMany()
|
|
153
|
+
// SELECT * FROM `users` WHERE `users`.`id` IN (SELECT id FROM users);
|
|
154
|
+
// or use -> await new DB('users').whereSubQuery('id',new DB('users').select('id').toString()).findMany()
|
|
155
|
+
|
|
150
156
|
const whereNull = await new DB('users').whereNull('username').findOne()
|
|
157
|
+
// SELECT * FROM `users` WHERE `users`.`username` IS NULL LIMIT 1;
|
|
158
|
+
|
|
151
159
|
const whereNotNull = await new DB('users').whereNotNull('username').findOne()
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
const
|
|
160
|
+
// SELECT * FROM `users` WHERE `users`.`username` IS NOT NULL LIMIT 1;
|
|
161
|
+
|
|
162
|
+
const whereQuery = await new DB('users').whereQuery(query => query.where('id',1).where('username','values')).whereIn('id',[1,2]).findOne()
|
|
163
|
+
// SELECT * FROM `users` WHERE ( `users`.`id` = '1' AND `users`.`username` = 'values') AND `users`.`id` IN ('1','2'') LIMIT 1;
|
|
164
|
+
|
|
165
|
+
const whereExists = await new DB('users').whereExists(new DB('users').select('id').where('id',1).toString()).findOne()
|
|
166
|
+
// SELECT * FROM `users` WHERE EXISTS (SELECT `id` FROM `users` WHERE id = 1) LIMIT 1;
|
|
167
|
+
|
|
168
|
+
const whereJson= await new DB('users').whereJSON('json', { targetKey : 'id', value : '1234' }).findOne()
|
|
169
|
+
// SELECT * FROM `users` WHERE `users`.`json`->>'$.id' = '1234' LIMIT 1;
|
|
155
170
|
```
|
|
156
171
|
|
|
157
172
|
Running A Hook Query
|
|
158
173
|
```js
|
|
159
|
-
const hookResult = (result) => console.log(result)
|
|
174
|
+
const hookResult = (result) => console.log('hook!! result => ',result)
|
|
160
175
|
const user = await new DB('users').where('id',1).hook(hookResult).findOne()
|
|
161
176
|
```
|
|
162
177
|
|
|
163
178
|
Running A Insert Query
|
|
164
179
|
```js
|
|
165
180
|
const user = await new DB('users')
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
181
|
+
.create({
|
|
182
|
+
name : 'tspace3',
|
|
183
|
+
email : 'tspace3@gmail.com'
|
|
184
|
+
})
|
|
185
|
+
.save()
|
|
186
|
+
// user => { id : 3 , username : 'tspace3', email : 'tspace3@gmail.com'}
|
|
171
187
|
|
|
172
188
|
+--------------------------------------------------------------------------+
|
|
173
189
|
|
|
174
190
|
const reposity = new DB('users')
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
await reposity.save()
|
|
178
|
-
const { result } = reposity
|
|
179
|
-
// result => { id : 4 , username : 'tspace4', email : 'tspace4@gmail.com'}
|
|
191
|
+
reposity.name = 'tspace4'
|
|
192
|
+
reposity.email = 'tspace4@gmail.com'
|
|
180
193
|
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
email : 'tspace4@gmail.com'
|
|
186
|
-
},
|
|
187
|
-
{
|
|
188
|
-
name :'tspace5',
|
|
189
|
-
email : 'tspace5@gmail.com'
|
|
190
|
-
},
|
|
191
|
-
{
|
|
192
|
-
name :'tspace6',
|
|
193
|
-
email : 'tspace6@gmail.com'
|
|
194
|
-
},
|
|
195
|
-
])
|
|
196
|
-
.save()
|
|
194
|
+
await reposity.save()
|
|
195
|
+
|
|
196
|
+
const { result } = reposity
|
|
197
|
+
// result => { id : 4 , username : 'tspace4', email : 'tspace4@gmail.com'}
|
|
197
198
|
|
|
198
199
|
const users = await new DB('users')
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
.createNotExists({
|
|
200
|
+
.createMultiple([
|
|
201
|
+
{
|
|
202
202
|
name :'tspace4',
|
|
203
203
|
email : 'tspace4@gmail.com'
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
|
|
204
|
+
},
|
|
205
|
+
{
|
|
206
|
+
name :'tspace5',
|
|
207
|
+
email : 'tspace5@gmail.com'
|
|
208
|
+
},
|
|
209
|
+
{
|
|
210
|
+
name :'tspace6',
|
|
211
|
+
email : 'tspace6@gmail.com'
|
|
212
|
+
},
|
|
213
|
+
])
|
|
214
|
+
.save()
|
|
207
215
|
|
|
208
216
|
const users = await new DB('users')
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
+
.where('name','tspace4')
|
|
218
|
+
.where('email','tspace4@gmail.com')
|
|
219
|
+
.createNotExists({
|
|
220
|
+
name :'tspace4',
|
|
221
|
+
email : 'tspace4@gmail.com'
|
|
222
|
+
})
|
|
223
|
+
.save()
|
|
224
|
+
// if has exists return null, if not exists created new data
|
|
225
|
+
|
|
226
|
+
const users = await new DB('users')
|
|
227
|
+
.where('name','tspace4')
|
|
228
|
+
.where('email','tspace4@gmail.com')
|
|
229
|
+
.createOrSelect({
|
|
230
|
+
name :'tspace4',
|
|
231
|
+
email : 'tspace4@gmail.com'
|
|
232
|
+
})
|
|
233
|
+
.save()
|
|
234
|
+
// if has exists return data, if not exists created new data
|
|
217
235
|
|
|
218
236
|
```
|
|
219
237
|
Running A Update Query
|
|
220
238
|
```js
|
|
221
239
|
const user = await new DB('users')
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
240
|
+
.where('id',1)
|
|
241
|
+
.update({
|
|
242
|
+
name : 'tspace1**',
|
|
243
|
+
email : 'tspace1@gmail.com'
|
|
244
|
+
}).save()
|
|
245
|
+
// user => { id : 1 , username : 'tspace1**', email : 'tspace1@gmail.com'}
|
|
228
246
|
|
|
229
247
|
+--------------------------------------------------------------------------+
|
|
230
248
|
|
|
231
249
|
const reposity = new DB('users').where('id',1)
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
250
|
+
reposity.name = 'tspace1++'
|
|
251
|
+
reposity.email = 'tspace1++@gmail.com'
|
|
252
|
+
|
|
253
|
+
await reposity.save()
|
|
254
|
+
|
|
235
255
|
const { result } = reposity
|
|
236
|
-
|
|
237
|
-
```
|
|
256
|
+
// result => { id : 1 , username : 'tspace1++', email : 'tspace1++@gmail.com'}
|
|
238
257
|
|
|
258
|
+
```
|
|
239
259
|
Running A Update Or Created Query
|
|
240
260
|
```js
|
|
241
261
|
const user = await new DB('users')
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
262
|
+
.where('id',1)
|
|
263
|
+
.updateOrCreate({
|
|
264
|
+
name : 'tspace1**',
|
|
265
|
+
email : 'tspace1@gmail.com'
|
|
266
|
+
}).save()
|
|
267
|
+
// user => { username : 'tspace1**', email : 'tspace1@gmail.com' }
|
|
248
268
|
```
|
|
249
269
|
|
|
250
270
|
Running A Delete Query
|
|
251
271
|
```js
|
|
252
272
|
const deleted = await new DB('users').where('id',1).delete()
|
|
253
|
-
|
|
273
|
+
// deleted => Boolean
|
|
254
274
|
```
|
|
255
275
|
## Database Transactions
|
|
256
276
|
|
|
@@ -313,7 +333,6 @@ try {
|
|
|
313
333
|
}
|
|
314
334
|
|
|
315
335
|
```
|
|
316
|
-
|
|
317
336
|
## Connection
|
|
318
337
|
When establishing a connection, you may establish options is this:
|
|
319
338
|
```js
|
|
@@ -326,8 +345,8 @@ const connection = await new DB().getConnection({
|
|
|
326
345
|
})
|
|
327
346
|
|
|
328
347
|
const users = await new DB('users')
|
|
329
|
-
|
|
330
|
-
|
|
348
|
+
.bind(connection)
|
|
349
|
+
.findMany()
|
|
331
350
|
// users => [{ .... }]
|
|
332
351
|
```
|
|
333
352
|
|
|
@@ -355,15 +374,15 @@ const backup = await new DB().backup({
|
|
|
355
374
|
* @param {object | null} conection defalut current connection
|
|
356
375
|
*/
|
|
357
376
|
const backupToFile = await new DB().backupToFile({
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
377
|
+
database: 'try-to-backup',
|
|
378
|
+
filePath: 'backup.sql',
|
|
379
|
+
connection ?: {
|
|
361
380
|
host: 'localhost',
|
|
362
381
|
port : 3306,
|
|
363
382
|
database: 'database'
|
|
364
383
|
username: 'username',
|
|
365
384
|
password: 'password',
|
|
366
|
-
|
|
385
|
+
}
|
|
367
386
|
})
|
|
368
387
|
// backupToFile => backup.sql
|
|
369
388
|
```
|
|
@@ -758,12 +777,11 @@ await new User().relationsExists('posts').findMany()
|
|
|
758
777
|
* ]
|
|
759
778
|
* }
|
|
760
779
|
* ]
|
|
761
|
-
* because posts id 1 and id 3 has been removed from database using soft delete
|
|
780
|
+
* because posts id 1 and id 3 has been removed from database (using soft delete)
|
|
762
781
|
*/
|
|
763
782
|
|
|
764
783
|
|
|
765
784
|
```
|
|
766
|
-
|
|
767
785
|
## Built in Relation Functions
|
|
768
786
|
Relationships can using built in function in results
|
|
769
787
|
let's example a built in function :
|
|
@@ -799,7 +817,7 @@ class Comment extends Model {
|
|
|
799
817
|
const user = await new User().findOne()
|
|
800
818
|
const posts = await user.$posts()
|
|
801
819
|
|
|
802
|
-
/** Warning built
|
|
820
|
+
/** Warning built-in function has Big-O effect */
|
|
803
821
|
for (const post of posts) {
|
|
804
822
|
const comments = await post.$comments()
|
|
805
823
|
}
|
|
@@ -808,7 +826,7 @@ for (const post of posts) {
|
|
|
808
826
|
|
|
809
827
|
## Schema Sync
|
|
810
828
|
Sync schema to Models in your directory,
|
|
811
|
-
Sync will check for create or update table or columns with useSchema in your
|
|
829
|
+
Sync will check for create or update table or columns with useSchema in your models.
|
|
812
830
|
Let's examine a basic model sync class:
|
|
813
831
|
|
|
814
832
|
```js
|
|
@@ -817,7 +835,8 @@ Let's examine a basic model sync class:
|
|
|
817
835
|
* @Ex directory
|
|
818
836
|
*
|
|
819
837
|
* - node_modules
|
|
820
|
-
* -
|
|
838
|
+
* - src
|
|
839
|
+
* - index.ts
|
|
821
840
|
* - Models
|
|
822
841
|
* - User.ts
|
|
823
842
|
* - Post.ts
|
|
@@ -858,7 +877,7 @@ Let's examine a basic model sync class:
|
|
|
858
877
|
* }
|
|
859
878
|
*
|
|
860
879
|
*/
|
|
861
|
-
await Schema.sync(`
|
|
880
|
+
await Schema.sync(`src/Models` , { force : true })
|
|
862
881
|
|
|
863
882
|
```
|
|
864
883
|
## Query Builder
|
|
@@ -875,6 +894,7 @@ whereNull(column)
|
|
|
875
894
|
whereNotNull(column)
|
|
876
895
|
whereBetween (column , [value1 , value2])
|
|
877
896
|
whereQuery(callback)
|
|
897
|
+
whereJson(column, { targetKey, value , operator })
|
|
878
898
|
whereRaw(sql)
|
|
879
899
|
whereExists(sql)
|
|
880
900
|
whereSubQuery(colmn , rawSQL)
|
|
@@ -884,6 +904,7 @@ orWhereRaw(sql)
|
|
|
884
904
|
orWhereIn(column , [])
|
|
885
905
|
orWhereSubQuery(colmn , rawSQL)
|
|
886
906
|
select(column1 ,column2 ,...N)
|
|
907
|
+
distinct()
|
|
887
908
|
selectRaw(column1 ,column2 ,...N)
|
|
888
909
|
except(column1 ,column2 ,...N)
|
|
889
910
|
only(column1 ,column2 ,...N)
|
|
@@ -952,7 +973,6 @@ find(id)
|
|
|
952
973
|
delelte()
|
|
953
974
|
exists ()
|
|
954
975
|
onlyTrashed()
|
|
955
|
-
toSQL()
|
|
956
976
|
toString()
|
|
957
977
|
toJSON()
|
|
958
978
|
toArray(column)
|
|
@@ -1068,9 +1088,9 @@ tspace-mysql dump:table "table" --values // backup with values in the table
|
|
|
1068
1088
|
# Generate Models
|
|
1069
1089
|
Command will be generate models from table in database
|
|
1070
1090
|
```js
|
|
1071
|
-
tspace-mysql generate:models --dir=<folder for creating>
|
|
1091
|
+
tspace-mysql generate:models --dir=<folder for creating>
|
|
1072
1092
|
or
|
|
1073
|
-
tspace-mysql gen:models --dir=<folder for creating>
|
|
1093
|
+
tspace-mysql gen:models --dir=<folder for creating> --env=development
|
|
1074
1094
|
|
|
1075
1095
|
```
|
|
1076
1096
|
|
|
@@ -1079,13 +1099,14 @@ Schema table created by command make:migration, you may use the:
|
|
|
1079
1099
|
```js
|
|
1080
1100
|
import { Schema , Blueprint , DB } from 'tspace-mysql'
|
|
1081
1101
|
(async () => {
|
|
1082
|
-
await new Schema().table('users',{
|
|
1083
|
-
id :
|
|
1102
|
+
await new Schema().table('users', {
|
|
1103
|
+
id : new Blueprint().int().notNull().primary().autoIncrement(),
|
|
1084
1104
|
uuid : new Blueprint().varchar(120).null()
|
|
1085
1105
|
name : new Blueprint().varchar(120).default('name'),
|
|
1086
1106
|
email : new Blueprint().varchar(255).unique().notNull(),
|
|
1087
1107
|
email_verify : new Blueprint().tinyInt(),
|
|
1088
1108
|
password : new Blueprint().varchar(255),
|
|
1109
|
+
json : new Blueprint().json(),
|
|
1089
1110
|
created_at : new Blueprint().null().timestamp(),
|
|
1090
1111
|
updated_at : new Blueprint().null().timestamp()
|
|
1091
1112
|
})
|
|
@@ -1097,15 +1118,16 @@ import { Schema , Blueprint , DB } from 'tspace-mysql'
|
|
|
1097
1118
|
})()
|
|
1098
1119
|
|
|
1099
1120
|
/**
|
|
1100
|
-
*
|
|
1121
|
+
* add Type of schema in database
|
|
1101
1122
|
* @Types
|
|
1102
1123
|
*
|
|
1103
1124
|
*/
|
|
1104
|
-
int ()
|
|
1125
|
+
int (number)
|
|
1105
1126
|
tinyInt (number)
|
|
1106
1127
|
bigInt (number)
|
|
1107
1128
|
double ()
|
|
1108
1129
|
float ()
|
|
1130
|
+
json ()
|
|
1109
1131
|
varchar (number)
|
|
1110
1132
|
char (number)
|
|
1111
1133
|
longText()
|
|
@@ -1118,7 +1140,7 @@ dateTime()
|
|
|
1118
1140
|
timestamp ()
|
|
1119
1141
|
|
|
1120
1142
|
/**
|
|
1121
|
-
*
|
|
1143
|
+
* add Attrbuites of schema in database
|
|
1122
1144
|
* @Attrbuites
|
|
1123
1145
|
*
|
|
1124
1146
|
*/
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { loadOptionsEnvironment } from './options';
|
|
2
2
|
import { Connection, Options } from '../tspace/Interface';
|
|
3
|
-
export { loadOptionsEnvironment };
|
|
4
3
|
export declare class PoolConnection {
|
|
5
4
|
private OPTIONS;
|
|
6
5
|
/**
|
|
@@ -31,4 +30,5 @@ export declare class PoolConnection {
|
|
|
31
30
|
*/
|
|
32
31
|
declare const pool: Connection;
|
|
33
32
|
export { pool as Pool };
|
|
33
|
+
export { loadOptionsEnvironment };
|
|
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.
|
|
29
|
+
exports.loadOptionsEnvironment = exports.Pool = 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"));
|
|
@@ -52,17 +52,16 @@ class PoolConnection {
|
|
|
52
52
|
*/
|
|
53
53
|
connection() {
|
|
54
54
|
const pool = (0, mysql2_1.createPool)(Object.fromEntries(this.OPTIONS));
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
55
|
+
pool.getConnection((err, _) => {
|
|
56
|
+
if (err == null || !err)
|
|
57
|
+
return;
|
|
58
|
+
const message = this._messageError.bind(this);
|
|
59
|
+
process.nextTick(() => {
|
|
60
|
+
console.log(message(err === null || err === void 0 ? void 0 : err.message));
|
|
61
|
+
if (options_1.default.CONNECTION_ERROR)
|
|
62
62
|
return process.exit();
|
|
63
|
-
});
|
|
64
63
|
});
|
|
65
|
-
}
|
|
64
|
+
});
|
|
66
65
|
return {
|
|
67
66
|
query: (sql) => {
|
|
68
67
|
return new Promise((resolve, reject) => {
|
|
@@ -30,7 +30,7 @@ const env = {
|
|
|
30
30
|
QUEUE_LIMIT: ENV.DB_QUEUE_LIMIT || ENV.TSPACE_QUEUE_LIMIT || 0,
|
|
31
31
|
TIMEOUT: ENV.DB_TIMEOUT || ENV.TSPACE_TIMEOUT || 1000 * 60,
|
|
32
32
|
CHARSET: ENV.DB_CHARSET || ENV.TSPACE_CHARSET || 'utf8mb4',
|
|
33
|
-
CONNECTION_ERROR: ENV.DB_CONNECTION_ERROR || ENV.TSPACE_CONNECTION_ERROR ||
|
|
33
|
+
CONNECTION_ERROR: ENV.DB_CONNECTION_ERROR || ENV.TSPACE_CONNECTION_ERROR || false,
|
|
34
34
|
WAIT_FOR_CONNECTIONS: ENV.DB_WAIT_FOR_CONNECTIONS || ENV.TSPACE_WAIT_FOR_CONNECTIONS || true,
|
|
35
35
|
DATE_STRINGS: ENV.DB_DATE_STRINGS || ENV.TSPACE_DATE_STRINGS || true,
|
|
36
36
|
KEEP_ALIVE_DELAY: ENV.DB_KEEP_ALIVE_DELAY || ENV.TSPACE_KEEP_ALIVE_DELAY || 0,
|
|
@@ -4,6 +4,7 @@ exports.CONSTANTS = void 0;
|
|
|
4
4
|
const CONSTANTS = Object.freeze({
|
|
5
5
|
ID: 'ID',
|
|
6
6
|
SHOW: 'SHOW',
|
|
7
|
+
BINARY: 'BINARY',
|
|
7
8
|
SHOW_TABLES: 'SHOW TABLES',
|
|
8
9
|
FIELDS: 'FIELDS',
|
|
9
10
|
COLUMNS: 'COLUMNS',
|
|
@@ -87,7 +88,7 @@ const CONSTANTS = Object.freeze({
|
|
|
87
88
|
PRIMARY_KEY: 'id',
|
|
88
89
|
VOID: false,
|
|
89
90
|
RESULT: null,
|
|
90
|
-
DISTINCT:
|
|
91
|
+
DISTINCT: false,
|
|
91
92
|
PLUCK: '',
|
|
92
93
|
SAVE: '',
|
|
93
94
|
DELETE: '',
|
|
@@ -148,7 +149,7 @@ const CONSTANTS = Object.freeze({
|
|
|
148
149
|
REGISTRY: {},
|
|
149
150
|
RESULT: null,
|
|
150
151
|
PATTERN: 'snake_case',
|
|
151
|
-
DISTINCT:
|
|
152
|
+
DISTINCT: false,
|
|
152
153
|
PLUCK: '',
|
|
153
154
|
SAVE: '',
|
|
154
155
|
HOOKS: [],
|
|
@@ -35,15 +35,20 @@ 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;
|
|
40
|
+
value: string;
|
|
41
|
+
operator: string;
|
|
42
|
+
}): this;
|
|
38
43
|
abstract orWhere(column: string, operator: string, value: string): this;
|
|
39
|
-
abstract whereIn(column: string, arrayValues:
|
|
40
|
-
abstract orWhereIn(column: string, arrayValues:
|
|
41
|
-
abstract whereNotIn(column: string, arrayValues:
|
|
44
|
+
abstract whereIn(column: string, arrayValues: any[]): this;
|
|
45
|
+
abstract orWhereIn(column: string, arrayValues: any[]): this;
|
|
46
|
+
abstract whereNotIn(column: string, arrayValues: any[]): this;
|
|
42
47
|
abstract whereSubQuery(column: string, subQuery: string): this;
|
|
43
48
|
abstract whereNotSubQuery(column: string, subQuery: string): this;
|
|
44
49
|
abstract orWhereSubQuery(column: string, subQuery: string): this;
|
|
45
|
-
abstract whereBetween(column: string, arrayValue:
|
|
46
|
-
abstract whereNotBetween(column: string, arrayValue:
|
|
50
|
+
abstract whereBetween(column: string, arrayValue: any[]): this;
|
|
51
|
+
abstract whereNotBetween(column: string, arrayValue: any[]): this;
|
|
47
52
|
abstract having(condition: string): this;
|
|
48
53
|
abstract havingRaw(condition: string): this;
|
|
49
54
|
abstract join(pk: string, fk: string): this;
|
|
@@ -52,32 +57,32 @@ declare abstract class AbstractBuilder {
|
|
|
52
57
|
abstract crossJoin(pk: string, fk: string): this;
|
|
53
58
|
abstract orderBy(column: string, order: string): this;
|
|
54
59
|
abstract orderByRaw(column: string, order: string): this;
|
|
55
|
-
abstract latest(...columns:
|
|
56
|
-
abstract latestRaw(...columns:
|
|
57
|
-
abstract oldest(...columns:
|
|
58
|
-
abstract oldestRaw(...columns:
|
|
60
|
+
abstract latest(...columns: string[]): this;
|
|
61
|
+
abstract latestRaw(...columns: string[]): this;
|
|
62
|
+
abstract oldest(...columns: string[]): this;
|
|
63
|
+
abstract oldestRaw(...columns: string[]): this;
|
|
59
64
|
abstract groupBy(...columns: string[]): this;
|
|
60
65
|
abstract groupByRaw(...columns: string[]): this;
|
|
61
66
|
abstract random(): this;
|
|
62
67
|
abstract inRandom(): this;
|
|
63
68
|
abstract limit(number: number): this;
|
|
64
69
|
abstract hidden(...columns: string[]): this;
|
|
65
|
-
abstract insert(
|
|
66
|
-
abstract create(
|
|
67
|
-
abstract update(
|
|
68
|
-
abstract insertNotExists(
|
|
69
|
-
abstract createNotExists(
|
|
70
|
-
abstract insertOrUpdate(
|
|
71
|
-
abstract createOrUpdate(
|
|
72
|
-
abstract updateOrInsert(
|
|
73
|
-
abstract updateOrCreate(
|
|
74
|
-
abstract createMultiple(
|
|
75
|
-
abstract insertMultiple(
|
|
70
|
+
abstract insert(data: Record<string, any>): this;
|
|
71
|
+
abstract create(data: Record<string, any>): this;
|
|
72
|
+
abstract update(data: Record<string, any>, updateNotExists?: string[]): this;
|
|
73
|
+
abstract insertNotExists(data: Record<string, any>): this;
|
|
74
|
+
abstract createNotExists(data: Record<string, any>): this;
|
|
75
|
+
abstract insertOrUpdate(data: Record<string, any>): this;
|
|
76
|
+
abstract createOrUpdate(data: Record<string, any>): this;
|
|
77
|
+
abstract updateOrInsert(data: Record<string, any>): this;
|
|
78
|
+
abstract updateOrCreate(data: Record<string, any>): this;
|
|
79
|
+
abstract createMultiple(data: Record<string, any>): this;
|
|
80
|
+
abstract insertMultiple(data: Record<string, any>): this;
|
|
76
81
|
abstract except(...columns: string[]): this;
|
|
77
82
|
abstract only(...columns: string[]): this;
|
|
78
83
|
abstract drop(): Promise<any>;
|
|
79
84
|
abstract truncate(): Promise<any>;
|
|
80
|
-
abstract all(): Promise<
|
|
85
|
+
abstract all(): Promise<any[]>;
|
|
81
86
|
abstract find(id: number): Promise<any>;
|
|
82
87
|
abstract pagination({ limit, page }: {
|
|
83
88
|
limit: number;
|
|
@@ -87,20 +92,16 @@ declare abstract class AbstractBuilder {
|
|
|
87
92
|
limit: number;
|
|
88
93
|
page: number;
|
|
89
94
|
}): Promise<Pagination>;
|
|
90
|
-
abstract first(): Promise<any>;
|
|
91
|
-
abstract firstOrError(message: string, options?:
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
abstract
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
abstract
|
|
98
|
-
abstract
|
|
99
|
-
abstract
|
|
100
|
-
abstract getGroupBy(column: string): Promise<any>;
|
|
101
|
-
abstract findManyGroupBy(column: string): Promise<any>;
|
|
102
|
-
abstract toArray(column: string): Promise<any>;
|
|
103
|
-
abstract toJSON(): Promise<any>;
|
|
95
|
+
abstract first(): Promise<Record<string, any> | null>;
|
|
96
|
+
abstract firstOrError(message: string, options?: Record<string, any>): Promise<Record<string, any>>;
|
|
97
|
+
abstract findOneOrError(message: string, options?: Record<string, any>): Promise<Record<string, any>>;
|
|
98
|
+
abstract get(): Promise<any[]>;
|
|
99
|
+
abstract findOne(): Promise<Record<string, any> | null>;
|
|
100
|
+
abstract findMany(): Promise<any[]>;
|
|
101
|
+
abstract getGroupBy(column: string): Promise<any[]>;
|
|
102
|
+
abstract findManyGroupBy(column: string): Promise<any[]>;
|
|
103
|
+
abstract toArray(column: string): Promise<any[]>;
|
|
104
|
+
abstract toJSON(): Promise<string>;
|
|
104
105
|
abstract toSQL(): string;
|
|
105
106
|
abstract toString(): string;
|
|
106
107
|
abstract count(column: string): Promise<number>;
|
|
@@ -108,15 +109,13 @@ declare abstract class AbstractBuilder {
|
|
|
108
109
|
abstract avg(column: string): Promise<number>;
|
|
109
110
|
abstract max(column: string): Promise<number>;
|
|
110
111
|
abstract min(column: string): Promise<number>;
|
|
111
|
-
abstract rawQuery(sql: string): Promise<
|
|
112
|
+
abstract rawQuery(sql: string): Promise<any[]>;
|
|
112
113
|
abstract delete(): Promise<boolean>;
|
|
113
114
|
abstract exists(): Promise<boolean>;
|
|
114
|
-
abstract save(): Promise<
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
abstract
|
|
118
|
-
abstract decrement(column: string, value: number): Promise<any>;
|
|
119
|
-
abstract faker(round: number): Promise<any>;
|
|
115
|
+
abstract save(): Promise<Record<string, any> | any[] | null | undefined>;
|
|
116
|
+
abstract increment(column: string, value: number): Promise<number>;
|
|
117
|
+
abstract decrement(column: string, value: number): Promise<number>;
|
|
118
|
+
abstract faker(round: number): Promise<void>;
|
|
120
119
|
}
|
|
121
120
|
export { AbstractBuilder };
|
|
122
121
|
export default AbstractBuilder;
|
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
import Builder from '../Builder';
|
|
2
2
|
import { Connection, ConnectionOptions } from '../Interface';
|
|
3
3
|
declare abstract class AbstractDB extends Builder {
|
|
4
|
-
abstract table(
|
|
4
|
+
abstract table(name: string): void;
|
|
5
5
|
abstract beginTransaction(): Promise<any>;
|
|
6
6
|
abstract makeObject(value: any): Record<string, any> | null;
|
|
7
7
|
abstract makeArray(value: any): Array<any>;
|
|
8
8
|
abstract generateUUID(): string;
|
|
9
9
|
abstract raw(sql: string): string;
|
|
10
|
-
abstract constants(constants?: string): string |
|
|
11
|
-
[key: string]: any;
|
|
12
|
-
};
|
|
10
|
+
abstract constants(constants?: string): string | Record<string, any>;
|
|
13
11
|
abstract caseUpdate(cases: {
|
|
14
12
|
when: string;
|
|
15
13
|
then: string;
|
|
@@ -10,7 +10,7 @@ declare abstract class AbstractModel extends Builder {
|
|
|
10
10
|
protected abstract useTableSingular(): this;
|
|
11
11
|
protected abstract useTimestamp(): this;
|
|
12
12
|
protected abstract useSoftDelete(): this;
|
|
13
|
-
protected abstract useHooks(
|
|
13
|
+
protected abstract useHooks(functions: Function[]): this;
|
|
14
14
|
protected abstract usePattern(pattern: string): this;
|
|
15
15
|
protected abstract useLoadRelationsInRegistry(): this;
|
|
16
16
|
protected abstract useBuiltInRelationFunctions(): this;
|
|
@@ -26,12 +26,10 @@ declare abstract class AbstractModel extends Builder {
|
|
|
26
26
|
protected abstract belongsToManyBuilder({ name, model, localKey, foreignKey, freezeTable, as }: RelationQuery, callback: Function): this;
|
|
27
27
|
abstract ignoreSoftDelete(): this;
|
|
28
28
|
abstract disableSoftDelete(): this;
|
|
29
|
-
abstract registry(func:
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
abstract
|
|
33
|
-
abstract trashed(): Promise<any>;
|
|
34
|
-
abstract restore(): Promise<any>;
|
|
29
|
+
abstract registry(func: Record<string, Function>): this;
|
|
30
|
+
abstract onlyTrashed(): Promise<any[]>;
|
|
31
|
+
abstract trashed(): Promise<any[]>;
|
|
32
|
+
abstract restore(): Promise<any[]>;
|
|
35
33
|
abstract with(...nameRelations: string[]): this;
|
|
36
34
|
abstract withQuery(nameRelations: string, callback: Function): this;
|
|
37
35
|
abstract withExists(...nameRelations: string[]): this;
|