@oino-ts/db 0.21.2 → 1.0.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.
- package/dist/cjs/OINODb.js +6 -144
- package/dist/cjs/OINODbApi.js +50 -318
- package/dist/cjs/OINODbConfig.js +10 -10
- package/dist/cjs/OINODbConstants.js +10 -0
- package/dist/cjs/OINODbDataField.js +28 -70
- package/dist/cjs/OINODbDataModel.js +30 -144
- package/dist/cjs/OINODbFactory.js +2 -2
- package/dist/cjs/OINODbModelSet.js +23 -23
- package/dist/cjs/OINODbQueryParams.js +201 -0
- package/dist/cjs/index.js +12 -41
- package/dist/esm/OINODb.js +6 -142
- package/dist/esm/OINODbApi.js +49 -314
- package/dist/esm/OINODbConstants.js +7 -0
- package/dist/esm/OINODbDataModel.js +31 -145
- package/dist/esm/OINODbFactory.js +1 -1
- package/dist/esm/OINODbQueryParams.js +194 -0
- package/dist/esm/index.js +4 -14
- package/dist/types/OINODb.d.ts +6 -173
- package/dist/types/OINODbApi.d.ts +18 -104
- package/dist/types/OINODbConstants.d.ts +23 -0
- package/dist/types/OINODbDataModel.d.ts +7 -61
- package/dist/types/OINODbFactory.d.ts +5 -2
- package/dist/types/OINODbQueryParams.d.ts +72 -0
- package/dist/types/index.d.ts +4 -108
- package/package.json +37 -37
- package/src/OINODb.ts +99 -348
- package/src/OINODbApi.test.ts +507 -498
- package/src/OINODbApi.ts +389 -667
- package/src/OINODbConstants.ts +32 -0
- package/src/OINODbDataModel.ts +191 -307
- package/src/OINODbFactory.ts +73 -68
- package/src/OINODbQueryParams.ts +203 -0
- package/src/index.ts +6 -118
- package/src/OINODbConfig.ts +0 -98
- package/src/OINODbDataField.ts +0 -405
- package/src/OINODbModelSet.ts +0 -353
- package/src/OINODbParser.ts +0 -438
- package/src/OINODbSqlParams.ts +0 -593
- package/src/OINODbSwagger.ts +0 -209
package/dist/types/OINODb.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { OINODbParams
|
|
1
|
+
import { OINODataSet, OINODataSource } from "@oino-ts/common";
|
|
2
|
+
import { OINODbParams } from "./OINODbConstants.js";
|
|
3
3
|
/**
|
|
4
4
|
* Base class for database abstraction, implementing methods for connecting, making queries and parsing/formatting data
|
|
5
5
|
* between SQL and serialization formats.
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
|
-
export declare abstract class OINODb {
|
|
9
|
-
protected
|
|
8
|
+
export declare abstract class OINODb extends OINODataSource {
|
|
9
|
+
protected readonly dbParams: OINODbParams;
|
|
10
10
|
/** Name of the database */
|
|
11
11
|
readonly name: string;
|
|
12
12
|
isConnected: boolean;
|
|
@@ -16,82 +16,20 @@ export declare abstract class OINODb {
|
|
|
16
16
|
* @param params database parameters
|
|
17
17
|
*/
|
|
18
18
|
constructor(params: OINODbParams);
|
|
19
|
-
/**
|
|
20
|
-
* Connect to database.
|
|
21
|
-
*
|
|
22
|
-
*/
|
|
23
|
-
abstract connect(): Promise<OINOResult>;
|
|
24
|
-
/**
|
|
25
|
-
* Validate connection to database is working.
|
|
26
|
-
*
|
|
27
|
-
*/
|
|
28
|
-
abstract validate(): Promise<OINOResult>;
|
|
29
|
-
/**
|
|
30
|
-
* Disconnect from database.
|
|
31
|
-
*
|
|
32
|
-
*/
|
|
33
|
-
abstract disconnect(): Promise<void>;
|
|
34
|
-
/**
|
|
35
|
-
* Print a table name using database specific SQL escaping.
|
|
36
|
-
*
|
|
37
|
-
* @param sqlTable name of the table
|
|
38
|
-
*
|
|
39
|
-
*/
|
|
40
|
-
abstract printSqlTablename(sqlTable: string): string;
|
|
41
|
-
/**
|
|
42
|
-
* Print a column name with correct SQL escaping.
|
|
43
|
-
*
|
|
44
|
-
* @param sqlColumn name of the column
|
|
45
|
-
*
|
|
46
|
-
*/
|
|
47
|
-
abstract printSqlColumnname(sqlColumn: string): string;
|
|
48
|
-
/**
|
|
49
|
-
* Print a single data value from serialization using the context of the native data
|
|
50
|
-
* type with the correct SQL escaping.
|
|
51
|
-
*
|
|
52
|
-
* @param cellValue data from sql results
|
|
53
|
-
* @param sqlType native type name for table column
|
|
54
|
-
*
|
|
55
|
-
*/
|
|
56
|
-
abstract printCellAsSqlValue(cellValue: OINODataCell, sqlType: string): string;
|
|
57
|
-
/**
|
|
58
|
-
* Print a single string value as valid sql literal
|
|
59
|
-
*
|
|
60
|
-
* @param sqlString string value
|
|
61
|
-
*
|
|
62
|
-
*/
|
|
63
|
-
abstract printSqlString(sqlString: string): string;
|
|
64
|
-
/**
|
|
65
|
-
* Parse a single SQL result value for serialization using the context of the native data
|
|
66
|
-
* type.
|
|
67
|
-
*
|
|
68
|
-
* @param sqlValue data from serialization
|
|
69
|
-
* @param sqlType native type name for table column
|
|
70
|
-
*
|
|
71
|
-
*/
|
|
72
|
-
abstract parseSqlValueAsCell(sqlValue: OINODataCell, sqlType: string): OINODataCell;
|
|
73
19
|
/**
|
|
74
20
|
* Execute a select operation.
|
|
75
21
|
*
|
|
76
22
|
* @param sql SQL statement.
|
|
77
23
|
*
|
|
78
24
|
*/
|
|
79
|
-
abstract sqlSelect(sql: string): Promise<
|
|
25
|
+
abstract sqlSelect(sql: string): Promise<OINODataSet>;
|
|
80
26
|
/**
|
|
81
27
|
* Execute other sql operations.
|
|
82
28
|
*
|
|
83
29
|
* @param sql SQL statement.
|
|
84
30
|
*
|
|
85
31
|
*/
|
|
86
|
-
abstract sqlExec(sql: string): Promise<
|
|
87
|
-
/**
|
|
88
|
-
* Initialize a data model by getting the SQL schema and populating OINODbDataFields of
|
|
89
|
-
* the model.
|
|
90
|
-
*
|
|
91
|
-
* @param api api which data model to initialize.
|
|
92
|
-
*
|
|
93
|
-
*/
|
|
94
|
-
abstract initializeApiDatamodel(api: OINODbApi): Promise<void>;
|
|
32
|
+
abstract sqlExec(sql: string): Promise<OINODataSet>;
|
|
95
33
|
/**
|
|
96
34
|
* Print SQL select statement with DB specific formatting.
|
|
97
35
|
*
|
|
@@ -115,108 +53,3 @@ export declare abstract class OINODb {
|
|
|
115
53
|
*/
|
|
116
54
|
printSqlInsert(tableName: string, columns: string, values: string, returnIdFields?: string[]): string;
|
|
117
55
|
}
|
|
118
|
-
/**
|
|
119
|
-
* Base class for SQL results that can be asynchronously iterated (but
|
|
120
|
-
* not necessarity rewinded). Idea is to handle database specific mechanisms
|
|
121
|
-
* for returning and formatting conventions in the database specific
|
|
122
|
-
* implementation. Data might be in memory or streamed in chunks and
|
|
123
|
-
* `OINODbDataSet` will serve it out consistently.
|
|
124
|
-
*
|
|
125
|
-
*/
|
|
126
|
-
export declare abstract class OINODbDataSet extends OINOResult {
|
|
127
|
-
private _data;
|
|
128
|
-
/** Error messages */
|
|
129
|
-
readonly messages: string[];
|
|
130
|
-
/**
|
|
131
|
-
* Constructor for `OINODbDataSet`.
|
|
132
|
-
*
|
|
133
|
-
* @param data internal database specific data type (constructor will throw if invalid)
|
|
134
|
-
* @param messages error messages from SQL-query
|
|
135
|
-
*
|
|
136
|
-
*/
|
|
137
|
-
constructor(data: unknown, messages?: string[]);
|
|
138
|
-
/**
|
|
139
|
-
* Is data set empty.
|
|
140
|
-
*
|
|
141
|
-
*/
|
|
142
|
-
abstract isEmpty(): boolean;
|
|
143
|
-
/**
|
|
144
|
-
* Is there no more content, i.e. either dataset is empty or we have moved beyond last line
|
|
145
|
-
*
|
|
146
|
-
*/
|
|
147
|
-
abstract isEof(): boolean;
|
|
148
|
-
/**
|
|
149
|
-
* Attempts to moves dataset to the next row, possibly waiting for more data to become available. Returns !isEof().
|
|
150
|
-
*
|
|
151
|
-
*/
|
|
152
|
-
abstract next(): Promise<boolean>;
|
|
153
|
-
/**
|
|
154
|
-
* Gets current row of data.
|
|
155
|
-
*
|
|
156
|
-
*/
|
|
157
|
-
abstract getRow(): OINODataRow;
|
|
158
|
-
/**
|
|
159
|
-
* Gets all rows of data.
|
|
160
|
-
*
|
|
161
|
-
* NOTE: This is left abstract instead of just using `getRow()` so that DB implementations can hopefully optimize not duplicating data *
|
|
162
|
-
*/
|
|
163
|
-
abstract getAllRows(): Promise<OINODataRow[]>;
|
|
164
|
-
/**
|
|
165
|
-
* Checks if the messages contain errors.
|
|
166
|
-
*
|
|
167
|
-
*/
|
|
168
|
-
hasErrors(): boolean;
|
|
169
|
-
/**
|
|
170
|
-
* Checks if the messages contain errors.
|
|
171
|
-
*
|
|
172
|
-
*/
|
|
173
|
-
getFirstError(): string;
|
|
174
|
-
}
|
|
175
|
-
/**
|
|
176
|
-
* Generic in memory implementation of a data set where data is an array of rows. Used
|
|
177
|
-
* by BunSqlite and automated testing. Can be rewinded.
|
|
178
|
-
*
|
|
179
|
-
*/
|
|
180
|
-
export declare class OINODbMemoryDataSet extends OINODbDataSet {
|
|
181
|
-
private _rows;
|
|
182
|
-
private _currentRow;
|
|
183
|
-
private _eof;
|
|
184
|
-
/**
|
|
185
|
-
* Constructor of `OINODbMemoryDataSet`.
|
|
186
|
-
*
|
|
187
|
-
* @param data data as OINODataRow[] (constructor will throw if invalid)
|
|
188
|
-
* @param errors error messages from SQL-query
|
|
189
|
-
*
|
|
190
|
-
*/
|
|
191
|
-
constructor(data: unknown, errors?: string[]);
|
|
192
|
-
/**
|
|
193
|
-
* Is data set empty.
|
|
194
|
-
*
|
|
195
|
-
*/
|
|
196
|
-
isEmpty(): boolean;
|
|
197
|
-
/**
|
|
198
|
-
* Is there no more content, i.e. either dataset is empty or we have moved beyond last line
|
|
199
|
-
*
|
|
200
|
-
*/
|
|
201
|
-
isEof(): boolean;
|
|
202
|
-
/**
|
|
203
|
-
* Attempts to moves dataset to the next row, possibly waiting for more data to become available. Returns !isEof().
|
|
204
|
-
*
|
|
205
|
-
*/
|
|
206
|
-
next(): Promise<boolean>;
|
|
207
|
-
/**
|
|
208
|
-
* Gets current row of data.
|
|
209
|
-
*
|
|
210
|
-
*/
|
|
211
|
-
getRow(): OINODataRow;
|
|
212
|
-
/**
|
|
213
|
-
* Gets all rows of data.
|
|
214
|
-
*
|
|
215
|
-
*/
|
|
216
|
-
getAllRows(): Promise<OINODataRow[]>;
|
|
217
|
-
/**
|
|
218
|
-
* Rewinds data set to the first row, returns !isEof().
|
|
219
|
-
*
|
|
220
|
-
*/
|
|
221
|
-
first(): boolean;
|
|
222
|
-
}
|
|
@@ -1,98 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
import { OINOResult, OINOHttpRequest, type OINOHttpRequestInit, OINOHttpResult, OINOHtmlTemplate, OINOContentType } from "@oino-ts/common";
|
|
5
|
-
import { OINODbApiParams, OINODb, OINODbDataModel, OINODataRow, OINODbModelSet, OINODbSqlParams, OINODbSqlAggregate, OINODbSqlSelect, OINODbSqlFilter, OINODbSqlOrder, OINODbSqlLimit } from "./index.js";
|
|
6
|
-
import { OINOHashid } from "@oino-ts/hashid";
|
|
7
|
-
export type OINODbApiData = string | OINODataRow[] | Buffer | Uint8Array | object | null;
|
|
8
|
-
export interface OINODbApiRequestInit extends OINOHttpRequestInit {
|
|
9
|
-
rowId?: string;
|
|
10
|
-
rowData?: OINODbApiData;
|
|
11
|
-
sqlParams?: OINODbSqlParams;
|
|
12
|
-
filter?: OINODbSqlFilter | string;
|
|
13
|
-
order?: OINODbSqlOrder | string;
|
|
14
|
-
limit?: OINODbSqlLimit | string;
|
|
15
|
-
aggregate?: OINODbSqlAggregate | string;
|
|
16
|
-
select?: OINODbSqlSelect | string;
|
|
17
|
-
}
|
|
18
|
-
export declare class OINODbApiRequest extends OINOHttpRequest {
|
|
19
|
-
rowId: string;
|
|
20
|
-
rowData: OINODbApiData;
|
|
21
|
-
sqlParams: OINODbSqlParams;
|
|
22
|
-
constructor(init: OINODbApiRequestInit);
|
|
23
|
-
static fromFetchRequest(request: Request, rowId?: string, rowData?: OINODbApiData, sqlParams?: OINODbSqlParams): Promise<OINODbApiRequest>;
|
|
24
|
-
static fromHttpRequest(request: OINOHttpRequest, rowId?: string, rowData?: OINODbApiData, sqlParams?: OINODbSqlParams): OINODbApiRequest;
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* OINO API request result object with returned data and/or http status code/message and
|
|
28
|
-
* error / warning messages.
|
|
29
|
-
*
|
|
30
|
-
*/
|
|
31
|
-
export declare class OINODbApiResult extends OINOResult {
|
|
32
|
-
/** DbApi request params */
|
|
33
|
-
request: OINODbApiRequest;
|
|
34
|
-
/** Returned data if any */
|
|
35
|
-
data?: OINODbModelSet;
|
|
36
|
-
/**
|
|
37
|
-
* Constructor of OINODbApiResult.
|
|
38
|
-
*
|
|
39
|
-
* @param request DbApi request parameters
|
|
40
|
-
* @param data result data
|
|
41
|
-
*
|
|
42
|
-
*/
|
|
43
|
-
constructor(request: OINODbApiRequest, data?: OINODbModelSet);
|
|
44
|
-
/**
|
|
45
|
-
* Creates a HTTP Response from API results.
|
|
46
|
-
*
|
|
47
|
-
* @param headers Headers to include in the response
|
|
48
|
-
*
|
|
49
|
-
*/
|
|
50
|
-
writeApiResponse(headers?: Record<string, string>): Promise<Response>;
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Specialized HTML template that can render ´OINODbApiResult´.
|
|
54
|
-
*
|
|
55
|
-
*/
|
|
56
|
-
export declare class OINODbHtmlTemplate extends OINOHtmlTemplate {
|
|
57
|
-
/** Locale validation regex */
|
|
58
|
-
static LOCALE_REGEX: RegExp;
|
|
59
|
-
/** Locale formatter */
|
|
60
|
-
protected _locale: Intl.DateTimeFormat | null;
|
|
61
|
-
protected _numberDecimals: number;
|
|
62
|
-
/**
|
|
63
|
-
* Constructor of OINODbHtmlTemplate.
|
|
64
|
-
*
|
|
65
|
-
* @param template HTML template string
|
|
66
|
-
* @param numberDecimals Number of decimals to use for numbers, -1 for no formatting
|
|
67
|
-
* @param dateLocaleStr Datetime format string, either "iso" for ISO8601 or "default" for system default or valid locale string
|
|
68
|
-
* @param dateLocaleStyle Datetime format style, either "short/medium/long/full" or Intl.DateTimeFormat options
|
|
69
|
-
*
|
|
70
|
-
*/
|
|
71
|
-
constructor(template: string, numberDecimals?: number, dateLocaleStr?: string, dateLocaleStyle?: string | any);
|
|
72
|
-
/**
|
|
73
|
-
* Creates HTML Response from API modelset.
|
|
74
|
-
*
|
|
75
|
-
* @param modelset OINO API dataset
|
|
76
|
-
* @param overrideValues values to override in the data
|
|
77
|
-
*
|
|
78
|
-
*/
|
|
79
|
-
renderFromDbData(modelset: OINODbModelSet, overrideValues?: any): Promise<OINOHttpResult>;
|
|
80
|
-
}
|
|
1
|
+
import { OINOApi, OINOApiParams, OINOHttpRequest, OINOApiRequest, OINOApiResult, OINOContentType, OINOQueryParams, OINOApiData } from "@oino-ts/common";
|
|
2
|
+
import { OINODb } from "./OINODb.js";
|
|
3
|
+
import { OINODbDataModel } from "./OINODbDataModel.js";
|
|
81
4
|
/**
|
|
82
5
|
* API class with method to process HTTP REST requests.
|
|
83
6
|
*
|
|
84
7
|
*/
|
|
85
|
-
export declare class OINODbApi {
|
|
86
|
-
/**
|
|
87
|
-
private _debugOnError;
|
|
88
|
-
/** API database reference */
|
|
8
|
+
export declare class OINODbApi extends OINOApi {
|
|
9
|
+
/** DB reference */
|
|
89
10
|
readonly db: OINODb;
|
|
90
|
-
/**
|
|
91
|
-
readonly
|
|
92
|
-
/**
|
|
93
|
-
|
|
94
|
-
/** API hashid */
|
|
95
|
-
readonly hashid: OINOHashid | null;
|
|
11
|
+
/** DB parameters reference */
|
|
12
|
+
readonly dbParams: OINOApiParams;
|
|
13
|
+
/** DB datamodel reference */
|
|
14
|
+
dbDatamodel: OINODbDataModel | null;
|
|
96
15
|
/**
|
|
97
16
|
* Constructor of API object.
|
|
98
17
|
* NOTE! OINODb.initDatamodel must be called if created manually instead of the factory.
|
|
@@ -101,19 +20,14 @@ export declare class OINODbApi {
|
|
|
101
20
|
* @param params parameters for the API
|
|
102
21
|
*
|
|
103
22
|
*/
|
|
104
|
-
constructor(db: OINODb, params:
|
|
23
|
+
constructor(db: OINODb, params: OINOApiParams);
|
|
24
|
+
initializeDatamodel(datamodel: OINODbDataModel): void;
|
|
105
25
|
private _validateRow;
|
|
106
26
|
private _parseData;
|
|
107
27
|
private _doGet;
|
|
108
28
|
private _doPost;
|
|
109
29
|
private _doPut;
|
|
110
30
|
private _doDelete;
|
|
111
|
-
/**
|
|
112
|
-
* Enable or disable debug output on errors.
|
|
113
|
-
*
|
|
114
|
-
* @param debugOnError true to enable debug output on errors, false to disable
|
|
115
|
-
*/
|
|
116
|
-
setDebugOnError(debugOnError: boolean): void;
|
|
117
31
|
/**
|
|
118
32
|
* Method for handling a HTTP REST request with GET, POST, PUT, DELETE corresponding to
|
|
119
33
|
* SQL select, insert, update and delete.
|
|
@@ -121,10 +35,10 @@ export declare class OINODbApi {
|
|
|
121
35
|
* @param request OINO HTTP request object containing all parameters of the REST request
|
|
122
36
|
* @param rowId URL id of the REST request
|
|
123
37
|
* @param rowData HTTP body data as either serialized string or unserialized JS object or OINODataRow-array or Buffer/Uint8Array binary data
|
|
124
|
-
* @param
|
|
38
|
+
* @param queryParams SQL parameters for the REST request
|
|
125
39
|
*
|
|
126
40
|
*/
|
|
127
|
-
doHttpRequest(request: OINOHttpRequest, rowId: string, rowData:
|
|
41
|
+
doHttpRequest(request: OINOHttpRequest, rowId: string, rowData: OINOApiData, queryParams: OINOQueryParams): Promise<OINOApiResult>;
|
|
128
42
|
/**
|
|
129
43
|
* Method for handling a HTTP REST request with GET, POST, PUT, DELETE corresponding to
|
|
130
44
|
* SQL select, insert, update and delete.
|
|
@@ -132,12 +46,12 @@ export declare class OINODbApi {
|
|
|
132
46
|
* @param method HTTP method of the REST request
|
|
133
47
|
* @param rowId URL id of the REST request
|
|
134
48
|
* @param rowData HTTP body data as either serialized string or unserialized JS object or OINODataRow-array or Buffer/Uint8Array binary data
|
|
135
|
-
* @param
|
|
49
|
+
* @param queryParams SQL parameters for the REST request
|
|
136
50
|
* @param contentType content type of the HTTP body data, default is JSON
|
|
137
51
|
*
|
|
138
52
|
*/
|
|
139
|
-
doRequest(method: string, rowId: string, rowData:
|
|
140
|
-
doApiRequest(request:
|
|
53
|
+
doRequest(method: string, rowId: string, rowData: OINOApiData, queryParams: OINOQueryParams, contentType?: OINOContentType): Promise<OINOApiResult>;
|
|
54
|
+
doApiRequest(request: OINOApiRequest): Promise<OINOApiResult>;
|
|
141
55
|
/**
|
|
142
56
|
* Method for handling a HTTP REST request with batch update using PUT or DELETE methods.
|
|
143
57
|
*
|
|
@@ -146,14 +60,14 @@ export declare class OINODbApi {
|
|
|
146
60
|
* @param rowData HTTP body data as either serialized string or unserialized JS object or OINODataRow-array or Buffer/Uint8Array binary data
|
|
147
61
|
*
|
|
148
62
|
*/
|
|
149
|
-
doBatchUpdate(method: string, rowId: string, rowData:
|
|
63
|
+
doBatchUpdate(method: string, rowId: string, rowData: OINOApiData, queryParams?: OINOQueryParams): Promise<OINOApiResult>;
|
|
150
64
|
/**
|
|
151
65
|
* Method for handling a HTTP REST request with batch update using PUT or DELETE methods.
|
|
152
66
|
*
|
|
153
67
|
* @param request HTTP URL parameters as key-value-pairs
|
|
154
68
|
*
|
|
155
69
|
*/
|
|
156
|
-
|
|
70
|
+
doBatchApiRequest(request: OINOApiRequest): Promise<OINOApiResult>;
|
|
157
71
|
/**
|
|
158
72
|
* Method to check if a field is included in the API params.
|
|
159
73
|
*
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { OINODb } from "./OINODb.js";
|
|
2
|
+
/**
|
|
3
|
+
* Database class (constructor) type
|
|
4
|
+
* @param dbParams database parameters
|
|
5
|
+
*/
|
|
6
|
+
export type OINODbConstructor = new (dbParams: OINODbParams) => OINODb;
|
|
7
|
+
/** Database parameters */
|
|
8
|
+
export type OINODbParams = {
|
|
9
|
+
/** Name of the database class (e.g. OINODbPostgresql) */
|
|
10
|
+
type: string;
|
|
11
|
+
/** Connection URL, either file://-path or an IP-address or an HTTP-url */
|
|
12
|
+
url: string;
|
|
13
|
+
/** Name of the database */
|
|
14
|
+
database: string;
|
|
15
|
+
/** TCP port of the database */
|
|
16
|
+
port?: number;
|
|
17
|
+
/** Username used to authenticate */
|
|
18
|
+
user?: string;
|
|
19
|
+
/** Password used to authenticate */
|
|
20
|
+
password?: string;
|
|
21
|
+
};
|
|
22
|
+
/** Constant for undefined values */
|
|
23
|
+
export declare const OINODB_UNDEFINED = "";
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { OINODataModel, OINODataField, OINODataRow, OINOQueryParams } from "@oino-ts/common";
|
|
2
|
+
import { OINODbApi } from "./OINODbApi.js";
|
|
2
3
|
/**
|
|
3
4
|
* OINO Datamodel object for representing one database table and it's columns.
|
|
4
5
|
*
|
|
5
6
|
*/
|
|
6
|
-
export declare class OINODbDataModel {
|
|
7
|
-
private _fieldIndexLookup;
|
|
7
|
+
export declare class OINODbDataModel extends OINODataModel {
|
|
8
8
|
/** Database refererence of the table */
|
|
9
|
-
readonly
|
|
9
|
+
readonly dbApi: OINODbApi;
|
|
10
10
|
/** Field refererences of the API */
|
|
11
|
-
readonly fields:
|
|
11
|
+
readonly fields: OINODataField[];
|
|
12
12
|
/**
|
|
13
13
|
* Constructor of the data model.
|
|
14
14
|
* NOTE! OINODbDataModel.initialize must be called after constructor to populate fields.
|
|
@@ -17,65 +17,11 @@ export declare class OINODbDataModel {
|
|
|
17
17
|
*
|
|
18
18
|
*/
|
|
19
19
|
constructor(api: OINODbApi);
|
|
20
|
-
|
|
21
|
-
* Initialize datamodel from SQL schema.
|
|
22
|
-
*
|
|
23
|
-
*/
|
|
24
|
-
initialize(): Promise<void>;
|
|
25
|
-
private _printSqlColumnNames;
|
|
20
|
+
private _printColumnNames;
|
|
26
21
|
private _printSqlInsertColumnsAndValues;
|
|
27
22
|
private _printSqlUpdateValues;
|
|
28
23
|
private _printSqlPrimaryKeyCondition;
|
|
29
24
|
private _printSqlPrimaryKeyColumns;
|
|
30
|
-
/**
|
|
31
|
-
* Add a field to the datamodel.
|
|
32
|
-
*
|
|
33
|
-
* @param field dataset field
|
|
34
|
-
*
|
|
35
|
-
*/
|
|
36
|
-
addField(field: OINODbDataField): void;
|
|
37
|
-
/**
|
|
38
|
-
* Find a field of a given name if any.
|
|
39
|
-
*
|
|
40
|
-
* @param name name of the field to find
|
|
41
|
-
*
|
|
42
|
-
*/
|
|
43
|
-
findFieldByName(name: string): OINODbDataField | null;
|
|
44
|
-
/**
|
|
45
|
-
* Find index of a field of a given name if any.
|
|
46
|
-
*
|
|
47
|
-
* @param name name of the field to find
|
|
48
|
-
*
|
|
49
|
-
*/
|
|
50
|
-
findFieldIndexByName(name: string): number;
|
|
51
|
-
/**
|
|
52
|
-
* Find all fields based of given filter callback criteria (e.g. fields of certain data type, primary keys etc.)
|
|
53
|
-
*
|
|
54
|
-
* @param filter callback called for each field to include or not
|
|
55
|
-
*
|
|
56
|
-
*/
|
|
57
|
-
filterFields(filter: OINODbDataFieldFilter): OINODbDataField[];
|
|
58
|
-
/**
|
|
59
|
-
* Return the primary key values of one row in order of the data model
|
|
60
|
-
*
|
|
61
|
-
* @param row data row
|
|
62
|
-
* @param hashidValues apply hashid when applicable
|
|
63
|
-
*
|
|
64
|
-
*/
|
|
65
|
-
getRowPrimarykeyValues(row: OINODataRow, hashidValues?: boolean): string[];
|
|
66
|
-
/**
|
|
67
|
-
* Print debug information about the fields.
|
|
68
|
-
*
|
|
69
|
-
* @param separator string to separate field prints
|
|
70
|
-
*
|
|
71
|
-
*/
|
|
72
|
-
printDebug(separator?: string): string;
|
|
73
|
-
/**
|
|
74
|
-
* Print all public properties (db, table name, fields) of the datamodel. Used
|
|
75
|
-
* in automated testing validate schema has stayed the same.
|
|
76
|
-
*
|
|
77
|
-
*/
|
|
78
|
-
printFieldPublicPropertiesJson(): string;
|
|
79
25
|
/**
|
|
80
26
|
* Print SQL select statement using optional id and filter.
|
|
81
27
|
*
|
|
@@ -83,7 +29,7 @@ export declare class OINODbDataModel {
|
|
|
83
29
|
* @param params OINO reqest params
|
|
84
30
|
*
|
|
85
31
|
*/
|
|
86
|
-
printSqlSelect(id: string, params:
|
|
32
|
+
printSqlSelect(id: string, params: OINOQueryParams): string;
|
|
87
33
|
/**
|
|
88
34
|
* Print SQL insert statement from one data row.
|
|
89
35
|
*
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { OINOApiParams } from "@oino-ts/common";
|
|
2
|
+
import { OINODbParams, OINODbConstructor } from "./OINODbConstants.js";
|
|
3
|
+
import { OINODbApi } from "./OINODbApi.js";
|
|
4
|
+
import { OINODb } from "./OINODb.js";
|
|
2
5
|
/**
|
|
3
6
|
* Static factory class for easily creating things based on data
|
|
4
7
|
*
|
|
@@ -27,5 +30,5 @@ export declare class OINODbFactory {
|
|
|
27
30
|
* @param db databased used in API
|
|
28
31
|
* @param params parameters of the API
|
|
29
32
|
*/
|
|
30
|
-
static createApi(db: OINODb, params:
|
|
33
|
+
static createApi(db: OINODb, params: OINOApiParams): Promise<OINODbApi>;
|
|
31
34
|
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { OINOQueryFilter, OINOQueryOrder, OINOQueryLimit, OINOQueryAggregate, OINOQuerySelect, OINODataModel } from "@oino-ts/common";
|
|
2
|
+
import { OINODbDataModel } from "./OINODbDataModel.js";
|
|
3
|
+
/**
|
|
4
|
+
* Class for recursively parsing of filters and printing them as SQL conditions.
|
|
5
|
+
* Supports three types of statements
|
|
6
|
+
* - comparison: (field)-lt|le|eq|ge|gt|like(value)
|
|
7
|
+
* - negation: -not(filter)
|
|
8
|
+
* - conjunction/disjunction: (filter)-and|or(filter)
|
|
9
|
+
* Supported conditions are comparisons (<, <=, =, >=, >) and substring match (LIKE).
|
|
10
|
+
*
|
|
11
|
+
*/
|
|
12
|
+
export declare class OINODbQueryFilter extends OINOQueryFilter {
|
|
13
|
+
private static operatorToSql;
|
|
14
|
+
/**
|
|
15
|
+
* Print filter as SQL condition based on the datamodel of the API.
|
|
16
|
+
*
|
|
17
|
+
* @param dataModel data model (and database) to use for formatting of values
|
|
18
|
+
*
|
|
19
|
+
*/
|
|
20
|
+
static printSql(filter: OINOQueryFilter, dataModel: OINODbDataModel): string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Class for ordering select results on a number of columns.
|
|
24
|
+
*
|
|
25
|
+
*/
|
|
26
|
+
export declare class OINODbQueryOrder extends OINOQueryOrder {
|
|
27
|
+
/**
|
|
28
|
+
* Print order as SQL condition based on the datamodel of the API.
|
|
29
|
+
*
|
|
30
|
+
* @param order order instance
|
|
31
|
+
* @param dataModel data model (and database) to use for formatting of values
|
|
32
|
+
*
|
|
33
|
+
*/
|
|
34
|
+
static printSql(order: OINOQueryOrder, dataModel: OINODbDataModel): string;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Class for limiting the number of results.
|
|
38
|
+
*
|
|
39
|
+
*/
|
|
40
|
+
export declare class OINODbQueryLimit extends OINOQueryLimit {
|
|
41
|
+
/**
|
|
42
|
+
* Print order as SQL condition based on the datamodel of the API.
|
|
43
|
+
*
|
|
44
|
+
* @param limit limit instance
|
|
45
|
+
* @param dataModel data model (and database) to use for formatting of values
|
|
46
|
+
*
|
|
47
|
+
*/
|
|
48
|
+
static printSql(limit: OINOQueryLimit, dataModel: OINODbDataModel): string;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Class for limiting the number of results.
|
|
52
|
+
*
|
|
53
|
+
*/
|
|
54
|
+
export declare class OINODbQueryAggregate extends OINOQueryAggregate {
|
|
55
|
+
/**
|
|
56
|
+
* Print non-aggregated fields as SQL GROUP BY-condition based on the datamodel of the API.
|
|
57
|
+
*
|
|
58
|
+
* @param aggregate aggregate instance
|
|
59
|
+
* @param dataModel data model (and database) to use for formatting of values
|
|
60
|
+
* @param select what fields to select
|
|
61
|
+
*
|
|
62
|
+
*/
|
|
63
|
+
static printSql(aggregate: OINOQueryAggregate, dataModel: OINODataModel, select?: OINOQuerySelect): string;
|
|
64
|
+
/**
|
|
65
|
+
* Print non-aggregated fields as SQL GROUP BY-condition based on the datamodel of the API.
|
|
66
|
+
*
|
|
67
|
+
* @param dataModel data model (and database) to use for formatting of values
|
|
68
|
+
* @param select what fields to select
|
|
69
|
+
*
|
|
70
|
+
*/
|
|
71
|
+
static printColumnNames(aggregate: OINOQueryAggregate, dataModel: OINODataModel, select?: OINOQuerySelect): string;
|
|
72
|
+
}
|