@oino-ts/db 0.6.1 → 0.7.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.
@@ -153,6 +153,8 @@ export class OINODbHtmlTemplate extends OINOHtmlTemplate {
153
153
  *
154
154
  */
155
155
  export class OINODbApi {
156
+ /** Enable debug output on errors */
157
+ _debugOnError = false;
156
158
  /** API database reference */
157
159
  db;
158
160
  /** API datamodel */
@@ -184,7 +186,20 @@ export class OINODbApi {
184
186
  this.hashid = null;
185
187
  }
186
188
  }
187
- _validateRowValues(httpResult, row, requirePrimaryKey) {
189
+ _printSql(result, rows, requirePrimaryKey, printer) {
190
+ let sql = "";
191
+ for (let i = 0; i < rows.length; i++) {
192
+ this._validateRow(result, rows[i], requirePrimaryKey);
193
+ if (result.success) {
194
+ sql += printer(rows[i]);
195
+ }
196
+ else if (this.params.failOnAnyInvalidRows === false) {
197
+ result.setOk(); // individual rows may fail and will just be messages in response similar to executing multiple sql statements
198
+ }
199
+ }
200
+ return sql;
201
+ }
202
+ _validateRow(result, row, requirePrimaryKey) {
188
203
  let field;
189
204
  for (let i = 0; i < this.datamodel.fields.length; i++) {
190
205
  field = this.datamodel.fields[i];
@@ -192,13 +207,13 @@ export class OINODbApi {
192
207
  const val = row[i];
193
208
  // OINOLog.debug("OINODbApi.validateHttpValues", {val:val})
194
209
  if ((val === null) && ((field.fieldParams.isNotNull) || (field.fieldParams.isPrimaryKey))) { // null is a valid SQL value except if it's not allowed
195
- httpResult.setError(405, "Field '" + field.name + "' is not allowed to be NULL!", "ValidateRowValues");
210
+ result.setError(405, "Field '" + field.name + "' is not allowed to be NULL!", "ValidateRowValues");
196
211
  }
197
212
  else if ((val === undefined) && (requirePrimaryKey) && (field.fieldParams.isPrimaryKey) && (!field.fieldParams.isAutoInc)) {
198
- httpResult.setError(405, "Primary key '" + field.name + "' is not autoinc and missing from the data!", "ValidateRowValues");
213
+ result.setError(405, "Primary key '" + field.name + "' is not autoinc and missing from the data!", "ValidateRowValues");
199
214
  }
200
215
  else if ((val !== undefined) && (this.params.failOnUpdateOnAutoinc) && (field.fieldParams.isAutoInc)) {
201
- httpResult.setError(405, "Autoinc field '" + field.name + "' can't be updated!", "ValidateRowValues");
216
+ result.setError(405, "Autoinc field '" + field.name + "' can't be updated!", "ValidateRowValues");
202
217
  }
203
218
  else {
204
219
  if ((field instanceof OINOStringDataField) && ((field.maxLength > 0))) {
@@ -206,10 +221,10 @@ export class OINODbApi {
206
221
  // OINOLog.debug("OINODbApi.validateHttpValues", {f:str_field, val:val})
207
222
  if (str_val.length > field.maxLength) {
208
223
  if (this.params.failOnOversizedValues) {
209
- httpResult.setError(405, "Field '" + field.name + "' length (" + str_val.length + ") exceeds maximum (" + field.maxLength + ") and can't be set!", "ValidateRowValues");
224
+ result.setError(405, "Field '" + field.name + "' length (" + str_val.length + ") exceeds maximum (" + field.maxLength + ") and can't be set!", "ValidateRowValues");
210
225
  }
211
226
  else {
212
- httpResult.addWarning("Field '" + field.name + "' length (" + str_val.length + ") exceeds maximum (" + field.maxLength + ") and might truncate or fail.", "ValidateRowValues");
227
+ result.addWarning("Field '" + field.name + "' length (" + str_val.length + ") exceeds maximum (" + field.maxLength + ") and might truncate or fail.", "ValidateRowValues");
213
228
  }
214
229
  }
215
230
  }
@@ -217,6 +232,21 @@ export class OINODbApi {
217
232
  }
218
233
  //logDebug("OINODbApi.validateHttpValues", {result:result})
219
234
  }
235
+ _parseData(httpResult, body, params) {
236
+ let rows = [];
237
+ try {
238
+ if (Array.isArray(body)) {
239
+ rows = body;
240
+ }
241
+ else {
242
+ rows = OINODbParser.createRows(this.datamodel, body, params);
243
+ }
244
+ }
245
+ catch (e) {
246
+ httpResult.setError(400, "Invalid data: " + e.message, "DoRequest");
247
+ }
248
+ return rows;
249
+ }
220
250
  async _doGet(result, id, params) {
221
251
  let sql = "";
222
252
  try {
@@ -240,27 +270,28 @@ export class OINODbApi {
240
270
  async _doPost(result, rows) {
241
271
  let sql = "";
242
272
  try {
243
- let i = 0;
244
- while (i < rows.length) {
245
- this._validateRowValues(result, rows[i], this.params.failOnInsertWithoutKey || false);
273
+ for (let i = 0; i < rows.length; i++) {
274
+ this._validateRow(result, rows[i], this.params.failOnInsertWithoutKey || false);
246
275
  if (result.success) {
247
276
  sql += this.datamodel.printSqlInsert(rows[i]);
248
277
  }
249
- result.setOk(); // individual rows may fail and will just be messages in response similar to executing multiple sql statements
250
- i++;
278
+ else if (this.params.failOnAnyInvalidRows == false) {
279
+ result.setOk(); // individual rows may fail and will just be messages in response similar to executing multiple sql statements
280
+ }
251
281
  }
252
- if (sql == "") {
282
+ if ((sql == "") && result.success) {
253
283
  result.setError(405, "No valid rows for POST!", "DoPost");
254
- result.addDebug("OINO POST DATA [" + rows.join("|") + "]", "DoPost");
255
284
  }
256
- else {
285
+ else if (result.success) {
257
286
  // OINOLog.debug("OINODbApi.doPost sql", {sql:sql})
258
287
  const sql_res = await this.db.sqlExec(sql);
259
288
  // OINOLog.debug("OINODbApi.doPost sql_res", {sql_res:sql_res})
260
289
  if (sql_res.hasErrors()) {
261
290
  result.setError(500, sql_res.getFirstError(), "DoPost");
262
- result.addDebug("OINO POST MESSAGES [" + sql_res.messages.join('|') + "]", "DoPost");
263
- result.addDebug("OINO POST SQL [" + sql + "]", "DoPost");
291
+ if (this._debugOnError) {
292
+ result.addDebug("OINO POST MESSAGES [" + sql_res.messages.join('|') + "]", "DoPost");
293
+ result.addDebug("OINO POST SQL [" + sql + "]", "DoPost");
294
+ }
264
295
  }
265
296
  }
266
297
  }
@@ -269,19 +300,33 @@ export class OINODbApi {
269
300
  result.addDebug("OINO POST SQL [" + sql + "]", "DoPost");
270
301
  }
271
302
  }
272
- async _doPut(result, id, row) {
303
+ async _doPut(result, id, rows) {
273
304
  let sql = "";
274
305
  try {
275
- this._validateRowValues(result, row, false);
276
- if (result.success) {
277
- sql = this.datamodel.printSqlUpdate(id, row);
306
+ // this._validateRowValues(result, row, false)
307
+ for (let i = 0; i < rows.length; i++) {
308
+ const row_id = id || OINODbConfig.printOINOId(this.datamodel.getRowPrimarykeyValues(rows[i], this.hashid != null));
309
+ this._validateRow(result, rows[i], this.params.failOnInsertWithoutKey || false);
310
+ if (result.success) {
311
+ sql += this.datamodel.printSqlUpdate(row_id, rows[i]);
312
+ }
313
+ else if (this.params.failOnAnyInvalidRows == false) {
314
+ result.setOk(); // individual rows may fail and will just be messages in response similar to executing multiple sql statements
315
+ }
316
+ }
317
+ if ((sql == "") && result.success) {
318
+ result.setError(405, "No valid rows for PUT!", "DoPut"); // only set error if there are multiple rows and no valid sql was created
319
+ }
320
+ else if (result.success) {
278
321
  // OINOLog.debug("OINODbApi.doPut sql", {sql:sql})
279
322
  const sql_res = await this.db.sqlExec(sql);
280
323
  // OINOLog.debug("OINODbApi.doPut sql_res", {sql_res:sql_res})
281
324
  if (sql_res.hasErrors()) {
282
325
  result.setError(500, sql_res.getFirstError(), "DoPut");
283
- result.addDebug("OINO PUT MESSAGES [" + sql_res.messages.join('|') + "]", "DoPut");
284
- result.addDebug("OINO PUT SQL [" + sql + "]", "DoPut");
326
+ if (this._debugOnError) {
327
+ result.addDebug("OINO PUT MESSAGES [" + sql_res.messages.join('|') + "]", "DoPut");
328
+ result.addDebug("OINO PUT SQL [" + sql + "]", "DoPut");
329
+ }
285
330
  }
286
331
  }
287
332
  }
@@ -290,17 +335,37 @@ export class OINODbApi {
290
335
  result.addDebug("OINO POST SQL [" + sql + "]", "DoPut");
291
336
  }
292
337
  }
293
- async _doDelete(result, id) {
338
+ async _doDelete(result, id, rows) {
294
339
  let sql = "";
295
340
  try {
296
- sql = this.datamodel.printSqlDelete(id);
297
- // OINOLog.debug("OINODbApi.doDelete sql", {sql:sql})
298
- const sql_res = await this.db.sqlExec(sql);
299
- // OINOLog.debug("OINODbApi.doDelete sql_res", {sql_res:sql_res})
300
- if (sql_res.hasErrors()) {
301
- result.setError(500, sql_res.getFirstError(), "DoDelete");
302
- result.addDebug("OINO DELETE MESSAGES [" + sql_res.messages.join('|') + "]", "DoDelete");
303
- result.addDebug("OINO DELETE SQL [" + sql + "]", "DoDelete");
341
+ if (rows != null) {
342
+ for (let i = 0; i < rows.length; i++) {
343
+ const row_id = OINODbConfig.printOINOId(this.datamodel.getRowPrimarykeyValues(rows[i], this.hashid != null));
344
+ if (row_id) {
345
+ sql += this.datamodel.printSqlDelete(row_id);
346
+ }
347
+ else if (this.params.failOnAnyInvalidRows == false) {
348
+ result.setOk(); // individual rows may fail and will just be messages in response similar to executing multiple sql statements
349
+ }
350
+ }
351
+ }
352
+ else if (id) {
353
+ sql = this.datamodel.printSqlDelete(id);
354
+ }
355
+ if ((sql == "") && result.success) {
356
+ result.setError(405, "No valid rows for DELETE!", "DoDelete"); // only set error if there are multiple rows and no valid sql was created
357
+ }
358
+ else if (result.success) {
359
+ // OINOLog.debug("OINODbApi.doDelete sql", {sql:sql})
360
+ const sql_res = await this.db.sqlExec(sql);
361
+ // OINOLog.debug("OINODbApi.doDelete sql_res", {sql_res:sql_res})
362
+ if (sql_res.hasErrors()) {
363
+ result.setError(500, sql_res.getFirstError(), "DoDelete");
364
+ if (this._debugOnError) {
365
+ result.addDebug("OINO DELETE MESSAGES [" + sql_res.messages.join('|') + "]", "DoDelete");
366
+ result.addDebug("OINO DELETE SQL [" + sql + "]", "DoDelete");
367
+ }
368
+ }
304
369
  }
305
370
  }
306
371
  catch (e) {
@@ -308,34 +373,31 @@ export class OINODbApi {
308
373
  result.addDebug("OINO DELETE SQL [" + sql + "]", "DoDelete");
309
374
  }
310
375
  }
376
+ /**
377
+ * Enable or disable debug output on errors.
378
+ *
379
+ * @param debugOnError true to enable debug output on errors, false to disable
380
+ */
381
+ setDebugOnError(debugOnError) {
382
+ this._debugOnError = debugOnError;
383
+ }
311
384
  /**
312
385
  * Method for handlind a HTTP REST request with GET, POST, PUT, DELETE corresponding to
313
386
  * SQL select, insert, update and delete.
314
387
  *
315
388
  * @param method HTTP verb (uppercase)
316
389
  * @param id URL id of the REST request
317
- * @param body HTTP body data as either serialized string or unserialized JS object / OINODataRow-array
390
+ * @param data HTTP body data as either serialized string or unserialized JS object / OINODataRow-array
318
391
  * @param params HTTP URL parameters as key-value-pairs
319
392
  *
320
393
  */
321
- async doRequest(method, id, body, params = API_EMPTY_PARAMS) {
394
+ async doRequest(method, id, data, params = API_EMPTY_PARAMS) {
322
395
  OINOBenchmark.start("OINODbApi", "doRequest");
323
396
  // OINOLog.debug("OINODbApi.doRequest enter", {method:method, id:id, body:body, params:params})
324
397
  let result = new OINODbApiResult(params);
325
398
  let rows = [];
326
399
  if ((method == "POST") || (method == "PUT")) {
327
- try {
328
- if (Array.isArray(body)) {
329
- rows = body;
330
- }
331
- else {
332
- rows = OINODbParser.createRows(this.datamodel, body, params);
333
- }
334
- }
335
- catch (e) {
336
- result.setError(400, "Invalid data: " + e.message, "DoRequest");
337
- }
338
- // OINOLog.debug("OINODbApi.doRequest - OINODataRow rows", {rows:rows})
400
+ rows = this._parseData(result, data, params);
339
401
  }
340
402
  if (method == "GET") {
341
403
  await this._doGet(result, id, params);
@@ -349,7 +411,7 @@ export class OINODbApi {
349
411
  }
350
412
  else {
351
413
  try {
352
- await this._doPut(result, id, rows[0]);
414
+ await this._doPut(result, id, rows);
353
415
  }
354
416
  catch (e) {
355
417
  result.setError(500, "Unhandled exception in HTTP PUT doRequest: " + e.message, "DoRequest");
@@ -379,7 +441,7 @@ export class OINODbApi {
379
441
  }
380
442
  else {
381
443
  try {
382
- await this._doDelete(result, id);
444
+ await this._doDelete(result, id, null);
383
445
  }
384
446
  catch (e) {
385
447
  result.setError(500, "Unhandled exception in HTTP DELETE doRequest: " + e.message, "DoRequest");
@@ -387,11 +449,50 @@ export class OINODbApi {
387
449
  }
388
450
  }
389
451
  else {
390
- result.setError(405, "Unsupported HTTP method '" + method + "'", "DoRequest");
452
+ result.setError(405, "Unsupported HTTP method '" + method + "' for REST request", "DoRequest");
391
453
  }
392
454
  OINOBenchmark.end("OINODbApi", "doRequest", method);
393
455
  return Promise.resolve(result);
394
456
  }
457
+ /**
458
+ * Method for handlind a HTTP REST request with GET, POST, PUT, DELETE corresponding to
459
+ * SQL select, insert, update and delete.
460
+ *
461
+ * @param method HTTP verb (uppercase)
462
+ * @param data HTTP body data as either serialized string or unserialized JS object / OINODataRow-array
463
+ * @param params HTTP URL parameters as key-value-pairs
464
+ *
465
+ */
466
+ async doBatchUpdate(method, data, params = API_EMPTY_PARAMS) {
467
+ OINOBenchmark.start("OINODbApi", "doBatchUpdate");
468
+ // OINOLog.debug("OINODbApi.doRequest enter", {method:method, id:id, body:body, params:params})
469
+ let result = new OINODbApiResult(params);
470
+ let rows = [];
471
+ if ((method == "PUT")) {
472
+ rows = this._parseData(result, data, params);
473
+ }
474
+ if (method == "PUT") {
475
+ try {
476
+ await this._doPut(result, null, rows);
477
+ }
478
+ catch (e) {
479
+ result.setError(500, "Unhandled exception in HTTP PUT doRequest: " + e.message, "DoBatchUpdate");
480
+ }
481
+ }
482
+ else if (method == "DELETE") {
483
+ try {
484
+ await this._doDelete(result, null, rows);
485
+ }
486
+ catch (e) {
487
+ result.setError(500, "Unhandled exception in HTTP DELETE doRequest: " + e.message, "DoBatchUpdate");
488
+ }
489
+ }
490
+ else {
491
+ result.setError(405, "Unsupported HTTP method '" + method + "' for batch update", "DoBatchUpdate");
492
+ }
493
+ OINOBenchmark.end("OINODbApi", "doBatchUpdate", method);
494
+ return Promise.resolve(result);
495
+ }
395
496
  /**
396
497
  * Method to check if a field is included in the API params.
397
498
  *
@@ -94,7 +94,12 @@ export class OINODbDataModel {
94
94
  if ((f instanceof OINONumberDataField) && (this.api.hashid)) {
95
95
  value = this.api.hashid.decode(value);
96
96
  }
97
- result += f.printSqlColumnName() + "=" + f.printCellAsSqlValue(value);
97
+ value = f.printCellAsSqlValue(value);
98
+ if (value == "") { // ids are user input and could be specially crafted to be empty
99
+ throw new Error(OINO_ERROR_PREFIX + ": empty condition for id '" + id_value + "' for table " + this.api.params.tableName);
100
+ }
101
+ // OINOLog.debug("OINODbDataModel._printSqlPrimaryKeyCondition", {field:f.name, value:value, id_value:id_value})
102
+ result += f.printSqlColumnName() + "=" + value;
98
103
  i = i + 1;
99
104
  }
100
105
  }
@@ -266,6 +271,7 @@ export class OINODbDataModel {
266
271
  */
267
272
  printSqlUpdate(id, row) {
268
273
  let result = "UPDATE " + this.api.db.printSqlTablename(this.api.params.tableName) + " SET " + this._printSqlUpdateValues(row) + " WHERE " + this._printSqlPrimaryKeyCondition(id) + ";";
274
+ // OINOLog.debug("OINODbDataModel.printSqlUpdate", {result:result, id:id, row:row})
269
275
  return result;
270
276
  }
271
277
  /**
@@ -25,6 +25,8 @@ export class OINODbFactory {
25
25
  * Create database from parameters from the registered classes.
26
26
  *
27
27
  * @param params database connection parameters
28
+ * @param connect if true, connects to the database
29
+ * @param validate if true, validates the database connection
28
30
  */
29
31
  static async createDb(params, connect = true, validate = true) {
30
32
  let result;
@@ -139,6 +139,12 @@ export declare abstract class OINODbDataSet {
139
139
  *
140
140
  */
141
141
  abstract getRow(): OINODataRow;
142
+ /**
143
+ * Gets all rows of data.
144
+ *
145
+ * NOTE: This is left abstract instead of just using `getRow()` so that DB implementations can hopefully optimize not duplicating data *
146
+ */
147
+ abstract getAllRows(): Promise<OINODataRow[]>;
142
148
  /**
143
149
  * Checks if the messages contain errors.
144
150
  *
@@ -187,6 +193,11 @@ export declare class OINODbMemoryDataSet extends OINODbDataSet {
187
193
  *
188
194
  */
189
195
  getRow(): OINODataRow;
196
+ /**
197
+ * Gets all rows of data.
198
+ *
199
+ */
200
+ getAllRows(): Promise<OINODataRow[]>;
190
201
  /**
191
202
  * Rewinds data set to the first row, returns !isEof().
192
203
  *
@@ -1,3 +1,5 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
1
3
  import { OINODbApiParams, OINODb, OINODbDataModel, OINODataRow, OINODbModelSet, OINODbApiRequestParams, OINOHttpResult, OINOHtmlTemplate } from "./index.js";
2
4
  import { OINOResult } from "@oino-ts/common";
3
5
  import { OINOHashid } from "@oino-ts/hashid";
@@ -59,6 +61,8 @@ export declare class OINODbHtmlTemplate extends OINOHtmlTemplate {
59
61
  *
60
62
  */
61
63
  export declare class OINODbApi {
64
+ /** Enable debug output on errors */
65
+ private _debugOnError;
62
66
  /** API database reference */
63
67
  readonly db: OINODb;
64
68
  /** API datamodel */
@@ -76,22 +80,40 @@ export declare class OINODbApi {
76
80
  *
77
81
  */
78
82
  constructor(db: OINODb, params: OINODbApiParams);
79
- private _validateRowValues;
83
+ private _printSql;
84
+ private _validateRow;
85
+ private _parseData;
80
86
  private _doGet;
81
87
  private _doPost;
82
88
  private _doPut;
83
89
  private _doDelete;
90
+ /**
91
+ * Enable or disable debug output on errors.
92
+ *
93
+ * @param debugOnError true to enable debug output on errors, false to disable
94
+ */
95
+ setDebugOnError(debugOnError: boolean): void;
84
96
  /**
85
97
  * Method for handlind a HTTP REST request with GET, POST, PUT, DELETE corresponding to
86
98
  * SQL select, insert, update and delete.
87
99
  *
88
100
  * @param method HTTP verb (uppercase)
89
101
  * @param id URL id of the REST request
90
- * @param body HTTP body data as either serialized string or unserialized JS object / OINODataRow-array
102
+ * @param data HTTP body data as either serialized string or unserialized JS object / OINODataRow-array
103
+ * @param params HTTP URL parameters as key-value-pairs
104
+ *
105
+ */
106
+ doRequest(method: string, id: string, data: string | OINODataRow[] | Buffer | any, params?: OINODbApiRequestParams): Promise<OINODbApiResult>;
107
+ /**
108
+ * Method for handlind a HTTP REST request with GET, POST, PUT, DELETE corresponding to
109
+ * SQL select, insert, update and delete.
110
+ *
111
+ * @param method HTTP verb (uppercase)
112
+ * @param data HTTP body data as either serialized string or unserialized JS object / OINODataRow-array
91
113
  * @param params HTTP URL parameters as key-value-pairs
92
114
  *
93
115
  */
94
- doRequest(method: string, id: string, body: string | OINODataRow[] | Buffer | any, params?: OINODbApiRequestParams): Promise<OINODbApiResult>;
116
+ doBatchUpdate(method: string, data: string | OINODataRow[] | Buffer | any, params?: OINODbApiRequestParams): Promise<OINODbApiResult>;
95
117
  /**
96
118
  * Method to check if a field is included in the API params.
97
119
  *
@@ -17,6 +17,8 @@ export declare class OINODbFactory {
17
17
  * Create database from parameters from the registered classes.
18
18
  *
19
19
  * @param params database connection parameters
20
+ * @param connect if true, connects to the database
21
+ * @param validate if true, validates the database connection
20
22
  */
21
23
  static createDb(params: OINODbParams, connect?: boolean, validate?: boolean): Promise<OINODb>;
22
24
  /**
@@ -1,3 +1,5 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
1
3
  import { OINODbDataModel, OINODataRow, OINODbApiRequestParams } from "./index.js";
2
4
  /**
3
5
  * Static factory class for easily creating things based on data
@@ -1,3 +1,5 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
1
3
  import { OINOContentType } from "@oino-ts/common";
2
4
  export { OINOContentType };
3
5
  export { OINO_ERROR_PREFIX, OINO_WARNING_PREFIX, OINO_INFO_PREFIX, OINO_DEBUG_PREFIX, OINOStr, OINOBenchmark, OINOLog, OINOLogLevel, OINOConsoleLog, OINOResult, OINOHttpResult, OINOHtmlTemplate } from "@oino-ts/common";
@@ -26,6 +28,8 @@ export type OINODbApiParams = {
26
28
  failOnUpdateOnAutoinc?: boolean;
27
29
  /** Reject POST-requests without primary key value (can work if DB-side ) */
28
30
  failOnInsertWithoutKey?: boolean;
31
+ /** Reject POST-requests without primary key value (can work if DB-side ) */
32
+ failOnAnyInvalidRows?: boolean;
29
33
  /** Treat date type fields as just strings and use the native formatting instead of the ISO 8601 format */
30
34
  useDatesAsString?: Boolean;
31
35
  /** Include given fields from the API and exclude rest (if defined) */
@@ -46,6 +50,7 @@ export type OINODbApiParams = {
46
50
  /**
47
51
  * Database class (constructor) type
48
52
  * @param dbParams database parameters
53
+ * @return OINODb instance
49
54
  */
50
55
  export type OINODbConstructor = new (dbParams: OINODbParams) => OINODb;
51
56
  /** Database parameters */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oino-ts/db",
3
- "version": "0.6.1",
3
+ "version": "0.7.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,12 +19,12 @@
19
19
  "module": "./dist/esm/index.js",
20
20
  "types": "./dist/types/index.d.ts",
21
21
  "dependencies": {
22
- "@oino-ts/common": "0.6.1"
22
+ "@oino-ts/common": "0.7.1"
23
23
  },
24
24
  "devDependencies": {
25
25
  "@types/node": "^20.14.10",
26
26
  "@types/bun": "^1.1.14",
27
- "@oino-ts/types": "0.6.1",
27
+ "@oino-ts/types": "0.7.1",
28
28
  "typedoc": "^0.25.13"
29
29
  },
30
30
  "files": [
package/src/OINODb.ts CHANGED
@@ -194,6 +194,13 @@ export abstract class OINODbDataSet {
194
194
  */
195
195
  abstract getRow(): OINODataRow;
196
196
 
197
+ /**
198
+ * Gets all rows of data.
199
+ *
200
+ * NOTE: This is left abstract instead of just using `getRow()` so that DB implementations can hopefully optimize not duplicating data *
201
+ */
202
+ abstract getAllRows(): Promise<OINODataRow[]>;
203
+
197
204
  /**
198
205
  * Checks if the messages contain errors.
199
206
  *
@@ -294,6 +301,14 @@ export class OINODbMemoryDataSet extends OINODbDataSet {
294
301
  }
295
302
  }
296
303
 
304
+ /**
305
+ * Gets all rows of data.
306
+ *
307
+ */
308
+ async getAllRows(): Promise<OINODataRow[]> {
309
+ return this._rows // at the moment theres no result streaming, so we can just return the rows
310
+ }
311
+
297
312
  /**
298
313
  * Rewinds data set to the first row, returns !isEof().
299
314
  *