@oino-ts/db 0.7.2 → 0.8.0
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/cjs/OINODb.js +1 -2
- package/dist/cjs/OINODbApi.js +24 -40
- package/dist/cjs/OINODbDataField.js +1 -8
- package/dist/cjs/OINODbDataModel.js +4 -9
- package/dist/cjs/OINODbFactory.js +1 -4
- package/dist/cjs/OINODbModelSet.js +4 -19
- package/dist/cjs/OINODbParser.js +15 -29
- package/dist/cjs/OINODbSqlParams.js +13 -18
- package/dist/esm/OINODb.js +2 -3
- package/dist/esm/OINODbApi.js +25 -41
- package/dist/esm/OINODbDataField.js +1 -8
- package/dist/esm/OINODbDataModel.js +5 -10
- package/dist/esm/OINODbFactory.js +2 -5
- package/dist/esm/OINODbModelSet.js +4 -19
- package/dist/esm/OINODbParser.js +15 -29
- package/dist/esm/OINODbSqlParams.js +13 -18
- package/dist/types/OINODbApi.d.ts +0 -1
- package/package.json +3 -3
- package/src/OINODb.ts +2 -3
- package/src/OINODbApi.test.ts +3 -22
- package/src/OINODbApi.ts +24 -39
- package/src/OINODbDataField.ts +1 -8
- package/src/OINODbDataModel.ts +4 -10
- package/src/OINODbFactory.ts +2 -6
- package/src/OINODbModelSet.ts +4 -20
- package/src/OINODbParser.ts +15 -29
- package/src/OINODbSqlParams.ts +13 -18
package/dist/cjs/OINODb.js
CHANGED
|
@@ -39,7 +39,6 @@ class OINODb {
|
|
|
39
39
|
*/
|
|
40
40
|
printSqlSelect(tableName, columnNames, whereCondition, orderCondition, limitCondition, groupByCondition) {
|
|
41
41
|
let result = "SELECT " + columnNames + " FROM " + tableName;
|
|
42
|
-
// OINOLog.debug("OINODb.printSqlSelect", {tableName:tableName, columnNames:columnNames, whereCondition:whereCondition, orderCondition:orderCondition, limitCondition:limitCondition })
|
|
43
42
|
if (whereCondition != "") {
|
|
44
43
|
result += " WHERE " + whereCondition;
|
|
45
44
|
}
|
|
@@ -53,7 +52,7 @@ class OINODb {
|
|
|
53
52
|
result += " LIMIT " + limitCondition;
|
|
54
53
|
}
|
|
55
54
|
result += ";";
|
|
56
|
-
|
|
55
|
+
index_js_1.OINOLog.debug("@oinots/db", "OINODb", "printSqlSelect", "Result", { sql: result });
|
|
57
56
|
return result;
|
|
58
57
|
}
|
|
59
58
|
}
|
package/dist/cjs/OINODbApi.js
CHANGED
|
@@ -106,22 +106,18 @@ class OINODbHtmlTemplate extends index_js_1.OINOHtmlTemplate {
|
|
|
106
106
|
const api = modelset.datamodel.api;
|
|
107
107
|
const modified_index = datamodel.findFieldIndexByName(api.params.cacheModifiedField || "");
|
|
108
108
|
let last_modified = this.modified;
|
|
109
|
-
// OINOLog.debug("OINOHtmlTemplate.renderFromDbData", {last_modified:last_modified})
|
|
110
109
|
while (!dataset.isEof()) {
|
|
111
110
|
const row = dataset.getRow();
|
|
112
111
|
if (modified_index >= 0) {
|
|
113
112
|
last_modified = Math.max(last_modified, new Date(row[modified_index]).getTime());
|
|
114
|
-
// OINOLog.debug("OINOHtmlTemplate.renderFromDbData", {last_modified:last_modified})
|
|
115
113
|
}
|
|
116
114
|
let row_id_seed = datamodel.getRowPrimarykeyValues(row).join(' ');
|
|
117
115
|
let primary_key_values = [];
|
|
118
116
|
this.clearVariables();
|
|
119
117
|
this.setVariableFromValue(index_js_1.OINODbConfig.OINODB_ID_FIELD, "");
|
|
120
|
-
// let html_row:string = this.template.replaceAll('###' + OINODbConfig.OINODB_ID_FIELD + '###', '###createHtmlFromData_temporary_oinoid###')
|
|
121
118
|
for (let i = 0; i < datamodel.fields.length; i++) {
|
|
122
119
|
const f = datamodel.fields[i];
|
|
123
120
|
let value;
|
|
124
|
-
// OINOLog.debug("OINOHtmlTemplate.renderFromDbData", {field:f.name, row_value:row[i], value_type:typeof row[i]})
|
|
125
121
|
if ((this._locale != null) && (f instanceof index_js_1.OINODatetimeDataField)) {
|
|
126
122
|
value = f.serializeCellWithLocale(row[i], this._locale);
|
|
127
123
|
}
|
|
@@ -136,16 +132,13 @@ class OINODbHtmlTemplate extends index_js_1.OINOHtmlTemplate {
|
|
|
136
132
|
primary_key_values.push(value || "");
|
|
137
133
|
}
|
|
138
134
|
}
|
|
139
|
-
// OINOLog.debug("renderFromDbData replace field value", {field:f.name, value:value })
|
|
140
135
|
this.setVariableFromValue(f.name, value || "");
|
|
141
136
|
}
|
|
142
137
|
this.setVariableFromProperties(overrideValues);
|
|
143
138
|
this.setVariableFromValue(index_js_1.OINODbConfig.OINODB_ID_FIELD, index_js_1.OINODbConfig.printOINOId(primary_key_values));
|
|
144
|
-
// html_row = html_row.replaceAll('###createHtmlFromData_temporary_oinoid###', OINOStr.encode(OINODbConfig.printOINOId(primary_key_values), OINOContentType.html))
|
|
145
139
|
html += this._renderHtml() + "\r\n";
|
|
146
140
|
await dataset.next();
|
|
147
141
|
}
|
|
148
|
-
// OINOLog.debug("OINOHtmlTemplate.renderFromDbData", {last_modified:last_modified})
|
|
149
142
|
this.modified = last_modified;
|
|
150
143
|
const result = this._createHttpResult(html, false);
|
|
151
144
|
index_js_1.OINOBenchmark.end("OINOHtmlTemplate", "renderFromDbData");
|
|
@@ -177,7 +170,6 @@ class OINODbApi {
|
|
|
177
170
|
*
|
|
178
171
|
*/
|
|
179
172
|
constructor(db, params) {
|
|
180
|
-
// OINOLog.debug("OINODbApi.constructor", {db:db, tableName:tableName, params:params})
|
|
181
173
|
if (!params.tableName) {
|
|
182
174
|
throw new Error(index_js_1.OINO_ERROR_PREFIX + ": OINODbApiParams needs to define a table name!");
|
|
183
175
|
}
|
|
@@ -191,26 +183,11 @@ class OINODbApi {
|
|
|
191
183
|
this.hashid = null;
|
|
192
184
|
}
|
|
193
185
|
}
|
|
194
|
-
_printSql(result, rows, requirePrimaryKey, printer) {
|
|
195
|
-
let sql = "";
|
|
196
|
-
for (let i = 0; i < rows.length; i++) {
|
|
197
|
-
this._validateRow(result, rows[i], requirePrimaryKey);
|
|
198
|
-
if (result.success) {
|
|
199
|
-
sql += printer(rows[i]);
|
|
200
|
-
}
|
|
201
|
-
else if (this.params.failOnAnyInvalidRows === false) {
|
|
202
|
-
result.setOk(); // individual rows may fail and will just be messages in response similar to executing multiple sql statements
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
return sql;
|
|
206
|
-
}
|
|
207
186
|
_validateRow(result, row, requirePrimaryKey) {
|
|
208
187
|
let field;
|
|
209
188
|
for (let i = 0; i < this.datamodel.fields.length; i++) {
|
|
210
189
|
field = this.datamodel.fields[i];
|
|
211
|
-
// OINOLog.debug("OINODbApi.validateHttpValues", {field:field})
|
|
212
190
|
const val = row[i];
|
|
213
|
-
// OINOLog.debug("OINODbApi.validateHttpValues", {val:val})
|
|
214
191
|
if ((val === null) && ((field.fieldParams.isNotNull) || (field.fieldParams.isPrimaryKey))) { // null is a valid SQL value except if it's not allowed
|
|
215
192
|
result.setError(405, "Field '" + field.name + "' is not allowed to be NULL!", "ValidateRowValues");
|
|
216
193
|
}
|
|
@@ -223,7 +200,6 @@ class OINODbApi {
|
|
|
223
200
|
else {
|
|
224
201
|
if ((field instanceof index_js_1.OINOStringDataField) && ((field.maxLength > 0))) {
|
|
225
202
|
const str_val = val?.toString() || "";
|
|
226
|
-
// OINOLog.debug("OINODbApi.validateHttpValues", {f:str_field, val:val})
|
|
227
203
|
if (str_val.length > field.maxLength) {
|
|
228
204
|
if (this.params.failOnOversizedValues) {
|
|
229
205
|
result.setError(405, "Field '" + field.name + "' length (" + str_val.length + ") exceeds maximum (" + field.maxLength + ") and can't be set!", "ValidateRowValues");
|
|
@@ -256,12 +232,13 @@ class OINODbApi {
|
|
|
256
232
|
let sql = "";
|
|
257
233
|
try {
|
|
258
234
|
sql = this.datamodel.printSqlSelect(id, params.sqlParams || {});
|
|
259
|
-
|
|
235
|
+
common_1.OINOLog.debug("@oinots/db", "OINODbApi", "_doGet", "Print SQL", { sql: sql });
|
|
260
236
|
const sql_res = await this.db.sqlSelect(sql);
|
|
261
|
-
// OINOLog.debug("OINODbApi.doGet sql_res", {sql_res:sql_res})
|
|
262
237
|
if (sql_res.hasErrors()) {
|
|
263
238
|
result.setError(500, sql_res.getFirstError(), "DoGet");
|
|
264
|
-
|
|
239
|
+
if (this._debugOnError) {
|
|
240
|
+
result.addDebug("OINO GET SQL [" + sql + "]", "DoPut");
|
|
241
|
+
}
|
|
265
242
|
}
|
|
266
243
|
else {
|
|
267
244
|
result.data = new index_js_1.OINODbModelSet(this.datamodel, sql_res, params.sqlParams);
|
|
@@ -269,7 +246,10 @@ class OINODbApi {
|
|
|
269
246
|
}
|
|
270
247
|
catch (e) {
|
|
271
248
|
result.setError(500, "Unhandled exception in doGet: " + e.message, "DoGet");
|
|
272
|
-
|
|
249
|
+
common_1.OINOLog.exception("@oinots/db", "OINODbApi", "_doGet", "Exception", { message: e.message, stack: e.stack });
|
|
250
|
+
if (this._debugOnError) {
|
|
251
|
+
result.addDebug("OINO GET SQL [" + sql + "]", "DoGet");
|
|
252
|
+
}
|
|
273
253
|
}
|
|
274
254
|
}
|
|
275
255
|
async _doPost(result, rows) {
|
|
@@ -288,7 +268,7 @@ class OINODbApi {
|
|
|
288
268
|
result.setError(405, "No valid rows for POST!", "DoPost");
|
|
289
269
|
}
|
|
290
270
|
else if (result.success) {
|
|
291
|
-
|
|
271
|
+
common_1.OINOLog.debug("@oinots/db", "OINODbApi", "_doPost", "Print SQL", { sql: sql });
|
|
292
272
|
const sql_res = await this.db.sqlExec(sql);
|
|
293
273
|
// OINOLog.debug("OINODbApi.doPost sql_res", {sql_res:sql_res})
|
|
294
274
|
if (sql_res.hasErrors()) {
|
|
@@ -302,7 +282,10 @@ class OINODbApi {
|
|
|
302
282
|
}
|
|
303
283
|
catch (e) {
|
|
304
284
|
result.setError(500, "Unhandled exception in doPost: " + e.message, "DoPost");
|
|
305
|
-
|
|
285
|
+
common_1.OINOLog.exception("@oinots/db", "OINODbApi", "_doGet", "Exception", { message: e.message, stack: e.stack });
|
|
286
|
+
if (this._debugOnError) {
|
|
287
|
+
result.addDebug("OINO POST SQL [" + sql + "]", "DoPost");
|
|
288
|
+
}
|
|
306
289
|
}
|
|
307
290
|
}
|
|
308
291
|
async _doPut(result, id, rows) {
|
|
@@ -323,9 +306,8 @@ class OINODbApi {
|
|
|
323
306
|
result.setError(405, "No valid rows for PUT!", "DoPut"); // only set error if there are multiple rows and no valid sql was created
|
|
324
307
|
}
|
|
325
308
|
else if (result.success) {
|
|
326
|
-
|
|
309
|
+
common_1.OINOLog.debug("@oinots/db", "OINODbApi", "_doPut", "Print SQL", { sql: sql });
|
|
327
310
|
const sql_res = await this.db.sqlExec(sql);
|
|
328
|
-
// OINOLog.debug("OINODbApi.doPut sql_res", {sql_res:sql_res})
|
|
329
311
|
if (sql_res.hasErrors()) {
|
|
330
312
|
result.setError(500, sql_res.getFirstError(), "DoPut");
|
|
331
313
|
if (this._debugOnError) {
|
|
@@ -337,7 +319,10 @@ class OINODbApi {
|
|
|
337
319
|
}
|
|
338
320
|
catch (e) {
|
|
339
321
|
result.setError(500, "Unhandled exception: " + e.message, "DoPut");
|
|
340
|
-
|
|
322
|
+
common_1.OINOLog.exception("@oinots/db", "OINODbApi", "_doGet", "Exception", { message: e.message, stack: e.stack });
|
|
323
|
+
if (this._debugOnError) {
|
|
324
|
+
result.addDebug("OINO POST SQL [" + sql + "]", "DoPut");
|
|
325
|
+
}
|
|
341
326
|
}
|
|
342
327
|
}
|
|
343
328
|
async _doDelete(result, id, rows) {
|
|
@@ -361,9 +346,8 @@ class OINODbApi {
|
|
|
361
346
|
result.setError(405, "No valid rows for DELETE!", "DoDelete"); // only set error if there are multiple rows and no valid sql was created
|
|
362
347
|
}
|
|
363
348
|
else if (result.success) {
|
|
364
|
-
|
|
349
|
+
common_1.OINOLog.debug("@oinots/db", "OINODbApi", "_doDelete", "Print SQL", { sql: sql });
|
|
365
350
|
const sql_res = await this.db.sqlExec(sql);
|
|
366
|
-
// OINOLog.debug("OINODbApi.doDelete sql_res", {sql_res:sql_res})
|
|
367
351
|
if (sql_res.hasErrors()) {
|
|
368
352
|
result.setError(500, sql_res.getFirstError(), "DoDelete");
|
|
369
353
|
if (this._debugOnError) {
|
|
@@ -375,7 +359,9 @@ class OINODbApi {
|
|
|
375
359
|
}
|
|
376
360
|
catch (e) {
|
|
377
361
|
result.setError(500, "Unhandled exception: " + e.message, "DoDelete");
|
|
378
|
-
|
|
362
|
+
if (this._debugOnError) {
|
|
363
|
+
result.addDebug("OINO DELETE SQL [" + sql + "]", "DoDelete");
|
|
364
|
+
}
|
|
379
365
|
}
|
|
380
366
|
}
|
|
381
367
|
/**
|
|
@@ -398,7 +384,7 @@ class OINODbApi {
|
|
|
398
384
|
*/
|
|
399
385
|
async doRequest(method, id, data, params = API_EMPTY_PARAMS) {
|
|
400
386
|
index_js_1.OINOBenchmark.start("OINODbApi", "doRequest");
|
|
401
|
-
|
|
387
|
+
common_1.OINOLog.debug("@oinots/db", "OINODbApi", "doRequest", "Request", { method: method, id: id, data: data });
|
|
402
388
|
let result = new OINODbApiResult(params);
|
|
403
389
|
let rows = [];
|
|
404
390
|
if ((method == "POST") || (method == "PUT")) {
|
|
@@ -432,7 +418,6 @@ class OINODbApi {
|
|
|
432
418
|
}
|
|
433
419
|
else {
|
|
434
420
|
try {
|
|
435
|
-
// OINOLog.debug("OINODbApi.doRequest / POST", {rows:rows})
|
|
436
421
|
await this._doPost(result, rows);
|
|
437
422
|
}
|
|
438
423
|
catch (e) {
|
|
@@ -470,7 +455,7 @@ class OINODbApi {
|
|
|
470
455
|
*/
|
|
471
456
|
async doBatchUpdate(method, data, params = API_EMPTY_PARAMS) {
|
|
472
457
|
index_js_1.OINOBenchmark.start("OINODbApi", "doBatchUpdate");
|
|
473
|
-
|
|
458
|
+
common_1.OINOLog.debug("@oinots/db", "OINODbApi", "doBatchUpdate", "Request", { method: method, data: data, params: params });
|
|
474
459
|
let result = new OINODbApiResult(params);
|
|
475
460
|
let rows = [];
|
|
476
461
|
if ((method == "PUT")) {
|
|
@@ -505,7 +490,6 @@ class OINODbApi {
|
|
|
505
490
|
*
|
|
506
491
|
*/
|
|
507
492
|
isFieldIncluded(fieldName) {
|
|
508
|
-
// OINOLog.debug("OINODbApi.isFieldIncluded", {fieldName:fieldName, included:this.params.includeFields})
|
|
509
493
|
const params = this.params;
|
|
510
494
|
return (((params.excludeFieldPrefix == undefined) || (params.excludeFieldPrefix == "") || (fieldName.startsWith(params.excludeFieldPrefix) == false)) &&
|
|
511
495
|
((params.excludeFields == undefined) || (params.excludeFields.length == 0) || (params.excludeFields.indexOf(fieldName) < 0)) &&
|
|
@@ -42,7 +42,6 @@ class OINODbDataField {
|
|
|
42
42
|
this.maxLength = maxLength;
|
|
43
43
|
this.sqlType = sqlType;
|
|
44
44
|
this.fieldParams = fieldParams;
|
|
45
|
-
// OINOLog.debug("OINODbDataField.constructor", {this:this})
|
|
46
45
|
}
|
|
47
46
|
/**
|
|
48
47
|
* Pring debug information for the field
|
|
@@ -248,7 +247,7 @@ class OINONumberDataField extends OINODbDataField {
|
|
|
248
247
|
else {
|
|
249
248
|
const result = parseFloat(value);
|
|
250
249
|
if (isNaN(result)) {
|
|
251
|
-
index_js_1.OINOLog.error("OINONumberDataField
|
|
250
|
+
index_js_1.OINOLog.error("@oinots/db", "OINONumberDataField", "toSql", "Invalid value!", { value: value });
|
|
252
251
|
throw new Error(index_js_1.OINO_ERROR_PREFIX + ": OINONumberDataField.deserializeCell - Invalid value '" + value + "'"); // incorrectly formatted data could be a security risk, abort processing
|
|
253
252
|
}
|
|
254
253
|
return result;
|
|
@@ -281,7 +280,6 @@ class OINOBlobDataField extends OINODbDataField {
|
|
|
281
280
|
*
|
|
282
281
|
*/
|
|
283
282
|
serializeCell(cellVal) {
|
|
284
|
-
// OINOLog.debug("OINOBlobDataField.serializeCell", {cellVal:cellVal})
|
|
285
283
|
if ((cellVal === null) || (cellVal === undefined)) {
|
|
286
284
|
return cellVal;
|
|
287
285
|
}
|
|
@@ -332,10 +330,8 @@ class OINODatetimeDataField extends OINODbDataField {
|
|
|
332
330
|
*
|
|
333
331
|
*/
|
|
334
332
|
serializeCell(cellVal) {
|
|
335
|
-
// OINOLog.debug("OINODatetimeDataField.serializeCell", {cellVal:cellVal, type:typeof(cellVal)})
|
|
336
333
|
if (typeof (cellVal) == "string") {
|
|
337
334
|
cellVal = this.db.parseSqlValueAsCell(cellVal, this.sqlType);
|
|
338
|
-
// OINOLog.debug("OINODatetimeDataField.serializeCell parsed", {cellVal:cellVal, type:typeof(cellVal)})
|
|
339
335
|
}
|
|
340
336
|
if ((cellVal === null) || (cellVal === undefined)) {
|
|
341
337
|
return cellVal;
|
|
@@ -355,10 +351,8 @@ class OINODatetimeDataField extends OINODbDataField {
|
|
|
355
351
|
*
|
|
356
352
|
*/
|
|
357
353
|
serializeCellWithLocale(cellVal, locale) {
|
|
358
|
-
// OINOLog.debug("OINODatetimeDataField.serializeCell", {cellVal:cellVal, type:typeof(cellVal)})
|
|
359
354
|
if (typeof (cellVal) == "string") {
|
|
360
355
|
cellVal = this.db.parseSqlValueAsCell(cellVal, this.sqlType);
|
|
361
|
-
// OINOLog.debug("OINODatetimeDataField.serializeCell parsed", {cellVal:cellVal, type:typeof(cellVal)})
|
|
362
356
|
}
|
|
363
357
|
if ((cellVal === null) || (cellVal === undefined)) {
|
|
364
358
|
return cellVal;
|
|
@@ -377,7 +371,6 @@ class OINODatetimeDataField extends OINODbDataField {
|
|
|
377
371
|
*
|
|
378
372
|
*/
|
|
379
373
|
deserializeCell(value) {
|
|
380
|
-
// OINOLog.debug("OINODatetimeDataField.deserializeCell", {strVal:strVal})
|
|
381
374
|
if ((value === null) || (value === undefined)) {
|
|
382
375
|
return value;
|
|
383
376
|
}
|
|
@@ -28,7 +28,6 @@ class OINODbDataModel {
|
|
|
28
28
|
this._columnLookup = {};
|
|
29
29
|
this.api = api;
|
|
30
30
|
this.fields = [];
|
|
31
|
-
// OINOLog_debug("OINODbDataModel (" + tableName + "):\n" + this._printTableDebug("\n"))
|
|
32
31
|
}
|
|
33
32
|
/**
|
|
34
33
|
* Initialize datamodel from SQL schema.
|
|
@@ -74,7 +73,6 @@ class OINODbDataModel {
|
|
|
74
73
|
for (let i = 0; i < this.fields.length; i++) {
|
|
75
74
|
const f = this.fields[i];
|
|
76
75
|
const val = row[i];
|
|
77
|
-
// OINOLog_debug("OINODbDataModel._printSqlUpdateValues", {field:f.name, primary_key:f.fieldParams.isPrimaryKey, val:val})
|
|
78
76
|
if ((!f.fieldParams.isPrimaryKey) && (val !== undefined)) {
|
|
79
77
|
if (result != "") {
|
|
80
78
|
result += ",";
|
|
@@ -101,7 +99,6 @@ class OINODbDataModel {
|
|
|
101
99
|
if (value == "") { // ids are user input and could be specially crafted to be empty
|
|
102
100
|
throw new Error(index_js_1.OINO_ERROR_PREFIX + ": empty condition for id '" + id_value + "' for table " + this.api.params.tableName);
|
|
103
101
|
}
|
|
104
|
-
// OINOLog.debug("OINODbDataModel._printSqlPrimaryKeyCondition", {field:f.name, value:value, id_value:id_value})
|
|
105
102
|
result += f.printSqlColumnName() + "=" + value;
|
|
106
103
|
i = i + 1;
|
|
107
104
|
}
|
|
@@ -128,7 +125,6 @@ class OINODbDataModel {
|
|
|
128
125
|
*
|
|
129
126
|
*/
|
|
130
127
|
findFieldByName(name) {
|
|
131
|
-
// OINOLog.debug("OINODbDataModel.findFieldByName", {_columnLookup:this._columnLookup})
|
|
132
128
|
const i = this._columnLookup[name];
|
|
133
129
|
if (i >= 0) {
|
|
134
130
|
return this.fields[i];
|
|
@@ -144,7 +140,6 @@ class OINODbDataModel {
|
|
|
144
140
|
*
|
|
145
141
|
*/
|
|
146
142
|
findFieldIndexByName(name) {
|
|
147
|
-
// OINOLog.debug("OINODbDataModel.findFieldIndexByName", {_columnLookup:this._columnLookup})
|
|
148
143
|
const i = this._columnLookup[name];
|
|
149
144
|
if (i >= 0) {
|
|
150
145
|
return i;
|
|
@@ -235,13 +230,11 @@ class OINODbDataModel {
|
|
|
235
230
|
else {
|
|
236
231
|
column_names = this._printSqlColumnNames(params.select);
|
|
237
232
|
}
|
|
238
|
-
// OINOLog.debug("OINODbDataModel.printSqlSelect", {column_names:column_names})
|
|
239
233
|
const order_sql = params.order?.toSql(this) || "";
|
|
240
234
|
const limit_sql = params.limit?.toSql(this) || "";
|
|
241
235
|
const filter_sql = params.filter?.toSql(this) || "";
|
|
242
236
|
const groupby_sql = params.aggregate?.toSql(this, params.select) || "";
|
|
243
237
|
let where_sql = "";
|
|
244
|
-
// OINOLog.debug("OINODbDataModel.printSqlSelect", {order_sql:order_sql, limit_sql:limit_sql, filter_sql:filter_sql, groupby_sql:groupby_sql})
|
|
245
238
|
if ((id != null) && (id != "") && (filter_sql != "")) {
|
|
246
239
|
where_sql = this._printSqlPrimaryKeyCondition(id) + " AND " + filter_sql;
|
|
247
240
|
}
|
|
@@ -252,7 +245,7 @@ class OINODbDataModel {
|
|
|
252
245
|
where_sql = filter_sql;
|
|
253
246
|
}
|
|
254
247
|
const result = this.api.db.printSqlSelect(this.api.params.tableName, column_names, where_sql, order_sql, limit_sql, groupby_sql);
|
|
255
|
-
|
|
248
|
+
index_js_1.OINOLog.debug("@oinots/db", "OINODbDataModel", "printSqlSelect", "Result", { sql: result });
|
|
256
249
|
return result;
|
|
257
250
|
}
|
|
258
251
|
/**
|
|
@@ -263,6 +256,7 @@ class OINODbDataModel {
|
|
|
263
256
|
*/
|
|
264
257
|
printSqlInsert(row) {
|
|
265
258
|
let result = "INSERT INTO " + this.api.db.printSqlTablename(this.api.params.tableName) + " " + this._printSqlInsertColumnsAndValues(row) + ";";
|
|
259
|
+
index_js_1.OINOLog.debug("@oinots/db", "OINODbDataModel", "printSqlInsert", "Result", { sql: result });
|
|
266
260
|
return result;
|
|
267
261
|
}
|
|
268
262
|
/**
|
|
@@ -274,7 +268,7 @@ class OINODbDataModel {
|
|
|
274
268
|
*/
|
|
275
269
|
printSqlUpdate(id, row) {
|
|
276
270
|
let result = "UPDATE " + this.api.db.printSqlTablename(this.api.params.tableName) + " SET " + this._printSqlUpdateValues(row) + " WHERE " + this._printSqlPrimaryKeyCondition(id) + ";";
|
|
277
|
-
|
|
271
|
+
index_js_1.OINOLog.debug("@oinots/db", "OINODbDataModel", "printSqlUpdate", "Result", { sql: result });
|
|
278
272
|
return result;
|
|
279
273
|
}
|
|
280
274
|
/**
|
|
@@ -285,6 +279,7 @@ class OINODbDataModel {
|
|
|
285
279
|
*/
|
|
286
280
|
printSqlDelete(id) {
|
|
287
281
|
let result = "DELETE FROM " + this.api.db.printSqlTablename(this.api.params.tableName) + " WHERE " + this._printSqlPrimaryKeyCondition(id) + ";";
|
|
282
|
+
index_js_1.OINOLog.debug("@oinots/db", "OINODbDataModel", "printSqlDelete", "Result", { sql: result });
|
|
288
283
|
return result;
|
|
289
284
|
}
|
|
290
285
|
}
|
|
@@ -21,7 +21,6 @@ class OINODbFactory {
|
|
|
21
21
|
* @param dbTypeClass constructor for creating a database of that type
|
|
22
22
|
*/
|
|
23
23
|
static registerDb(dbName, dbTypeClass) {
|
|
24
|
-
// OINOLog.debug("OINODbFactory.registerDb", {dbType:dbName})
|
|
25
24
|
this._dbRegistry[dbName] = dbTypeClass;
|
|
26
25
|
}
|
|
27
26
|
/**
|
|
@@ -109,12 +108,10 @@ class OINODbFactory {
|
|
|
109
108
|
result.requestType = index_js_1.OINOContentType.json;
|
|
110
109
|
}
|
|
111
110
|
const response_type = url.searchParams.get(index_js_1.OINODbConfig.OINODB_RESPONSE_TYPE) || request.headers.get("accept"); // accept header can be overridden by query parameter
|
|
112
|
-
// OINOLog.debug("createParamsFromRequest: accept headers", {accept:accept})
|
|
113
111
|
const accept_types = response_type?.split(', ') || [];
|
|
114
112
|
for (let i = 0; i < accept_types.length; i++) {
|
|
115
113
|
if (Object.values(index_js_1.OINOContentType).includes(accept_types[i])) {
|
|
116
114
|
result.responseType = accept_types[i];
|
|
117
|
-
// OINOLog.debug("createParamsFromRequest: response type found", {respnse_type:result.responseType})
|
|
118
115
|
break;
|
|
119
116
|
}
|
|
120
117
|
}
|
|
@@ -129,7 +126,7 @@ class OINODbFactory {
|
|
|
129
126
|
if (etags) {
|
|
130
127
|
result.etags = etags;
|
|
131
128
|
}
|
|
132
|
-
|
|
129
|
+
index_js_1.OINOLog.debug("@oinots/db", "OINODbFactory", "createParamsFromRequest", "Result", { params: result });
|
|
133
130
|
return result;
|
|
134
131
|
}
|
|
135
132
|
}
|
|
@@ -63,7 +63,7 @@ class OINODbModelSet {
|
|
|
63
63
|
}
|
|
64
64
|
let value = f.serializeCell(row[i]);
|
|
65
65
|
if (value === undefined) {
|
|
66
|
-
|
|
66
|
+
index_js_1.OINOLog.info("@oinots/db", "OINODbModelSet", "_writeRowJson", "Undefined value skipped", { field_name: f.name });
|
|
67
67
|
}
|
|
68
68
|
else if (value === null) {
|
|
69
69
|
json_row += "," + index_js_1.OINOStr.encode(f.name, index_js_1.OINOContentType.json) + ":null";
|
|
@@ -79,7 +79,6 @@ class OINODbModelSet {
|
|
|
79
79
|
}
|
|
80
80
|
}
|
|
81
81
|
json_row = index_js_1.OINOStr.encode(index_js_1.OINODbConfig.OINODB_ID_FIELD, index_js_1.OINOContentType.json) + ":" + index_js_1.OINOStr.encode(index_js_1.OINODbConfig.printOINOId(primary_key_values), index_js_1.OINOContentType.json) + json_row;
|
|
82
|
-
// OINOLog_debug("OINODbModelSet._writeRowJson="+json_row)
|
|
83
82
|
return "{" + json_row + "}";
|
|
84
83
|
}
|
|
85
84
|
async _writeStringJson() {
|
|
@@ -89,12 +88,10 @@ class OINODbModelSet {
|
|
|
89
88
|
result += ",\r\n";
|
|
90
89
|
}
|
|
91
90
|
const row = this.dataset.getRow();
|
|
92
|
-
// OINOLog.debug("OINODbModelSet._writeStringJson: row", {row:row})
|
|
93
91
|
result += this._writeRowJson(row);
|
|
94
92
|
await this.dataset.next();
|
|
95
93
|
}
|
|
96
94
|
result = "[\r\n" + result + "\r\n]";
|
|
97
|
-
// OINOLog_debug("OINODbModelSet._writeStringJson="+result)
|
|
98
95
|
return result;
|
|
99
96
|
}
|
|
100
97
|
_writeHeaderCsv() {
|
|
@@ -104,11 +101,9 @@ class OINODbModelSet {
|
|
|
104
101
|
for (let i = 0; i < fields.length; i++) {
|
|
105
102
|
csv_header += ",\"" + fields[i].name + "\"";
|
|
106
103
|
}
|
|
107
|
-
// OINOLog_debug("OINODbModelSet._writeHeaderCsv="+csv_header)
|
|
108
104
|
return csv_header;
|
|
109
105
|
}
|
|
110
106
|
_writeRowCsv(row) {
|
|
111
|
-
// OINOLog_debug("OINODbModelSet._writeRowCsv", {row:row})
|
|
112
107
|
const model = this.datamodel;
|
|
113
108
|
const fields = model.fields;
|
|
114
109
|
let row_id_seed = model.getRowPrimarykeyValues(row).join(' ');
|
|
@@ -129,7 +124,6 @@ class OINODbModelSet {
|
|
|
129
124
|
}
|
|
130
125
|
}
|
|
131
126
|
csv_row = index_js_1.OINOStr.encode(index_js_1.OINODbConfig.printOINOId(primary_key_values), index_js_1.OINOContentType.csv) + csv_row;
|
|
132
|
-
// OINOLog_debug("OINODbModelSet._writeRowCsv="+csv_row)
|
|
133
127
|
return csv_row;
|
|
134
128
|
}
|
|
135
129
|
async _writeStringCsv() {
|
|
@@ -139,11 +133,9 @@ class OINODbModelSet {
|
|
|
139
133
|
result += "\r\n";
|
|
140
134
|
}
|
|
141
135
|
const row = this.dataset.getRow();
|
|
142
|
-
// OINOLog.debug("OINODbModelSet._writeStringCsv: row", {row:row})
|
|
143
136
|
result += this._writeRowCsv(row);
|
|
144
137
|
await this.dataset.next();
|
|
145
138
|
}
|
|
146
|
-
// OINOLog_debug("OINODbModelSet._writeStringCsv="+result)
|
|
147
139
|
return result;
|
|
148
140
|
}
|
|
149
141
|
_writeRowFormdataParameterBlock(blockName, blockValue, multipartBoundary) {
|
|
@@ -158,7 +150,6 @@ class OINODbModelSet {
|
|
|
158
150
|
return multipartBoundary + "\r\n" + "Content-Disposition: form-data; name=\"" + blockName + "\"; filename=" + blockName + "\"\r\nContent-Type: application/octet-stream\r\nContent-Transfer-Encoding: BASE64\r\n\r\n" + blockValue + "\r\n";
|
|
159
151
|
}
|
|
160
152
|
_writeRowFormdata(row) {
|
|
161
|
-
// console.log("OINODbModelSet._writeRowFormdata: row", row)
|
|
162
153
|
const multipart_boundary = "---------OINOMultipartBoundary35424568"; // this method is just used for test data generation and we want it to be static
|
|
163
154
|
const model = this.datamodel;
|
|
164
155
|
const fields = model.fields;
|
|
@@ -174,7 +165,7 @@ class OINODbModelSet {
|
|
|
174
165
|
let formdata_block = "";
|
|
175
166
|
let is_file = (f instanceof index_js_1.OINOBlobDataField);
|
|
176
167
|
if (value === undefined) {
|
|
177
|
-
index_js_1.OINOLog.info("OINODbModelSet
|
|
168
|
+
index_js_1.OINOLog.info("@oinots/db", "OINODbModelSet", "_writeRowFormdata", "Undefined value skipped", { field_name: f.name });
|
|
178
169
|
}
|
|
179
170
|
else if (value === null) {
|
|
180
171
|
formdata_block = this._writeRowFormdataParameterBlock(fields[i].name, null, multipart_boundary);
|
|
@@ -188,7 +179,6 @@ class OINODbModelSet {
|
|
|
188
179
|
formdata_block = this._writeRowFormdataParameterBlock(fields[i].name, value, multipart_boundary);
|
|
189
180
|
}
|
|
190
181
|
}
|
|
191
|
-
// OINOLog.debug("OINODbModelSet._writeRowFormdata next block", {formdata_block:formdata_block})
|
|
192
182
|
result += formdata_block;
|
|
193
183
|
}
|
|
194
184
|
result = this._writeRowFormdataParameterBlock(index_js_1.OINODbConfig.OINODB_ID_FIELD, index_js_1.OINODbConfig.printOINOId(primary_key_values), multipart_boundary) + result;
|
|
@@ -196,12 +186,10 @@ class OINODbModelSet {
|
|
|
196
186
|
}
|
|
197
187
|
_writeStringFormdata() {
|
|
198
188
|
const row = this.dataset.getRow();
|
|
199
|
-
// OINOLog.debug("OINODbModelSet._writeStringFormdata: row", {row:row})
|
|
200
189
|
let result = this._writeRowFormdata(row);
|
|
201
190
|
return result;
|
|
202
191
|
}
|
|
203
192
|
_writeRowUrlencode(row) {
|
|
204
|
-
// console.log("OINODbModelSet._writeRowUrlencode row=" + row)
|
|
205
193
|
const model = this.datamodel;
|
|
206
194
|
const fields = model.fields;
|
|
207
195
|
let row_id_seed = model.getRowPrimarykeyValues(row).join(' ');
|
|
@@ -225,7 +213,6 @@ class OINODbModelSet {
|
|
|
225
213
|
}
|
|
226
214
|
}
|
|
227
215
|
urlencode_row = index_js_1.OINOStr.encode(index_js_1.OINODbConfig.OINODB_ID_FIELD, index_js_1.OINOContentType.urlencode) + "=" + index_js_1.OINOStr.encode(index_js_1.OINODbConfig.printOINOId(primary_key_values), index_js_1.OINOContentType.urlencode) + "&" + urlencode_row;
|
|
228
|
-
// OINOLog_debug("OINODbModelSet._writeRowCsv="+csv_row)
|
|
229
216
|
return urlencode_row;
|
|
230
217
|
}
|
|
231
218
|
async _writeStringUrlencode() {
|
|
@@ -233,14 +220,12 @@ class OINODbModelSet {
|
|
|
233
220
|
let line_count = 0;
|
|
234
221
|
while (!this.dataset.isEof()) {
|
|
235
222
|
const row = this.dataset.getRow();
|
|
236
|
-
// OINOLog.debug("OINODbModelSet._writeStringUrlencode: row", {row:row})
|
|
237
223
|
result += this._writeRowUrlencode(row) + "\r\n";
|
|
238
224
|
await this.dataset.next();
|
|
239
225
|
line_count += 1;
|
|
240
226
|
}
|
|
241
|
-
// OINOLog_debug("OINODbModelSet._writeStringCsv="+result)
|
|
242
227
|
if (line_count > 1) {
|
|
243
|
-
index_js_1.OINOLog.warning("OINODbModelSet
|
|
228
|
+
index_js_1.OINOLog.warning("@oinots/db", "OINODbModelSet", "_writeStringUrlencode", "Content type " + index_js_1.OINOContentType.urlencode + " does not officially support multiline content!", {});
|
|
244
229
|
}
|
|
245
230
|
return result;
|
|
246
231
|
}
|
|
@@ -265,7 +250,7 @@ class OINODbModelSet {
|
|
|
265
250
|
result += await this._writeStringUrlencode();
|
|
266
251
|
}
|
|
267
252
|
else {
|
|
268
|
-
index_js_1.OINOLog.error("OINODbModelSet
|
|
253
|
+
index_js_1.OINOLog.error("@oinots/db", "OINODbModelSet", "writeString", "Content type is only for input!", { contentType: contentType });
|
|
269
254
|
}
|
|
270
255
|
return result;
|
|
271
256
|
}
|