tspace-mysql 1.7.0 → 1.7.1
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 +2 -1
- package/build/lib/core/Abstracts/AbstractModel.d.ts +2 -2
- package/build/lib/core/Builder.d.ts +21 -5
- package/build/lib/core/Builder.js +33 -15
- package/build/lib/core/Builder.js.map +1 -1
- package/build/lib/core/Cache/DBCache.d.ts +8 -3
- package/build/lib/core/Cache/DBCache.js +115 -68
- package/build/lib/core/Cache/DBCache.js.map +1 -1
- package/build/lib/core/Cache/MemoryCache.d.ts +3 -1
- package/build/lib/core/Cache/MemoryCache.js +15 -4
- package/build/lib/core/Cache/MemoryCache.js.map +1 -1
- package/build/lib/core/Cache/RedisCache.d.ts +5 -1
- package/build/lib/core/Cache/RedisCache.js +37 -8
- package/build/lib/core/Cache/RedisCache.js.map +1 -1
- package/build/lib/core/Cache/index.d.ts +48 -4
- package/build/lib/core/Cache/index.js +84 -18
- package/build/lib/core/Cache/index.js.map +1 -1
- package/build/lib/core/DB.js.map +1 -1
- package/build/lib/core/Model.d.ts +9 -5
- package/build/lib/core/Model.js +25 -28
- package/build/lib/core/Model.js.map +1 -1
- package/build/lib/core/Tools/index.d.ts +5 -0
- package/build/lib/core/Tools/index.js +16 -0
- package/build/lib/core/Tools/index.js.map +1 -0
- package/build/tests/03-Model-default.test.d.ts +1 -0
- package/build/tests/03-Model-default.test.js +353 -0
- package/build/tests/03-Model-default.test.js.map +1 -0
- package/build/tests/04-Model-pattern.test.d.ts +1 -0
- package/build/tests/04-Model-pattern.test.js +354 -0
- package/build/tests/04-Model-pattern.test.js.map +1 -0
- package/build/tests/default-spec.d.ts +244 -0
- package/build/tests/default-spec.js +73 -0
- package/build/tests/default-spec.js.map +1 -0
- package/build/tests/schema-spec.d.ts +9 -0
- package/build/tests/schema-spec.js +33 -1
- package/build/tests/schema-spec.js.map +1 -1
- package/package.json +2 -3
package/README.md
CHANGED
|
@@ -2147,15 +2147,16 @@ Let's illustrate this with an example of a cache:
|
|
|
2147
2147
|
// support memory db and redis
|
|
2148
2148
|
// set cache in file config .env , .env.development ... etc
|
|
2149
2149
|
DB_CACHE = memory // by default
|
|
2150
|
+
|
|
2150
2151
|
// for redis
|
|
2151
2152
|
DB_REDIS_URL = redis://username:password@server:6379
|
|
2152
2153
|
|
|
2153
2154
|
const users = await new User()
|
|
2154
|
-
.limit(30_000)
|
|
2155
2155
|
.cache({
|
|
2156
2156
|
key : 'users', // key of the cache
|
|
2157
2157
|
expires : 1000 * 60 // cache expires in 60 seconds
|
|
2158
2158
|
})
|
|
2159
|
+
.sleep(5) // assume the query takes longer than 5 seconds...
|
|
2159
2160
|
.findMany()
|
|
2160
2161
|
|
|
2161
2162
|
```
|
|
@@ -2,10 +2,10 @@ import { TPattern, TRelationOptions, TRelationQueryOptions, TValidateSchema } fr
|
|
|
2
2
|
import { Blueprint } from '../Blueprint';
|
|
3
3
|
import { Builder } from '../Builder';
|
|
4
4
|
import { RelationHandler } from '../Handlers/Relation';
|
|
5
|
-
import {
|
|
5
|
+
import { TCache } from '../Cache';
|
|
6
6
|
import { Model } from '../Model';
|
|
7
7
|
declare abstract class AbstractModel<T, R> extends Builder {
|
|
8
|
-
protected $cache:
|
|
8
|
+
protected $cache: TCache;
|
|
9
9
|
protected $relation: RelationHandler;
|
|
10
10
|
protected $schema: Record<string, Blueprint>;
|
|
11
11
|
protected $validateSchema: TValidateSchema;
|
|
@@ -10,7 +10,15 @@ declare class Builder extends AbstractBuilder {
|
|
|
10
10
|
static get instance(): Builder;
|
|
11
11
|
/**
|
|
12
12
|
* The 'unset' method is used to drop a property as desired.
|
|
13
|
-
*
|
|
13
|
+
* @param {object} options
|
|
14
|
+
* @property {boolean | undefined} options.select
|
|
15
|
+
* @property {boolean | undefined} options.where
|
|
16
|
+
* @property {boolean | undefined} options.join
|
|
17
|
+
* @property {boolean | undefined} options.limit
|
|
18
|
+
* @property {boolean | undefined} options.offset
|
|
19
|
+
* @property {boolean | undefined} options.orderBy
|
|
20
|
+
* @property {boolean | undefined} options.groupBy
|
|
21
|
+
* @property {boolean | undefined} options.having
|
|
14
22
|
* @returns {this} this
|
|
15
23
|
*/
|
|
16
24
|
unset(options: {
|
|
@@ -119,6 +127,7 @@ declare class Builder extends AbstractBuilder {
|
|
|
119
127
|
* The 'only' method is used to specify which columns you don't want to retrieve from a result.
|
|
120
128
|
*
|
|
121
129
|
* It allows you to choose the specific columns that should be not included in the result.
|
|
130
|
+
*
|
|
122
131
|
* @param {...string} columns show only colums selected
|
|
123
132
|
* @returns {this} this
|
|
124
133
|
*/
|
|
@@ -1364,19 +1373,26 @@ declare class Builder extends AbstractBuilder {
|
|
|
1364
1373
|
*/
|
|
1365
1374
|
faker(rows: number, cb?: (results: Record<string, any>, index: number) => Record<string, any>): Promise<void>;
|
|
1366
1375
|
/**
|
|
1376
|
+
* The 'truncate' method is used to clear all data in the table.
|
|
1367
1377
|
*
|
|
1368
|
-
*
|
|
1378
|
+
* @param {object} option
|
|
1379
|
+
* @property {boolean} option.force
|
|
1369
1380
|
* @returns {promise<boolean>}
|
|
1370
1381
|
*/
|
|
1371
1382
|
truncate({ force }?: {
|
|
1372
|
-
force?: boolean
|
|
1383
|
+
force?: boolean;
|
|
1373
1384
|
}): Promise<boolean>;
|
|
1374
1385
|
/**
|
|
1375
1386
|
*
|
|
1376
|
-
* drop
|
|
1387
|
+
* The 'drop' method is used to drop the table.
|
|
1388
|
+
*
|
|
1389
|
+
* @param {object} option
|
|
1390
|
+
* @property {boolean} option.force
|
|
1377
1391
|
* @returns {promise<boolean>}
|
|
1378
1392
|
*/
|
|
1379
|
-
drop(
|
|
1393
|
+
drop({ force }?: {
|
|
1394
|
+
force?: boolean;
|
|
1395
|
+
}): Promise<boolean>;
|
|
1380
1396
|
protected exceptColumns(): Promise<string[]>;
|
|
1381
1397
|
protected _updateHandler(column: string, value?: string | number | null | boolean): string;
|
|
1382
1398
|
protected copyBuilder(instance: Builder, options?: {
|
|
@@ -42,7 +42,15 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
42
42
|
}
|
|
43
43
|
/**
|
|
44
44
|
* The 'unset' method is used to drop a property as desired.
|
|
45
|
-
*
|
|
45
|
+
* @param {object} options
|
|
46
|
+
* @property {boolean | undefined} options.select
|
|
47
|
+
* @property {boolean | undefined} options.where
|
|
48
|
+
* @property {boolean | undefined} options.join
|
|
49
|
+
* @property {boolean | undefined} options.limit
|
|
50
|
+
* @property {boolean | undefined} options.offset
|
|
51
|
+
* @property {boolean | undefined} options.orderBy
|
|
52
|
+
* @property {boolean | undefined} options.groupBy
|
|
53
|
+
* @property {boolean | undefined} options.having
|
|
46
54
|
* @returns {this} this
|
|
47
55
|
*/
|
|
48
56
|
unset(options) {
|
|
@@ -280,6 +288,7 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
280
288
|
* The 'only' method is used to specify which columns you don't want to retrieve from a result.
|
|
281
289
|
*
|
|
282
290
|
* It allows you to choose the specific columns that should be not included in the result.
|
|
291
|
+
*
|
|
283
292
|
* @param {...string} columns show only colums selected
|
|
284
293
|
* @returns {this} this
|
|
285
294
|
*/
|
|
@@ -491,16 +500,8 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
491
500
|
const value = this.$utils.escape(columns[column]);
|
|
492
501
|
const useOp = this._checkValueHasOp(value);
|
|
493
502
|
if (useOp == null) {
|
|
494
|
-
this
|
|
495
|
-
|
|
496
|
-
[
|
|
497
|
-
this.$state.get('WHERE').length ? `${this.$constants('AND')}` : '',
|
|
498
|
-
`${this.bindColumn(String(column))}`,
|
|
499
|
-
`${operator}`,
|
|
500
|
-
`${this._checkValueHasRaw(value)}`
|
|
501
|
-
].join(' ')
|
|
502
|
-
]);
|
|
503
|
-
return this;
|
|
503
|
+
this.where(column, operator, value);
|
|
504
|
+
continue;
|
|
504
505
|
}
|
|
505
506
|
switch (useOp.op) {
|
|
506
507
|
case 'IN': {
|
|
@@ -3294,18 +3295,24 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
3294
3295
|
});
|
|
3295
3296
|
}
|
|
3296
3297
|
/**
|
|
3298
|
+
* The 'truncate' method is used to clear all data in the table.
|
|
3297
3299
|
*
|
|
3298
|
-
*
|
|
3300
|
+
* @param {object} option
|
|
3301
|
+
* @property {boolean} option.force
|
|
3299
3302
|
* @returns {promise<boolean>}
|
|
3300
3303
|
*/
|
|
3301
3304
|
truncate() {
|
|
3302
3305
|
return __awaiter(this, arguments, void 0, function* ({ force = false } = {}) {
|
|
3306
|
+
if (this.$state.get('TABLE_NAME') == null || this.$state.get('TABLE_NAME') === '') {
|
|
3307
|
+
console.log(`Please set the your table name`);
|
|
3308
|
+
return false;
|
|
3309
|
+
}
|
|
3303
3310
|
const sql = [
|
|
3304
3311
|
`${this.$constants('TRUNCATE_TABLE')}`,
|
|
3305
3312
|
`${this.$state.get('TABLE_NAME')}`
|
|
3306
3313
|
].join(' ');
|
|
3307
3314
|
if (!force) {
|
|
3308
|
-
console.log(`Truncating will delete all data from the table ${this.$state.get('TABLE_NAME')}. Are you sure you want to proceed
|
|
3315
|
+
console.log(`Truncating will delete all data from the table '${this.$state.get('TABLE_NAME')}'. Are you sure you want to proceed?. Please confirm if you want to force the operation.`);
|
|
3309
3316
|
return false;
|
|
3310
3317
|
}
|
|
3311
3318
|
yield this._queryStatement(sql);
|
|
@@ -3314,15 +3321,26 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
3314
3321
|
}
|
|
3315
3322
|
/**
|
|
3316
3323
|
*
|
|
3317
|
-
* drop
|
|
3324
|
+
* The 'drop' method is used to drop the table.
|
|
3325
|
+
*
|
|
3326
|
+
* @param {object} option
|
|
3327
|
+
* @property {boolean} option.force
|
|
3318
3328
|
* @returns {promise<boolean>}
|
|
3319
3329
|
*/
|
|
3320
3330
|
drop() {
|
|
3321
|
-
return __awaiter(this,
|
|
3331
|
+
return __awaiter(this, arguments, void 0, function* ({ force = false } = {}) {
|
|
3332
|
+
if (this.$state.get('TABLE_NAME') == null || this.$state.get('TABLE_NAME') === '') {
|
|
3333
|
+
console.log(`Please set the your table name`);
|
|
3334
|
+
return false;
|
|
3335
|
+
}
|
|
3322
3336
|
const sql = [
|
|
3323
3337
|
`${this.$constants('DROP_TABLE')}`,
|
|
3324
3338
|
`${this.$state.get('TABLE_NAME')}`
|
|
3325
3339
|
].join(' ');
|
|
3340
|
+
if (!force) {
|
|
3341
|
+
console.log(`Droping will drop the table '${this.$state.get('TABLE_NAME')}'. Are you sure you want to proceed?. Please confirm if you want to force the operation.`);
|
|
3342
|
+
return false;
|
|
3343
|
+
}
|
|
3326
3344
|
yield this._queryStatement(sql);
|
|
3327
3345
|
return true;
|
|
3328
3346
|
});
|