tspace-mysql 1.8.8-beta.2 → 1.8.8-beta.3
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 +151 -36
- package/build/lib/config/index.d.ts +28 -0
- package/build/lib/config/index.js +89 -0
- package/build/lib/config/index.js.map +1 -0
- package/build/lib/constants/index.d.ts +7 -0
- package/build/lib/constants/index.js +8 -1
- package/build/lib/constants/index.js.map +1 -1
- package/build/lib/core/Abstracts/AbstractBuilder.d.ts +3 -0
- package/build/lib/core/Abstracts/AbstractBuilder.js +8 -1
- package/build/lib/core/Abstracts/AbstractBuilder.js.map +1 -1
- package/build/lib/core/Abstracts/AbstractDB.d.ts +2 -2
- package/build/lib/core/Blueprint.d.ts +8 -3
- package/build/lib/core/Blueprint.js +17 -7
- package/build/lib/core/Blueprint.js.map +1 -1
- package/build/lib/core/Builder.d.ts +32 -65
- package/build/lib/core/Builder.js +172 -457
- package/build/lib/core/Builder.js.map +1 -1
- package/build/lib/core/Cache/index.d.ts +1 -1
- package/build/lib/core/Cache/index.js +6 -6
- package/build/lib/core/Cache/index.js.map +1 -1
- package/build/lib/core/DB.d.ts +3 -3
- package/build/lib/core/DB.js +2 -2
- package/build/lib/core/DB.js.map +1 -1
- package/build/lib/core/Driver/index.d.ts +104 -0
- package/build/lib/core/Driver/index.js +137 -0
- package/build/lib/core/Driver/index.js.map +1 -0
- package/build/lib/core/Driver/mariadb/MariadbDriver.d.ts +17 -0
- package/build/lib/core/Driver/mariadb/MariadbDriver.js +137 -0
- package/build/lib/core/Driver/mariadb/MariadbDriver.js.map +1 -0
- package/build/lib/core/Driver/mariadb/MariadbQueryBuilder.d.ts +81 -0
- package/build/lib/core/Driver/mariadb/MariadbQueryBuilder.js +304 -0
- package/build/lib/core/Driver/mariadb/MariadbQueryBuilder.js.map +1 -0
- package/build/lib/core/Driver/mysql/MysqlDriver.d.ts +17 -0
- package/build/lib/core/Driver/mysql/MysqlDriver.js +164 -0
- package/build/lib/core/Driver/mysql/MysqlDriver.js.map +1 -0
- package/build/lib/core/Driver/mysql/MysqlQueryBuilder.d.ts +81 -0
- package/build/lib/core/Driver/mysql/MysqlQueryBuilder.js +304 -0
- package/build/lib/core/Driver/mysql/MysqlQueryBuilder.js.map +1 -0
- package/build/lib/core/Driver/postgres/PostgresDriver.d.ts +17 -0
- package/build/lib/core/Driver/postgres/PostgresDriver.js +167 -0
- package/build/lib/core/Driver/postgres/PostgresDriver.js.map +1 -0
- package/build/lib/core/Driver/postgres/PostgresQueryBuilder.d.ts +82 -0
- package/build/lib/core/Driver/postgres/PostgresQueryBuilder.js +395 -0
- package/build/lib/core/Driver/postgres/PostgresQueryBuilder.js.map +1 -0
- package/build/lib/core/Handlers/Relation.d.ts +1 -2
- package/build/lib/core/Handlers/Relation.js +61 -42
- package/build/lib/core/Handlers/Relation.js.map +1 -1
- package/build/lib/core/Handlers/State.d.ts +135 -127
- package/build/lib/core/Handlers/State.js +10 -13
- package/build/lib/core/Handlers/State.js.map +1 -1
- package/build/lib/core/Meta.d.ts +49 -32
- package/build/lib/core/Meta.js +54 -58
- package/build/lib/core/Meta.js.map +1 -1
- package/build/lib/core/Model.d.ts +29 -17
- package/build/lib/core/Model.js +144 -217
- package/build/lib/core/Model.js.map +1 -1
- package/build/lib/core/Pool.d.ts +6 -18
- package/build/lib/core/Pool.js +62 -279
- package/build/lib/core/Pool.js.map +1 -1
- package/build/lib/core/Schema.d.ts +1 -1
- package/build/lib/core/Schema.js +125 -72
- package/build/lib/core/Schema.js.map +1 -1
- package/build/lib/core/index.d.ts +1 -1
- package/build/lib/types/index.d.ts +23 -7
- package/build/tests/00-Driver.test.d.ts +1 -0
- package/build/tests/00-Driver.test.js +62 -0
- package/build/tests/00-Driver.test.js.map +1 -0
- package/build/tests/01-Pool.test.js +2 -0
- package/build/tests/01-Pool.test.js.map +1 -1
- package/build/tests/02-DB.test.js.map +1 -1
- package/build/tests/03-Transaction.test.d.ts +1 -0
- package/build/tests/03-Transaction.test.js +167 -0
- package/build/tests/03-Transaction.test.js.map +1 -0
- package/build/tests/04-Model-default.test.d.ts +1 -0
- package/build/tests/04-Model-default.test.js +392 -0
- package/build/tests/04-Model-default.test.js.map +1 -0
- package/build/tests/04.1-Model-camelCase.test.d.ts +1 -0
- package/build/tests/04.1-Model-camelCase.test.js +392 -0
- package/build/tests/04.1-Model-camelCase.test.js.map +1 -0
- package/build/tests/04.2-Model-snake-case.test.d.ts +1 -0
- package/build/tests/04.2-Model-snake-case.test.js +392 -0
- package/build/tests/04.2-Model-snake-case.test.js.map +1 -0
- package/build/tests/05-Repository.test.d.ts +0 -0
- package/build/tests/05-Repository.test.js +2 -0
- package/build/tests/05-Repository.test.js.map +1 -0
- package/build/tests/06-Meta.test.js +35 -30
- package/build/tests/06-Meta.test.js.map +1 -1
- package/build/tests/07-View.test.d.ts +1 -0
- package/build/tests/07-View.test.js +72 -0
- package/build/tests/07-View.test.js.map +1 -0
- package/build/tests/08-Virtual-column.test.d.ts +1 -0
- package/build/tests/08-Virtual-column.test.js +131 -0
- package/build/tests/08-Virtual-column.test.js.map +1 -0
- package/build/tests/default-spec.js +33 -0
- package/build/tests/default-spec.js.map +1 -1
- package/build/tests/mock-data-spec.d.ts +0 -4
- package/build/tests/mock-data-spec.js +0 -4
- package/build/tests/mock-data-spec.js.map +1 -1
- package/build/tests/schema-spec.d.ts +0 -9
- package/build/tests/schema-spec.js +6 -37
- package/build/tests/schema-spec.js.map +1 -1
- package/package.json +6 -2
package/README.md
CHANGED
|
@@ -7,8 +7,9 @@ tspace-mysql is an Object-Relational Mapping (ORM) tool designed to run seamless
|
|
|
7
7
|
|
|
8
8
|
## Feature
|
|
9
9
|
|
|
10
|
-
| **Feature**
|
|
11
|
-
|
|
10
|
+
| **Feature** | **Description** |
|
|
11
|
+
|--------------------------------|---------------------------------------------------------------------------------------------------------|
|
|
12
|
+
| **Supports Driver** | MySQL ✅ / MariaDB ✅ / Postgres ✅ MSSQL ⏳ / SQLite3 ⏳ / Oracle ⏳ |
|
|
12
13
|
| **Query Builder** | Create flexible queries like `SELECT`, `INSERT`, `UPDATE`, and `DELETE`. You can also use raw SQL. |
|
|
13
14
|
| **Join Clauses** | Use `INNER JOIN`, `LEFT JOIN`, `RIGHT JOIN`, and `CROSS JOIN` to combine data from multiple tables. |
|
|
14
15
|
| **Model** | Provides a way to interact with database records as objects in code. You can perform create, read, update, and delete (CRUD) operations. Models also support soft deletes and relationship methods. |
|
|
@@ -31,8 +32,20 @@ tspace-mysql is an Object-Relational Mapping (ORM) tool designed to run seamless
|
|
|
31
32
|
Install with [npm](https://www.npmjs.com/):
|
|
32
33
|
|
|
33
34
|
```sh
|
|
35
|
+
# Install tspace-mysql locally for your project
|
|
34
36
|
npm install tspace-mysql --save
|
|
35
|
-
|
|
37
|
+
|
|
38
|
+
# Install tspace-mysql globally (optional)
|
|
39
|
+
npm install -g tspace-mysql
|
|
40
|
+
|
|
41
|
+
# Install database drivers if needed:
|
|
42
|
+
# For MariaDB
|
|
43
|
+
npm install mariadb --save
|
|
44
|
+
|
|
45
|
+
# For PostgreSQL
|
|
46
|
+
npm install pg --save
|
|
47
|
+
|
|
48
|
+
# MySQL2 driver is installed by default with tspace-mysql
|
|
36
49
|
```
|
|
37
50
|
|
|
38
51
|
## Basic Usage
|
|
@@ -77,6 +90,7 @@ npm install tspace-mysql -g
|
|
|
77
90
|
- [Union](#union)
|
|
78
91
|
- [More Methods](#more-methods)
|
|
79
92
|
- [Database Transactions](#database-transactions)
|
|
93
|
+
- [Race Condition](#race-condition)
|
|
80
94
|
- [Connection](#connection)
|
|
81
95
|
- [Backup](#backup)
|
|
82
96
|
- [Injection](#injection)
|
|
@@ -151,6 +165,9 @@ npm install tspace-mysql -g
|
|
|
151
165
|
To establish a connection, the recommended method for creating your environment variables is by using a '.env' file. using the following:
|
|
152
166
|
|
|
153
167
|
```js
|
|
168
|
+
DB_DRIVER = mysql
|
|
169
|
+
// DB_DRIVER = mariadb
|
|
170
|
+
// DB_DRIVER = postgres
|
|
154
171
|
DB_HOST = localhost;
|
|
155
172
|
DB_PORT = 3306;
|
|
156
173
|
DB_USERNAME = root;
|
|
@@ -1262,14 +1279,14 @@ makeCreateTableStatement()
|
|
|
1262
1279
|
Within a database transaction, you can utilize the following:
|
|
1263
1280
|
|
|
1264
1281
|
```js
|
|
1265
|
-
const
|
|
1282
|
+
const trx = await new DB().beginTransaction();
|
|
1266
1283
|
|
|
1267
1284
|
try {
|
|
1268
1285
|
/**
|
|
1269
1286
|
*
|
|
1270
1287
|
* @startTransaction start transaction in scopes function
|
|
1271
1288
|
*/
|
|
1272
|
-
await
|
|
1289
|
+
await trx.startTransaction();
|
|
1273
1290
|
|
|
1274
1291
|
const user = await new User()
|
|
1275
1292
|
.create({
|
|
@@ -1278,10 +1295,10 @@ try {
|
|
|
1278
1295
|
})
|
|
1279
1296
|
/**
|
|
1280
1297
|
*
|
|
1281
|
-
* bind method for make sure this
|
|
1282
|
-
* @params {Function}
|
|
1298
|
+
* bind method for make sure this trx has same transaction in trx
|
|
1299
|
+
* @params {Function} trx
|
|
1283
1300
|
*/
|
|
1284
|
-
.bind(
|
|
1301
|
+
.bind(trx)
|
|
1285
1302
|
.save();
|
|
1286
1303
|
|
|
1287
1304
|
const posts = await new Post()
|
|
@@ -1299,17 +1316,17 @@ try {
|
|
|
1299
1316
|
title: `tspace-post3`,
|
|
1300
1317
|
},
|
|
1301
1318
|
])
|
|
1302
|
-
.bind(
|
|
1319
|
+
.bind(trx) // don't forget this
|
|
1303
1320
|
.save();
|
|
1304
1321
|
|
|
1305
1322
|
/**
|
|
1306
1323
|
*
|
|
1307
1324
|
* @commit commit transaction to database
|
|
1308
1325
|
*/
|
|
1309
|
-
// After your use commit if use same
|
|
1310
|
-
await
|
|
1326
|
+
// After your use commit if use same trx for actions this transction will auto commit
|
|
1327
|
+
await trx.commit();
|
|
1311
1328
|
|
|
1312
|
-
// If you need to start a new transaction again, just use wait
|
|
1329
|
+
// If you need to start a new transaction again, just use wait trx.startTransaction();
|
|
1313
1330
|
|
|
1314
1331
|
const postsAfterCommited = await new Post()
|
|
1315
1332
|
.createMultiple([
|
|
@@ -1326,25 +1343,137 @@ try {
|
|
|
1326
1343
|
title: `tspace-post3`,
|
|
1327
1344
|
},
|
|
1328
1345
|
])
|
|
1329
|
-
// Using this
|
|
1330
|
-
.bind(
|
|
1346
|
+
// Using this trx now will auto-commit to the database.
|
|
1347
|
+
.bind(trx) // If you need to perform additional operations, use await trx.startTransaction(); again.
|
|
1331
1348
|
.save();
|
|
1332
1349
|
|
|
1333
1350
|
|
|
1334
|
-
// Do not perform any operations with this
|
|
1335
|
-
// The transaction has already been committed, and the
|
|
1351
|
+
// Do not perform any operations with this trx.
|
|
1352
|
+
// The transaction has already been committed, and the trx is closed.
|
|
1336
1353
|
// Just ensure everything is handled at the end of the transaction.
|
|
1337
|
-
await
|
|
1354
|
+
await trx.end();
|
|
1338
1355
|
|
|
1339
1356
|
} catch (err) {
|
|
1340
1357
|
/**
|
|
1341
1358
|
*
|
|
1342
1359
|
* @rollback rollback transaction
|
|
1343
1360
|
*/
|
|
1344
|
-
await
|
|
1361
|
+
await trx.rollback();
|
|
1345
1362
|
}
|
|
1346
1363
|
```
|
|
1347
1364
|
|
|
1365
|
+
## Race Condition
|
|
1366
|
+
|
|
1367
|
+
Within a race condition, you can utilize the following:
|
|
1368
|
+
|
|
1369
|
+
```js
|
|
1370
|
+
|
|
1371
|
+
import { Model, DB } from 'tspace-mysql'
|
|
1372
|
+
|
|
1373
|
+
class Product extends Model {}
|
|
1374
|
+
|
|
1375
|
+
class Order extends Model {}
|
|
1376
|
+
|
|
1377
|
+
async function purchaseForUpdate({userId , productId , qty } : {
|
|
1378
|
+
userId: number;
|
|
1379
|
+
productId: number;
|
|
1380
|
+
qty: number
|
|
1381
|
+
}): Promise<void> {
|
|
1382
|
+
const trx = await DB.beginTransaction()
|
|
1383
|
+
try {
|
|
1384
|
+
|
|
1385
|
+
await trx.startTransaction()
|
|
1386
|
+
|
|
1387
|
+
const product = await new Product()
|
|
1388
|
+
.where('id',productId)
|
|
1389
|
+
.rowLock('FOR_UPDATE') // don't forget this, lock this product for update
|
|
1390
|
+
.bind(trx)
|
|
1391
|
+
.first()
|
|
1392
|
+
|
|
1393
|
+
if (product == null) throw new Error("Product not found");
|
|
1394
|
+
|
|
1395
|
+
if (product.stock < qty) throw new Error("Not enough stock");
|
|
1396
|
+
|
|
1397
|
+
await new Product()
|
|
1398
|
+
.where('id',productId)
|
|
1399
|
+
.update({
|
|
1400
|
+
stock : `${DB.raw('stock')} - ${qty}`,
|
|
1401
|
+
id: productId
|
|
1402
|
+
})
|
|
1403
|
+
.bind(trx)
|
|
1404
|
+
.save()
|
|
1405
|
+
|
|
1406
|
+
await new Order()
|
|
1407
|
+
.create({
|
|
1408
|
+
user_id : userId,
|
|
1409
|
+
product_id : productId,
|
|
1410
|
+
qty
|
|
1411
|
+
})
|
|
1412
|
+
.bind(trx)
|
|
1413
|
+
.save()
|
|
1414
|
+
|
|
1415
|
+
await trx.commit();
|
|
1416
|
+
console.log(`✅ [FOR UPDATE] User ${userId} purchased ${qty}`);
|
|
1417
|
+
|
|
1418
|
+
} catch (err: any) {
|
|
1419
|
+
await trx.rollback();
|
|
1420
|
+
console.log(`❌ [FOR UPDATE] User ${userId} failed: ${err.message}`);
|
|
1421
|
+
} finally {
|
|
1422
|
+
await trx.end();
|
|
1423
|
+
}
|
|
1424
|
+
}
|
|
1425
|
+
|
|
1426
|
+
async function simulateRaceConnection(): Promise<void> {
|
|
1427
|
+
const MAX_CONNECTION = 500;
|
|
1428
|
+
const TASKS: Function[] = [];
|
|
1429
|
+
const STOCK = MAX_CONNECTION * 10
|
|
1430
|
+
|
|
1431
|
+
await new Product()
|
|
1432
|
+
.where('id',1)
|
|
1433
|
+
.update({
|
|
1434
|
+
stock : STOCK,
|
|
1435
|
+
})
|
|
1436
|
+
.save()
|
|
1437
|
+
|
|
1438
|
+
const successes : number[] = []
|
|
1439
|
+
const fails : number[] = []
|
|
1440
|
+
let purchased : number = 0
|
|
1441
|
+
let outOfStock : number = 0
|
|
1442
|
+
for (let i = 1; i <= MAX_CONNECTION; i++) {
|
|
1443
|
+
TASKS.push(async () => {
|
|
1444
|
+
const qty = Math.floor(Math.random() * 30) + 1
|
|
1445
|
+
await purchaseForUpdate({
|
|
1446
|
+
userId : i,
|
|
1447
|
+
productId : 1 ,
|
|
1448
|
+
qty
|
|
1449
|
+
})
|
|
1450
|
+
.then(_ => {
|
|
1451
|
+
successes.push(1)
|
|
1452
|
+
purchased += qty
|
|
1453
|
+
})
|
|
1454
|
+
.catch(_ => {
|
|
1455
|
+
fails.push(1)
|
|
1456
|
+
outOfStock += qty
|
|
1457
|
+
})
|
|
1458
|
+
});
|
|
1459
|
+
}
|
|
1460
|
+
|
|
1461
|
+
console.log("=== Simulation ===");
|
|
1462
|
+
const start = Date.now();
|
|
1463
|
+
await Promise.all(TASKS.map(v => v()));
|
|
1464
|
+
const end = Date.now();
|
|
1465
|
+
console.log(`USING TIME TO TEST IN ${end - start} ms`)
|
|
1466
|
+
console.log(`ALL STOCK: ${STOCK} qty`)
|
|
1467
|
+
console.log(`✅ [SUCCESS(${successes.length})] [Purchased]: ${purchased} qty`);
|
|
1468
|
+
console.log(`❌ [FAIL(${fails.length})] [OutOfStock]: ${outOfStock} qty`);
|
|
1469
|
+
console.log('======== DONE ============')
|
|
1470
|
+
process.exit(0)
|
|
1471
|
+
}
|
|
1472
|
+
|
|
1473
|
+
simulateRaceConnection();
|
|
1474
|
+
|
|
1475
|
+
```
|
|
1476
|
+
|
|
1348
1477
|
## Connection
|
|
1349
1478
|
|
|
1350
1479
|
When establishing a connection, you can specify options as follows:
|
|
@@ -3253,6 +3382,7 @@ const schema = {
|
|
|
3253
3382
|
username : Blueprint.varchar(255).notNull(),
|
|
3254
3383
|
password : Blueprint.varchar(255).notNull(),
|
|
3255
3384
|
status : Blueprint.tinyInt().notNull().default(0),
|
|
3385
|
+
role : Blueprint.enum('admin','user').default('user'),
|
|
3256
3386
|
createdAt : Blueprint.timestamp().null(),
|
|
3257
3387
|
updatedAt : Blueprint.timestamp().null()
|
|
3258
3388
|
}
|
|
@@ -3263,8 +3393,6 @@ class User extends Model<TS> {
|
|
|
3263
3393
|
constructor() {
|
|
3264
3394
|
super()
|
|
3265
3395
|
this.useSchema(schema)
|
|
3266
|
-
this.useUUID()
|
|
3267
|
-
this.useTimestamp()
|
|
3268
3396
|
}
|
|
3269
3397
|
}
|
|
3270
3398
|
|
|
@@ -3280,22 +3408,9 @@ const hasColumn = meta.hasColumn('idx') // false
|
|
|
3280
3408
|
const primaryKey = meta.primaryKey() // 'id'
|
|
3281
3409
|
const indexes = meta.indexes() // ['users.email@index']
|
|
3282
3410
|
const nullable = meta.nullable() // ['uuid','name','createdAt','updatedAt']
|
|
3283
|
-
const defaults = meta.defaults() // { status : 0 }
|
|
3284
|
-
|
|
3285
|
-
|
|
3286
|
-
table,
|
|
3287
|
-
column,
|
|
3288
|
-
columnRef,
|
|
3289
|
-
columnTypeOf,
|
|
3290
|
-
columnType,
|
|
3291
|
-
columns,
|
|
3292
|
-
hasColumn,
|
|
3293
|
-
primaryKey,
|
|
3294
|
-
indexes,
|
|
3295
|
-
nullable,
|
|
3296
|
-
defaults
|
|
3297
|
-
})
|
|
3298
|
-
|
|
3411
|
+
const defaults = meta.defaults() // { id : null, uuid : null, ..., status : 0, role: 'user' ,..updatedAt : null }
|
|
3412
|
+
const enums = meta.enums('role') // [ 'admin', 'user' ]
|
|
3413
|
+
const enumsObj = meta.enum('role', { asObject: true }) // { admin: 'admin', user: 'user' }
|
|
3299
3414
|
```
|
|
3300
3415
|
|
|
3301
3416
|
## Repository
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export declare const loadOptionsEnvironment: () => {
|
|
2
|
+
readonly host: string | undefined;
|
|
3
|
+
readonly port: string | 3306;
|
|
4
|
+
readonly username: string | undefined;
|
|
5
|
+
readonly password: string;
|
|
6
|
+
readonly database: string | undefined;
|
|
7
|
+
};
|
|
8
|
+
declare const _default: Readonly<{
|
|
9
|
+
readonly DRIVER: string;
|
|
10
|
+
readonly HOST: string;
|
|
11
|
+
readonly PORT: string | 3306;
|
|
12
|
+
readonly USERNAME: string | undefined;
|
|
13
|
+
readonly PASSWORD: string;
|
|
14
|
+
readonly DATABASE: string | undefined;
|
|
15
|
+
readonly CONNECTION_LIMIT: string | 20;
|
|
16
|
+
readonly QUEUE_LIMIT: string | 0;
|
|
17
|
+
readonly TIMEOUT: string | number;
|
|
18
|
+
readonly CHARSET: string;
|
|
19
|
+
readonly CONNECTION_ERROR: string | false;
|
|
20
|
+
readonly CONNECTION_SUCCESS: string | false;
|
|
21
|
+
readonly WAIT_FOR_CONNECTIONS: string | true;
|
|
22
|
+
readonly DATE_STRINGS: string | false;
|
|
23
|
+
readonly KEEP_ALIVE_DELAY: string | 0;
|
|
24
|
+
readonly ENABLE_KEEP_ALIVE: string | true;
|
|
25
|
+
readonly MULTIPLE_STATEMENTS: string | false;
|
|
26
|
+
readonly CACHE: string;
|
|
27
|
+
}>;
|
|
28
|
+
export default _default;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.loadOptionsEnvironment = void 0;
|
|
7
|
+
const tools_1 = require("../tools");
|
|
8
|
+
const dotenv_1 = __importDefault(require("dotenv"));
|
|
9
|
+
const environment = () => {
|
|
10
|
+
const NODE_ENV = process.env?.NODE_ENV;
|
|
11
|
+
const env = tools_1.Tool.path.join(tools_1.Tool.path.resolve(), '.env');
|
|
12
|
+
if (NODE_ENV == null)
|
|
13
|
+
return env;
|
|
14
|
+
const envWithEnviroment = tools_1.Tool.path.join(tools_1.Tool.path.resolve(), `.env.${NODE_ENV}`);
|
|
15
|
+
if (tools_1.Tool.fs.existsSync(envWithEnviroment))
|
|
16
|
+
return envWithEnviroment;
|
|
17
|
+
return env;
|
|
18
|
+
};
|
|
19
|
+
dotenv_1.default.config({ path: environment() });
|
|
20
|
+
const ENV = process.env;
|
|
21
|
+
const rawEnv = {
|
|
22
|
+
DRIVER: ENV.DB_DRIVER ?? 'mysql2',
|
|
23
|
+
HOST: ENV.DB_HOST ?? 'localhost',
|
|
24
|
+
PORT: ENV.DB_PORT ?? 3306,
|
|
25
|
+
USERNAME: ENV.DB_USERNAME ?? ENV.DB_USER,
|
|
26
|
+
PASSWORD: ENV.DB_PASSWORD ?? '',
|
|
27
|
+
DATABASE: ENV.DB_DATABASE,
|
|
28
|
+
CONNECTION_LIMIT: ENV.DB_CONNECTION_LIMIT ?? 20,
|
|
29
|
+
QUEUE_LIMIT: ENV.DB_QUEUE_LIMIT ?? 0,
|
|
30
|
+
TIMEOUT: ENV.DB_TIMEOUT ?? 1000 * 120,
|
|
31
|
+
CHARSET: ENV.DB_CHARSET ?? 'utf8mb4',
|
|
32
|
+
CONNECTION_ERROR: ENV.DB_CONNECTION_ERROR ?? false,
|
|
33
|
+
CONNECTION_SUCCESS: ENV.DB_CONNECTION_SUCCESS ?? false,
|
|
34
|
+
WAIT_FOR_CONNECTIONS: ENV.DB_WAIT_FOR_CONNECTIONS ?? true,
|
|
35
|
+
DATE_STRINGS: ENV.DB_DATE_STRINGS ?? false,
|
|
36
|
+
KEEP_ALIVE_DELAY: ENV.DB_KEEP_ALIVE_DELAY ?? 0,
|
|
37
|
+
ENABLE_KEEP_ALIVE: ENV.DB_ENABLE_KEEP_ALIVE ?? true,
|
|
38
|
+
MULTIPLE_STATEMENTS: ENV.DB_MULTIPLE_STATEMENTS ?? false,
|
|
39
|
+
CACHE: ENV.DB_CACHE ?? 'memory'
|
|
40
|
+
};
|
|
41
|
+
const parseEnv = (env) => {
|
|
42
|
+
const parsed = {};
|
|
43
|
+
for (const [key, value] of Object.entries(env)) {
|
|
44
|
+
if (value == null)
|
|
45
|
+
continue;
|
|
46
|
+
if (value === '') {
|
|
47
|
+
parsed[key] = value;
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
if (!isNaN(Number(value))) {
|
|
51
|
+
(parsed)[key] = Number(value);
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
if (typeof value === 'string' && (value.toLowerCase() === 'true' || value.toLowerCase() === 'false')) {
|
|
55
|
+
(parsed)[key] = value.toLowerCase() === 'true';
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
parsed[key] = value;
|
|
59
|
+
}
|
|
60
|
+
return parsed;
|
|
61
|
+
};
|
|
62
|
+
const env = parseEnv(rawEnv);
|
|
63
|
+
const loadOptionsEnvironment = () => {
|
|
64
|
+
const environment = () => {
|
|
65
|
+
const NODE_ENV = process.env?.NODE_ENV;
|
|
66
|
+
const env = tools_1.Tool.path.join(tools_1.Tool.path.resolve(), '.env');
|
|
67
|
+
if (NODE_ENV == null)
|
|
68
|
+
return env;
|
|
69
|
+
const envWithEnviroment = tools_1.Tool.path.join(tools_1.Tool.path.resolve(), `.env.${NODE_ENV}`);
|
|
70
|
+
if (tools_1.Tool.fs.existsSync(envWithEnviroment))
|
|
71
|
+
return envWithEnviroment;
|
|
72
|
+
return env;
|
|
73
|
+
};
|
|
74
|
+
dotenv_1.default.config({ path: environment() });
|
|
75
|
+
const ENV = process.env;
|
|
76
|
+
const rawEnv = {
|
|
77
|
+
host: ENV?.DB_HOST || ENV?.TSPACE_HOST,
|
|
78
|
+
port: ENV?.DB_PORT || ENV?.TSPACE_PORT || 3306,
|
|
79
|
+
username: ENV?.DB_USERNAME || ENV?.TSPACE_USERNAME,
|
|
80
|
+
password: ENV?.DB_PASSWORD || ENV?.TSPACE_PASSWORD || '',
|
|
81
|
+
database: ENV?.DB_DATABASE || ENV?.TSPACE_DATABASE,
|
|
82
|
+
};
|
|
83
|
+
//@ts-ignore
|
|
84
|
+
const env = parseEnv(rawEnv);
|
|
85
|
+
return Object.freeze(env);
|
|
86
|
+
};
|
|
87
|
+
exports.loadOptionsEnvironment = loadOptionsEnvironment;
|
|
88
|
+
exports.default = Object.freeze(env);
|
|
89
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/lib/config/index.ts"],"names":[],"mappings":";;;;;;AAAA,oCAA+B;AAC/B,oDAA2B;AAE3B,MAAM,WAAW,GAAG,GAAY,EAAE;IAC9B,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,EAAE,QAAQ,CAAA;IACtC,MAAM,GAAG,GAAG,YAAI,CAAC,IAAI,CAAC,IAAI,CAAC,YAAI,CAAC,IAAI,CAAC,OAAO,EAAE,EAAE,MAAM,CAAC,CAAA;IAEvD,IAAG,QAAQ,IAAI,IAAI;QAAG,OAAO,GAAG,CAAA;IAChC,MAAM,iBAAiB,GAAG,YAAI,CAAC,IAAI,CAAC,IAAI,CAAC,YAAI,CAAC,IAAI,CAAC,OAAO,EAAE,EAAG,QAAQ,QAAQ,EAAE,CAAC,CAAA;IAClF,IAAI,YAAI,CAAC,EAAE,CAAC,UAAU,CAAC,iBAAiB,CAAC;QAAE,OAAO,iBAAiB,CAAA;IAEnE,OAAO,GAAG,CAAA;AACd,CAAC,CAAA;AAED,gBAAM,CAAC,MAAM,CAAC,EAAE,IAAI,EAAG,WAAW,EAAE,EAAE,CAAC,CAAA;AAEvC,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAA;AAEvB,MAAM,MAAM,GAAI;IACZ,MAAM,EAAoB,GAAG,CAAC,SAAS,IAAI,QAAQ;IACnD,IAAI,EAAsB,GAAG,CAAC,OAAO,IAAI,WAAW;IACpD,IAAI,EAAsB,GAAG,CAAC,OAAO,IAAI,IAAI;IAC7C,QAAQ,EAAkB,GAAG,CAAC,WAAW,IAAI,GAAG,CAAC,OAAO;IACxD,QAAQ,EAAkB,GAAG,C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AI,EAAmB,GAAG,EAAE,OAAO,IAAI,GAAG,EAAE,WAAW,IAAI,IAAI;QAC/D,QAAQ,EAAe,GAAG,EAAE,WAAW,IAAI,GAAG,EAAE,eAAe;QAC/D,QAAQ,EAAe,GAAG,EAAE,WAAW,IAAI,GAAG,EAAE,eAAe,IAAI,EAAE;QACrE,QAAQ,EAAe,GAAG,EAAE,WAAW,IAAI,GAAG,EAAE,eAAe;KACzD,CAAA;IAEV,YAAY;IACZ,MAAM,GAAG,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAA;IAE5B,OAAO,MAAM,CAAC,MAAM,CAAC,GAAG,CAA6B,CAAA;AACzD,CAAC,CAAA;AA9BY,QAAA,sBAAsB,0BA8BlC;AAED,kBAAe,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA"}
|
|
@@ -87,6 +87,7 @@ declare const CONSTANTS: Readonly<{
|
|
|
87
87
|
ADD_CONSTRAINT: "ADD CONSTRAINT";
|
|
88
88
|
AFTER: "AFTER";
|
|
89
89
|
ALTER_TABLE: "ALTER TABLE";
|
|
90
|
+
ALTER_COLUMN: "ALTER COLUMN";
|
|
90
91
|
IFNULL: "IFNULL";
|
|
91
92
|
JSON_ARRAY: "JSON_ARRAY";
|
|
92
93
|
JSON_ARRAYAGG: "JSON_ARRAYAGG";
|
|
@@ -99,11 +100,17 @@ declare const CONSTANTS: Readonly<{
|
|
|
99
100
|
hasMany: string;
|
|
100
101
|
belongsTo: string;
|
|
101
102
|
belongsToMany: string;
|
|
103
|
+
belongsToManySingle: string;
|
|
102
104
|
};
|
|
103
105
|
PATTERN: {
|
|
106
|
+
maybeSnake_case: string;
|
|
104
107
|
snake_case: string;
|
|
105
108
|
camelCase: string;
|
|
106
109
|
};
|
|
110
|
+
ROW_LEVEL_LOCK: {
|
|
111
|
+
update: string;
|
|
112
|
+
share: string;
|
|
113
|
+
};
|
|
107
114
|
}>;
|
|
108
115
|
export { CONSTANTS };
|
|
109
116
|
export default CONSTANTS;
|
|
@@ -90,6 +90,7 @@ const CONSTANTS = Object.freeze({
|
|
|
90
90
|
ADD_CONSTRAINT: 'ADD CONSTRAINT',
|
|
91
91
|
AFTER: 'AFTER',
|
|
92
92
|
ALTER_TABLE: 'ALTER TABLE',
|
|
93
|
+
ALTER_COLUMN: 'ALTER COLUMN',
|
|
93
94
|
IFNULL: 'IFNULL',
|
|
94
95
|
JSON_ARRAY: 'JSON_ARRAY',
|
|
95
96
|
JSON_ARRAYAGG: 'JSON_ARRAYAGG',
|
|
@@ -101,11 +102,17 @@ const CONSTANTS = Object.freeze({
|
|
|
101
102
|
hasOne: 'hasOne',
|
|
102
103
|
hasMany: 'hasMany',
|
|
103
104
|
belongsTo: 'belongsTo',
|
|
104
|
-
belongsToMany: 'belongsToMany'
|
|
105
|
+
belongsToMany: 'belongsToMany',
|
|
106
|
+
belongsToManySingle: 'belongsToManySingle'
|
|
105
107
|
},
|
|
106
108
|
PATTERN: {
|
|
109
|
+
maybeSnake_case: 'maybeSnake_case',
|
|
107
110
|
snake_case: 'snake_case',
|
|
108
111
|
camelCase: 'camelCase'
|
|
112
|
+
},
|
|
113
|
+
ROW_LEVEL_LOCK: {
|
|
114
|
+
update: 'FOR UPDATE',
|
|
115
|
+
share: 'LOCK IN SHARE MODE'
|
|
109
116
|
}
|
|
110
117
|
});
|
|
111
118
|
exports.CONSTANTS = CONSTANTS;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/lib/constants/index.ts"],"names":[],"mappings":";;;AAAA,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC;IAC5B,EAAE,EAAG,IAAI;IACT,IAAI,EAAG,MAAM;IACb,MAAM,EAAE,QAAQ;IAChB,MAAM,EAAG,QAAQ;IACjB,OAAO,EAAG,SAAS;IACnB,MAAM,EAAG,QAAQ;IACjB,KAAK,EAAG,OAAO;IACf,OAAO,EAAG,SAAS;IACnB,WAAW,EAAG,aAAa;IAC3B,GAAG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b,MAAM,EAAG,YAAY;QACrB,KAAK,EAAI,oBAAoB;KAChC;CACJ,CAAC,CAAA;AAEO,8BAAS;AAClB,kBAAe,SAAS,CAAA"}
|
|
@@ -5,12 +5,15 @@ import type { TPagination, TConstant } from '../../types';
|
|
|
5
5
|
declare abstract class AbstractBuilder {
|
|
6
6
|
protected $setters: string[];
|
|
7
7
|
protected $utils: TUtils;
|
|
8
|
+
protected $database: string;
|
|
9
|
+
protected $driver: string;
|
|
8
10
|
protected $constants: (name?: keyof TConstant) => any;
|
|
9
11
|
protected $state: StateHandler;
|
|
10
12
|
protected $pool: {
|
|
11
13
|
query: Function;
|
|
12
14
|
set: Function;
|
|
13
15
|
get: Function;
|
|
16
|
+
queryBuilder: Function;
|
|
14
17
|
};
|
|
15
18
|
protected $logger: {
|
|
16
19
|
get: Function;
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.AbstractBuilder = void 0;
|
|
7
|
+
const config_1 = __importDefault(require("../../config"));
|
|
4
8
|
class AbstractBuilder {
|
|
5
9
|
$setters = [
|
|
6
10
|
'$attributes',
|
|
@@ -12,12 +16,15 @@ class AbstractBuilder {
|
|
|
12
16
|
'$relation'
|
|
13
17
|
];
|
|
14
18
|
$utils;
|
|
19
|
+
$database = String(config_1.default.DATABASE ?? '');
|
|
20
|
+
$driver = String(config_1.default.DRIVER ?? 'mysql');
|
|
15
21
|
$constants;
|
|
16
22
|
$state;
|
|
17
23
|
$pool = {
|
|
18
24
|
query: (sql) => { },
|
|
19
25
|
set: (pool) => { },
|
|
20
|
-
get: () => { }
|
|
26
|
+
get: () => { },
|
|
27
|
+
queryBuilder: () => { }
|
|
21
28
|
};
|
|
22
29
|
$logger = {
|
|
23
30
|
get: () => { },
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AbstractBuilder.js","sourceRoot":"","sources":["../../../../src/lib/core/Abstracts/AbstractBuilder.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"AbstractBuilder.js","sourceRoot":"","sources":["../../../../src/lib/core/Abstracts/AbstractBuilder.ts"],"names":[],"mappings":";;;;;;AAGA,0DAA4C;AAK5C,MAAe,eAAe;IAEhB,QAAQ,GAAG;QACjB,aAAa;QACb,SAAS;QACT,QAAQ;QACR,YAAY;QACZ,OAAO;QACP,QAAQ;QACR,WAAW;KACd,CAAA;IAES,MAAM,CAAU;IAEhB,SAAS,GAAY,MAAM,CAAC,gBAAM,CAAC,QAAQ,IAAI,EAAE,CAAC,CAAA;IAClD,OAAO,GAAY,MAAM,CAAC,gBAAM,CAAC,MAAM,IAAI,OAAO,CAAC,CAAA;IAEnD,UAAU,CAAoC;IAE9C,MAAM,CAAgB;IAEtB,KAAK,GAAmF;QAC9F,KAAK,EAAE,CAAC,GAAW,EAAE,EAAE,GAAE,CAAC;QAC1B,GAAG,EAAE,CAAC,IAAU,EAAE,EAAE,GAAE,CAAC;QACvB,GAAG,EAAE,GAAG,EAAE,GAAE,CAAC;QACb,YAAY,EAAE,GAAG,EAAE,GAAE,CAAC;KACzB,CAAA;IAES,OAAO,GAA8G;QAC3H,GAAG,EAAE,GAAG,EAAE,GAAE,CAAC;QACb,GAAG,EAAE,CAAC,KAAc,EAAE,EAAE,GAAE,CAAC;QAC3B,KAAK,EAAE,GAAG,EAAE,GAAE,CAAC;QACf,KAAK,EAAE,CAAC,KAAc,EAAE,EAAE,CAAC,IAAI,IAAI,KAAK;KAC3C,CAAA;IAES,WAAW,CAA6B;CA0FrD;AAES,0CAAe;AACzB,kBAAe,eAAe,CAAA"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import Builder from '../Builder';
|
|
2
|
-
import type {
|
|
2
|
+
import type { TPoolConnected, TConnectionOptions, TConnectionTransaction } from '../../types';
|
|
3
3
|
declare abstract class AbstractDB extends Builder {
|
|
4
4
|
abstract beginTransaction(): Promise<TConnectionTransaction>;
|
|
5
5
|
abstract generateUUID(): string;
|
|
@@ -15,7 +15,7 @@ declare abstract class AbstractDB extends Builder {
|
|
|
15
15
|
when: string;
|
|
16
16
|
then: string;
|
|
17
17
|
}[], final?: string): string | [];
|
|
18
|
-
abstract getConnection(options: TConnectionOptions): Promise<
|
|
18
|
+
abstract getConnection(options: TConnectionOptions): Promise<TPoolConnected>;
|
|
19
19
|
}
|
|
20
20
|
export { AbstractDB };
|
|
21
21
|
export default AbstractDB;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { Model } from "./Model";
|
|
2
|
+
type NoType = {};
|
|
2
3
|
/**
|
|
3
4
|
* Class 'Blueprint' is used to make the schema for table
|
|
4
5
|
* @example
|
|
5
6
|
* import { Schema , Blueprint } from 'tspace-mysql'
|
|
6
|
-
import sql from '../../../build/lib/core/SqlLike';
|
|
7
|
+
* import sql from '../../../build/lib/core/SqlLike';
|
|
7
8
|
* await new Schema().table('users',{
|
|
8
9
|
* id : Blueprint.int().notNull().primary().autoIncrement(),
|
|
9
10
|
* name : Blueprint.varchar(255).default('my name'),
|
|
@@ -15,13 +16,15 @@ import sql from '../../../build/lib/core/SqlLike';
|
|
|
15
16
|
* deleted_at : Blueprint.timestamp().null()
|
|
16
17
|
* })
|
|
17
18
|
*/
|
|
18
|
-
declare class Blueprint<T = any> {
|
|
19
|
+
declare class Blueprint<T = any, S = NoType> {
|
|
20
|
+
private _default;
|
|
19
21
|
private _enum;
|
|
20
22
|
private _type;
|
|
21
23
|
private _attributes;
|
|
22
24
|
private _foreignKey;
|
|
23
25
|
private _index;
|
|
24
26
|
private _column;
|
|
27
|
+
private _isVirtual;
|
|
25
28
|
private _sql;
|
|
26
29
|
private _valueType;
|
|
27
30
|
/**
|
|
@@ -427,7 +430,6 @@ declare class Blueprint<T = any> {
|
|
|
427
430
|
* @return {Blueprint<T>} Blueprint
|
|
428
431
|
*/
|
|
429
432
|
index(name?: string): Blueprint<T>;
|
|
430
|
-
bindColumn(column: string): this;
|
|
431
433
|
get sql(): {
|
|
432
434
|
select?: string | undefined;
|
|
433
435
|
where?: string | undefined;
|
|
@@ -440,6 +442,9 @@ declare class Blueprint<T = any> {
|
|
|
440
442
|
get foreignKey(): Record<string, any> | null;
|
|
441
443
|
get indexKey(): string | null;
|
|
442
444
|
get valueType(): DateConstructor | NumberConstructor | StringConstructor | BooleanConstructor;
|
|
445
|
+
get valueEnum(): string[];
|
|
446
|
+
get valueDefault(): unknown;
|
|
447
|
+
get isVirtual(): boolean;
|
|
443
448
|
private _addAssignType;
|
|
444
449
|
private _addAssignAttribute;
|
|
445
450
|
}
|
|
@@ -5,7 +5,7 @@ exports.Blueprint = void 0;
|
|
|
5
5
|
* Class 'Blueprint' is used to make the schema for table
|
|
6
6
|
* @example
|
|
7
7
|
* import { Schema , Blueprint } from 'tspace-mysql'
|
|
8
|
-
import sql from '../../../build/lib/core/SqlLike';
|
|
8
|
+
* import sql from '../../../build/lib/core/SqlLike';
|
|
9
9
|
* await new Schema().table('users',{
|
|
10
10
|
* id : Blueprint.int().notNull().primary().autoIncrement(),
|
|
11
11
|
* name : Blueprint.varchar(255).default('my name'),
|
|
@@ -18,12 +18,14 @@ import sql from '../../../build/lib/core/SqlLike';
|
|
|
18
18
|
* })
|
|
19
19
|
*/
|
|
20
20
|
class Blueprint {
|
|
21
|
+
_default = null;
|
|
21
22
|
_enum = [];
|
|
22
23
|
_type = "INT";
|
|
23
24
|
_attributes = [];
|
|
24
25
|
_foreignKey = null;
|
|
25
26
|
_index = null;
|
|
26
27
|
_column = null;
|
|
28
|
+
_isVirtual = false;
|
|
27
29
|
_sql = null;
|
|
28
30
|
_valueType;
|
|
29
31
|
/**
|
|
@@ -41,6 +43,7 @@ class Blueprint {
|
|
|
41
43
|
*/
|
|
42
44
|
virtualColumn(sql) {
|
|
43
45
|
const instance = new Blueprint();
|
|
46
|
+
instance._isVirtual = true;
|
|
44
47
|
if (typeof sql === "object" && sql !== null) {
|
|
45
48
|
instance._sql = sql;
|
|
46
49
|
return instance;
|
|
@@ -575,13 +578,16 @@ class Blueprint {
|
|
|
575
578
|
default(value) {
|
|
576
579
|
if (typeof value === 'boolean') {
|
|
577
580
|
this._addAssignAttribute(`DEFAULT ${value ? 1 : 0}`);
|
|
581
|
+
this._default = value ? 1 : 0;
|
|
578
582
|
return this;
|
|
579
583
|
}
|
|
580
584
|
if (typeof value === 'number') {
|
|
581
585
|
this._addAssignAttribute(`DEFAULT ${value}`);
|
|
586
|
+
this._default = value;
|
|
582
587
|
return this;
|
|
583
588
|
}
|
|
584
589
|
this._addAssignAttribute(`DEFAULT '${value}'`);
|
|
590
|
+
this._default = `${value}`;
|
|
585
591
|
return this;
|
|
586
592
|
}
|
|
587
593
|
/**
|
|
@@ -590,8 +596,7 @@ class Blueprint {
|
|
|
590
596
|
* @return {Blueprint<T>} Blueprint
|
|
591
597
|
*/
|
|
592
598
|
defaultValue(value) {
|
|
593
|
-
this.default(value);
|
|
594
|
-
return this;
|
|
599
|
+
return this.default(value);
|
|
595
600
|
}
|
|
596
601
|
/**
|
|
597
602
|
* Assign attributes 'default currentTimestamp' in table
|
|
@@ -655,10 +660,6 @@ class Blueprint {
|
|
|
655
660
|
this._index = name;
|
|
656
661
|
return this;
|
|
657
662
|
}
|
|
658
|
-
bindColumn(column) {
|
|
659
|
-
this._column = column;
|
|
660
|
-
return this;
|
|
661
|
-
}
|
|
662
663
|
get sql() {
|
|
663
664
|
return this._sql;
|
|
664
665
|
}
|
|
@@ -680,6 +681,15 @@ class Blueprint {
|
|
|
680
681
|
get valueType() {
|
|
681
682
|
return this._valueType;
|
|
682
683
|
}
|
|
684
|
+
get valueEnum() {
|
|
685
|
+
return this._enum;
|
|
686
|
+
}
|
|
687
|
+
get valueDefault() {
|
|
688
|
+
return this._default;
|
|
689
|
+
}
|
|
690
|
+
get isVirtual() {
|
|
691
|
+
return this._isVirtual;
|
|
692
|
+
}
|
|
683
693
|
_addAssignType(type) {
|
|
684
694
|
this._type = type;
|
|
685
695
|
return this;
|