pg-mvc-service 2.0.101 → 2.0.103

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.
@@ -241,13 +241,25 @@ 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
+ if (Array.isArray(param2)) {
248
+ let expression = param1;
249
+ const startIndex = this.vars.length + 1;
250
+ expression = expression.replace(/\$(\d+)/g, (match, num) => {
251
+ const originalNum = parseInt(num, 10);
252
+ return `$${startIndex + originalNum - 1}`;
253
+ });
254
+ this.vars = [...this.vars, ...param2];
255
+ this.whereExpressions.push(expression);
256
+ }
257
+ else {
258
+ this.whereExpressions.push(param1);
259
+ }
248
260
  }
249
261
  else {
250
- const query = WhereExpression_1.WhereExpression.create({ model: this, name: left }, operator, right, this.vars.length + 1);
262
+ const query = WhereExpression_1.WhereExpression.create({ model: this, name: param1 }, param2, right, this.vars.length + 1);
251
263
  this.whereExpressions.push(query.expression);
252
264
  if (query.vars !== undefined) {
253
265
  this.vars = [...this.vars, ...query.vars];
@@ -255,12 +267,12 @@ class TableModel {
255
267
  }
256
268
  return;
257
269
  }
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.`);
270
+ if ('model' in param1 && 'name' in param1) {
271
+ if (param2 === undefined || right === undefined || Array.isArray(param2)) {
272
+ throw new Error(`If left is TColumnInfo, please set operator and right. Do not pass an array to operator.`);
261
273
  }
262
274
  else {
263
- const query = WhereExpression_1.WhereExpression.create(left, operator, right, this.vars.length + 1);
275
+ const query = WhereExpression_1.WhereExpression.create(param1, param2, right, this.vars.length + 1);
264
276
  this.whereExpressions.push(query.expression);
265
277
  if (query.vars !== undefined) {
266
278
  this.vars = [...this.vars, ...query.vars];
@@ -268,8 +280,8 @@ class TableModel {
268
280
  }
269
281
  return;
270
282
  }
271
- if (Array.isArray(left)) {
272
- const query = WhereExpression_1.WhereExpression.createCondition(left, this, this.vars.length + 1);
283
+ if (Array.isArray(param1)) {
284
+ const query = WhereExpression_1.WhereExpression.createCondition(param1, this, this.vars.length + 1);
273
285
  this.whereExpressions.push(query.expression);
274
286
  if (query.vars !== undefined) {
275
287
  this.vars = [...this.vars, ...query.vars];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pg-mvc-service",
3
- "version": "2.0.101",
3
+ "version": "2.0.103",
4
4
  "description": "",
5
5
  "homepage": "https://github.com/n-daira/npm-pack_mvc-service#readme",
6
6
  "bugs": {
@@ -286,15 +286,27 @@ 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
+ if (Array.isArray(param2)) {
297
+ let expression = param1;
298
+ const startIndex = this.vars.length + 1;
299
+ expression = expression.replace(/\$(\d+)/g, (match, num) => {
300
+ const originalNum = parseInt(num, 10);
301
+ return `$${startIndex + originalNum - 1}`;
302
+ });
303
+ this.vars = [...this.vars, ...param2];
304
+ this.whereExpressions.push(expression);
305
+ } else {
306
+ this.whereExpressions.push(param1);
307
+ }
296
308
  } else {
297
- const query = WhereExpression.create({model: this, name: left}, operator, right, this.vars.length + 1);
309
+ const query = WhereExpression.create({model: this, name: param1}, param2, right, this.vars.length + 1);
298
310
  this.whereExpressions.push(query.expression);
299
311
  if (query.vars !== undefined) {
300
312
  this.vars = [...this.vars, ...query.vars];
@@ -303,11 +315,11 @@ export class TableModel {
303
315
  return;
304
316
  }
305
317
 
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.`);
318
+ if ('model' in param1 && 'name' in param1) {
319
+ if (param2 === undefined || right === undefined || Array.isArray(param2)) {
320
+ throw new Error(`If left is TColumnInfo, please set operator and right. Do not pass an array to operator.`);
309
321
  } else {
310
- const query = WhereExpression.create(left, operator, right, this.vars.length + 1);
322
+ const query = WhereExpression.create(param1, param2, right, this.vars.length + 1);
311
323
  this.whereExpressions.push(query.expression);
312
324
  if (query.vars !== undefined) {
313
325
  this.vars = [...this.vars, ...query.vars];
@@ -316,8 +328,8 @@ export class TableModel {
316
328
  return;
317
329
  }
318
330
 
319
- if (Array.isArray(left)) {
320
- const query = WhereExpression.createCondition(left, this, this.vars.length + 1);
331
+ if (Array.isArray(param1)) {
332
+ const query = WhereExpression.createCondition(param1, this, this.vars.length + 1);
321
333
  this.whereExpressions.push(query.expression);
322
334
  if (query.vars !== undefined) {
323
335
  this.vars = [...this.vars, ...query.vars];