pg-mvc-service 2.0.99 → 2.0.101
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) {
|
|
@@ -375,17 +376,24 @@ class WhereExpression {
|
|
|
375
376
|
*/
|
|
376
377
|
static makeSqlNormalizeCharVariants(expression, replaceOption) {
|
|
377
378
|
var _a;
|
|
378
|
-
if (replaceOption
|
|
379
|
+
if (replaceOption === true) {
|
|
380
|
+
replaceOption = {
|
|
381
|
+
halfToFull: true,
|
|
382
|
+
hiraganaToKatakana: true,
|
|
383
|
+
numeric: true
|
|
384
|
+
};
|
|
385
|
+
}
|
|
386
|
+
if ((replaceOption === null || replaceOption === void 0 ? void 0 : replaceOption.numeric) === true) {
|
|
379
387
|
replaceOption.numeric = {
|
|
380
388
|
japanese: true
|
|
381
389
|
};
|
|
382
390
|
}
|
|
383
391
|
const objs = {};
|
|
384
|
-
if (replaceOption.hiraganaToKatakana === true) {
|
|
392
|
+
if ((replaceOption === null || replaceOption === void 0 ? void 0 : replaceOption.hiraganaToKatakana) === true) {
|
|
385
393
|
objs['あいうえおかきくけこさしすせそたちつてとなにぬねのはひふへほまみむめもやゆよらりるれろわをんゔがぎぐげござじずぜぞだぢづでどばびぶべぼぱぴぷぺぽぁぃぅぇぉゃゅょっー、。・「」゛゜']
|
|
386
394
|
= 'アイウエオカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワヲンヴガギグゲゴザジズゼゾダヂヅデドバビブベボパピプペポァィゥェォャュョッー、。・「」゛゜';
|
|
387
395
|
}
|
|
388
|
-
if (((_a = replaceOption.numeric) === null || _a === void 0 ? void 0 : _a.japanese) === true) {
|
|
396
|
+
if (((_a = replaceOption === null || replaceOption === void 0 ? void 0 : replaceOption.numeric) === null || _a === void 0 ? void 0 : _a.japanese) === true) {
|
|
389
397
|
objs['零〇'] = '00';
|
|
390
398
|
objs['一壱弌'] = '111';
|
|
391
399
|
objs['二弐'] = '22';
|
|
@@ -397,7 +405,7 @@ class WhereExpression {
|
|
|
397
405
|
objs['八捌'] = '88';
|
|
398
406
|
objs['九玖'] = '99';
|
|
399
407
|
}
|
|
400
|
-
if (replaceOption.halfToFull === true) {
|
|
408
|
+
if ((replaceOption === null || replaceOption === void 0 ? void 0 : replaceOption.halfToFull) === true) {
|
|
401
409
|
objs['0123456789'] = '0123456789';
|
|
402
410
|
objs['アイウエオカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワヲンヴガギグゲゴザジズゼゾダヂヅデドバビブベボパピプペポァィゥェォャュョッー、。・「」゛゜']
|
|
403
411
|
= 'アイウエオカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワヲンヴガギグゲゴザジズゼゾダヂヅデドハハビブベボパピプペポァィゥェォャュョッー、。・「」 ゙ ゚';
|
|
@@ -409,4 +417,4 @@ class WhereExpression {
|
|
|
409
417
|
return sql;
|
|
410
418
|
}
|
|
411
419
|
}
|
|
412
|
-
exports.
|
|
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 =
|
|
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.
|
|
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.
|
|
144
|
+
query = WhereExpression_1.WhereExpression.createConditionPk(this, { id: pkOrId });
|
|
145
145
|
}
|
|
146
146
|
else {
|
|
147
|
-
query = WhereExpression_1.
|
|
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);
|
|
@@ -247,7 +247,7 @@ class TableModel {
|
|
|
247
247
|
this.whereExpressions.push(left);
|
|
248
248
|
}
|
|
249
249
|
else {
|
|
250
|
-
const query = WhereExpression_1.
|
|
250
|
+
const query = WhereExpression_1.WhereExpression.create({ model: this, name: left }, operator, right, this.vars.length + 1);
|
|
251
251
|
this.whereExpressions.push(query.expression);
|
|
252
252
|
if (query.vars !== undefined) {
|
|
253
253
|
this.vars = [...this.vars, ...query.vars];
|
|
@@ -260,7 +260,7 @@ class TableModel {
|
|
|
260
260
|
throw new Error(`If left is TColumnInfo, please set operator and right.`);
|
|
261
261
|
}
|
|
262
262
|
else {
|
|
263
|
-
const query = WhereExpression_1.
|
|
263
|
+
const query = WhereExpression_1.WhereExpression.create(left, operator, right, this.vars.length + 1);
|
|
264
264
|
this.whereExpressions.push(query.expression);
|
|
265
265
|
if (query.vars !== undefined) {
|
|
266
266
|
this.vars = [...this.vars, ...query.vars];
|
|
@@ -269,7 +269,7 @@ class TableModel {
|
|
|
269
269
|
return;
|
|
270
270
|
}
|
|
271
271
|
if (Array.isArray(left)) {
|
|
272
|
-
const query = WhereExpression_1.
|
|
272
|
+
const query = WhereExpression_1.WhereExpression.createCondition(left, this, this.vars.length + 1);
|
|
273
273
|
this.whereExpressions.push(query.expression);
|
|
274
274
|
if (query.vars !== undefined) {
|
|
275
275
|
this.vars = [...this.vars, ...query.vars];
|
|
@@ -485,10 +485,10 @@ class TableModel {
|
|
|
485
485
|
let whereQuery;
|
|
486
486
|
if (typeof pkOrId === 'string' || typeof pkOrId === 'number' || typeof pkOrId === 'boolean') {
|
|
487
487
|
ValidateValueUtil_1.default.validateId(this.Columns, pkOrId);
|
|
488
|
-
whereQuery = WhereExpression_1.
|
|
488
|
+
whereQuery = WhereExpression_1.WhereExpression.createConditionPk(this, { id: pkOrId }, updateSetQuery.vars);
|
|
489
489
|
}
|
|
490
490
|
else {
|
|
491
|
-
whereQuery = WhereExpression_1.
|
|
491
|
+
whereQuery = WhereExpression_1.WhereExpression.createConditionPk(this, pkOrId, updateSetQuery.vars);
|
|
492
492
|
}
|
|
493
493
|
const sql = updateSetQuery.expression + ' WHERE ' + whereQuery.expression;
|
|
494
494
|
const data = yield this.executeQuery(sql, whereQuery.vars);
|
|
@@ -503,10 +503,10 @@ class TableModel {
|
|
|
503
503
|
let whereQuery;
|
|
504
504
|
if (typeof pkOrId === 'string' || typeof pkOrId === 'number' || typeof pkOrId === 'boolean') {
|
|
505
505
|
ValidateValueUtil_1.default.validateId(this.Columns, pkOrId);
|
|
506
|
-
whereQuery = WhereExpression_1.
|
|
506
|
+
whereQuery = WhereExpression_1.WhereExpression.createConditionPk(this, { id: pkOrId });
|
|
507
507
|
}
|
|
508
508
|
else {
|
|
509
|
-
whereQuery = WhereExpression_1.
|
|
509
|
+
whereQuery = WhereExpression_1.WhereExpression.createConditionPk(this, pkOrId);
|
|
510
510
|
}
|
|
511
511
|
const sql = `DELETE FROM ${this.TableName} WHERE ${whereQuery.expression}`;
|
|
512
512
|
const data = yield this.executeQuery(sql, whereQuery.vars);
|
|
@@ -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.
|
|
533
|
+
const query = WhereExpression_1.WhereExpression.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.
|
|
555
|
+
const query = WhereExpression_1.WhereExpression.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/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
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
|
|
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 = [];
|
|
@@ -405,23 +405,31 @@ export default class WhereExpression {
|
|
|
405
405
|
* @param {string} columnName Column name
|
|
406
406
|
* @returns SQL statement
|
|
407
407
|
*/
|
|
408
|
-
public static makeSqlNormalizeCharVariants(expression: string, replaceOption
|
|
408
|
+
public static makeSqlNormalizeCharVariants(expression: string, replaceOption?: true | {
|
|
409
409
|
halfToFull?: boolean; hiraganaToKatakana?: boolean;
|
|
410
410
|
numeric?: true | { japanese?: boolean; }
|
|
411
411
|
}) {
|
|
412
|
-
if (replaceOption
|
|
412
|
+
if (replaceOption === true) {
|
|
413
|
+
replaceOption = {
|
|
414
|
+
halfToFull: true,
|
|
415
|
+
hiraganaToKatakana: true,
|
|
416
|
+
numeric: true
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
if (replaceOption?.numeric === true) {
|
|
413
421
|
replaceOption.numeric = {
|
|
414
422
|
japanese: true
|
|
415
423
|
}
|
|
416
424
|
}
|
|
417
425
|
|
|
418
426
|
const objs: { [key: string]: string } = {}
|
|
419
|
-
if (replaceOption
|
|
427
|
+
if (replaceOption?.hiraganaToKatakana === true) {
|
|
420
428
|
objs['あいうえおかきくけこさしすせそたちつてとなにぬねのはひふへほまみむめもやゆよらりるれろわをんゔがぎぐげござじずぜぞだぢづでどばびぶべぼぱぴぷぺぽぁぃぅぇぉゃゅょっー、。・「」゛゜']
|
|
421
429
|
= 'アイウエオカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワヲンヴガギグゲゴザジズゼゾダヂヅデドバビブベボパピプペポァィゥェォャュョッー、。・「」゛゜';
|
|
422
430
|
}
|
|
423
431
|
|
|
424
|
-
if (replaceOption
|
|
432
|
+
if (replaceOption?.numeric?.japanese === true) {
|
|
425
433
|
objs['零〇'] = '00';
|
|
426
434
|
objs['一壱弌'] = '111';
|
|
427
435
|
objs['二弐'] = '22';
|
|
@@ -434,7 +442,7 @@ export default class WhereExpression {
|
|
|
434
442
|
objs['九玖'] = '99';
|
|
435
443
|
}
|
|
436
444
|
|
|
437
|
-
if (replaceOption
|
|
445
|
+
if (replaceOption?.halfToFull === true) {
|
|
438
446
|
objs['0123456789'] = '0123456789';
|
|
439
447
|
objs['アイウエオカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワヲンヴガギグゲゴザジズゼゾダヂヅデドバビブベボパピプペポァィゥェォャュョッー、。・「」゛゜']
|
|
440
448
|
= 'アイウエオカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワヲンヴガギグゲゴザジズゼゾダヂヅデドハハビブベボパピプペポァィゥェォャュョッー、。・「」 ゙ ゚';
|
package/src/models/TableModel.ts
CHANGED
|
@@ -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';
|