tspace-mysql 1.3.3 → 1.3.4

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.
@@ -79,22 +79,20 @@ class PoolConnection {
79
79
  }
80
80
  _defaultOptions() {
81
81
  return new Map(Object.entries({
82
+ multipleStatements: options_1.default.MULTIPLE_STATEMENTS || false,
83
+ enableKeepAlive: options_1.default.ENABLE_KEEP_ALIVE || false,
84
+ keepAliveInitialDelay: options_1.default.KEEP_ALIVE_DELAY || 0,
82
85
  connectionLimit: Number(options_1.default.CONNECTION_LIMIT),
83
86
  dateStrings: Boolean(options_1.default.DATE_STRINGS),
84
87
  connectTimeout: Number(options_1.default.TIMEOUT),
85
88
  waitForConnections: Boolean(options_1.default.WAIT_FOR_CONNECTIONS),
86
89
  queueLimit: Number(options_1.default.QUEUE_LIMIT),
87
- multipleStatements: true,
88
90
  charset: String(options_1.default.CHARSET),
89
91
  host: String(options_1.default.HOST),
90
- port: Number.isNaN(Number(options_1.default.PORT))
91
- ? 3306
92
- : Number(options_1.default.PORT),
92
+ port: Number.isNaN(Number(options_1.default.PORT)) ? 3306 : Number(options_1.default.PORT),
93
93
  database: String(options_1.default.DATABASE),
94
94
  user: String(options_1.default.USERNAME),
95
- password: String(options_1.default.PASSWORD) !== ''
96
- ? String(options_1.default.PASSWORD)
97
- : ''
95
+ password: String(options_1.default.PASSWORD) === '' ? '' : String(options_1.default.PASSWORD)
98
96
  }));
99
97
  }
100
98
  _loadOptions() {
@@ -110,7 +108,7 @@ class PoolConnection {
110
108
  "password" : "",
111
109
  "connectionLimit" : "",
112
110
  "dateStrings" : "",
113
- "idleTimeout" : "",
111
+ "connectTimeout" : "",
114
112
  "waitForConnections" : "",
115
113
  "queueLimit" : "",
116
114
  "charset" : ""
@@ -11,5 +11,8 @@ declare const _default: Readonly<{
11
11
  CONNECTION_ERROR?: string | boolean | undefined;
12
12
  WAIT_FOR_CONNECTIONS?: string | boolean | undefined;
13
13
  DATE_STRINGS?: string | boolean | undefined;
14
+ KEEP_ALIVE_DELAY?: string | number | undefined;
15
+ ENABLE_KEEP_ALIVE?: string | boolean | undefined;
16
+ MULTIPLE_STATEMENTS?: string | boolean | undefined;
14
17
  }>;
15
18
  export default _default;
@@ -30,7 +30,10 @@ const env = {
30
30
  CHARSET: process.env.DB_CHARSET || process.env.TSPACE_CHARSET || 'utf8mb4',
31
31
  CONNECTION_ERROR: process.env.DB_CONNECTION_ERROR || process.env.TSPACE_CONNECTION_ERROR || true,
32
32
  WAIT_FOR_CONNECTIONS: process.env.DB_WAIT_FOR_CONNECTIONS || process.env.TSPACE_WAIT_FOR_CONNECTIONS || true,
33
- DATE_STRINGS: process.env.DB_DATE_STRINGS || process.env.TSPACE_DATE_STRINGS || true
33
+ DATE_STRINGS: process.env.DB_DATE_STRINGS || process.env.TSPACE_DATE_STRINGS || true,
34
+ KEEP_ALIVE_DELAY: process.env.DB_KEEP_ALIVE_DELAY || process.env.TSPACE_KEEP_ALIVE_DELAY || 0,
35
+ ENABLE_KEEP_ALIVE: process.env.DB_ENABLE_KEEP_ALIVE || process.env.TSPACE_ENABLE_KEEP_ALIVE || false,
36
+ MULTIPLE_STATEMENTS: process.env.MULTIPLE_STATEMENTS || process.env.TSPACE_MULTIPLE_STATEMENTS || false
34
37
  };
35
38
  for (const [key, value] of Object.entries(env)) {
36
39
  if (value == null)
@@ -1803,10 +1803,6 @@ class Model extends AbstractModel_1.AbstractModel {
1803
1803
  return [];
1804
1804
  const query = yield relation.query;
1805
1805
  this._assertError(query == null, `Unknown callback query in [Relation : ${relation.name}]`);
1806
- const relationIsHasOneOrBelongsTo = [
1807
- this.$constants('RELATIONSHIP').hasOne,
1808
- this.$constants('RELATIONSHIP').belongsTo
1809
- ].some(r => r === relation.relation);
1810
1806
  const dataFromRelation = yield query
1811
1807
  .bind(this.$pool.get())
1812
1808
  .whereIn(foreignKey, dataPerentId)
@@ -2265,7 +2261,7 @@ class Model extends AbstractModel_1.AbstractModel {
2265
2261
  _insertNotExistsModel() {
2266
2262
  return __awaiter(this, void 0, void 0, function* () {
2267
2263
  this._assertError(!this.$state.get('WHERE'), "Can't insert [insertNotExists] without where condition");
2268
- const clone = new Model().copyModel(this, { where: true });
2264
+ const clone = new Model().bind(this.$pool.get()).copyModel(this, { where: true });
2269
2265
  const check = (yield clone.exists()) || false;
2270
2266
  if (check)
2271
2267
  return null;
@@ -2275,7 +2271,7 @@ class Model extends AbstractModel_1.AbstractModel {
2275
2271
  });
2276
2272
  if (!result)
2277
2273
  return null;
2278
- return yield new Model().copyModel(this).where('id', id).first();
2274
+ return yield new Model().bind(this.$pool.get()).copyModel(this).where('id', id).first();
2279
2275
  });
2280
2276
  }
2281
2277
  _insertModel() {
@@ -2290,6 +2286,7 @@ class Model extends AbstractModel_1.AbstractModel {
2290
2286
  return null;
2291
2287
  return yield new Model().copyModel(this)
2292
2288
  .where('id', id)
2289
+ .bind(this.$pool.get())
2293
2290
  .first();
2294
2291
  });
2295
2292
  }
@@ -2304,7 +2301,7 @@ class Model extends AbstractModel_1.AbstractModel {
2304
2301
  if (!result)
2305
2302
  return null;
2306
2303
  const arrayId = [...Array(result)].map((_, i) => i + id);
2307
- const data = new Model().copyModel(this).whereIn('id', arrayId).get();
2304
+ const data = new Model().copyModel(this).bind(this.$pool.get()).whereIn('id', arrayId).get();
2308
2305
  const resultData = data || [];
2309
2306
  this.$state.set('RESULT', resultData);
2310
2307
  return resultData;
@@ -2313,7 +2310,7 @@ class Model extends AbstractModel_1.AbstractModel {
2313
2310
  _updateOrInsertModel() {
2314
2311
  return __awaiter(this, void 0, void 0, function* () {
2315
2312
  this._assertError(!this.$state.get('WHERE'), "Can not update or insert [updateOrInsert] without where condition");
2316
- const clone = new Model().copyModel(this, { where: true });
2313
+ const clone = new Model().bind(this.$pool.get()).copyModel(this, { where: true });
2317
2314
  const check = (yield clone.exists()) || false;
2318
2315
  switch (check) {
2319
2316
  case false: {
@@ -2325,7 +2322,7 @@ class Model extends AbstractModel_1.AbstractModel {
2325
2322
  return null;
2326
2323
  if (!result)
2327
2324
  return null;
2328
- const data = yield new Model().copyModel(this).where('id', id).first();
2325
+ const data = yield new Model().bind(this.$pool.get()).copyModel(this).where('id', id).first();
2329
2326
  const resultData = data == null
2330
2327
  ? null
2331
2328
  : Object.assign(Object.assign({}, data), { action_status: 'insert' });
@@ -2340,7 +2337,7 @@ class Model extends AbstractModel_1.AbstractModel {
2340
2337
  return null;
2341
2338
  if (!result)
2342
2339
  return null;
2343
- const data = yield new Model().copyModel(this, { where: true }).get();
2340
+ const data = yield new Model().bind(this.$pool.get()).copyModel(this, { where: true }).get();
2344
2341
  if ((data === null || data === void 0 ? void 0 : data.length) > 1) {
2345
2342
  for (const v of data)
2346
2343
  v.action_status = 'update';
@@ -2357,7 +2354,7 @@ class Model extends AbstractModel_1.AbstractModel {
2357
2354
  _insertOrSelectModel() {
2358
2355
  return __awaiter(this, void 0, void 0, function* () {
2359
2356
  this._assertError(!this.$state.get('WHERE'), "Can not update or insert [updateOrInsert] without where condition");
2360
- const clone = new Model().copyModel(this, { where: true });
2357
+ const clone = new Model().bind(this.$pool.get()).copyModel(this, { where: true });
2361
2358
  const check = (yield clone.exists()) || false;
2362
2359
  switch (check) {
2363
2360
  case false: {
@@ -2369,7 +2366,7 @@ class Model extends AbstractModel_1.AbstractModel {
2369
2366
  return null;
2370
2367
  if (!result)
2371
2368
  return null;
2372
- const data = yield new Model().copyModel(this).where('id', id).first();
2369
+ const data = yield new Model().bind(this.$pool.get()).copyModel(this).where('id', id).first();
2373
2370
  const resultData = data == null
2374
2371
  ? null
2375
2372
  : Object.assign(Object.assign({}, data), { action_status: 'insert' });
@@ -2379,7 +2376,7 @@ class Model extends AbstractModel_1.AbstractModel {
2379
2376
  case true: {
2380
2377
  if (this.$state.get('VOID'))
2381
2378
  return null;
2382
- const data = yield new Model().copyModel(this, { where: true }).get();
2379
+ const data = yield new Model().bind(this.$pool.get()).copyModel(this, { where: true }).get();
2383
2380
  if ((data === null || data === void 0 ? void 0 : data.length) > 1) {
2384
2381
  for (const v of data)
2385
2382
  v.action_status = 'select';
@@ -2402,7 +2399,7 @@ class Model extends AbstractModel_1.AbstractModel {
2402
2399
  return null;
2403
2400
  if (result == null || !result)
2404
2401
  return null;
2405
- const data = yield new Model().copyModel(this, { where: true }).get();
2402
+ const data = yield new Model().bind(this.$pool.get()).copyModel(this, { where: true }).get();
2406
2403
  if ((data === null || data === void 0 ? void 0 : data.length) > 1) {
2407
2404
  this.$state.set('RESULT', data);
2408
2405
  return data || [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tspace-mysql",
3
- "version": "1.3.3",
3
+ "version": "1.3.4",
4
4
  "description": "mysql query builder object relational mapping",
5
5
  "main": "dist/lib/index.js",
6
6
  "types": "dist/lib/index.d.ts",