pg-mvc-service 2.0.100 → 2.0.102

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/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.runCron = exports.BaseCron = exports.rollback = exports.migrate = exports.MigrateDatabase = exports.MigrateTable = exports.createTableDoc = exports.TableModel = exports.ResponseType = exports.RequestType = exports.EncryptClient = exports.StringClient = exports.Base64Client = exports.AwsS3Client = exports.createSwagger = exports.NotFoundException = exports.UnprocessableException = exports.DbConflictException = exports.ForbiddenException = exports.InputErrorException = exports.AuthException = exports.MaintenanceException = exports.Service = void 0;
3
+ exports.runCron = exports.BaseCron = exports.rollback = exports.migrate = exports.MigrateDatabase = exports.MigrateTable = exports.createTableDoc = exports.WhereExpression = exports.TableModel = exports.ResponseType = exports.RequestType = exports.EncryptClient = exports.StringClient = exports.Base64Client = exports.AwsS3Client = exports.createSwagger = exports.NotFoundException = exports.UnprocessableException = exports.DbConflictException = exports.ForbiddenException = exports.InputErrorException = exports.AuthException = exports.MaintenanceException = exports.Service = void 0;
4
4
  var Service_1 = require("./Service");
5
5
  Object.defineProperty(exports, "Service", { enumerable: true, get: function () { return Service_1.Service; } });
6
6
  var Exception_1 = require("./exceptions/Exception");
@@ -28,6 +28,8 @@ Object.defineProperty(exports, "ResponseType", { enumerable: true, get: function
28
28
  // models
29
29
  var TableModel_1 = require("./models/TableModel");
30
30
  Object.defineProperty(exports, "TableModel", { enumerable: true, get: function () { return TableModel_1.TableModel; } });
31
+ var WhereExpression_1 = require("./models/SqlUtils/WhereExpression");
32
+ Object.defineProperty(exports, "WhereExpression", { enumerable: true, get: function () { return WhereExpression_1.WhereExpression; } });
31
33
  var TableDoc_1 = require("./models/TableDoc");
32
34
  Object.defineProperty(exports, "createTableDoc", { enumerable: true, get: function () { return TableDoc_1.createTableDoc; } });
33
35
  var MigrateTable_1 = require("./models/MigrateTable");
@@ -3,6 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.WhereExpression = void 0;
6
7
  const ValidateValueUtil_1 = __importDefault(require("./ValidateValueUtil"));
7
8
  class WhereExpression {
8
9
  static createConditionPk(model, pk, vars = null, isSetAlias = false) {
@@ -416,4 +417,4 @@ class WhereExpression {
416
417
  return sql;
417
418
  }
418
419
  }
419
- exports.default = WhereExpression;
420
+ exports.WhereExpression = WhereExpression;
@@ -15,7 +15,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.TableModel = void 0;
16
16
  const ValidateValueUtil_1 = __importDefault(require("./SqlUtils/ValidateValueUtil"));
17
17
  const SelectExpression_1 = __importDefault(require("./SqlUtils/SelectExpression"));
18
- const WhereExpression_1 = __importDefault(require("./SqlUtils/WhereExpression"));
18
+ const WhereExpression_1 = require("./SqlUtils/WhereExpression");
19
19
  const ValidateClient_1 = __importDefault(require("./ValidateClient"));
20
20
  const Exception_1 = require("../exceptions/Exception");
21
21
  const ExpressionClient_1 = __importDefault(require("./ExpressionClient"));
@@ -68,7 +68,7 @@ class TableModel {
68
68
  };
69
69
  sql += joins[join.type];
70
70
  sql += ` ${join.model.TableName} as "${join.model.TableAlias}" ON `;
71
- const query = WhereExpression_1.default.createCondition(join.conditions, this, this.vars.length + 1);
71
+ const query = WhereExpression_1.WhereExpression.createCondition(join.conditions, this, this.vars.length + 1);
72
72
  sql += query.expression;
73
73
  if (query.vars !== undefined) {
74
74
  this.vars = [...this.vars, ...query.vars];
@@ -141,10 +141,10 @@ class TableModel {
141
141
  let query;
142
142
  if (typeof pkOrId === 'string' || typeof pkOrId === 'number' || typeof pkOrId === 'boolean') {
143
143
  ValidateValueUtil_1.default.validateId(this.Columns, pkOrId);
144
- query = WhereExpression_1.default.createConditionPk(this, { id: pkOrId });
144
+ query = WhereExpression_1.WhereExpression.createConditionPk(this, { id: pkOrId });
145
145
  }
146
146
  else {
147
- query = WhereExpression_1.default.createConditionPk(this, pkOrId);
147
+ query = WhereExpression_1.WhereExpression.createConditionPk(this, pkOrId);
148
148
  }
149
149
  const sql = `SELECT ${selects.join(',')} FROM ${this.TableName} WHERE ${query.expression}`;
150
150
  let datas = yield this.executeQuery(sql, query.vars);
@@ -241,13 +241,16 @@ class TableModel {
241
241
  join(joinType, joinModel, conditions) {
242
242
  this.joinConditions.push({ type: joinType, model: joinModel, conditions: conditions });
243
243
  }
244
- where(left, operator, right) {
245
- if (typeof left === 'string') {
246
- if (operator === undefined || right === undefined) {
247
- this.whereExpressions.push(left);
244
+ where(param1, param2, right) {
245
+ if (typeof param1 === 'string') {
246
+ if (param2 === undefined || right === undefined || Array.isArray(param2)) {
247
+ this.whereExpressions.push(param1);
248
+ if (Array.isArray(param2)) {
249
+ this.vars = [...this.vars, ...param2];
250
+ }
248
251
  }
249
252
  else {
250
- const query = WhereExpression_1.default.create({ model: this, name: left }, operator, right, this.vars.length + 1);
253
+ const query = WhereExpression_1.WhereExpression.create({ model: this, name: param1 }, param2, right, this.vars.length + 1);
251
254
  this.whereExpressions.push(query.expression);
252
255
  if (query.vars !== undefined) {
253
256
  this.vars = [...this.vars, ...query.vars];
@@ -255,12 +258,12 @@ class TableModel {
255
258
  }
256
259
  return;
257
260
  }
258
- if ('model' in left && 'name' in left) {
259
- if (operator === undefined || right === undefined) {
260
- throw new Error(`If left is TColumnInfo, please set operator and right.`);
261
+ if ('model' in param1 && 'name' in param1) {
262
+ if (param2 === undefined || right === undefined || Array.isArray(param2)) {
263
+ throw new Error(`If left is TColumnInfo, please set operator and right. Do not pass an array to operator.`);
261
264
  }
262
265
  else {
263
- const query = WhereExpression_1.default.create(left, operator, right, this.vars.length + 1);
266
+ const query = WhereExpression_1.WhereExpression.create(param1, param2, right, this.vars.length + 1);
264
267
  this.whereExpressions.push(query.expression);
265
268
  if (query.vars !== undefined) {
266
269
  this.vars = [...this.vars, ...query.vars];
@@ -268,8 +271,8 @@ class TableModel {
268
271
  }
269
272
  return;
270
273
  }
271
- if (Array.isArray(left)) {
272
- const query = WhereExpression_1.default.createCondition(left, this, this.vars.length + 1);
274
+ if (Array.isArray(param1)) {
275
+ const query = WhereExpression_1.WhereExpression.createCondition(param1, this, this.vars.length + 1);
273
276
  this.whereExpressions.push(query.expression);
274
277
  if (query.vars !== undefined) {
275
278
  this.vars = [...this.vars, ...query.vars];
@@ -485,10 +488,10 @@ class TableModel {
485
488
  let whereQuery;
486
489
  if (typeof pkOrId === 'string' || typeof pkOrId === 'number' || typeof pkOrId === 'boolean') {
487
490
  ValidateValueUtil_1.default.validateId(this.Columns, pkOrId);
488
- whereQuery = WhereExpression_1.default.createConditionPk(this, { id: pkOrId }, updateSetQuery.vars);
491
+ whereQuery = WhereExpression_1.WhereExpression.createConditionPk(this, { id: pkOrId }, updateSetQuery.vars);
489
492
  }
490
493
  else {
491
- whereQuery = WhereExpression_1.default.createConditionPk(this, pkOrId, updateSetQuery.vars);
494
+ whereQuery = WhereExpression_1.WhereExpression.createConditionPk(this, pkOrId, updateSetQuery.vars);
492
495
  }
493
496
  const sql = updateSetQuery.expression + ' WHERE ' + whereQuery.expression;
494
497
  const data = yield this.executeQuery(sql, whereQuery.vars);
@@ -503,10 +506,10 @@ class TableModel {
503
506
  let whereQuery;
504
507
  if (typeof pkOrId === 'string' || typeof pkOrId === 'number' || typeof pkOrId === 'boolean') {
505
508
  ValidateValueUtil_1.default.validateId(this.Columns, pkOrId);
506
- whereQuery = WhereExpression_1.default.createConditionPk(this, { id: pkOrId });
509
+ whereQuery = WhereExpression_1.WhereExpression.createConditionPk(this, { id: pkOrId });
507
510
  }
508
511
  else {
509
- whereQuery = WhereExpression_1.default.createConditionPk(this, pkOrId);
512
+ whereQuery = WhereExpression_1.WhereExpression.createConditionPk(this, pkOrId);
510
513
  }
511
514
  const sql = `DELETE FROM ${this.TableName} WHERE ${whereQuery.expression}`;
512
515
  const data = yield this.executeQuery(sql, whereQuery.vars);
@@ -530,7 +533,7 @@ class TableModel {
530
533
  const tables = [];
531
534
  for (const join of this.joinConditions) {
532
535
  tables.push(`${join.model.TableName} as "${join.model.TableAlias}"`);
533
- const query = WhereExpression_1.default.createCondition(join.conditions, this, this.vars.length + 1);
536
+ const query = WhereExpression_1.WhereExpression.createCondition(join.conditions, this, this.vars.length + 1);
534
537
  this.whereExpressions.push(query.expression);
535
538
  if (query.vars !== undefined) {
536
539
  this.vars = [...this.vars, ...query.vars];
@@ -552,7 +555,7 @@ class TableModel {
552
555
  const tables = [];
553
556
  for (const join of this.joinConditions) {
554
557
  tables.push(`${join.model.TableName} as "${join.model.TableAlias}"`);
555
- const query = WhereExpression_1.default.createCondition(join.conditions, this, this.vars.length + 1);
558
+ const query = WhereExpression_1.WhereExpression.createCondition(join.conditions, this, this.vars.length + 1);
556
559
  this.whereExpressions.push(query.expression);
557
560
  if (query.vars !== undefined) {
558
561
  this.vars = [...this.vars, ...query.vars];
package/index.d.ts CHANGED
@@ -20,6 +20,9 @@ import ValidateClient from './src/models/ValidateClient';
20
20
  import { TableModel } from "./src/models/TableModel";
21
21
  export { TableModel } from "./src/models/TableModel";
22
22
 
23
+ import { WhereExpression } from './src/models/SqlUtils/WhereExpression';
24
+ export { WhereExpression } from './src/models/SqlUtils/WhereExpression';
25
+
23
26
  export { TColumnAttribute, TColumnType, TColumnArrayType, TColumn, TColumnDetail, TOperator, TColumnInfo, TQuery, TSelectExpression, TAggregateFuncType, TCondition, TNestedCondition, TSortKeyword, TKeyFormat } from './src/models/Type';
24
27
 
25
28
  export { DayType, MonthType, DateType, HourType, MinuteSecondType } from './src/cron/CronType';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pg-mvc-service",
3
- "version": "2.0.100",
3
+ "version": "2.0.102",
4
4
  "description": "",
5
5
  "homepage": "https://github.com/n-daira/npm-pack_mvc-service#readme",
6
6
  "bugs": {
package/src/index.ts CHANGED
@@ -12,6 +12,7 @@ export { PropertyType } from './reqestResponse/ReqResType';
12
12
 
13
13
  // models
14
14
  export { TableModel } from './models/TableModel';
15
+ export { WhereExpression } from './models/SqlUtils/WhereExpression';
15
16
  export { createTableDoc } from './models/TableDoc';
16
17
  export { MigrateTable } from './models/MigrateTable';
17
18
  export { MigrateDatabase } from './models/MigrateDatabase';
@@ -2,7 +2,7 @@ import { TableModel } from "../TableModel";
2
2
  import { TColumnArrayType, TColumnDetail, TColumnInfo, TColumnType, TNestedCondition, TOperator, TQuery } from "../Type";
3
3
  import ValidateValueUtil from "./ValidateValueUtil";
4
4
 
5
- export default class WhereExpression {
5
+ export class WhereExpression {
6
6
 
7
7
  public static createConditionPk(model: TableModel, pk: {[key: string]: any}, vars: Array<any> | null = null, isSetAlias: boolean = false): TQuery {
8
8
  const conditions = [];
@@ -2,7 +2,7 @@ import { Pool, PoolClient } from 'pg';
2
2
  import { TAggregateFuncType, TColumn, TColumnArrayType, TColumnDetail, TColumnInfo, TColumnType, TKeyFormat, TNestedCondition, TOperator, TQuery, TSelectExpression, TSortKeyword } from "./Type";
3
3
  import ValidateValueUtil from './SqlUtils/ValidateValueUtil';
4
4
  import SelectExpression from './SqlUtils/SelectExpression';
5
- import WhereExpression from './SqlUtils/WhereExpression';
5
+ import { WhereExpression } from './SqlUtils/WhereExpression';
6
6
  import ValidateClient from './ValidateClient';
7
7
  import { DbConflictException, NotFoundException, UnprocessableException } from '../exceptions/Exception';
8
8
  import ExpressionClient from './ExpressionClient';
@@ -286,15 +286,19 @@ export class TableModel {
286
286
  }
287
287
 
288
288
  public where(expression: string): void;
289
+ public where(expression: string, vars: Array<any>): void;
289
290
  public where(conditions: Array<TNestedCondition>): void;
290
291
  public where(left: string, operator: TOperator, right: TColumnInfo | any): void;
291
292
  public where(left: TColumnInfo, operator: TOperator, right: TColumnInfo | any): void;
292
- public where(left: string | TColumnInfo | Array<TNestedCondition>, operator?: TOperator, right?: TColumnInfo | any): void {
293
- if (typeof left === 'string') {
294
- if (operator === undefined || right === undefined) {
295
- this.whereExpressions.push(left);
293
+ public where(param1: string | TColumnInfo | Array<TNestedCondition>, param2?: Array<any> | TOperator, right?: TColumnInfo | any): void {
294
+ if (typeof param1 === 'string') {
295
+ if (param2 === undefined || right === undefined || Array.isArray(param2)) {
296
+ this.whereExpressions.push(param1);
297
+ if (Array.isArray(param2)) {
298
+ this.vars = [...this.vars, ...param2];
299
+ }
296
300
  } else {
297
- const query = WhereExpression.create({model: this, name: left}, operator, right, this.vars.length + 1);
301
+ const query = WhereExpression.create({model: this, name: param1}, param2, right, this.vars.length + 1);
298
302
  this.whereExpressions.push(query.expression);
299
303
  if (query.vars !== undefined) {
300
304
  this.vars = [...this.vars, ...query.vars];
@@ -303,11 +307,11 @@ export class TableModel {
303
307
  return;
304
308
  }
305
309
 
306
- if ('model' in left && 'name' in left) {
307
- if (operator === undefined || right === undefined) {
308
- throw new Error(`If left is TColumnInfo, please set operator and right.`);
310
+ if ('model' in param1 && 'name' in param1) {
311
+ if (param2 === undefined || right === undefined || Array.isArray(param2)) {
312
+ throw new Error(`If left is TColumnInfo, please set operator and right. Do not pass an array to operator.`);
309
313
  } else {
310
- const query = WhereExpression.create(left, operator, right, this.vars.length + 1);
314
+ const query = WhereExpression.create(param1, param2, right, this.vars.length + 1);
311
315
  this.whereExpressions.push(query.expression);
312
316
  if (query.vars !== undefined) {
313
317
  this.vars = [...this.vars, ...query.vars];
@@ -316,8 +320,8 @@ export class TableModel {
316
320
  return;
317
321
  }
318
322
 
319
- if (Array.isArray(left)) {
320
- const query = WhereExpression.createCondition(left, this, this.vars.length + 1);
323
+ if (Array.isArray(param1)) {
324
+ const query = WhereExpression.createCondition(param1, this, this.vars.length + 1);
321
325
  this.whereExpressions.push(query.expression);
322
326
  if (query.vars !== undefined) {
323
327
  this.vars = [...this.vars, ...query.vars];