pg-mvc-service 2.0.47 → 2.0.49
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.
|
@@ -78,14 +78,18 @@ class SelectExpression {
|
|
|
78
78
|
* 指定された形式に変換されたSQLの文字列。
|
|
79
79
|
*/
|
|
80
80
|
static createDateTime(column, to) {
|
|
81
|
-
const
|
|
81
|
+
const columnInfo = column.model.getColumn(column.name);
|
|
82
|
+
// switch (column.type) {
|
|
83
|
+
if (['date', 'datetime', 'timestamp'].includes(columnInfo.type) !== false) {
|
|
84
|
+
return '';
|
|
85
|
+
}
|
|
82
86
|
switch (to) {
|
|
83
87
|
case 'date':
|
|
84
|
-
return `to_char(${
|
|
88
|
+
return `to_char(${columnInfo.expression}, 'YYYY-MM-DD')`;
|
|
85
89
|
case 'datetime':
|
|
86
|
-
return `to_char(${
|
|
90
|
+
return `to_char(${columnInfo.expression}, 'YYYY-MM-DD HH24:mi:ss')`;
|
|
87
91
|
case 'time':
|
|
88
|
-
return `to_char(${
|
|
92
|
+
return `to_char(${columnInfo.expression}, 'HH24:mi:ss')`;
|
|
89
93
|
}
|
|
90
94
|
}
|
|
91
95
|
}
|
|
@@ -209,7 +209,7 @@ class TableModel {
|
|
|
209
209
|
* @param toValue NULLの場合に変換する値。
|
|
210
210
|
* @param alias 結果セットで使用するエイリアス名。
|
|
211
211
|
*/
|
|
212
|
-
|
|
212
|
+
selectNullToValue(columnInfo, toValue, alias) {
|
|
213
213
|
this.vars.push(toValue);
|
|
214
214
|
if (typeof columnInfo === 'string') {
|
|
215
215
|
columnInfo = { name: columnInfo, model: this };
|
|
@@ -217,6 +217,21 @@ class TableModel {
|
|
|
217
217
|
const column = columnInfo.model.getColumn(columnInfo.name);
|
|
218
218
|
this.selectExpressions.push(`COALESCE(${column.expression}, $${this.vars.length}) as "${alias}"`);
|
|
219
219
|
}
|
|
220
|
+
/**
|
|
221
|
+
* 指定されたカラムを特定のフォーマットの日付情報に変換し、SELECT句で使用します。
|
|
222
|
+
*
|
|
223
|
+
* @param column カラム情報。文字列または{name: string, model: TableModel}のオブジェクト。
|
|
224
|
+
* @param to 変換先のフォーマットを指定します。'date'、'time'、'datetime'のいずれか。
|
|
225
|
+
* @param alias 結果セットで使用するエイリアス名。
|
|
226
|
+
*/
|
|
227
|
+
selectDateAsFormat(column, to, alias) {
|
|
228
|
+
column = typeof column === 'string' ? { name: column, model: this } : column;
|
|
229
|
+
const columnInfo = column.model.getColumn(column.name);
|
|
230
|
+
if (['date', 'datetime', 'timestamp'].includes(columnInfo.type) !== false) {
|
|
231
|
+
throw new Error('The first argument of the selectDateAsFormat method must specify a column of type date, datetime, or timestamp.');
|
|
232
|
+
}
|
|
233
|
+
this.selectExpressions.push(`${SelectExpression_1.default.createDateTime(column, to)} as "${alias}"`);
|
|
234
|
+
}
|
|
220
235
|
/**
|
|
221
236
|
* 指定された条件に基づいてテーブルを結合します。
|
|
222
237
|
* @param joinType 結合の種類を指定します
|
package/package.json
CHANGED
|
@@ -83,15 +83,21 @@ export default class SelectExpression {
|
|
|
83
83
|
* @returns The SQL string converted to the specified format.
|
|
84
84
|
* 指定された形式に変換されたSQLの文字列。
|
|
85
85
|
*/
|
|
86
|
-
static createDateTime(column:
|
|
87
|
-
const
|
|
86
|
+
public static createDateTime(column: TColumnInfo, to: 'date' | 'time' | 'datetime') {
|
|
87
|
+
const columnInfo = column.model.getColumn(column.name);
|
|
88
|
+
|
|
89
|
+
// switch (column.type) {
|
|
90
|
+
if (['date', 'datetime', 'timestamp'].includes(columnInfo.type) !== false) {
|
|
91
|
+
return '';
|
|
92
|
+
}
|
|
93
|
+
|
|
88
94
|
switch (to) {
|
|
89
95
|
case 'date':
|
|
90
|
-
return `to_char(${
|
|
96
|
+
return `to_char(${columnInfo.expression}, 'YYYY-MM-DD')`;
|
|
91
97
|
case 'datetime':
|
|
92
|
-
return `to_char(${
|
|
98
|
+
return `to_char(${columnInfo.expression}, 'YYYY-MM-DD HH24:mi:ss')`;
|
|
93
99
|
case 'time':
|
|
94
|
-
return `to_char(${
|
|
100
|
+
return `to_char(${columnInfo.expression}, 'HH24:mi:ss')`;
|
|
95
101
|
}
|
|
96
102
|
}
|
|
97
103
|
}
|
package/src/models/TableModel.ts
CHANGED
|
@@ -246,7 +246,7 @@ export class TableModel {
|
|
|
246
246
|
* @param toValue NULLの場合に変換する値。
|
|
247
247
|
* @param alias 結果セットで使用するエイリアス名。
|
|
248
248
|
*/
|
|
249
|
-
public
|
|
249
|
+
public selectNullToValue(columnInfo: string | {name: string, model: TableModel}, toValue: any, alias: string) {
|
|
250
250
|
this.vars.push(toValue);
|
|
251
251
|
|
|
252
252
|
if (typeof columnInfo === 'string') {
|
|
@@ -257,6 +257,24 @@ export class TableModel {
|
|
|
257
257
|
this.selectExpressions.push(`COALESCE(${column.expression}, $${this.vars.length}) as "${alias}"`)
|
|
258
258
|
}
|
|
259
259
|
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* 指定されたカラムを特定のフォーマットの日付情報に変換し、SELECT句で使用します。
|
|
263
|
+
*
|
|
264
|
+
* @param column カラム情報。文字列または{name: string, model: TableModel}のオブジェクト。
|
|
265
|
+
* @param to 変換先のフォーマットを指定します。'date'、'time'、'datetime'のいずれか。
|
|
266
|
+
* @param alias 結果セットで使用するエイリアス名。
|
|
267
|
+
*/
|
|
268
|
+
public selectDateAsFormat(column: string | {name: string, model: TableModel}, to: 'date' | 'time' | 'datetime', alias: string) {
|
|
269
|
+
column = typeof column === 'string' ? {name: column, model: this} : column;
|
|
270
|
+
const columnInfo = column.model.getColumn(column.name);
|
|
271
|
+
|
|
272
|
+
if (['date', 'datetime', 'timestamp'].includes(columnInfo.type) !== false) {
|
|
273
|
+
throw new Error('The first argument of the selectDateAsFormat method must specify a column of type date, datetime, or timestamp.');
|
|
274
|
+
}
|
|
275
|
+
this.selectExpressions.push(`${SelectExpression.createDateTime(column, to)} as "${alias}"`);
|
|
276
|
+
}
|
|
277
|
+
|
|
260
278
|
/**
|
|
261
279
|
* 指定された条件に基づいてテーブルを結合します。
|
|
262
280
|
* @param joinType 結合の種類を指定します
|