@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.
@@ -52,7 +52,6 @@ class OINODb {
52
52
  result += " LIMIT " + limitCondition;
53
53
  }
54
54
  result += ";";
55
- index_js_1.OINOLog.debug("@oino-ts/db", "OINODb", "printSqlSelect", "Result", { sql: result });
56
55
  return result;
57
56
  }
58
57
  }
@@ -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
- _numberOfDecimals = -1;
66
+ _numberDecimals = -1;
67
67
  /**
68
68
  * Constructor of OINODbHtmlTemplate.
69
69
  *
70
70
  * @param template HTML template string
71
- * @param numberOfDecimals Number of decimals to use for numbers, -1 for no formatting
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, numberOfDecimals = -1, dateLocaleStr = "", dateLocaleStyle = "") {
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._numberOfDecimals = numberOfDecimals;
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._numberOfDecimals >= 0) && (typeof row[i] === "number")) {
128
- value = row[i].toFixed(this._numberOfDecimals);
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
  }
@@ -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, OINOLog } from "./index.js";
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
  }
@@ -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
- _numberOfDecimals = -1;
62
+ _numberDecimals = -1;
63
63
  /**
64
64
  * Constructor of OINODbHtmlTemplate.
65
65
  *
66
66
  * @param template HTML template string
67
- * @param numberOfDecimals Number of decimals to use for numbers, -1 for no formatting
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, numberOfDecimals = -1, dateLocaleStr = "", dateLocaleStyle = "") {
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._numberOfDecimals = numberOfDecimals;
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._numberOfDecimals >= 0) && (typeof row[i] === "number")) {
124
- value = row[i].toFixed(this._numberOfDecimals);
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, OINOLog, OINODB_UNDEFINED } from "./index.js";
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 _numberOfDecimals: number;
41
+ protected _numberDecimals: number;
42
42
  /**
43
43
  * Constructor of OINODbHtmlTemplate.
44
44
  *
45
45
  * @param template HTML template string
46
- * @param numberOfDecimals Number of decimals to use for numbers, -1 for no formatting
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, numberOfDecimals?: number, dateLocaleStr?: string, dateLocaleStyle?: string | any);
51
+ constructor(template: string, numberDecimals?: number, dateLocaleStr?: string, dateLocaleStyle?: string | any);
52
52
  /**
53
53
  * Creates HTML Response from API modelset.
54
54
  *
@@ -50,7 +50,6 @@ export type OINODbApiParams = {
50
50
  /**
51
51
  * Database class (constructor) type
52
52
  * @param dbParams database parameters
53
- * @return OINODb instance
54
53
  */
55
54
  export type OINODbConstructor = new (dbParams: OINODbParams) => OINODb;
56
55
  /** Database parameters */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oino-ts/db",
3
- "version": "0.10.3",
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.10.3"
22
+ "@oino-ts/common": "0.11.0",
23
+ "oino-ts": "file:.."
23
24
  },
24
25
  "devDependencies": {
25
- "@types/node": "^20.14.10",
26
+ "@oino-ts/types": "0.11.0",
26
27
  "@types/bun": "^1.1.14",
27
- "@oino-ts/types": "0.10.3",
28
- "typedoc": "^0.25.13"
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
@@ -137,7 +137,6 @@ export abstract class OINODb {
137
137
  result += " LIMIT " + limitCondition
138
138
  }
139
139
  result += ";"
140
- OINOLog.debug("@oino-ts/db", "OINODb", "printSqlSelect", "Result", {sql:result})
141
140
  return result;
142
141
  }
143
142
  }
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 _numberOfDecimals:number = -1
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 numberOfDecimals Number of decimals to use for numbers, -1 for no formatting
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, numberOfDecimals:number=-1, dateLocaleStr:string="", dateLocaleStyle:string|any="") {
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._numberOfDecimals = numberOfDecimals
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._numberOfDecimals >= 0) && (typeof row[i] === "number")) {
131
- value = (row[i]! as number).toFixed(this._numberOfDecimals)
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) {
@@ -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
  }
package/src/index.ts CHANGED
@@ -53,7 +53,6 @@ export type OINODbApiParams = {
53
53
  /**
54
54
  * Database class (constructor) type
55
55
  * @param dbParams database parameters
56
- * @return OINODb instance
57
56
  */
58
57
  export type OINODbConstructor = new (dbParams:OINODbParams) => OINODb
59
58