@oino-ts/db-bunsqlite 0.21.2 → 1.0.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.
@@ -6,14 +6,15 @@
6
6
  */
7
7
  Object.defineProperty(exports, "__esModule", { value: true });
8
8
  exports.OINODbBunSqlite = void 0;
9
+ const node_buffer_1 = require("node:buffer");
9
10
  const common_1 = require("@oino-ts/common");
10
11
  const db_1 = require("@oino-ts/db");
11
12
  const bun_sqlite_1 = require("bun:sqlite");
12
13
  /**
13
- * Implmentation of OINODbDataSet for BunSqlite.
14
+ * Implmentation of OINODataSet for BunSqlite.
14
15
  *
15
16
  */
16
- class OINOBunSqliteDataset extends db_1.OINODbMemoryDataSet {
17
+ class OINOBunSqliteDataset extends common_1.OINOMemoryDataset {
17
18
  constructor(data, messages = []) {
18
19
  super(data, messages);
19
20
  }
@@ -35,11 +36,11 @@ class OINODbBunSqlite extends db_1.OINODb {
35
36
  constructor(params) {
36
37
  super(params);
37
38
  this._db = null;
38
- if (!this._params.url.startsWith("file://")) {
39
+ if (!this.dbParams.url.startsWith("file://")) {
39
40
  throw new Error(common_1.OINO_ERROR_PREFIX + ": OINODbBunSqlite url must be a file://-url!");
40
41
  }
41
- if (this._params.type !== "OINODbBunSqlite") {
42
- throw new Error(common_1.OINO_ERROR_PREFIX + ": Not OINODbBunSqlite-type: " + this._params.type);
42
+ if (this.dbParams.type !== "OINODbBunSqlite") {
43
+ throw new Error(common_1.OINO_ERROR_PREFIX + ": Not OINODbBunSqlite-type: " + this.dbParams.type);
43
44
  }
44
45
  }
45
46
  _parseDbFieldParams(fieldStr) {
@@ -57,7 +58,7 @@ class OINODbBunSqlite extends db_1.OINODb {
57
58
  * @param sqlTable name of the table
58
59
  *
59
60
  */
60
- printSqlTablename(sqlTable) {
61
+ printTableName(sqlTable) {
61
62
  return "[" + sqlTable + "]";
62
63
  }
63
64
  /**
@@ -66,7 +67,7 @@ class OINODbBunSqlite extends db_1.OINODb {
66
67
  * @param sqlColumn name of the column
67
68
  *
68
69
  */
69
- printSqlColumnname(sqlColumn) {
70
+ printColumnName(sqlColumn) {
70
71
  return "\"" + sqlColumn + "\"";
71
72
  }
72
73
  /**
@@ -74,35 +75,35 @@ class OINODbBunSqlite extends db_1.OINODb {
74
75
  * type with the correct SQL escaping.
75
76
  *
76
77
  * @param cellValue data from sql results
77
- * @param sqlType native type name for table column
78
+ * @param nativeType native type name for table column
78
79
  *
79
80
  */
80
- printCellAsSqlValue(cellValue, sqlType) {
81
+ printCellAsValue(cellValue, nativeType) {
81
82
  if (cellValue === null) {
82
83
  return "NULL";
83
84
  }
84
85
  else if (cellValue === undefined) {
85
86
  return "UNDEFINED";
86
87
  }
87
- else if ((sqlType == "INTEGER") || (sqlType == "REAL") || (sqlType == "DOUBLE" || (sqlType == "NUMERIC") || (sqlType == "DECIMAL"))) {
88
+ else if ((nativeType == "INTEGER") || (nativeType == "REAL") || (nativeType == "DOUBLE" || (nativeType == "NUMERIC") || (nativeType == "DECIMAL"))) {
88
89
  return cellValue.toString();
89
90
  }
90
- else if (sqlType == "BLOB") {
91
- if (cellValue instanceof Buffer) {
91
+ else if (nativeType == "BLOB") {
92
+ if (cellValue instanceof node_buffer_1.Buffer) {
92
93
  return "X'" + cellValue.toString("hex") + "'";
93
94
  }
94
95
  else if (cellValue instanceof Uint8Array) {
95
- return "X'" + Buffer.from(cellValue).toString("hex") + "'";
96
+ return "X'" + node_buffer_1.Buffer.from(cellValue).toString("hex") + "'";
96
97
  }
97
98
  else {
98
99
  return "'" + cellValue?.toString() + "'";
99
100
  }
100
101
  }
101
- else if (((sqlType == "DATETIME") || (sqlType == "DATE")) && (cellValue instanceof Date)) {
102
+ else if (((nativeType == "DATETIME") || (nativeType == "DATE")) && (cellValue instanceof Date)) {
102
103
  return "\'" + cellValue.toISOString() + "\'";
103
104
  }
104
105
  else {
105
- return this.printSqlString(cellValue.toString());
106
+ return this.printStringValue(cellValue.toString());
106
107
  }
107
108
  }
108
109
  /**
@@ -111,7 +112,7 @@ class OINODbBunSqlite extends db_1.OINODb {
111
112
  * @param sqlString string value
112
113
  *
113
114
  */
114
- printSqlString(sqlString) {
115
+ printStringValue(sqlString) {
115
116
  return "\"" + sqlString.replaceAll("\"", "\"\"") + "\"";
116
117
  }
117
118
  /**
@@ -119,25 +120,25 @@ class OINODbBunSqlite extends db_1.OINODb {
119
120
  * type.
120
121
  *
121
122
  * @param sqlValue data from serialization
122
- * @param sqlType native type name for table column
123
+ * @param nativeType native type name for table column
123
124
  *
124
125
  */
125
- parseSqlValueAsCell(sqlValue, sqlType) {
126
+ parseValueAsCell(sqlValue, nativeType) {
126
127
  if ((sqlValue === null) || (sqlValue == "NULL")) {
127
128
  return null;
128
129
  }
129
130
  else if (sqlValue === undefined) {
130
131
  return undefined;
131
132
  }
132
- else if (((sqlType == "DATETIME") || (sqlType == "DATE")) && (typeof (sqlValue) == "string") && (sqlValue != "")) {
133
+ else if (((nativeType == "DATETIME") || (nativeType == "DATE")) && (typeof (sqlValue) == "string") && (sqlValue != "")) {
133
134
  return new Date(sqlValue);
134
135
  }
135
- else if ((sqlType == "BOOLEAN")) {
136
+ else if ((nativeType == "BOOLEAN")) {
136
137
  return sqlValue == 1;
137
138
  }
138
- else if ((sqlType == "BLOB")) {
139
+ else if ((nativeType == "BLOB")) {
139
140
  if (sqlValue instanceof Uint8Array) {
140
- return Buffer.from(sqlValue);
141
+ return node_buffer_1.Buffer.from(sqlValue);
141
142
  }
142
143
  else {
143
144
  return sqlValue;
@@ -157,7 +158,7 @@ class OINODbBunSqlite extends db_1.OINODb {
157
158
  if (this.isConnected) {
158
159
  return result;
159
160
  }
160
- const filepath = this._params.url.substring(7);
161
+ const filepath = this.dbParams.url.substring(7);
161
162
  try {
162
163
  this._db = bun_sqlite_1.Database.open(filepath, { create: true, readonly: false, readwrite: true });
163
164
  this.isConnected = true;
@@ -181,7 +182,7 @@ class OINODbBunSqlite extends db_1.OINODb {
181
182
  let result = new common_1.OINOResult();
182
183
  try {
183
184
  this.isValidated = false;
184
- const sql = this._getValidateSql(this._params.database);
185
+ const sql = this._getValidateSql(this.dbParams.database);
185
186
  const sql_res = await this._query(sql);
186
187
  if (sql_res.isEmpty()) {
187
188
  result.setError(400, "DB returned no rows for select!", "OINODbBunSqlite.validate");
@@ -219,11 +220,11 @@ class OINODbBunSqlite extends db_1.OINODb {
219
220
  result = new OINOBunSqliteDataset(sql_res, []);
220
221
  }
221
222
  else {
222
- result = new OINOBunSqliteDataset(db_1.OINODB_EMPTY_ROWS, []);
223
+ result = new OINOBunSqliteDataset(common_1.OINO_EMPTY_ROWS, []);
223
224
  }
224
225
  }
225
226
  catch (e) {
226
- result = new OINOBunSqliteDataset(db_1.OINODB_EMPTY_ROWS, []).setError(500, common_1.OINO_ERROR_PREFIX + " (OINODbBunSqlite._query): Exception in db query: " + e.message, "OINODbBunSqlite._query");
227
+ result = new OINOBunSqliteDataset(common_1.OINO_EMPTY_ROWS, []).setError(500, common_1.OINO_ERROR_PREFIX + " (OINODbBunSqlite._query): Exception in db query: " + e.message, "OINODbBunSqlite._query");
227
228
  }
228
229
  return result;
229
230
  }
@@ -236,11 +237,11 @@ class OINODbBunSqlite extends db_1.OINODb {
236
237
  result = new OINOBunSqliteDataset(sql_res, []);
237
238
  }
238
239
  else {
239
- result = new OINOBunSqliteDataset(db_1.OINODB_EMPTY_ROWS, []);
240
+ result = new OINOBunSqliteDataset(common_1.OINO_EMPTY_ROWS, []);
240
241
  }
241
242
  }
242
243
  catch (e) {
243
- result = new OINOBunSqliteDataset(db_1.OINODB_EMPTY_ROWS, []).setError(500, common_1.OINO_ERROR_PREFIX + ": Exception in db exec: " + e.message, "OINODbBunSqlite._exec");
244
+ result = new OINOBunSqliteDataset(common_1.OINO_EMPTY_ROWS, []).setError(500, common_1.OINO_ERROR_PREFIX + ": Exception in db exec: " + e.message, "OINODbBunSqlite._exec");
244
245
  }
245
246
  return result;
246
247
  }
@@ -267,7 +268,7 @@ class OINODbBunSqlite extends db_1.OINODb {
267
268
  */
268
269
  async sqlExec(sql) {
269
270
  if (!this.isValidated) {
270
- return new OINOBunSqliteDataset(db_1.OINODB_EMPTY_ROWS, [common_1.OINO_ERROR_PREFIX + " (OINODbBunSqlite.sqlExec): Database connection not validated!"]);
271
+ return new OINOBunSqliteDataset(common_1.OINO_EMPTY_ROWS, [common_1.OINO_ERROR_PREFIX + " (OINODbBunSqlite.sqlExec): Database connection not validated!"]);
271
272
  }
272
273
  common_1.OINOBenchmark.startMetric("OINODb", "sqlExec");
273
274
  let result = await this._exec(sql);
@@ -283,14 +284,15 @@ class OINODbBunSqlite extends db_1.OINODb {
283
284
  return sql;
284
285
  }
285
286
  /**
286
- * Initialize a data model by getting the SQL schema and populating OINODbDataFields of
287
+ * Initialize a data model by getting the SQL schema and populating OINODataFields of
287
288
  * the model.
288
289
  *
289
290
  * @param api api which data model to initialize.
290
291
  *
291
292
  */
292
293
  async initializeApiDatamodel(api) {
293
- const schema_sql = this._getSchemaSql(this._params.database, api.params.tableName);
294
+ api.initializeDatamodel(new db_1.OINODbDataModel(api));
295
+ const schema_sql = this._getSchemaSql(this.dbParams.database, api.params.tableName);
294
296
  const res = await this._query(schema_sql);
295
297
  const sql_desc = (res?.getRow()[0]);
296
298
  const excluded_fields = [];
@@ -345,28 +347,28 @@ class OINODbBunSqlite extends db_1.OINODb {
345
347
  }
346
348
  else {
347
349
  if ((sql_type == "INTEGER") || (sql_type == "REAL") || (sql_type == "DOUBLE") || (sql_type == "NUMERIC") || (sql_type == "DECIMAL")) {
348
- api.datamodel.addField(new db_1.OINONumberDataField(this, field_name, sql_type, field_params));
350
+ api.datamodel.addField(new common_1.OINONumberDataField(this, field_name, sql_type, field_params));
349
351
  }
350
352
  else if ((sql_type == "BLOB")) {
351
- api.datamodel.addField(new db_1.OINOBlobDataField(this, field_name, sql_type, field_params, field_length));
353
+ api.datamodel.addField(new common_1.OINOBlobDataField(this, field_name, sql_type, field_params, field_length));
352
354
  }
353
355
  else if ((sql_type == "TEXT")) {
354
- api.datamodel.addField(new db_1.OINOStringDataField(this, field_name, sql_type, field_params, field_length));
356
+ api.datamodel.addField(new common_1.OINOStringDataField(this, field_name, sql_type, field_params, field_length));
355
357
  }
356
358
  else if ((sql_type == "DATETIME") || (sql_type == "DATE")) {
357
359
  if (api.params.useDatesAsString) {
358
- api.datamodel.addField(new db_1.OINOStringDataField(this, field_name, sql_type, field_params, 0));
360
+ api.datamodel.addField(new common_1.OINOStringDataField(this, field_name, sql_type, field_params, 0));
359
361
  }
360
362
  else {
361
- api.datamodel.addField(new db_1.OINODatetimeDataField(this, field_name, sql_type, field_params));
363
+ api.datamodel.addField(new common_1.OINODatetimeDataField(this, field_name, sql_type, field_params));
362
364
  }
363
365
  }
364
366
  else if ((sql_type == "BOOLEAN")) {
365
- api.datamodel.addField(new db_1.OINOBooleanDataField(this, field_name, sql_type, field_params));
367
+ api.datamodel.addField(new common_1.OINOBooleanDataField(this, field_name, sql_type, field_params));
366
368
  }
367
369
  else {
368
370
  common_1.OINOLog.info("@oino-ts/db-bunsqlite", "OINODbBunSqlite", "initializeApiDatamodel", "Unrecognized field type treated as string", { field_name: field_name, sql_type: sql_type, field_length: field_length, field_params: field_params });
369
- api.datamodel.addField(new db_1.OINOStringDataField(this, field_name, sql_type, field_params, 0));
371
+ api.datamodel.addField(new common_1.OINOStringDataField(this, field_name, sql_type, field_params, 0));
370
372
  }
371
373
  }
372
374
  }
@@ -3,14 +3,15 @@
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, OINOBenchmark, OINOStr, OINOLog, OINOResult } from "@oino-ts/common";
7
- import { OINODb, OINOBooleanDataField, OINONumberDataField, OINOStringDataField, OINODbMemoryDataSet, OINOBlobDataField, OINODatetimeDataField, OINODB_EMPTY_ROWS } from "@oino-ts/db";
6
+ import { Buffer } from "node:buffer";
7
+ import { OINO_ERROR_PREFIX, OINOBenchmark, OINOStr, OINOLog, OINOResult, OINOBooleanDataField, OINONumberDataField, OINOStringDataField, OINOMemoryDataset, OINOBlobDataField, OINODatetimeDataField, OINO_EMPTY_ROWS } from "@oino-ts/common";
8
+ import { OINODb, OINODbDataModel } from "@oino-ts/db";
8
9
  import { Database as BunSqliteDb } from "bun:sqlite";
9
10
  /**
10
- * Implmentation of OINODbDataSet for BunSqlite.
11
+ * Implmentation of OINODataSet for BunSqlite.
11
12
  *
12
13
  */
13
- class OINOBunSqliteDataset extends OINODbMemoryDataSet {
14
+ class OINOBunSqliteDataset extends OINOMemoryDataset {
14
15
  constructor(data, messages = []) {
15
16
  super(data, messages);
16
17
  }
@@ -32,11 +33,11 @@ export class OINODbBunSqlite extends OINODb {
32
33
  constructor(params) {
33
34
  super(params);
34
35
  this._db = null;
35
- if (!this._params.url.startsWith("file://")) {
36
+ if (!this.dbParams.url.startsWith("file://")) {
36
37
  throw new Error(OINO_ERROR_PREFIX + ": OINODbBunSqlite url must be a file://-url!");
37
38
  }
38
- if (this._params.type !== "OINODbBunSqlite") {
39
- throw new Error(OINO_ERROR_PREFIX + ": Not OINODbBunSqlite-type: " + this._params.type);
39
+ if (this.dbParams.type !== "OINODbBunSqlite") {
40
+ throw new Error(OINO_ERROR_PREFIX + ": Not OINODbBunSqlite-type: " + this.dbParams.type);
40
41
  }
41
42
  }
42
43
  _parseDbFieldParams(fieldStr) {
@@ -54,7 +55,7 @@ export class OINODbBunSqlite extends OINODb {
54
55
  * @param sqlTable name of the table
55
56
  *
56
57
  */
57
- printSqlTablename(sqlTable) {
58
+ printTableName(sqlTable) {
58
59
  return "[" + sqlTable + "]";
59
60
  }
60
61
  /**
@@ -63,7 +64,7 @@ export class OINODbBunSqlite extends OINODb {
63
64
  * @param sqlColumn name of the column
64
65
  *
65
66
  */
66
- printSqlColumnname(sqlColumn) {
67
+ printColumnName(sqlColumn) {
67
68
  return "\"" + sqlColumn + "\"";
68
69
  }
69
70
  /**
@@ -71,20 +72,20 @@ export class OINODbBunSqlite extends OINODb {
71
72
  * type with the correct SQL escaping.
72
73
  *
73
74
  * @param cellValue data from sql results
74
- * @param sqlType native type name for table column
75
+ * @param nativeType native type name for table column
75
76
  *
76
77
  */
77
- printCellAsSqlValue(cellValue, sqlType) {
78
+ printCellAsValue(cellValue, nativeType) {
78
79
  if (cellValue === null) {
79
80
  return "NULL";
80
81
  }
81
82
  else if (cellValue === undefined) {
82
83
  return "UNDEFINED";
83
84
  }
84
- else if ((sqlType == "INTEGER") || (sqlType == "REAL") || (sqlType == "DOUBLE" || (sqlType == "NUMERIC") || (sqlType == "DECIMAL"))) {
85
+ else if ((nativeType == "INTEGER") || (nativeType == "REAL") || (nativeType == "DOUBLE" || (nativeType == "NUMERIC") || (nativeType == "DECIMAL"))) {
85
86
  return cellValue.toString();
86
87
  }
87
- else if (sqlType == "BLOB") {
88
+ else if (nativeType == "BLOB") {
88
89
  if (cellValue instanceof Buffer) {
89
90
  return "X'" + cellValue.toString("hex") + "'";
90
91
  }
@@ -95,11 +96,11 @@ export class OINODbBunSqlite extends OINODb {
95
96
  return "'" + cellValue?.toString() + "'";
96
97
  }
97
98
  }
98
- else if (((sqlType == "DATETIME") || (sqlType == "DATE")) && (cellValue instanceof Date)) {
99
+ else if (((nativeType == "DATETIME") || (nativeType == "DATE")) && (cellValue instanceof Date)) {
99
100
  return "\'" + cellValue.toISOString() + "\'";
100
101
  }
101
102
  else {
102
- return this.printSqlString(cellValue.toString());
103
+ return this.printStringValue(cellValue.toString());
103
104
  }
104
105
  }
105
106
  /**
@@ -108,7 +109,7 @@ export class OINODbBunSqlite extends OINODb {
108
109
  * @param sqlString string value
109
110
  *
110
111
  */
111
- printSqlString(sqlString) {
112
+ printStringValue(sqlString) {
112
113
  return "\"" + sqlString.replaceAll("\"", "\"\"") + "\"";
113
114
  }
114
115
  /**
@@ -116,23 +117,23 @@ export class OINODbBunSqlite extends OINODb {
116
117
  * type.
117
118
  *
118
119
  * @param sqlValue data from serialization
119
- * @param sqlType native type name for table column
120
+ * @param nativeType native type name for table column
120
121
  *
121
122
  */
122
- parseSqlValueAsCell(sqlValue, sqlType) {
123
+ parseValueAsCell(sqlValue, nativeType) {
123
124
  if ((sqlValue === null) || (sqlValue == "NULL")) {
124
125
  return null;
125
126
  }
126
127
  else if (sqlValue === undefined) {
127
128
  return undefined;
128
129
  }
129
- else if (((sqlType == "DATETIME") || (sqlType == "DATE")) && (typeof (sqlValue) == "string") && (sqlValue != "")) {
130
+ else if (((nativeType == "DATETIME") || (nativeType == "DATE")) && (typeof (sqlValue) == "string") && (sqlValue != "")) {
130
131
  return new Date(sqlValue);
131
132
  }
132
- else if ((sqlType == "BOOLEAN")) {
133
+ else if ((nativeType == "BOOLEAN")) {
133
134
  return sqlValue == 1;
134
135
  }
135
- else if ((sqlType == "BLOB")) {
136
+ else if ((nativeType == "BLOB")) {
136
137
  if (sqlValue instanceof Uint8Array) {
137
138
  return Buffer.from(sqlValue);
138
139
  }
@@ -154,7 +155,7 @@ export class OINODbBunSqlite extends OINODb {
154
155
  if (this.isConnected) {
155
156
  return result;
156
157
  }
157
- const filepath = this._params.url.substring(7);
158
+ const filepath = this.dbParams.url.substring(7);
158
159
  try {
159
160
  this._db = BunSqliteDb.open(filepath, { create: true, readonly: false, readwrite: true });
160
161
  this.isConnected = true;
@@ -178,7 +179,7 @@ export class OINODbBunSqlite extends OINODb {
178
179
  let result = new OINOResult();
179
180
  try {
180
181
  this.isValidated = false;
181
- const sql = this._getValidateSql(this._params.database);
182
+ const sql = this._getValidateSql(this.dbParams.database);
182
183
  const sql_res = await this._query(sql);
183
184
  if (sql_res.isEmpty()) {
184
185
  result.setError(400, "DB returned no rows for select!", "OINODbBunSqlite.validate");
@@ -216,11 +217,11 @@ export class OINODbBunSqlite extends OINODb {
216
217
  result = new OINOBunSqliteDataset(sql_res, []);
217
218
  }
218
219
  else {
219
- result = new OINOBunSqliteDataset(OINODB_EMPTY_ROWS, []);
220
+ result = new OINOBunSqliteDataset(OINO_EMPTY_ROWS, []);
220
221
  }
221
222
  }
222
223
  catch (e) {
223
- result = new OINOBunSqliteDataset(OINODB_EMPTY_ROWS, []).setError(500, OINO_ERROR_PREFIX + " (OINODbBunSqlite._query): Exception in db query: " + e.message, "OINODbBunSqlite._query");
224
+ result = new OINOBunSqliteDataset(OINO_EMPTY_ROWS, []).setError(500, OINO_ERROR_PREFIX + " (OINODbBunSqlite._query): Exception in db query: " + e.message, "OINODbBunSqlite._query");
224
225
  }
225
226
  return result;
226
227
  }
@@ -233,11 +234,11 @@ export class OINODbBunSqlite extends OINODb {
233
234
  result = new OINOBunSqliteDataset(sql_res, []);
234
235
  }
235
236
  else {
236
- result = new OINOBunSqliteDataset(OINODB_EMPTY_ROWS, []);
237
+ result = new OINOBunSqliteDataset(OINO_EMPTY_ROWS, []);
237
238
  }
238
239
  }
239
240
  catch (e) {
240
- result = new OINOBunSqliteDataset(OINODB_EMPTY_ROWS, []).setError(500, OINO_ERROR_PREFIX + ": Exception in db exec: " + e.message, "OINODbBunSqlite._exec");
241
+ result = new OINOBunSqliteDataset(OINO_EMPTY_ROWS, []).setError(500, OINO_ERROR_PREFIX + ": Exception in db exec: " + e.message, "OINODbBunSqlite._exec");
241
242
  }
242
243
  return result;
243
244
  }
@@ -264,7 +265,7 @@ export class OINODbBunSqlite extends OINODb {
264
265
  */
265
266
  async sqlExec(sql) {
266
267
  if (!this.isValidated) {
267
- return new OINOBunSqliteDataset(OINODB_EMPTY_ROWS, [OINO_ERROR_PREFIX + " (OINODbBunSqlite.sqlExec): Database connection not validated!"]);
268
+ return new OINOBunSqliteDataset(OINO_EMPTY_ROWS, [OINO_ERROR_PREFIX + " (OINODbBunSqlite.sqlExec): Database connection not validated!"]);
268
269
  }
269
270
  OINOBenchmark.startMetric("OINODb", "sqlExec");
270
271
  let result = await this._exec(sql);
@@ -280,14 +281,15 @@ export class OINODbBunSqlite extends OINODb {
280
281
  return sql;
281
282
  }
282
283
  /**
283
- * Initialize a data model by getting the SQL schema and populating OINODbDataFields of
284
+ * Initialize a data model by getting the SQL schema and populating OINODataFields of
284
285
  * the model.
285
286
  *
286
287
  * @param api api which data model to initialize.
287
288
  *
288
289
  */
289
290
  async initializeApiDatamodel(api) {
290
- const schema_sql = this._getSchemaSql(this._params.database, api.params.tableName);
291
+ api.initializeDatamodel(new OINODbDataModel(api));
292
+ const schema_sql = this._getSchemaSql(this.dbParams.database, api.params.tableName);
291
293
  const res = await this._query(schema_sql);
292
294
  const sql_desc = (res?.getRow()[0]);
293
295
  const excluded_fields = [];
@@ -1,5 +1,5 @@
1
- import { OINOResult } from "@oino-ts/common";
2
- import { OINODb, OINODbParams, OINODbDataSet, OINODbApi, OINODataCell } from "@oino-ts/db";
1
+ import { OINOResult, OINODataSet, OINODataCell } from "@oino-ts/common";
2
+ import { OINODb, OINODbApi, OINODbParams } from "@oino-ts/db";
3
3
  /**
4
4
  * Implementation of BunSqlite-database.
5
5
  *
@@ -22,39 +22,39 @@ export declare class OINODbBunSqlite extends OINODb {
22
22
  * @param sqlTable name of the table
23
23
  *
24
24
  */
25
- printSqlTablename(sqlTable: string): string;
25
+ printTableName(sqlTable: string): string;
26
26
  /**
27
27
  * Print a column name with correct SQL escaping.
28
28
  *
29
29
  * @param sqlColumn name of the column
30
30
  *
31
31
  */
32
- printSqlColumnname(sqlColumn: string): string;
32
+ printColumnName(sqlColumn: string): string;
33
33
  /**
34
34
  * Print a single data value from serialization using the context of the native data
35
35
  * type with the correct SQL escaping.
36
36
  *
37
37
  * @param cellValue data from sql results
38
- * @param sqlType native type name for table column
38
+ * @param nativeType native type name for table column
39
39
  *
40
40
  */
41
- printCellAsSqlValue(cellValue: OINODataCell, sqlType: string): string;
41
+ printCellAsValue(cellValue: OINODataCell, nativeType: string): string;
42
42
  /**
43
43
  * Print a single string value as valid sql literal
44
44
  *
45
45
  * @param sqlString string value
46
46
  *
47
47
  */
48
- printSqlString(sqlString: string): string;
48
+ printStringValue(sqlString: string): string;
49
49
  /**
50
50
  * Parse a single SQL result value for serialization using the context of the native data
51
51
  * type.
52
52
  *
53
53
  * @param sqlValue data from serialization
54
- * @param sqlType native type name for table column
54
+ * @param nativeType native type name for table column
55
55
  *
56
56
  */
57
- parseSqlValueAsCell(sqlValue: OINODataCell, sqlType: string): OINODataCell;
57
+ parseValueAsCell(sqlValue: OINODataCell, nativeType: string): OINODataCell;
58
58
  /**
59
59
  * Connect to database.
60
60
  *
@@ -78,18 +78,18 @@ export declare class OINODbBunSqlite extends OINODb {
78
78
  * @param sql SQL statement.
79
79
  *
80
80
  */
81
- sqlSelect(sql: string): Promise<OINODbDataSet>;
81
+ sqlSelect(sql: string): Promise<OINODataSet>;
82
82
  /**
83
83
  * Execute other sql operations.
84
84
  *
85
85
  * @param sql SQL statement.
86
86
  *
87
87
  */
88
- sqlExec(sql: string): Promise<OINODbDataSet>;
88
+ sqlExec(sql: string): Promise<OINODataSet>;
89
89
  private _getSchemaSql;
90
90
  private _getValidateSql;
91
91
  /**
92
- * Initialize a data model by getting the SQL schema and populating OINODbDataFields of
92
+ * Initialize a data model by getting the SQL schema and populating OINODataFields of
93
93
  * the model.
94
94
  *
95
95
  * @param api api which data model to initialize.
package/package.json CHANGED
@@ -1,37 +1,37 @@
1
- {
2
- "name": "@oino-ts/db-bunsqlite",
3
- "version": "0.21.2",
4
- "description": "OINO TS package for using Bun Sqlite databases.",
5
- "author": "Matias Kiviniemi (pragmatta)",
6
- "license": "MPL-2.0",
7
- "repository": {
8
- "type": "git",
9
- "url": "https://github.com/pragmatta/oino-ts.git"
10
- },
11
- "keywords": [
12
- "sql",
13
- "database",
14
- "rest-api",
15
- "typescript",
16
- "library",
17
- "sqlite"
18
- ],
19
- "main": "./dist/cjs/index.js",
20
- "module": "./dist/esm/index.js",
21
- "types": "./dist/types/index.d.ts",
22
- "dependencies": {
23
- "@oino-ts/common": "^0.21.2",
24
- "@oino-ts/db": "^0.21.2"
25
- },
26
- "devDependencies": {
27
- "@types/bun": "latest",
28
- "@types/node": "^20.12.7",
29
- "typescript": "~5.9.0"
30
- },
31
- "files": [
32
- "src/*.ts",
33
- "dist/cjs/*.js",
34
- "dist/esm/*.js",
35
- "dist/types/*.d.ts"
36
- ]
37
- }
1
+ {
2
+ "name": "@oino-ts/db-bunsqlite",
3
+ "version": "1.0.0",
4
+ "description": "OINO TS package for using Bun Sqlite databases.",
5
+ "author": "Matias Kiviniemi (pragmatta)",
6
+ "license": "MPL-2.0",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/pragmatta/oino-ts.git"
10
+ },
11
+ "keywords": [
12
+ "sql",
13
+ "database",
14
+ "rest-api",
15
+ "typescript",
16
+ "library",
17
+ "sqlite"
18
+ ],
19
+ "main": "./dist/cjs/index.js",
20
+ "module": "./dist/esm/index.js",
21
+ "types": "./dist/types/index.d.ts",
22
+ "dependencies": {
23
+ "@oino-ts/common": "^1.0.0",
24
+ "@oino-ts/db": "^1.0.0"
25
+ },
26
+ "devDependencies": {
27
+ "@types/bun": "latest",
28
+ "@types/node": "^20.12.7",
29
+ "typescript": "~5.9.0"
30
+ },
31
+ "files": [
32
+ "src/*.ts",
33
+ "dist/cjs/*.js",
34
+ "dist/esm/*.js",
35
+ "dist/types/*.d.ts"
36
+ ]
37
+ }