@oino-ts/db 0.10.3 → 0.11.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 +0 -1
- package/dist/cjs/OINODbApi.js +7 -7
- package/dist/cjs/OINODbDataModel.js +0 -4
- package/dist/esm/OINODb.js +1 -2
- package/dist/esm/OINODbApi.js +7 -7
- package/dist/esm/OINODbDataModel.js +1 -5
- package/dist/types/OINODbApi.d.ts +3 -3
- package/dist/types/index.d.ts +0 -1
- package/package.json +6 -5
- package/src/OINODb.ts +0 -1
- package/src/OINODbApi.ts +7 -7
- package/src/OINODbDataModel.ts +0 -4
- package/src/index.ts +0 -1
package/dist/cjs/OINODb.js
CHANGED
package/dist/cjs/OINODbApi.js
CHANGED
|
@@ -63,17 +63,17 @@ class OINODbHtmlTemplate extends index_js_1.OINOHtmlTemplate {
|
|
|
63
63
|
static LOCALE_REGEX = /^(\w\w)(\-\w\w)?$/;
|
|
64
64
|
/** Locale formatter */
|
|
65
65
|
_locale;
|
|
66
|
-
|
|
66
|
+
_numberDecimals = -1;
|
|
67
67
|
/**
|
|
68
68
|
* Constructor of OINODbHtmlTemplate.
|
|
69
69
|
*
|
|
70
70
|
* @param template HTML template string
|
|
71
|
-
* @param
|
|
71
|
+
* @param numberDecimals Number of decimals to use for numbers, -1 for no formatting
|
|
72
72
|
* @param dateLocaleStr Datetime format string, either "iso" for ISO8601 or "default" for system default or valid locale string
|
|
73
73
|
* @param dateLocaleStyle Datetime format style, either "short/medium/long/full" or Intl.DateTimeFormat options
|
|
74
74
|
*
|
|
75
75
|
*/
|
|
76
|
-
constructor(template,
|
|
76
|
+
constructor(template, numberDecimals = -1, dateLocaleStr = "", dateLocaleStyle = "") {
|
|
77
77
|
super(template);
|
|
78
78
|
let locale_opts;
|
|
79
79
|
if ((dateLocaleStyle == null) || (dateLocaleStyle == "")) {
|
|
@@ -86,7 +86,7 @@ class OINODbHtmlTemplate extends index_js_1.OINOHtmlTemplate {
|
|
|
86
86
|
locale_opts = dateLocaleStyle;
|
|
87
87
|
}
|
|
88
88
|
this._locale = null;
|
|
89
|
-
this.
|
|
89
|
+
this._numberDecimals = numberDecimals;
|
|
90
90
|
if ((dateLocaleStr != null) && (dateLocaleStr != "") && OINODbHtmlTemplate.LOCALE_REGEX.test(dateLocaleStr)) {
|
|
91
91
|
try {
|
|
92
92
|
this._locale = new Intl.DateTimeFormat(dateLocaleStr, locale_opts);
|
|
@@ -124,8 +124,9 @@ class OINODbHtmlTemplate extends index_js_1.OINOHtmlTemplate {
|
|
|
124
124
|
if ((f instanceof index_js_1.OINODatetimeDataField) && (this._locale != null)) {
|
|
125
125
|
value = f.serializeCellWithLocale(row[i], this._locale);
|
|
126
126
|
}
|
|
127
|
-
else if ((f instanceof index_js_1.OINONumberDataField) && (this.
|
|
128
|
-
value
|
|
127
|
+
else if ((f instanceof index_js_1.OINONumberDataField) && (this._numberDecimals >= 0) && (typeof row[i] === "number")) {
|
|
128
|
+
// console.debug("renderFromDbData number decimals", { field: f.name, value: row[i], type: typeof row[i] });
|
|
129
|
+
value = row[i].toFixed(this._numberDecimals);
|
|
129
130
|
}
|
|
130
131
|
else {
|
|
131
132
|
value = f.serializeCell(row[i]);
|
|
@@ -276,7 +277,6 @@ class OINODbApi {
|
|
|
276
277
|
else if (result.success) {
|
|
277
278
|
common_1.OINOLog.debug("@oino-ts/db", "OINODbApi", "_doPost", "Print SQL", { sql: sql });
|
|
278
279
|
const sql_res = await this.db.sqlExec(sql);
|
|
279
|
-
// OINOLog.debug("OINODbApi.doPost sql_res", {sql_res:sql_res})
|
|
280
280
|
if (sql_res.hasErrors()) {
|
|
281
281
|
result.setError(500, sql_res.getFirstError(), "DoPost");
|
|
282
282
|
if (this._debugOnError) {
|
|
@@ -245,7 +245,6 @@ class OINODbDataModel {
|
|
|
245
245
|
where_sql = filter_sql;
|
|
246
246
|
}
|
|
247
247
|
const result = this.api.db.printSqlSelect(this.api.params.tableName, column_names, where_sql, order_sql, limit_sql, groupby_sql);
|
|
248
|
-
index_js_1.OINOLog.debug("@oino-ts/db", "OINODbDataModel", "printSqlSelect", "Result", { sql: result });
|
|
249
248
|
return result;
|
|
250
249
|
}
|
|
251
250
|
/**
|
|
@@ -256,7 +255,6 @@ class OINODbDataModel {
|
|
|
256
255
|
*/
|
|
257
256
|
printSqlInsert(row) {
|
|
258
257
|
let result = "INSERT INTO " + this.api.db.printSqlTablename(this.api.params.tableName) + " " + this._printSqlInsertColumnsAndValues(row) + ";";
|
|
259
|
-
index_js_1.OINOLog.debug("@oino-ts/db", "OINODbDataModel", "printSqlInsert", "Result", { sql: result });
|
|
260
258
|
return result;
|
|
261
259
|
}
|
|
262
260
|
/**
|
|
@@ -268,7 +266,6 @@ class OINODbDataModel {
|
|
|
268
266
|
*/
|
|
269
267
|
printSqlUpdate(id, row) {
|
|
270
268
|
let result = "UPDATE " + this.api.db.printSqlTablename(this.api.params.tableName) + " SET " + this._printSqlUpdateValues(row) + " WHERE " + this._printSqlPrimaryKeyCondition(id) + ";";
|
|
271
|
-
index_js_1.OINOLog.debug("@oino-ts/db", "OINODbDataModel", "printSqlUpdate", "Result", { sql: result });
|
|
272
269
|
return result;
|
|
273
270
|
}
|
|
274
271
|
/**
|
|
@@ -279,7 +276,6 @@ class OINODbDataModel {
|
|
|
279
276
|
*/
|
|
280
277
|
printSqlDelete(id) {
|
|
281
278
|
let result = "DELETE FROM " + this.api.db.printSqlTablename(this.api.params.tableName) + " WHERE " + this._printSqlPrimaryKeyCondition(id) + ";";
|
|
282
|
-
index_js_1.OINOLog.debug("@oino-ts/db", "OINODbDataModel", "printSqlDelete", "Result", { sql: result });
|
|
283
279
|
return result;
|
|
284
280
|
}
|
|
285
281
|
}
|
package/dist/esm/OINODb.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
4
4
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
5
5
|
*/
|
|
6
|
-
import { OINO_ERROR_PREFIX, OINODB_EMPTY_ROW
|
|
6
|
+
import { OINO_ERROR_PREFIX, OINODB_EMPTY_ROW } from "./index.js";
|
|
7
7
|
/**
|
|
8
8
|
* Base class for database abstraction, implementing methods for connecting, making queries and parsing/formatting data
|
|
9
9
|
* between SQL and serialization formats.
|
|
@@ -49,7 +49,6 @@ export class OINODb {
|
|
|
49
49
|
result += " LIMIT " + limitCondition;
|
|
50
50
|
}
|
|
51
51
|
result += ";";
|
|
52
|
-
OINOLog.debug("@oino-ts/db", "OINODb", "printSqlSelect", "Result", { sql: result });
|
|
53
52
|
return result;
|
|
54
53
|
}
|
|
55
54
|
}
|
package/dist/esm/OINODbApi.js
CHANGED
|
@@ -59,17 +59,17 @@ export class OINODbHtmlTemplate extends OINOHtmlTemplate {
|
|
|
59
59
|
static LOCALE_REGEX = /^(\w\w)(\-\w\w)?$/;
|
|
60
60
|
/** Locale formatter */
|
|
61
61
|
_locale;
|
|
62
|
-
|
|
62
|
+
_numberDecimals = -1;
|
|
63
63
|
/**
|
|
64
64
|
* Constructor of OINODbHtmlTemplate.
|
|
65
65
|
*
|
|
66
66
|
* @param template HTML template string
|
|
67
|
-
* @param
|
|
67
|
+
* @param numberDecimals Number of decimals to use for numbers, -1 for no formatting
|
|
68
68
|
* @param dateLocaleStr Datetime format string, either "iso" for ISO8601 or "default" for system default or valid locale string
|
|
69
69
|
* @param dateLocaleStyle Datetime format style, either "short/medium/long/full" or Intl.DateTimeFormat options
|
|
70
70
|
*
|
|
71
71
|
*/
|
|
72
|
-
constructor(template,
|
|
72
|
+
constructor(template, numberDecimals = -1, dateLocaleStr = "", dateLocaleStyle = "") {
|
|
73
73
|
super(template);
|
|
74
74
|
let locale_opts;
|
|
75
75
|
if ((dateLocaleStyle == null) || (dateLocaleStyle == "")) {
|
|
@@ -82,7 +82,7 @@ export class OINODbHtmlTemplate extends OINOHtmlTemplate {
|
|
|
82
82
|
locale_opts = dateLocaleStyle;
|
|
83
83
|
}
|
|
84
84
|
this._locale = null;
|
|
85
|
-
this.
|
|
85
|
+
this._numberDecimals = numberDecimals;
|
|
86
86
|
if ((dateLocaleStr != null) && (dateLocaleStr != "") && OINODbHtmlTemplate.LOCALE_REGEX.test(dateLocaleStr)) {
|
|
87
87
|
try {
|
|
88
88
|
this._locale = new Intl.DateTimeFormat(dateLocaleStr, locale_opts);
|
|
@@ -120,8 +120,9 @@ export class OINODbHtmlTemplate extends OINOHtmlTemplate {
|
|
|
120
120
|
if ((f instanceof OINODatetimeDataField) && (this._locale != null)) {
|
|
121
121
|
value = f.serializeCellWithLocale(row[i], this._locale);
|
|
122
122
|
}
|
|
123
|
-
else if ((f instanceof OINONumberDataField) && (this.
|
|
124
|
-
value
|
|
123
|
+
else if ((f instanceof OINONumberDataField) && (this._numberDecimals >= 0) && (typeof row[i] === "number")) {
|
|
124
|
+
// console.debug("renderFromDbData number decimals", { field: f.name, value: row[i], type: typeof row[i] });
|
|
125
|
+
value = row[i].toFixed(this._numberDecimals);
|
|
125
126
|
}
|
|
126
127
|
else {
|
|
127
128
|
value = f.serializeCell(row[i]);
|
|
@@ -271,7 +272,6 @@ export class OINODbApi {
|
|
|
271
272
|
else if (result.success) {
|
|
272
273
|
OINOLog.debug("@oino-ts/db", "OINODbApi", "_doPost", "Print SQL", { sql: sql });
|
|
273
274
|
const sql_res = await this.db.sqlExec(sql);
|
|
274
|
-
// OINOLog.debug("OINODbApi.doPost sql_res", {sql_res:sql_res})
|
|
275
275
|
if (sql_res.hasErrors()) {
|
|
276
276
|
result.setError(500, sql_res.getFirstError(), "DoPost");
|
|
277
277
|
if (this._debugOnError) {
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
4
4
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
5
5
|
*/
|
|
6
|
-
import { OINO_ERROR_PREFIX, OINODbConfig, OINONumberDataField,
|
|
6
|
+
import { OINO_ERROR_PREFIX, OINODbConfig, OINONumberDataField, OINODB_UNDEFINED } from "./index.js";
|
|
7
7
|
/**
|
|
8
8
|
* OINO Datamodel object for representing one database table and it's columns.
|
|
9
9
|
*
|
|
@@ -242,7 +242,6 @@ export class OINODbDataModel {
|
|
|
242
242
|
where_sql = filter_sql;
|
|
243
243
|
}
|
|
244
244
|
const result = this.api.db.printSqlSelect(this.api.params.tableName, column_names, where_sql, order_sql, limit_sql, groupby_sql);
|
|
245
|
-
OINOLog.debug("@oino-ts/db", "OINODbDataModel", "printSqlSelect", "Result", { sql: result });
|
|
246
245
|
return result;
|
|
247
246
|
}
|
|
248
247
|
/**
|
|
@@ -253,7 +252,6 @@ export class OINODbDataModel {
|
|
|
253
252
|
*/
|
|
254
253
|
printSqlInsert(row) {
|
|
255
254
|
let result = "INSERT INTO " + this.api.db.printSqlTablename(this.api.params.tableName) + " " + this._printSqlInsertColumnsAndValues(row) + ";";
|
|
256
|
-
OINOLog.debug("@oino-ts/db", "OINODbDataModel", "printSqlInsert", "Result", { sql: result });
|
|
257
255
|
return result;
|
|
258
256
|
}
|
|
259
257
|
/**
|
|
@@ -265,7 +263,6 @@ export class OINODbDataModel {
|
|
|
265
263
|
*/
|
|
266
264
|
printSqlUpdate(id, row) {
|
|
267
265
|
let result = "UPDATE " + this.api.db.printSqlTablename(this.api.params.tableName) + " SET " + this._printSqlUpdateValues(row) + " WHERE " + this._printSqlPrimaryKeyCondition(id) + ";";
|
|
268
|
-
OINOLog.debug("@oino-ts/db", "OINODbDataModel", "printSqlUpdate", "Result", { sql: result });
|
|
269
266
|
return result;
|
|
270
267
|
}
|
|
271
268
|
/**
|
|
@@ -276,7 +273,6 @@ export class OINODbDataModel {
|
|
|
276
273
|
*/
|
|
277
274
|
printSqlDelete(id) {
|
|
278
275
|
let result = "DELETE FROM " + this.api.db.printSqlTablename(this.api.params.tableName) + " WHERE " + this._printSqlPrimaryKeyCondition(id) + ";";
|
|
279
|
-
OINOLog.debug("@oino-ts/db", "OINODbDataModel", "printSqlDelete", "Result", { sql: result });
|
|
280
276
|
return result;
|
|
281
277
|
}
|
|
282
278
|
}
|
|
@@ -38,17 +38,17 @@ export declare class OINODbHtmlTemplate extends OINOHtmlTemplate {
|
|
|
38
38
|
static LOCALE_REGEX: RegExp;
|
|
39
39
|
/** Locale formatter */
|
|
40
40
|
protected _locale: Intl.DateTimeFormat | null;
|
|
41
|
-
protected
|
|
41
|
+
protected _numberDecimals: number;
|
|
42
42
|
/**
|
|
43
43
|
* Constructor of OINODbHtmlTemplate.
|
|
44
44
|
*
|
|
45
45
|
* @param template HTML template string
|
|
46
|
-
* @param
|
|
46
|
+
* @param numberDecimals Number of decimals to use for numbers, -1 for no formatting
|
|
47
47
|
* @param dateLocaleStr Datetime format string, either "iso" for ISO8601 or "default" for system default or valid locale string
|
|
48
48
|
* @param dateLocaleStyle Datetime format style, either "short/medium/long/full" or Intl.DateTimeFormat options
|
|
49
49
|
*
|
|
50
50
|
*/
|
|
51
|
-
constructor(template: string,
|
|
51
|
+
constructor(template: string, numberDecimals?: number, dateLocaleStr?: string, dateLocaleStyle?: string | any);
|
|
52
52
|
/**
|
|
53
53
|
* Creates HTML Response from API modelset.
|
|
54
54
|
*
|
package/dist/types/index.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oino-ts/db",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.0",
|
|
4
4
|
"description": "OINO TS library package for publishing an SQL database tables as a REST API.",
|
|
5
5
|
"author": "Matias Kiviniemi (pragmatta)",
|
|
6
6
|
"license": "MPL-2.0",
|
|
@@ -19,13 +19,14 @@
|
|
|
19
19
|
"module": "./dist/esm/index.js",
|
|
20
20
|
"types": "./dist/types/index.d.ts",
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@oino-ts/common": "0.
|
|
22
|
+
"@oino-ts/common": "0.11.0",
|
|
23
|
+
"oino-ts": "file:.."
|
|
23
24
|
},
|
|
24
25
|
"devDependencies": {
|
|
25
|
-
"@types
|
|
26
|
+
"@oino-ts/types": "0.11.0",
|
|
26
27
|
"@types/bun": "^1.1.14",
|
|
27
|
-
"@
|
|
28
|
-
"
|
|
28
|
+
"@types/node": "^20.14.10",
|
|
29
|
+
"typescript": "~5.9.0"
|
|
29
30
|
},
|
|
30
31
|
"files": [
|
|
31
32
|
"src/*.ts",
|
package/src/OINODb.ts
CHANGED
package/src/OINODbApi.ts
CHANGED
|
@@ -65,18 +65,18 @@ export class OINODbHtmlTemplate extends OINOHtmlTemplate {
|
|
|
65
65
|
static LOCALE_REGEX:RegExp = /^(\w\w)(\-\w\w)?$/
|
|
66
66
|
/** Locale formatter */
|
|
67
67
|
protected _locale:Intl.DateTimeFormat|null
|
|
68
|
-
protected
|
|
68
|
+
protected _numberDecimals:number = -1
|
|
69
69
|
|
|
70
70
|
/**
|
|
71
71
|
* Constructor of OINODbHtmlTemplate.
|
|
72
72
|
*
|
|
73
73
|
* @param template HTML template string
|
|
74
|
-
* @param
|
|
74
|
+
* @param numberDecimals Number of decimals to use for numbers, -1 for no formatting
|
|
75
75
|
* @param dateLocaleStr Datetime format string, either "iso" for ISO8601 or "default" for system default or valid locale string
|
|
76
76
|
* @param dateLocaleStyle Datetime format style, either "short/medium/long/full" or Intl.DateTimeFormat options
|
|
77
77
|
*
|
|
78
78
|
*/
|
|
79
|
-
constructor (template:string,
|
|
79
|
+
constructor (template:string, numberDecimals:number=-1, dateLocaleStr:string="", dateLocaleStyle:string|any="") {
|
|
80
80
|
super(template)
|
|
81
81
|
let locale_opts:any
|
|
82
82
|
if ((dateLocaleStyle == null) || (dateLocaleStyle == "")) {
|
|
@@ -87,7 +87,7 @@ export class OINODbHtmlTemplate extends OINOHtmlTemplate {
|
|
|
87
87
|
locale_opts = dateLocaleStyle
|
|
88
88
|
}
|
|
89
89
|
this._locale = null
|
|
90
|
-
this.
|
|
90
|
+
this._numberDecimals = numberDecimals
|
|
91
91
|
|
|
92
92
|
if ((dateLocaleStr != null) && (dateLocaleStr != "") && OINODbHtmlTemplate.LOCALE_REGEX.test(dateLocaleStr)) {
|
|
93
93
|
try {
|
|
@@ -127,8 +127,9 @@ export class OINODbHtmlTemplate extends OINOHtmlTemplate {
|
|
|
127
127
|
if ((f instanceof OINODatetimeDataField) && (this._locale != null)) {
|
|
128
128
|
value = f.serializeCellWithLocale(row[i], this._locale)
|
|
129
129
|
|
|
130
|
-
} else if ((f instanceof OINONumberDataField) && (this.
|
|
131
|
-
value
|
|
130
|
+
} else if ((f instanceof OINONumberDataField) && (this._numberDecimals >= 0) && (typeof row[i] === "number")) {
|
|
131
|
+
// console.debug("renderFromDbData number decimals", { field: f.name, value: row[i], type: typeof row[i] });
|
|
132
|
+
value = (row[i]! as number).toFixed(this._numberDecimals)
|
|
132
133
|
|
|
133
134
|
} else {
|
|
134
135
|
value = f.serializeCell(row[i])
|
|
@@ -286,7 +287,6 @@ export class OINODbApi {
|
|
|
286
287
|
} else if (result.success) {
|
|
287
288
|
OINOLog.debug("@oino-ts/db", "OINODbApi", "_doPost", "Print SQL", {sql:sql})
|
|
288
289
|
const sql_res:OINODbDataSet = await this.db.sqlExec(sql)
|
|
289
|
-
// OINOLog.debug("OINODbApi.doPost sql_res", {sql_res:sql_res})
|
|
290
290
|
if (sql_res.hasErrors()) {
|
|
291
291
|
result.setError(500, sql_res.getFirstError(), "DoPost")
|
|
292
292
|
if (this._debugOnError) {
|
package/src/OINODbDataModel.ts
CHANGED
|
@@ -252,7 +252,6 @@ export class OINODbDataModel {
|
|
|
252
252
|
where_sql = filter_sql
|
|
253
253
|
}
|
|
254
254
|
const result = this.api.db.printSqlSelect(this.api.params.tableName, column_names, where_sql, order_sql, limit_sql, groupby_sql)
|
|
255
|
-
OINOLog.debug("@oino-ts/db", "OINODbDataModel", "printSqlSelect", "Result", {sql:result})
|
|
256
255
|
return result;
|
|
257
256
|
}
|
|
258
257
|
|
|
@@ -264,7 +263,6 @@ export class OINODbDataModel {
|
|
|
264
263
|
*/
|
|
265
264
|
printSqlInsert(row: OINODataRow): string {
|
|
266
265
|
let result: string = "INSERT INTO " + this.api.db.printSqlTablename(this.api.params.tableName) + " " + this._printSqlInsertColumnsAndValues(row) + ";";
|
|
267
|
-
OINOLog.debug("@oino-ts/db", "OINODbDataModel", "printSqlInsert", "Result", {sql:result})
|
|
268
266
|
return result;
|
|
269
267
|
}
|
|
270
268
|
|
|
@@ -277,7 +275,6 @@ export class OINODbDataModel {
|
|
|
277
275
|
*/
|
|
278
276
|
printSqlUpdate(id: string, row: OINODataRow): string {
|
|
279
277
|
let result: string = "UPDATE " + this.api.db.printSqlTablename(this.api.params.tableName) + " SET " + this._printSqlUpdateValues(row) + " WHERE " + this._printSqlPrimaryKeyCondition(id) + ";";
|
|
280
|
-
OINOLog.debug("@oino-ts/db", "OINODbDataModel", "printSqlUpdate", "Result", {sql:result})
|
|
281
278
|
return result;
|
|
282
279
|
}
|
|
283
280
|
|
|
@@ -289,7 +286,6 @@ export class OINODbDataModel {
|
|
|
289
286
|
*/
|
|
290
287
|
printSqlDelete(id: string): string {
|
|
291
288
|
let result: string = "DELETE FROM " + this.api.db.printSqlTablename(this.api.params.tableName) + " WHERE " + this._printSqlPrimaryKeyCondition(id) + ";";
|
|
292
|
-
OINOLog.debug("@oino-ts/db", "OINODbDataModel", "printSqlDelete", "Result", {sql:result})
|
|
293
289
|
return result;
|
|
294
290
|
}
|
|
295
291
|
}
|