tspace-mysql 1.3.2 → 1.3.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.
@@ -9,6 +9,7 @@ const CONSTANTS = Object.freeze({
9
9
  COLUMNS: 'COLUMNS',
10
10
  WHERE: 'WHERE',
11
11
  BETWEEN: 'BETWEEN',
12
+ NOT_BETWEEN: 'NOT BETWEEN',
12
13
  AND: 'AND',
13
14
  IS_NULL: 'IS NULL',
14
15
  IS_NOT_NULL: 'IS NOT NULL',
@@ -46,6 +46,7 @@ declare abstract class AbstractBuilder {
46
46
  abstract whereNotSubQuery(column: string, subQuery: string): this;
47
47
  abstract orWhereSubQuery(column: string, subQuery: string): this;
48
48
  abstract whereBetween(column: string, arrayValue: Array<any>): this;
49
+ abstract whereNotBetween(column: string, arrayValue: Array<any>): this;
49
50
  abstract having(condition: string): this;
50
51
  abstract havingRaw(condition: string): this;
51
52
  abstract join(pk: string, fk: string): this;
@@ -3,6 +3,8 @@ import { Connection, ConnectionOptions } from './Interface';
3
3
  declare abstract class AbstractDB extends Builder {
4
4
  abstract table(tableName: string): void;
5
5
  abstract beginTransaction(): Promise<any>;
6
+ abstract makeObject(value: any): Record<string, any> | null;
7
+ abstract makeArray(value: any): Array<any>;
6
8
  abstract generateUUID(): string;
7
9
  abstract raw(sql: string): string;
8
10
  abstract constants(constants?: string): string | {
@@ -182,6 +182,13 @@ declare class Builder extends AbstractBuilder {
182
182
  * @return {this}
183
183
  */
184
184
  whereBetween(column: string, array: Array<any>): this;
185
+ /**
186
+ * where not between using [value1, value2]
187
+ * @param {string} column
188
+ * @param {array} array
189
+ * @return {this}
190
+ */
191
+ whereNotBetween(column: string, array: Array<any>): this;
185
192
  /**
186
193
  * where null using NULL
187
194
  * @param {string} column
@@ -268,7 +268,7 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
268
268
  this._queryWhereIsExists()
269
269
  ? `${this.$state.get('WHERE')} ${this.$constants('AND')}`
270
270
  : `${this.$constants('WHERE')}`,
271
- `${this._bindTableAndColumnInQueryWhere(column)} = ${id}`,
271
+ `${this._bindTableAndColumnInQueryWhere(column)} = ${this.$utils.escape(id)}`,
272
272
  ].join(' '));
273
273
  return this;
274
274
  }
@@ -404,7 +404,7 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
404
404
  : `${this.$constants('WHERE')}`,
405
405
  `${this._bindTableAndColumnInQueryWhere(column)}`,
406
406
  `${this.$constants('IN')}`,
407
- `(${this.$utils.escape(subQuery)})`
407
+ `(${subQuery})`
408
408
  ].join(' '));
409
409
  return this;
410
410
  }
@@ -421,7 +421,7 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
421
421
  : `${this.$constants('WHERE')}`,
422
422
  `${this._bindTableAndColumnInQueryWhere(column)}`,
423
423
  `${this.$constants('NOT_IN')}`,
424
- `(${this.$utils.escape(subQuery)})`
424
+ `(${subQuery})`
425
425
  ].join(' '));
426
426
  return this;
427
427
  }
@@ -438,7 +438,7 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
438
438
  : `${this.$constants('WHERE')}`,
439
439
  `${this._bindTableAndColumnInQueryWhere(column)}`,
440
440
  `${this.$constants('IN')}`,
441
- `(${this.$utils.escape(subQuery)})`
441
+ `(${subQuery})`
442
442
  ].join(' '));
443
443
  return this;
444
444
  }
@@ -455,7 +455,7 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
455
455
  : `${this.$constants('WHERE')}`,
456
456
  `${this._bindTableAndColumnInQueryWhere(column)}`,
457
457
  `${this.$constants('NOT_IN')}`,
458
- `(${this.$utils.escape(subQuery)})`
458
+ `(${subQuery})`
459
459
  ].join(' '));
460
460
  return this;
461
461
  }
@@ -476,7 +476,28 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
476
476
  ? `${this.$state.get('WHERE')} ${this.$constants('AND')}`
477
477
  : `${this.$constants('WHERE')}`,
478
478
  `${this._bindTableAndColumnInQueryWhere(column)} ${this.$constants('BETWEEN')}`,
479
- `'${this.$utils.escape(value1)}' ${this.$constants('AND')} '${this.$utils.escape(value2)}'`
479
+ `${this._checkValueHasRaw(this.$utils.escape(value1))} ${this.$constants('AND')} ${this._checkValueHasRaw(this.$utils.escape(value2))}`
480
+ ].join(' '));
481
+ return this;
482
+ }
483
+ /**
484
+ * where not between using [value1, value2]
485
+ * @param {string} column
486
+ * @param {array} array
487
+ * @return {this}
488
+ */
489
+ whereNotBetween(column, array) {
490
+ if (!Array.isArray(array))
491
+ throw new Error("Value is't array");
492
+ if (!array.length)
493
+ return this;
494
+ const [value1, value2] = array;
495
+ this.$state.set('WHERE', [
496
+ this._queryWhereIsExists()
497
+ ? `${this.$state.get('WHERE')} ${this.$constants('AND')}`
498
+ : `${this.$constants('WHERE')}`,
499
+ `${this._bindTableAndColumnInQueryWhere(column)} ${this.$constants('NOT_BETWEEN')}`,
500
+ `${this._checkValueHasRaw(this.$utils.escape(value1))} ${this.$constants('AND')} ${this._checkValueHasRaw(this.$utils.escape(value2))}`
480
501
  ].join(' '));
481
502
  return this;
482
503
  }
@@ -2,7 +2,6 @@ import { AbstractDB } from './AbstractDB';
2
2
  import { Connection, ConnectionOptions, ConnectionTransaction } from './Interface';
3
3
  declare class DB extends AbstractDB {
4
4
  constructor(table?: string);
5
- union(a: string, b: string): Promise<any[]>;
6
5
  /**
7
6
  * Covert result to array
8
7
  * @param {any} result table name
@@ -32,15 +32,6 @@ class DB extends AbstractDB_1.AbstractDB {
32
32
  this.table(table);
33
33
  return new Proxy(this, ProxyHandler_1.proxyHandler);
34
34
  }
35
- union(a, b) {
36
- return __awaiter(this, void 0, void 0, function* () {
37
- return yield this.queryStatement([
38
- a,
39
- 'UNION',
40
- b
41
- ].join(' '));
42
- });
43
- }
44
35
  /**
45
36
  * Covert result to array
46
37
  * @param {any} result table name
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tspace-mysql",
3
- "version": "1.3.2",
3
+ "version": "1.3.3",
4
4
  "description": "mysql query builder object relational mapping",
5
5
  "main": "dist/lib/index.js",
6
6
  "types": "dist/lib/index.d.ts",