@oino-ts/db-bunsqlite 0.2.0 → 0.3.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.
|
@@ -193,7 +193,7 @@ class OINODbBunSqlite extends db_1.OINODb {
|
|
|
193
193
|
async initializeApiDatamodel(api) {
|
|
194
194
|
const res = await this.sqlSelect("select sql from sqlite_schema WHERE name='" + api.params.tableName + "'");
|
|
195
195
|
const sql_desc = (res?.getRow()[0]);
|
|
196
|
-
const
|
|
196
|
+
const excluded_fields = [];
|
|
197
197
|
// OINOLog.debug("OINODbBunSqlite.initDatamodel.sql_desc=" + sql_desc)
|
|
198
198
|
let table_matches = OINODbBunSqlite._tableDescriptionRegex.exec(sql_desc);
|
|
199
199
|
// OINOLog.debug("OINODbBunSqlite.initDatamodel", {table_matches:table_matches})
|
|
@@ -212,11 +212,14 @@ class OINODbBunSqlite extends db_1.OINODb {
|
|
|
212
212
|
if ((!field_match) || (field_match.length < 3)) {
|
|
213
213
|
let primarykey_match = OINODbBunSqlite._tablePrimarykeyRegex.exec(field_str);
|
|
214
214
|
let foreignkey_match = OINODbBunSqlite._tableForeignkeyRegex.exec(field_str);
|
|
215
|
-
|
|
215
|
+
// OINOLog.debug("initDatamodel non-field definition", {primarykey_match:primarykey_match, foreignkey_match:foreignkey_match})
|
|
216
216
|
if (primarykey_match && primarykey_match.length >= 2) {
|
|
217
217
|
const primary_keys = primarykey_match[1].replaceAll("\"", "").split(','); // not sure if will have space or not so split by comma and trim later
|
|
218
218
|
for (let i = 0; i < primary_keys.length; i++) {
|
|
219
219
|
const pk = primary_keys[i].trim(); //..the trim
|
|
220
|
+
if (excluded_fields.indexOf(pk) >= 0) {
|
|
221
|
+
throw new Error(db_1.OINO_ERROR_PREFIX + "Primary key field excluded in API parameters: " + pk);
|
|
222
|
+
}
|
|
220
223
|
for (let j = 0; j < api.datamodel.fields.length; j++) {
|
|
221
224
|
if (api.datamodel.fields[j].name == pk) {
|
|
222
225
|
api.datamodel.fields[j].fieldParams.isPrimaryKey = true;
|
|
@@ -243,7 +246,8 @@ class OINODbBunSqlite extends db_1.OINODb {
|
|
|
243
246
|
const sql_type = field_match[2];
|
|
244
247
|
const field_length = parseInt(field_match[4]) || 0;
|
|
245
248
|
// OINOLog.debug("OINODbBunSqlite.initializeApiDatamodel: field regex matches", { api.params: api.params, field_name:field_name })
|
|
246
|
-
if (
|
|
249
|
+
if (api.isFieldIncluded(field_name) == false) {
|
|
250
|
+
excluded_fields.push(field_name);
|
|
247
251
|
db_1.OINOLog.info("OINODbBunSqlite.initializeApiDatamodel: field excluded in API parameters.", { field: field_name });
|
|
248
252
|
}
|
|
249
253
|
else {
|
|
@@ -190,7 +190,7 @@ export class OINODbBunSqlite extends OINODb {
|
|
|
190
190
|
async initializeApiDatamodel(api) {
|
|
191
191
|
const res = await this.sqlSelect("select sql from sqlite_schema WHERE name='" + api.params.tableName + "'");
|
|
192
192
|
const sql_desc = (res?.getRow()[0]);
|
|
193
|
-
const
|
|
193
|
+
const excluded_fields = [];
|
|
194
194
|
// OINOLog.debug("OINODbBunSqlite.initDatamodel.sql_desc=" + sql_desc)
|
|
195
195
|
let table_matches = OINODbBunSqlite._tableDescriptionRegex.exec(sql_desc);
|
|
196
196
|
// OINOLog.debug("OINODbBunSqlite.initDatamodel", {table_matches:table_matches})
|
|
@@ -209,11 +209,14 @@ export class OINODbBunSqlite extends OINODb {
|
|
|
209
209
|
if ((!field_match) || (field_match.length < 3)) {
|
|
210
210
|
let primarykey_match = OINODbBunSqlite._tablePrimarykeyRegex.exec(field_str);
|
|
211
211
|
let foreignkey_match = OINODbBunSqlite._tableForeignkeyRegex.exec(field_str);
|
|
212
|
-
OINOLog.debug("initDatamodel non-field definition", {
|
|
212
|
+
// OINOLog.debug("initDatamodel non-field definition", {primarykey_match:primarykey_match, foreignkey_match:foreignkey_match})
|
|
213
213
|
if (primarykey_match && primarykey_match.length >= 2) {
|
|
214
214
|
const primary_keys = primarykey_match[1].replaceAll("\"", "").split(','); // not sure if will have space or not so split by comma and trim later
|
|
215
215
|
for (let i = 0; i < primary_keys.length; i++) {
|
|
216
216
|
const pk = primary_keys[i].trim(); //..the trim
|
|
217
|
+
if (excluded_fields.indexOf(pk) >= 0) {
|
|
218
|
+
throw new Error(OINO_ERROR_PREFIX + "Primary key field excluded in API parameters: " + pk);
|
|
219
|
+
}
|
|
217
220
|
for (let j = 0; j < api.datamodel.fields.length; j++) {
|
|
218
221
|
if (api.datamodel.fields[j].name == pk) {
|
|
219
222
|
api.datamodel.fields[j].fieldParams.isPrimaryKey = true;
|
|
@@ -240,7 +243,8 @@ export class OINODbBunSqlite extends OINODb {
|
|
|
240
243
|
const sql_type = field_match[2];
|
|
241
244
|
const field_length = parseInt(field_match[4]) || 0;
|
|
242
245
|
// OINOLog.debug("OINODbBunSqlite.initializeApiDatamodel: field regex matches", { api.params: api.params, field_name:field_name })
|
|
243
|
-
if (
|
|
246
|
+
if (api.isFieldIncluded(field_name) == false) {
|
|
247
|
+
excluded_fields.push(field_name);
|
|
244
248
|
OINOLog.info("OINODbBunSqlite.initializeApiDatamodel: field excluded in API parameters.", { field: field_name });
|
|
245
249
|
}
|
|
246
250
|
else {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oino-ts/db-bunsqlite",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "OINO TS package for using Bun Sqlite databases.",
|
|
5
5
|
"author": "Matias Kiviniemi (pragmatta)",
|
|
6
6
|
"license": "MPL-2.0",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"module": "./dist/esm/index.js",
|
|
21
21
|
"types": "./dist/types/index.d.ts",
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@oino-ts/db": "^0.
|
|
23
|
+
"@oino-ts/db": "^0.3.1"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"@types/node": "^20.12.7",
|
package/src/OINODbBunSqlite.ts
CHANGED
|
@@ -205,7 +205,7 @@ export class OINODbBunSqlite extends OINODb {
|
|
|
205
205
|
async initializeApiDatamodel(api:OINODbApi): Promise<void> {
|
|
206
206
|
const res:OINODbDataSet|null = await this.sqlSelect("select sql from sqlite_schema WHERE name='" + api.params.tableName + "'")
|
|
207
207
|
const sql_desc:string = (res?.getRow()[0]) as string
|
|
208
|
-
const
|
|
208
|
+
const excluded_fields:string[] = []
|
|
209
209
|
// OINOLog.debug("OINODbBunSqlite.initDatamodel.sql_desc=" + sql_desc)
|
|
210
210
|
let table_matches = OINODbBunSqlite._tableDescriptionRegex.exec(sql_desc)
|
|
211
211
|
// OINOLog.debug("OINODbBunSqlite.initDatamodel", {table_matches:table_matches})
|
|
@@ -224,11 +224,14 @@ export class OINODbBunSqlite extends OINODb {
|
|
|
224
224
|
if ((!field_match) || (field_match.length < 3)) {
|
|
225
225
|
let primarykey_match = OINODbBunSqlite._tablePrimarykeyRegex.exec(field_str)
|
|
226
226
|
let foreignkey_match = OINODbBunSqlite._tableForeignkeyRegex.exec(field_str)
|
|
227
|
-
OINOLog.debug("initDatamodel non-field definition", {primarykey_match:primarykey_match, foreignkey_match:foreignkey_match})
|
|
227
|
+
// OINOLog.debug("initDatamodel non-field definition", {primarykey_match:primarykey_match, foreignkey_match:foreignkey_match})
|
|
228
228
|
if (primarykey_match && primarykey_match.length >= 2) {
|
|
229
229
|
const primary_keys:string[] = primarykey_match[1].replaceAll("\"", "").split(',') // not sure if will have space or not so split by comma and trim later
|
|
230
230
|
for (let i:number=0; i<primary_keys.length; i++) {
|
|
231
231
|
const pk:string = primary_keys[i].trim() //..the trim
|
|
232
|
+
if (excluded_fields.indexOf(pk) >= 0) {
|
|
233
|
+
throw new Error(OINO_ERROR_PREFIX + "Primary key field excluded in API parameters: " + pk)
|
|
234
|
+
}
|
|
232
235
|
for (let j:number=0; j<api.datamodel.fields.length; j++) {
|
|
233
236
|
if (api.datamodel.fields[j].name == pk) {
|
|
234
237
|
api.datamodel.fields[j].fieldParams.isPrimaryKey = true
|
|
@@ -255,7 +258,8 @@ export class OINODbBunSqlite extends OINODb {
|
|
|
255
258
|
const sql_type:string = field_match[2]
|
|
256
259
|
const field_length:number = parseInt(field_match[4]) || 0
|
|
257
260
|
// OINOLog.debug("OINODbBunSqlite.initializeApiDatamodel: field regex matches", { api.params: api.params, field_name:field_name })
|
|
258
|
-
if (
|
|
261
|
+
if (api.isFieldIncluded(field_name) == false) {
|
|
262
|
+
excluded_fields.push(field_name)
|
|
259
263
|
OINOLog.info("OINODbBunSqlite.initializeApiDatamodel: field excluded in API parameters.", {field:field_name})
|
|
260
264
|
|
|
261
265
|
} else {
|