pg-mvc-service 2.0.22 → 2.0.24
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/models/TableModel.js +2 -0
- package/index.d.ts +3 -0
- package/package.json +2 -1
- package/src/cron/BaseCron.ts +37 -0
- package/src/cron/CronExecuter.ts +34 -0
- package/src/cron/TimeType.ts +25 -0
- package/src/index.ts +5 -1
- package/src/models/TableModel.ts +2 -1
|
@@ -315,10 +315,12 @@ class TableModel {
|
|
|
315
315
|
}
|
|
316
316
|
this.Limit = pageCount;
|
|
317
317
|
this.Offset = (currentPage - 1) * pageCount;
|
|
318
|
+
const tempVars = [...this.vars];
|
|
318
319
|
const tempWhereExpression = [...this.whereExpressions];
|
|
319
320
|
const tempJoinConditions = [...this.joinConditions];
|
|
320
321
|
let sql = ` SELECT ${this.selectExpressions.join(",")} ${this.createSqlFromJoinWhereSortLimit}`;
|
|
321
322
|
const data = yield this.executeQuery(sql, this.vars);
|
|
323
|
+
this.vars = tempVars;
|
|
322
324
|
this.whereExpressions = tempWhereExpression;
|
|
323
325
|
this.joinConditions = tempJoinConditions;
|
|
324
326
|
let countSql = ` SELECT COUNT(*) as "count" ${this.createSqlFromJoinWhere}`;
|
package/index.d.ts
CHANGED
|
@@ -22,6 +22,9 @@ export { TableModel } from "./src/models/TableModel";
|
|
|
22
22
|
|
|
23
23
|
export { TColumnAttribute, TColumnType, TColumnArrayType, TColumn, TColumnDetail, TOperator, TColumnInfo, TQuery, TSelectExpression, TAggregateFuncType, TCondition, TNestedCondition, TSortKeyword, TKeyFormat } from './src/models/Type';
|
|
24
24
|
|
|
25
|
+
export { BaseCron } from "./src/cron/BaseCron";
|
|
26
|
+
export { runCron } from "./src/cron/CronExecuter";
|
|
27
|
+
|
|
25
28
|
declare module 'pg-mvc-service' {
|
|
26
29
|
export class Service {
|
|
27
30
|
protected readonly method: MethodType;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pg-mvc-service",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.24",
|
|
4
4
|
"description": "",
|
|
5
5
|
"homepage": "https://github.com/n-daira/npm-pack_mvc-service#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
"@types/express": "5.0.1",
|
|
31
31
|
"axios": "1.10.0",
|
|
32
32
|
"crypto": "1.0.1",
|
|
33
|
+
"node-cron": "4.2.1",
|
|
33
34
|
"pdf-lib": "1.17.1",
|
|
34
35
|
"sharp": "0.34.1",
|
|
35
36
|
"type-utils-n-daira": "1.0.11"
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { DateType, DayType, HourType, MinuteSecondType, MonthType } from "./TimeType";
|
|
2
|
+
|
|
3
|
+
export class BaseCron {
|
|
4
|
+
|
|
5
|
+
// **********************************************************************
|
|
6
|
+
// こちらのメソッド、プロパティを各サブクラスで設定してください
|
|
7
|
+
// **********************************************************************
|
|
8
|
+
protected cronCode: string = '';
|
|
9
|
+
protected minute: MinuteSecondType | '*' = '*';
|
|
10
|
+
protected hour: HourType | '*' = '*';
|
|
11
|
+
protected date: DateType | '*' = '*';
|
|
12
|
+
protected month: MonthType | '*' = '*';
|
|
13
|
+
protected day: DayType | '*' = '*';
|
|
14
|
+
public async run() { }
|
|
15
|
+
|
|
16
|
+
// **********************************************************************
|
|
17
|
+
// ベースクラスで設定
|
|
18
|
+
// **********************************************************************
|
|
19
|
+
get CronSchedule(): string {
|
|
20
|
+
let schedule = '';
|
|
21
|
+
schedule += this.minute.toString() + ' ';
|
|
22
|
+
schedule += this.hour.toString() + ' ';
|
|
23
|
+
schedule += this.date.toString() + ' ';
|
|
24
|
+
schedule += this.month.toString() + ' ';
|
|
25
|
+
schedule += this.day.toString();
|
|
26
|
+
return schedule;
|
|
27
|
+
}
|
|
28
|
+
get CronCode(): string { return this.cronCode; }
|
|
29
|
+
|
|
30
|
+
public async setUp() {
|
|
31
|
+
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
public async tearDown() {
|
|
35
|
+
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
const cron = require('node-cron');
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import { BaseCron } from "./BaseCron";
|
|
5
|
+
|
|
6
|
+
export const runCron = async (dir: string, logCallback?: (ex: Error) => Promise<void>) => {
|
|
7
|
+
const files = fs.readdirSync(dir);
|
|
8
|
+
for (let file of files) {
|
|
9
|
+
if (['BaseCron.ts'].includes(file)) {
|
|
10
|
+
continue;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const filePath = path.join(dir, file);
|
|
14
|
+
const module = await import(`./${filePath.replace('src/', '').replace('.ts', '')}`);
|
|
15
|
+
const cronClass = module.default;
|
|
16
|
+
const cronInstance: BaseCron = new cronClass();
|
|
17
|
+
|
|
18
|
+
cron.schedule(cronInstance.CronSchedule, async () => {
|
|
19
|
+
try {
|
|
20
|
+
await cronInstance.setUp();
|
|
21
|
+
await cronInstance.run();
|
|
22
|
+
} catch (ex: unknown) {
|
|
23
|
+
if (logCallback !== undefined && ex instanceof Error) {
|
|
24
|
+
await logCallback(ex).
|
|
25
|
+
catch(() => {
|
|
26
|
+
// ログ送信時にエラーになっても握りつぶす
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
} finally {
|
|
30
|
+
await cronInstance.tearDown();
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export type DayType =
|
|
2
|
+
1 | 2 | 3 | 4 | 5 | 6 | 7
|
|
3
|
+
|
|
4
|
+
export type MonthType =
|
|
5
|
+
1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
|
|
6
|
+
10 | 11 | 12
|
|
7
|
+
|
|
8
|
+
export type DateType =
|
|
9
|
+
1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
|
|
10
|
+
10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 |
|
|
11
|
+
20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 |
|
|
12
|
+
30 | 31
|
|
13
|
+
|
|
14
|
+
export type HourType =
|
|
15
|
+
0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
|
|
16
|
+
10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 |
|
|
17
|
+
20 | 21 | 22 | 23
|
|
18
|
+
|
|
19
|
+
export type MinuteSecondType =
|
|
20
|
+
0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
|
|
21
|
+
10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 |
|
|
22
|
+
20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 |
|
|
23
|
+
30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 |
|
|
24
|
+
40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 |
|
|
25
|
+
50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59
|
package/src/index.ts
CHANGED
|
@@ -15,4 +15,8 @@ export { TableModel } from './models/TableModel';
|
|
|
15
15
|
export { createTableDoc } from './models/TableDoc';
|
|
16
16
|
export { MigrateTable } from './models/MigrateTable';
|
|
17
17
|
export { MigrateDatabase } from './models/MigrateDatabase';
|
|
18
|
-
export { migrate, rollback } from './models/MigrateRollback';
|
|
18
|
+
export { migrate, rollback } from './models/MigrateRollback';
|
|
19
|
+
|
|
20
|
+
// cron
|
|
21
|
+
export { BaseCron } from './cron/BaseCron';
|
|
22
|
+
export { runCron } from './cron/CronExecuter';
|
package/src/models/TableModel.ts
CHANGED
|
@@ -371,13 +371,14 @@ export class TableModel {
|
|
|
371
371
|
this.Offset = (currentPage - 1) * pageCount;
|
|
372
372
|
|
|
373
373
|
|
|
374
|
+
const tempVars = [...this.vars];
|
|
374
375
|
const tempWhereExpression = [...this.whereExpressions];
|
|
375
376
|
const tempJoinConditions = [...this.joinConditions];
|
|
376
377
|
|
|
377
378
|
let sql = ` SELECT ${this.selectExpressions.join(",")} ${this.createSqlFromJoinWhereSortLimit}`;
|
|
378
379
|
const data = await this.executeQuery(sql, this.vars);
|
|
379
380
|
|
|
380
|
-
|
|
381
|
+
this.vars = tempVars;
|
|
381
382
|
this.whereExpressions = tempWhereExpression;
|
|
382
383
|
this.joinConditions = tempJoinConditions;
|
|
383
384
|
let countSql = ` SELECT COUNT(*) as "count" ${this.createSqlFromJoinWhere}`;
|