pg-mvc-service 2.0.97 → 2.0.99

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.
@@ -177,7 +177,7 @@ class WhereExpression {
177
177
  case 'h2f_like': // half to full like
178
178
  case 'h2f_ilike': // half to full ilike
179
179
  return {
180
- expression: `${this.makeSqlReplaceHalfToFull(leftColumn.expression)} ${operator.replace("h2f_", "")} ${this.makeSqlReplaceHalfToFull(`'%' || ${rightColumn.expression} || '%'`)}`
180
+ expression: `${this.makeSqlNormalizeCharVariants(leftColumn.expression, { halfToFull: true })} ${operator.replace("h2f_", "")} ${this.makeSqlNormalizeCharVariants(`'%' || ${rightColumn.expression} || '%'`, { halfToFull: true })}`
181
181
  };
182
182
  }
183
183
  return {
@@ -196,7 +196,7 @@ class WhereExpression {
196
196
  case 'h2f_like': // half to full like
197
197
  case 'h2f_ilike': // half to full ilike
198
198
  return {
199
- expression: `${this.makeSqlReplaceHalfToFull(leftColumn.expression)} ${operator.replace("h2f_", "")} ${this.makeSqlReplaceHalfToFull(`$${varLength}`)}`,
199
+ expression: `${this.makeSqlNormalizeCharVariants(leftColumn.expression, { halfToFull: true })} ${operator.replace("h2f_", "")} ${this.makeSqlNormalizeCharVariants(`$${varLength}`, { halfToFull: true })}`,
200
200
  vars: [`%${right}%`]
201
201
  };
202
202
  }
@@ -373,14 +373,38 @@ class WhereExpression {
373
373
  * @param {string} columnName Column name
374
374
  * @returns SQL statement
375
375
  */
376
- static makeSqlReplaceHalfToFull(columnNameOrValue) {
377
- let objs = {
378
- '0123456789': '0123456789',
379
- 'アイウエオカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワヲンヴガギグゲゴザジズゼゾダヂヅデドバビブベボパピプペポァィゥェォャュョッー、。・「」゛゜': 'アイウエオカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワヲンヴガギグゲゴザジズゼゾダヂヅデドハハビブベボパピプペポァィゥェォャュョッー、。・「」 ゙ ゚',
380
- 'ABCDEFGHIJKLMNOPQRSTUVWXYZ': 'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
381
- 'abcdefghijklmnopqrstuvwxyz': 'abcdefghijklmnopqrstuvwxyz'
382
- };
383
- let sql = columnNameOrValue;
376
+ static makeSqlNormalizeCharVariants(expression, replaceOption) {
377
+ var _a;
378
+ if (replaceOption.numeric === true) {
379
+ replaceOption.numeric = {
380
+ japanese: true
381
+ };
382
+ }
383
+ const objs = {};
384
+ if (replaceOption.hiraganaToKatakana === true) {
385
+ objs['あいうえおかきくけこさしすせそたちつてとなにぬねのはひふへほまみむめもやゆよらりるれろわをんゔがぎぐげござじずぜぞだぢづでどばびぶべぼぱぴぷぺぽぁぃぅぇぉゃゅょっー、。・「」゛゜']
386
+ = 'アイウエオカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワヲンヴガギグゲゴザジズゼゾダヂヅデドバビブベボパピプペポァィゥェォャュョッー、。・「」゛゜';
387
+ }
388
+ if (((_a = replaceOption.numeric) === null || _a === void 0 ? void 0 : _a.japanese) === true) {
389
+ objs['零〇'] = '00';
390
+ objs['一壱弌'] = '111';
391
+ objs['二弐'] = '22';
392
+ objs['三参'] = '33';
393
+ objs['四肆'] = '44';
394
+ objs['五伍'] = '55';
395
+ objs['六陸'] = '66';
396
+ objs['七漆'] = '77';
397
+ objs['八捌'] = '88';
398
+ objs['九玖'] = '99';
399
+ }
400
+ if (replaceOption.halfToFull === true) {
401
+ objs['0123456789'] = '0123456789';
402
+ objs['アイウエオカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワヲンヴガギグゲゴザジズゼゾダヂヅデドバビブベボパピプペポァィゥェォャュョッー、。・「」゛゜']
403
+ = 'アイウエオカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワヲンヴガギグゲゴザジズゼゾダヂヅデドハハビブベボパピプペポァィゥェォャュョッー、。・「」 ゙ ゚';
404
+ objs['ABCDEFGHIJKLMNOPQRSTUVWXYZ'] = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
405
+ objs['abcdefghijklmnopqrstuvwxyz'] = 'abcdefghijklmnopqrstuvwxyz';
406
+ }
407
+ let sql = expression;
384
408
  Object.keys(objs).forEach(key => sql = `TRANSLATE(${sql} ,'${key}','${objs[key]}')`);
385
409
  return sql;
386
410
  }
@@ -530,7 +530,7 @@ class TableModel {
530
530
  const tables = [];
531
531
  for (const join of this.joinConditions) {
532
532
  tables.push(`${join.model.TableName} as "${join.model.TableAlias}"`);
533
- const query = WhereExpression_1.default.createCondition(join.conditions, this, this.vars.length);
533
+ const query = WhereExpression_1.default.createCondition(join.conditions, this, this.vars.length + 1);
534
534
  this.whereExpressions.push(query.expression);
535
535
  if (query.vars !== undefined) {
536
536
  this.vars = [...this.vars, ...query.vars];
@@ -552,7 +552,7 @@ class TableModel {
552
552
  const tables = [];
553
553
  for (const join of this.joinConditions) {
554
554
  tables.push(`${join.model.TableName} as "${join.model.TableAlias}"`);
555
- const query = WhereExpression_1.default.createCondition(join.conditions, this, this.vars.length);
555
+ const query = WhereExpression_1.default.createCondition(join.conditions, this, this.vars.length + 1);
556
556
  this.whereExpressions.push(query.expression);
557
557
  if (query.vars !== undefined) {
558
558
  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.97",
3
+ "version": "2.0.99",
4
4
  "description": "",
5
5
  "homepage": "https://github.com/n-daira/npm-pack_mvc-service#readme",
6
6
  "bugs": {
@@ -197,7 +197,7 @@ export default class WhereExpression {
197
197
  case 'h2f_like': // half to full like
198
198
  case 'h2f_ilike': // half to full ilike
199
199
  return {
200
- expression: `${this.makeSqlReplaceHalfToFull(leftColumn.expression)} ${operator.replace("h2f_", "")} ${this.makeSqlReplaceHalfToFull(`'%' || ${rightColumn.expression} || '%'`)}`
200
+ expression: `${this.makeSqlNormalizeCharVariants(leftColumn.expression, {halfToFull: true})} ${operator.replace("h2f_", "")} ${this.makeSqlNormalizeCharVariants(`'%' || ${rightColumn.expression} || '%'`, {halfToFull: true})}`
201
201
  }
202
202
  }
203
203
 
@@ -218,7 +218,7 @@ export default class WhereExpression {
218
218
  case 'h2f_like': // half to full like
219
219
  case 'h2f_ilike': // half to full ilike
220
220
  return {
221
- expression: `${this.makeSqlReplaceHalfToFull(leftColumn.expression)} ${operator.replace("h2f_", "")} ${this.makeSqlReplaceHalfToFull(`$${varLength}`)}`,
221
+ expression: `${this.makeSqlNormalizeCharVariants(leftColumn.expression, {halfToFull: true})} ${operator.replace("h2f_", "")} ${this.makeSqlNormalizeCharVariants(`$${varLength}`, {halfToFull: true})}`,
222
222
  vars: [`%${right}%`]
223
223
  }
224
224
  }
@@ -405,15 +405,44 @@ export default class WhereExpression {
405
405
  * @param {string} columnName Column name
406
406
  * @returns SQL statement
407
407
  */
408
- private static makeSqlReplaceHalfToFull(columnNameOrValue: string) {
409
- let objs: { [key: string]: string } = {
410
- '0123456789': '0123456789',
411
- 'アイウエオカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワヲンヴガギグゲゴザジズゼゾダヂヅデドバビブベボパピプペポァィゥェォャュョッー、。・「」゛゜': 'アイウエオカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワヲンヴガギグゲゴザジズゼゾダヂヅデドハハビブベボパピプペポァィゥェォャュョッー、。・「」 ゙ ゚',
412
- 'ABCDEFGHIJKLMNOPQRSTUVWXYZ': 'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
413
- 'abcdefghijklmnopqrstuvwxyz': 'abcdefghijklmnopqrstuvwxyz'
414
- };
408
+ public static makeSqlNormalizeCharVariants(expression: string, replaceOption: {
409
+ halfToFull?: boolean; hiraganaToKatakana?: boolean;
410
+ numeric?: true | { japanese?: boolean; }
411
+ }) {
412
+ if (replaceOption.numeric === true) {
413
+ replaceOption.numeric = {
414
+ japanese: true
415
+ }
416
+ }
417
+
418
+ const objs: { [key: string]: string } = {}
419
+ if (replaceOption.hiraganaToKatakana === true) {
420
+ objs['あいうえおかきくけこさしすせそたちつてとなにぬねのはひふへほまみむめもやゆよらりるれろわをんゔがぎぐげござじずぜぞだぢづでどばびぶべぼぱぴぷぺぽぁぃぅぇぉゃゅょっー、。・「」゛゜']
421
+ = 'アイウエオカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワヲンヴガギグゲゴザジズゼゾダヂヅデドバビブベボパピプペポァィゥェォャュョッー、。・「」゛゜';
422
+ }
423
+
424
+ if (replaceOption.numeric?.japanese === true) {
425
+ objs['零〇'] = '00';
426
+ objs['一壱弌'] = '111';
427
+ objs['二弐'] = '22';
428
+ objs['三参'] = '33';
429
+ objs['四肆'] = '44';
430
+ objs['五伍'] = '55';
431
+ objs['六陸'] = '66';
432
+ objs['七漆'] = '77';
433
+ objs['八捌'] = '88';
434
+ objs['九玖'] = '99';
435
+ }
436
+
437
+ if (replaceOption.halfToFull === true) {
438
+ objs['0123456789'] = '0123456789';
439
+ objs['アイウエオカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワヲンヴガギグゲゴザジズゼゾダヂヅデドバビブベボパピプペポァィゥェォャュョッー、。・「」゛゜']
440
+ = 'アイウエオカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワヲンヴガギグゲゴザジズゼゾダヂヅデドハハビブベボパピプペポァィゥェォャュョッー、。・「」 ゙ ゚';
441
+ objs['ABCDEFGHIJKLMNOPQRSTUVWXYZ'] = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
442
+ objs['abcdefghijklmnopqrstuvwxyz'] = 'abcdefghijklmnopqrstuvwxyz';
443
+ }
415
444
 
416
- let sql = columnNameOrValue;
445
+ let sql = expression;
417
446
  Object.keys(objs).forEach(key => sql = `TRANSLATE(${sql} ,'${key}','${objs[key]}')`);
418
447
 
419
448
  return sql;
@@ -613,7 +613,7 @@ export class TableModel {
613
613
  for (const join of this.joinConditions) {
614
614
  tables.push(`${join.model.TableName} as "${join.model.TableAlias}"`);
615
615
 
616
- const query = WhereExpression.createCondition(join.conditions, this, this.vars.length);
616
+ const query = WhereExpression.createCondition(join.conditions, this, this.vars.length + 1);
617
617
  this.whereExpressions.push(query.expression);
618
618
  if (query.vars !== undefined) {
619
619
  this.vars = [...this.vars, ...query.vars]
@@ -638,7 +638,7 @@ export class TableModel {
638
638
  for (const join of this.joinConditions) {
639
639
  tables.push(`${join.model.TableName} as "${join.model.TableAlias}"`);
640
640
 
641
- const query = WhereExpression.createCondition(join.conditions, this, this.vars.length);
641
+ const query = WhereExpression.createCondition(join.conditions, this, this.vars.length + 1);
642
642
  this.whereExpressions.push(query.expression);
643
643
  if (query.vars !== undefined) {
644
644
  this.vars = [...this.vars, ...query.vars]