@oino-ts/db 0.13.0 → 0.13.2

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
  /**
@@ -238,18 +238,20 @@ class OINODbModelSet {
238
238
  let result = {};
239
239
  for (let i = 0; i < fields.length; i++) {
240
240
  const f = fields[i];
241
+ if (f.fieldParams.isPrimaryKey) {
242
+ primary_key_values.push(f.serializeCell(row[i]) || "");
243
+ }
241
244
  if (this.sqlParams?.select?.isSelected(f) === false) {
242
245
  continue;
243
246
  }
244
- let value = f.serializeCell(row[i]);
247
+ let value = f.db.parseSqlValueAsCell(row[i], f.sqlType); // retain original value without serialization
245
248
  if (value === undefined) {
246
249
  // skip undefined values
247
250
  }
248
- else if (value === null) {
251
+ else if (value === null) { // differentiate null and undefined
249
252
  result[f.name] = null;
250
253
  }
251
254
  else {
252
- value = this._encodeAndHashFieldValue(f, value, index_js_1.OINOContentType.json, primary_key_values, f.name + " " + row_id_seed);
253
255
  result[f.name] = value;
254
256
  }
255
257
  }
@@ -303,6 +305,10 @@ class OINODbModelSet {
303
305
  }
304
306
  return result;
305
307
  }
308
+ /**
309
+ * Export all rows as a record with OINOId as key and object with row cells as values.
310
+ *
311
+ */
306
312
  async exportAsRecord() {
307
313
  const result = {};
308
314
  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
  /**
@@ -235,18 +235,20 @@ export class OINODbModelSet {
235
235
  let result = {};
236
236
  for (let i = 0; i < fields.length; i++) {
237
237
  const f = fields[i];
238
+ if (f.fieldParams.isPrimaryKey) {
239
+ primary_key_values.push(f.serializeCell(row[i]) || "");
240
+ }
238
241
  if (this.sqlParams?.select?.isSelected(f) === false) {
239
242
  continue;
240
243
  }
241
- let value = f.serializeCell(row[i]);
244
+ let value = f.db.parseSqlValueAsCell(row[i], f.sqlType); // retain original value without serialization
242
245
  if (value === undefined) {
243
246
  // skip undefined values
244
247
  }
245
- else if (value === null) {
248
+ else if (value === null) { // differentiate null and undefined
246
249
  result[f.name] = null;
247
250
  }
248
251
  else {
249
- value = this._encodeAndHashFieldValue(f, value, OINOContentType.json, primary_key_values, f.name + " " + row_id_seed);
250
252
  result[f.name] = value;
251
253
  }
252
254
  }
@@ -300,6 +302,10 @@ export class OINODbModelSet {
300
302
  }
301
303
  return result;
302
304
  }
305
+ /**
306
+ * Export all rows as a record with OINOId as key and object with row cells as values.
307
+ *
308
+ */
303
309
  async exportAsRecord() {
304
310
  const result = {};
305
311
  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.2",
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.2",
23
23
  "oino-ts": "file:.."
24
24
  },
25
25
  "devDependencies": {
26
- "@oino-ts/types": "0.13.0",
26
+ "@oino-ts/types": "0.13.2",
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
 
@@ -256,18 +256,20 @@ export class OINODbModelSet {
256
256
  let result:any = {}
257
257
  for (let i=0; i<fields.length; i++) {
258
258
  const f = fields[i]
259
+ if (f.fieldParams.isPrimaryKey) {
260
+ primary_key_values.push(f.serializeCell(row[i]) || "")
261
+ }
259
262
  if (this.sqlParams?.select?.isSelected(f) === false) {
260
263
  continue
261
264
  }
262
- let value:string|null|undefined = f.serializeCell(row[i])
265
+ let value:OINODataCell = f.db.parseSqlValueAsCell(row[i], f.sqlType) // retain original value without serialization
263
266
  if (value === undefined) {
264
267
  // skip undefined values
265
268
 
266
- } else if (value === null) {
269
+ } else if (value === null) { // differentiate null and undefined
267
270
  result[f.name] = null
268
271
 
269
272
  } else {
270
- value = this._encodeAndHashFieldValue(f, value, OINOContentType.json, primary_key_values, f.name + " " + row_id_seed)
271
273
  result[f.name] = value
272
274
  }
273
275
  }
@@ -329,7 +331,7 @@ export class OINODbModelSet {
329
331
  * Export all rows as a record with OINOId as key and object with row cells as values.
330
332
  *
331
333
  */
332
-
334
+
333
335
  async exportAsRecord():Promise<Record<string, any>> {
334
336
  const result:Record<string, any> = {}
335
337
  while (!this.dataset.isEof()) {