@oino-ts/db 0.13.2 → 0.13.4
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.
- package/dist/cjs/OINODbDataModel.js +5 -5
- package/dist/cjs/OINODbModelSet.js +5 -2
- package/dist/esm/OINODbDataModel.js +5 -5
- package/dist/esm/OINODbModelSet.js +5 -2
- package/dist/types/OINODbDataModel.d.ts +1 -1
- package/dist/types/OINODbModelSet.d.ts +2 -1
- package/package.json +3 -3
- package/src/OINODbDataModel.ts +5 -5
- package/src/OINODbModelSet.ts +6 -3
|
@@ -12,7 +12,7 @@ const index_js_1 = require("./index.js");
|
|
|
12
12
|
*
|
|
13
13
|
*/
|
|
14
14
|
class OINODbDataModel {
|
|
15
|
-
|
|
15
|
+
_fieldIndexLookup;
|
|
16
16
|
/** Database refererence of the table */
|
|
17
17
|
api;
|
|
18
18
|
/** Field refererences of the API */
|
|
@@ -25,7 +25,7 @@ class OINODbDataModel {
|
|
|
25
25
|
*
|
|
26
26
|
*/
|
|
27
27
|
constructor(api) {
|
|
28
|
-
this.
|
|
28
|
+
this._fieldIndexLookup = {};
|
|
29
29
|
this.api = api;
|
|
30
30
|
this.fields = [];
|
|
31
31
|
}
|
|
@@ -116,7 +116,7 @@ class OINODbDataModel {
|
|
|
116
116
|
*/
|
|
117
117
|
addField(field) {
|
|
118
118
|
this.fields.push(field);
|
|
119
|
-
this.
|
|
119
|
+
this._fieldIndexLookup[field.name] = this.fields.length - 1;
|
|
120
120
|
}
|
|
121
121
|
/**
|
|
122
122
|
* Find a field of a given name if any.
|
|
@@ -125,7 +125,7 @@ class OINODbDataModel {
|
|
|
125
125
|
*
|
|
126
126
|
*/
|
|
127
127
|
findFieldByName(name) {
|
|
128
|
-
const i = this.
|
|
128
|
+
const i = this._fieldIndexLookup[name];
|
|
129
129
|
if (i >= 0) {
|
|
130
130
|
return this.fields[i];
|
|
131
131
|
}
|
|
@@ -140,7 +140,7 @@ class OINODbDataModel {
|
|
|
140
140
|
*
|
|
141
141
|
*/
|
|
142
142
|
findFieldIndexByName(name) {
|
|
143
|
-
const i = this.
|
|
143
|
+
const i = this._fieldIndexLookup[name];
|
|
144
144
|
if (i >= 0) {
|
|
145
145
|
return i;
|
|
146
146
|
}
|
|
@@ -308,13 +308,16 @@ class OINODbModelSet {
|
|
|
308
308
|
/**
|
|
309
309
|
* Export all rows as a record with OINOId as key and object with row cells as values.
|
|
310
310
|
*
|
|
311
|
+
* @param idFieldName optional field name to use as key instead of OINOId
|
|
311
312
|
*/
|
|
312
|
-
async exportAsRecord() {
|
|
313
|
+
async exportAsRecord(idFieldName) {
|
|
313
314
|
const result = {};
|
|
315
|
+
const row_id_field = idFieldName || index_js_1.OINODbConfig.OINODB_ID_FIELD;
|
|
314
316
|
while (!this.dataset.isEof()) {
|
|
315
317
|
const row_data = this.dataset.getRow();
|
|
316
318
|
const row_export = this._exportRow(row_data);
|
|
317
|
-
|
|
319
|
+
const row_id = row_export[row_id_field];
|
|
320
|
+
result[row_id] = row_export;
|
|
318
321
|
await this.dataset.next();
|
|
319
322
|
}
|
|
320
323
|
return result;
|
|
@@ -9,7 +9,7 @@ import { OINO_ERROR_PREFIX, OINODbConfig, OINONumberDataField, OINODB_UNDEFINED
|
|
|
9
9
|
*
|
|
10
10
|
*/
|
|
11
11
|
export class OINODbDataModel {
|
|
12
|
-
|
|
12
|
+
_fieldIndexLookup;
|
|
13
13
|
/** Database refererence of the table */
|
|
14
14
|
api;
|
|
15
15
|
/** Field refererences of the API */
|
|
@@ -22,7 +22,7 @@ export class OINODbDataModel {
|
|
|
22
22
|
*
|
|
23
23
|
*/
|
|
24
24
|
constructor(api) {
|
|
25
|
-
this.
|
|
25
|
+
this._fieldIndexLookup = {};
|
|
26
26
|
this.api = api;
|
|
27
27
|
this.fields = [];
|
|
28
28
|
}
|
|
@@ -113,7 +113,7 @@ export class OINODbDataModel {
|
|
|
113
113
|
*/
|
|
114
114
|
addField(field) {
|
|
115
115
|
this.fields.push(field);
|
|
116
|
-
this.
|
|
116
|
+
this._fieldIndexLookup[field.name] = this.fields.length - 1;
|
|
117
117
|
}
|
|
118
118
|
/**
|
|
119
119
|
* Find a field of a given name if any.
|
|
@@ -122,7 +122,7 @@ export class OINODbDataModel {
|
|
|
122
122
|
*
|
|
123
123
|
*/
|
|
124
124
|
findFieldByName(name) {
|
|
125
|
-
const i = this.
|
|
125
|
+
const i = this._fieldIndexLookup[name];
|
|
126
126
|
if (i >= 0) {
|
|
127
127
|
return this.fields[i];
|
|
128
128
|
}
|
|
@@ -137,7 +137,7 @@ export class OINODbDataModel {
|
|
|
137
137
|
*
|
|
138
138
|
*/
|
|
139
139
|
findFieldIndexByName(name) {
|
|
140
|
-
const i = this.
|
|
140
|
+
const i = this._fieldIndexLookup[name];
|
|
141
141
|
if (i >= 0) {
|
|
142
142
|
return i;
|
|
143
143
|
}
|
|
@@ -305,13 +305,16 @@ export class OINODbModelSet {
|
|
|
305
305
|
/**
|
|
306
306
|
* Export all rows as a record with OINOId as key and object with row cells as values.
|
|
307
307
|
*
|
|
308
|
+
* @param idFieldName optional field name to use as key instead of OINOId
|
|
308
309
|
*/
|
|
309
|
-
async exportAsRecord() {
|
|
310
|
+
async exportAsRecord(idFieldName) {
|
|
310
311
|
const result = {};
|
|
312
|
+
const row_id_field = idFieldName || OINODbConfig.OINODB_ID_FIELD;
|
|
311
313
|
while (!this.dataset.isEof()) {
|
|
312
314
|
const row_data = this.dataset.getRow();
|
|
313
315
|
const row_export = this._exportRow(row_data);
|
|
314
|
-
|
|
316
|
+
const row_id = row_export[row_id_field];
|
|
317
|
+
result[row_id] = row_export;
|
|
315
318
|
await this.dataset.next();
|
|
316
319
|
}
|
|
317
320
|
return result;
|
|
@@ -4,7 +4,7 @@ import { OINODbDataField, OINODbApi, OINODataRow, OINODbDataFieldFilter, OINODbS
|
|
|
4
4
|
*
|
|
5
5
|
*/
|
|
6
6
|
export declare class OINODbDataModel {
|
|
7
|
-
private
|
|
7
|
+
private _fieldIndexLookup;
|
|
8
8
|
/** Database refererence of the table */
|
|
9
9
|
readonly api: OINODbApi;
|
|
10
10
|
/** Field refererences of the API */
|
|
@@ -55,6 +55,7 @@ export declare class OINODbModelSet {
|
|
|
55
55
|
/**
|
|
56
56
|
* Export all rows as a record with OINOId as key and object with row cells as values.
|
|
57
57
|
*
|
|
58
|
+
* @param idFieldName optional field name to use as key instead of OINOId
|
|
58
59
|
*/
|
|
59
|
-
exportAsRecord(): Promise<Record<string, any>>;
|
|
60
|
+
exportAsRecord(idFieldName?: string): Promise<Record<string, any>>;
|
|
60
61
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oino-ts/db",
|
|
3
|
-
"version": "0.13.
|
|
3
|
+
"version": "0.13.4",
|
|
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.
|
|
22
|
+
"@oino-ts/common": "0.13.4",
|
|
23
23
|
"oino-ts": "file:.."
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"@oino-ts/types": "0.13.
|
|
26
|
+
"@oino-ts/types": "0.13.4",
|
|
27
27
|
"@types/bun": "^1.1.14",
|
|
28
28
|
"@types/node": "^20.14.10",
|
|
29
29
|
"typescript": "~5.9.0"
|
package/src/OINODbDataModel.ts
CHANGED
|
@@ -11,7 +11,7 @@ import { OINODbDataField, OINODbApi, OINODataRow, OINO_ERROR_PREFIX, OINODbDataF
|
|
|
11
11
|
*
|
|
12
12
|
*/
|
|
13
13
|
export class OINODbDataModel {
|
|
14
|
-
private
|
|
14
|
+
private _fieldIndexLookup:Record<string, number>;
|
|
15
15
|
|
|
16
16
|
/** Database refererence of the table */
|
|
17
17
|
readonly api:OINODbApi
|
|
@@ -27,7 +27,7 @@ export class OINODbDataModel {
|
|
|
27
27
|
*
|
|
28
28
|
*/
|
|
29
29
|
constructor(api:OINODbApi) {
|
|
30
|
-
this.
|
|
30
|
+
this._fieldIndexLookup = {}
|
|
31
31
|
this.api = api
|
|
32
32
|
this.fields = []
|
|
33
33
|
}
|
|
@@ -122,7 +122,7 @@ export class OINODbDataModel {
|
|
|
122
122
|
*/
|
|
123
123
|
addField(field:OINODbDataField) {
|
|
124
124
|
this.fields.push(field)
|
|
125
|
-
this.
|
|
125
|
+
this._fieldIndexLookup[field.name] = this.fields.length-1
|
|
126
126
|
}
|
|
127
127
|
|
|
128
128
|
/**
|
|
@@ -132,7 +132,7 @@ export class OINODbDataModel {
|
|
|
132
132
|
*
|
|
133
133
|
*/
|
|
134
134
|
findFieldByName(name:string):OINODbDataField|null {
|
|
135
|
-
const i:number = this.
|
|
135
|
+
const i:number = this._fieldIndexLookup[name]
|
|
136
136
|
if (i >= 0) {
|
|
137
137
|
return this.fields[i]
|
|
138
138
|
} else {
|
|
@@ -147,7 +147,7 @@ export class OINODbDataModel {
|
|
|
147
147
|
*
|
|
148
148
|
*/
|
|
149
149
|
findFieldIndexByName(name:string):number {
|
|
150
|
-
const i:number = this.
|
|
150
|
+
const i:number = this._fieldIndexLookup[name]
|
|
151
151
|
if (i >= 0) {
|
|
152
152
|
return i
|
|
153
153
|
} else {
|
package/src/OINODbModelSet.ts
CHANGED
|
@@ -329,15 +329,18 @@ export class OINODbModelSet {
|
|
|
329
329
|
|
|
330
330
|
/**
|
|
331
331
|
* Export all rows as a record with OINOId as key and object with row cells as values.
|
|
332
|
-
*
|
|
332
|
+
*
|
|
333
|
+
* @param idFieldName optional field name to use as key instead of OINOId
|
|
333
334
|
*/
|
|
334
335
|
|
|
335
|
-
async exportAsRecord():Promise<Record<string, any>> {
|
|
336
|
+
async exportAsRecord(idFieldName?:string):Promise<Record<string, any>> {
|
|
336
337
|
const result:Record<string, any> = {}
|
|
338
|
+
const row_id_field = idFieldName || OINODbConfig.OINODB_ID_FIELD
|
|
337
339
|
while (!this.dataset.isEof()) {
|
|
338
340
|
const row_data:OINODataRow = this.dataset.getRow()
|
|
339
341
|
const row_export = this._exportRow(row_data)
|
|
340
|
-
|
|
342
|
+
const row_id = row_export[row_id_field]
|
|
343
|
+
result[row_id] = row_export
|
|
341
344
|
await this.dataset.next()
|
|
342
345
|
}
|
|
343
346
|
return result
|