@oino-ts/db 0.13.0 → 0.13.1

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.
@@ -280,14 +280,18 @@ class OINOBlobDataField extends OINODbDataField {
280
280
  *
281
281
  */
282
282
  serializeCell(cellVal) {
283
+ // console.log("OINOBlobDataField.serializeCell: cellVal", cellVal, typeof(cellVal))
283
284
  if ((cellVal === null) || (cellVal === undefined)) {
284
285
  return cellVal;
285
286
  }
287
+ else if (cellVal instanceof Buffer) {
288
+ return cellVal.toString('base64');
289
+ }
286
290
  else if (cellVal instanceof Uint8Array) {
287
291
  return Buffer.from(cellVal).toString('base64');
288
292
  }
289
293
  else {
290
- return cellVal.toString();
294
+ return this.db.parseSqlValueAsCell(cellVal, this.sqlType)?.toString();
291
295
  }
292
296
  }
293
297
  /**
@@ -241,15 +241,14 @@ class OINODbModelSet {
241
241
  if (this.sqlParams?.select?.isSelected(f) === false) {
242
242
  continue;
243
243
  }
244
- let value = f.serializeCell(row[i]);
244
+ let value = f.db.parseSqlValueAsCell(row[i], f.sqlType); // retain original value without serialization
245
245
  if (value === undefined) {
246
246
  // skip undefined values
247
247
  }
248
- else if (value === null) {
248
+ else if (value === null) { // differentiate null and undefined
249
249
  result[f.name] = null;
250
250
  }
251
251
  else {
252
- value = this._encodeAndHashFieldValue(f, value, index_js_1.OINOContentType.json, primary_key_values, f.name + " " + row_id_seed);
253
252
  result[f.name] = value;
254
253
  }
255
254
  }
@@ -303,6 +302,10 @@ class OINODbModelSet {
303
302
  }
304
303
  return result;
305
304
  }
305
+ /**
306
+ * Export all rows as a record with OINOId as key and object with row cells as values.
307
+ *
308
+ */
306
309
  async exportAsRecord() {
307
310
  const result = {};
308
311
  while (!this.dataset.isEof()) {
@@ -273,14 +273,18 @@ export class OINOBlobDataField extends OINODbDataField {
273
273
  *
274
274
  */
275
275
  serializeCell(cellVal) {
276
+ // console.log("OINOBlobDataField.serializeCell: cellVal", cellVal, typeof(cellVal))
276
277
  if ((cellVal === null) || (cellVal === undefined)) {
277
278
  return cellVal;
278
279
  }
280
+ else if (cellVal instanceof Buffer) {
281
+ return cellVal.toString('base64');
282
+ }
279
283
  else if (cellVal instanceof Uint8Array) {
280
284
  return Buffer.from(cellVal).toString('base64');
281
285
  }
282
286
  else {
283
- return cellVal.toString();
287
+ return this.db.parseSqlValueAsCell(cellVal, this.sqlType)?.toString();
284
288
  }
285
289
  }
286
290
  /**
@@ -238,15 +238,14 @@ export class OINODbModelSet {
238
238
  if (this.sqlParams?.select?.isSelected(f) === false) {
239
239
  continue;
240
240
  }
241
- let value = f.serializeCell(row[i]);
241
+ let value = f.db.parseSqlValueAsCell(row[i], f.sqlType); // retain original value without serialization
242
242
  if (value === undefined) {
243
243
  // skip undefined values
244
244
  }
245
- else if (value === null) {
245
+ else if (value === null) { // differentiate null and undefined
246
246
  result[f.name] = null;
247
247
  }
248
248
  else {
249
- value = this._encodeAndHashFieldValue(f, value, OINOContentType.json, primary_key_values, f.name + " " + row_id_seed);
250
249
  result[f.name] = value;
251
250
  }
252
251
  }
@@ -300,6 +299,10 @@ export class OINODbModelSet {
300
299
  }
301
300
  return result;
302
301
  }
302
+ /**
303
+ * Export all rows as a record with OINOId as key and object with row cells as values.
304
+ *
305
+ */
303
306
  async exportAsRecord() {
304
307
  const result = {};
305
308
  while (!this.dataset.isEof()) {
@@ -52,5 +52,9 @@ export declare class OINODbModelSet {
52
52
  *
53
53
  */
54
54
  getValueByFieldName(fieldName: string, serialize?: boolean): OINODataCell;
55
+ /**
56
+ * Export all rows as a record with OINOId as key and object with row cells as values.
57
+ *
58
+ */
55
59
  exportAsRecord(): Promise<Record<string, any>>;
56
60
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oino-ts/db",
3
- "version": "0.13.0",
3
+ "version": "0.13.1",
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,11 +19,11 @@
19
19
  "module": "./dist/esm/index.js",
20
20
  "types": "./dist/types/index.d.ts",
21
21
  "dependencies": {
22
- "@oino-ts/common": "0.13.0",
22
+ "@oino-ts/common": "0.13.1",
23
23
  "oino-ts": "file:.."
24
24
  },
25
25
  "devDependencies": {
26
- "@oino-ts/types": "0.13.0",
26
+ "@oino-ts/types": "0.13.1",
27
27
  "@types/bun": "^1.1.14",
28
28
  "@types/node": "^20.14.10",
29
29
  "typescript": "~5.9.0"
@@ -128,6 +128,7 @@ const OWASP_CROSSCHECKS:string[] = [
128
128
  Math.random()
129
129
 
130
130
  OINOLog.setInstance(new OINOConsoleLog(OINOLogLevel.warning))
131
+ // OINOLog.setLogLevel(OINOLogLevel.debug, "@oino-ts/db-mssql", "OINODbMsSql", "printSqlSelect")
131
132
  OINODbFactory.registerDb("OINODbBunSqlite", OINODbBunSqlite)
132
133
  OINODbFactory.registerDb("OINODbPostgresql", OINODbPostgresql)
133
134
  OINODbFactory.registerDb("OINODbMariadb", OINODbMariadb)
@@ -292,14 +292,18 @@ export class OINOBlobDataField extends OINODbDataField {
292
292
  *
293
293
  */
294
294
  serializeCell(cellVal: OINODataCell):string|null|undefined {
295
+ // console.log("OINOBlobDataField.serializeCell: cellVal", cellVal, typeof(cellVal))
295
296
  if ((cellVal === null) || (cellVal === undefined)) {
296
297
  return cellVal
297
298
 
299
+ } else if (cellVal instanceof Buffer) {
300
+ return cellVal.toString('base64')
301
+
298
302
  } else if (cellVal instanceof Uint8Array) {
299
- return Buffer.from(cellVal as Uint8Array).toString('base64')
303
+ return Buffer.from(cellVal).toString('base64')
300
304
 
301
305
  } else {
302
- return cellVal.toString()
306
+ return this.db.parseSqlValueAsCell(cellVal, this.sqlType)?.toString()
303
307
  }
304
308
  }
305
309
 
@@ -259,15 +259,14 @@ export class OINODbModelSet {
259
259
  if (this.sqlParams?.select?.isSelected(f) === false) {
260
260
  continue
261
261
  }
262
- let value:string|null|undefined = f.serializeCell(row[i])
262
+ let value:OINODataCell = f.db.parseSqlValueAsCell(row[i], f.sqlType) // retain original value without serialization
263
263
  if (value === undefined) {
264
264
  // skip undefined values
265
265
 
266
- } else if (value === null) {
266
+ } else if (value === null) { // differentiate null and undefined
267
267
  result[f.name] = null
268
268
 
269
269
  } else {
270
- value = this._encodeAndHashFieldValue(f, value, OINOContentType.json, primary_key_values, f.name + " " + row_id_seed)
271
270
  result[f.name] = value
272
271
  }
273
272
  }
@@ -329,7 +328,7 @@ export class OINODbModelSet {
329
328
  * Export all rows as a record with OINOId as key and object with row cells as values.
330
329
  *
331
330
  */
332
-
331
+
333
332
  async exportAsRecord():Promise<Record<string, any>> {
334
333
  const result:Record<string, any> = {}
335
334
  while (!this.dataset.isEof()) {