pg-mvc-service 2.0.46 → 2.0.48

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.
@@ -202,6 +202,21 @@ class TableModel {
202
202
  return;
203
203
  }
204
204
  }
205
+ /**
206
+ * 指定されたカラム情報がNULLの場合に、指定された値に変換して選択します。
207
+ *
208
+ * @param columnInfo カラム情報。文字列または{name: string, model: TableModel}のオブジェクト。
209
+ * @param toValue NULLの場合に変換する値。
210
+ * @param alias 結果セットで使用するエイリアス名。
211
+ */
212
+ selectNullToValue(columnInfo, toValue, alias) {
213
+ this.vars.push(toValue);
214
+ if (typeof columnInfo === 'string') {
215
+ columnInfo = { name: columnInfo, model: this };
216
+ }
217
+ const column = columnInfo.model.getColumn(columnInfo.name);
218
+ this.selectExpressions.push(`COALESCE(${column.expression}, $${this.vars.length}) as "${alias}"`);
219
+ }
205
220
  /**
206
221
  * 指定された条件に基づいてテーブルを結合します。
207
222
  * @param joinType 結合の種類を指定します
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pg-mvc-service",
3
- "version": "2.0.46",
3
+ "version": "2.0.48",
4
4
  "description": "",
5
5
  "homepage": "https://github.com/n-daira/npm-pack_mvc-service#readme",
6
6
  "bugs": {
@@ -239,6 +239,24 @@ export class TableModel {
239
239
  }
240
240
  }
241
241
 
242
+ /**
243
+ * 指定されたカラム情報がNULLの場合に、指定された値に変換して選択します。
244
+ *
245
+ * @param columnInfo カラム情報。文字列または{name: string, model: TableModel}のオブジェクト。
246
+ * @param toValue NULLの場合に変換する値。
247
+ * @param alias 結果セットで使用するエイリアス名。
248
+ */
249
+ public selectNullToValue(columnInfo: string | {name: string, model: TableModel}, toValue: any, alias: string) {
250
+ this.vars.push(toValue);
251
+
252
+ if (typeof columnInfo === 'string') {
253
+ columnInfo = {name: columnInfo, model: this}
254
+ }
255
+
256
+ const column = columnInfo.model.getColumn(columnInfo.name);
257
+ this.selectExpressions.push(`COALESCE(${column.expression}, $${this.vars.length}) as "${alias}"`)
258
+ }
259
+
242
260
  /**
243
261
  * 指定された条件に基づいてテーブルを結合します。
244
262
  * @param joinType 結合の種類を指定します