@oino-ts/types 0.0.18 → 0.1.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/types → common/src}/index.d.ts +0 -1
- package/db/src/OINODb.d.ts +180 -0
- package/db/src/OINODbApi.d.ts +82 -0
- package/db/src/OINODbConfig.d.ts +52 -0
- package/db/src/OINODbDataField.d.ts +202 -0
- package/db/src/OINODbDataModel.d.ts +108 -0
- package/db/src/OINODbDataSet.d.ts +95 -0
- package/db/src/OINODbFactory.d.ts +35 -0
- package/db/src/OINODbModelSet.d.ts +51 -0
- package/{dist/types/OINOParser.d.ts → db/src/OINODbParser.d.ts} +3 -3
- package/db/src/OINODbRequestParams.d.ts +146 -0
- package/db/src/OINODbSqlParams.d.ts +147 -0
- package/db/src/OINODbSwagger.d.ts +25 -0
- package/db/src/index.d.ts +111 -0
- package/db-bunsqlite/src/OINODbBunSqlite.d.ts +77 -0
- package/db-bunsqlite/src/index.d.ts +1 -0
- package/db-mariadb/src/OINODbMariadb.d.ts +78 -0
- package/db-mariadb/src/index.d.ts +1 -0
- package/db-mssql/src/OINODbMsSql.d.ts +86 -0
- package/db-mssql/src/index.d.ts +1 -0
- package/db-postgresql/src/OINODbPostgresql.d.ts +76 -0
- package/db-postgresql/src/index.d.ts +1 -0
- package/hashid/src/OINOHashid.d.ts +40 -0
- package/hashid/src/index.d.ts +1 -0
- package/index.d.ts +23 -0
- package/package.json +5 -8
- package/README.md +0 -190
- package/dist/cjs/OINOBenchmark.js +0 -108
- package/dist/cjs/OINOHtmlTemplate.js +0 -177
- package/dist/cjs/OINOLog.js +0 -151
- package/dist/cjs/OINOParser.js +0 -466
- package/dist/cjs/OINOResult.js +0 -216
- package/dist/cjs/OINOStr.js +0 -265
- package/dist/cjs/index.js +0 -42
- package/dist/esm/OINOBenchmark.js +0 -104
- package/dist/esm/OINOHtmlTemplate.js +0 -173
- package/dist/esm/OINOLog.js +0 -146
- package/dist/esm/OINOParser.js +0 -462
- package/dist/esm/OINOResult.js +0 -211
- package/dist/esm/OINOStr.js +0 -261
- package/dist/esm/index.js +0 -30
- package/src/OINOBenchmark.ts +0 -112
- package/src/OINOHtmlTemplate.ts +0 -186
- package/src/OINOLog.ts +0 -168
- package/src/OINOParser.ts +0 -458
- package/src/OINOResult.ts +0 -234
- package/src/OINOStr.ts +0 -254
- package/src/index.ts +0 -32
- /package/{dist/types → common/src}/OINOBenchmark.d.ts +0 -0
- /package/{dist/types → common/src}/OINOHtmlTemplate.d.ts +0 -0
- /package/{dist/types → common/src}/OINOLog.d.ts +0 -0
- /package/{dist/types → common/src}/OINOResult.d.ts +0 -0
- /package/{dist/types → common/src}/OINOStr.d.ts +0 -0
|
@@ -3,7 +3,6 @@ export { OINOLog, OINOLogLevel, OINOConsoleLog } from "./OINOLog.js";
|
|
|
3
3
|
export { OINOResult, OINOHttpResult } from "./OINOResult.js";
|
|
4
4
|
export { OINOStr } from "./OINOStr.js";
|
|
5
5
|
export { OINOHtmlTemplate } from "./OINOHtmlTemplate.js";
|
|
6
|
-
export { OINOParser } from "./OINOParser";
|
|
7
6
|
/** OINO error message prefix */
|
|
8
7
|
export declare const OINO_ERROR_PREFIX = "OINO ERROR";
|
|
9
8
|
/** OINO warning message prefix */
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import { OINODbParams, OINODbApi, OINODataCell, OINODataRow } from "./index.js";
|
|
2
|
+
/**
|
|
3
|
+
* Base class for database abstraction, implementing methods for connecting, making queries and parsing/formatting data
|
|
4
|
+
* between SQL and serialization formats.
|
|
5
|
+
*
|
|
6
|
+
*/
|
|
7
|
+
export declare abstract class OINODb {
|
|
8
|
+
protected _params: OINODbParams;
|
|
9
|
+
/** Name of the database */
|
|
10
|
+
readonly name: string;
|
|
11
|
+
/**
|
|
12
|
+
* Constructor for `OINODb`.
|
|
13
|
+
* @param params database parameters
|
|
14
|
+
*/
|
|
15
|
+
constructor(params: OINODbParams);
|
|
16
|
+
/**
|
|
17
|
+
* Connect to database.
|
|
18
|
+
*
|
|
19
|
+
*/
|
|
20
|
+
abstract connect(): Promise<boolean>;
|
|
21
|
+
/**
|
|
22
|
+
* Print a table name using database specific SQL escaping.
|
|
23
|
+
*
|
|
24
|
+
* @param sqlTable name of the table
|
|
25
|
+
*
|
|
26
|
+
*/
|
|
27
|
+
abstract printSqlTablename(sqlTable: string): string;
|
|
28
|
+
/**
|
|
29
|
+
* Print a column name with correct SQL escaping.
|
|
30
|
+
*
|
|
31
|
+
* @param sqlColumn name of the column
|
|
32
|
+
*
|
|
33
|
+
*/
|
|
34
|
+
abstract printSqlColumnname(sqlColumn: string): string;
|
|
35
|
+
/**
|
|
36
|
+
* Print a single data value from serialization using the context of the native data
|
|
37
|
+
* type with the correct SQL escaping.
|
|
38
|
+
*
|
|
39
|
+
* @param cellValue data from sql results
|
|
40
|
+
* @param sqlType native type name for table column
|
|
41
|
+
*
|
|
42
|
+
*/
|
|
43
|
+
abstract printCellAsSqlValue(cellValue: OINODataCell, sqlType: string): string;
|
|
44
|
+
/**
|
|
45
|
+
* Parse a single SQL result value for serialization using the context of the native data
|
|
46
|
+
* type.
|
|
47
|
+
*
|
|
48
|
+
* @param sqlValue data from serialization
|
|
49
|
+
* @param sqlType native type name for table column
|
|
50
|
+
*
|
|
51
|
+
*/
|
|
52
|
+
abstract parseSqlValueAsCell(sqlValue: OINODataCell, sqlType: string): OINODataCell;
|
|
53
|
+
/**
|
|
54
|
+
* Execute a select operation.
|
|
55
|
+
*
|
|
56
|
+
* @param sql SQL statement.
|
|
57
|
+
*
|
|
58
|
+
*/
|
|
59
|
+
abstract sqlSelect(sql: string): Promise<OINODbDataSet>;
|
|
60
|
+
/**
|
|
61
|
+
* Execute other sql operations.
|
|
62
|
+
*
|
|
63
|
+
* @param sql SQL statement.
|
|
64
|
+
*
|
|
65
|
+
*/
|
|
66
|
+
abstract sqlExec(sql: string): Promise<OINODbDataSet>;
|
|
67
|
+
/**
|
|
68
|
+
* Initialize a data model by getting the SQL schema and populating OINODbDataFields of
|
|
69
|
+
* the model.
|
|
70
|
+
*
|
|
71
|
+
* @param api api which data model to initialize.
|
|
72
|
+
*
|
|
73
|
+
*/
|
|
74
|
+
abstract initializeApiDatamodel(api: OINODbApi): Promise<void>;
|
|
75
|
+
/**
|
|
76
|
+
* Print SQL select statement with DB specific formatting.
|
|
77
|
+
*
|
|
78
|
+
* @param tableName - The name of the table to select from.
|
|
79
|
+
* @param columnNames - The columns to be selected.
|
|
80
|
+
* @param whereCondition - The WHERE clause to filter the results.
|
|
81
|
+
* @param orderCondition - The ORDER BY clause to sort the results.
|
|
82
|
+
* @param limitCondition - The LIMIT clause to limit the number of results.
|
|
83
|
+
*
|
|
84
|
+
*/
|
|
85
|
+
printSqlSelect(tableName: string, columnNames: string, whereCondition: string, orderCondition: string, limitCondition: string): string;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Base class for SQL results that can be asynchronously iterated (but
|
|
89
|
+
* not necessarity rewinded). Idea is to handle database specific mechanisms
|
|
90
|
+
* for returning and formatting conventions in the database specific
|
|
91
|
+
* implementation. Data might be in memory or streamed in chunks and
|
|
92
|
+
* `OINODbDataSet` will serve it out consistently.
|
|
93
|
+
*
|
|
94
|
+
*/
|
|
95
|
+
export declare abstract class OINODbDataSet {
|
|
96
|
+
private _data;
|
|
97
|
+
/** Error messages */
|
|
98
|
+
readonly messages: string[];
|
|
99
|
+
/**
|
|
100
|
+
* Constructor for `OINODbDataSet`.
|
|
101
|
+
*
|
|
102
|
+
* @param data internal database specific data type (constructor will throw if invalid)
|
|
103
|
+
* @param messages error messages from SQL-query
|
|
104
|
+
*
|
|
105
|
+
*/
|
|
106
|
+
constructor(data: unknown, messages?: string[]);
|
|
107
|
+
/**
|
|
108
|
+
* Is data set empty.
|
|
109
|
+
*
|
|
110
|
+
*/
|
|
111
|
+
abstract isEmpty(): boolean;
|
|
112
|
+
/**
|
|
113
|
+
* Is there no more content, i.e. either dataset is empty or we have moved beyond last line
|
|
114
|
+
*
|
|
115
|
+
*/
|
|
116
|
+
abstract isEof(): boolean;
|
|
117
|
+
/**
|
|
118
|
+
* Attempts to moves dataset to the next row, possibly waiting for more data to become available. Returns !isEof().
|
|
119
|
+
*
|
|
120
|
+
*/
|
|
121
|
+
abstract next(): Promise<boolean>;
|
|
122
|
+
/**
|
|
123
|
+
* Gets current row of data.
|
|
124
|
+
*
|
|
125
|
+
*/
|
|
126
|
+
abstract getRow(): OINODataRow;
|
|
127
|
+
/**
|
|
128
|
+
* Checks if the messages contain errors.
|
|
129
|
+
*
|
|
130
|
+
*/
|
|
131
|
+
hasErrors(): boolean;
|
|
132
|
+
/**
|
|
133
|
+
* Checks if the messages contain errors.
|
|
134
|
+
*
|
|
135
|
+
*/
|
|
136
|
+
getFirstError(): string;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Generic in memory implementation of a data set where data is an array of rows. Used
|
|
140
|
+
* by BunSqlite and automated testing. Can be rewinded.
|
|
141
|
+
*
|
|
142
|
+
*/
|
|
143
|
+
export declare class OINODbMemoryDataSet extends OINODbDataSet {
|
|
144
|
+
private _rows;
|
|
145
|
+
private _currentRow;
|
|
146
|
+
private _eof;
|
|
147
|
+
/**
|
|
148
|
+
* Constructor of `OINODbMemoryDataSet`.
|
|
149
|
+
*
|
|
150
|
+
* @param data data as OINODataRow[] (constructor will throw if invalid)
|
|
151
|
+
* @param errors error messages from SQL-query
|
|
152
|
+
*
|
|
153
|
+
*/
|
|
154
|
+
constructor(data: unknown, errors?: string[]);
|
|
155
|
+
/**
|
|
156
|
+
* Is data set empty.
|
|
157
|
+
*
|
|
158
|
+
*/
|
|
159
|
+
isEmpty(): boolean;
|
|
160
|
+
/**
|
|
161
|
+
* Is there no more content, i.e. either dataset is empty or we have moved beyond last line
|
|
162
|
+
*
|
|
163
|
+
*/
|
|
164
|
+
isEof(): boolean;
|
|
165
|
+
/**
|
|
166
|
+
* Attempts to moves dataset to the next row, possibly waiting for more data to become available. Returns !isEof().
|
|
167
|
+
*
|
|
168
|
+
*/
|
|
169
|
+
next(): Promise<boolean>;
|
|
170
|
+
/**
|
|
171
|
+
* Gets current row of data.
|
|
172
|
+
*
|
|
173
|
+
*/
|
|
174
|
+
getRow(): OINODataRow;
|
|
175
|
+
/**
|
|
176
|
+
* Rewinds data set to the first row, returns !isEof().
|
|
177
|
+
*
|
|
178
|
+
*/
|
|
179
|
+
first(): boolean;
|
|
180
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { OINODbApiParams, OINODb, OINODbDataModel, OINODataRow, OINODbModelSet, OINODbApiRequestParams, OINOHttpResult, OINOHtmlTemplate } from "./index.js";
|
|
2
|
+
import { OINOResult } from "@oino-ts/common";
|
|
3
|
+
import { OINOHashid } from "@oino-ts/hashid";
|
|
4
|
+
/**
|
|
5
|
+
* OINO API request result object with returned data and/or http status code/message and
|
|
6
|
+
* error / warning messages.
|
|
7
|
+
*
|
|
8
|
+
*/
|
|
9
|
+
export declare class OINODbApiResult extends OINOResult {
|
|
10
|
+
/** DbApi request params */
|
|
11
|
+
params: OINODbApiRequestParams;
|
|
12
|
+
/** Returned data if any */
|
|
13
|
+
data?: OINODbModelSet;
|
|
14
|
+
/**
|
|
15
|
+
* Constructor of OINODbApiResult.
|
|
16
|
+
*
|
|
17
|
+
* @param params DbApi request parameters
|
|
18
|
+
* @param data result data
|
|
19
|
+
*
|
|
20
|
+
*/
|
|
21
|
+
constructor(params: OINODbApiRequestParams, data?: OINODbModelSet);
|
|
22
|
+
/**
|
|
23
|
+
* Creates a HTTP Response from API results.
|
|
24
|
+
*
|
|
25
|
+
* @param headers Headers to include in the response
|
|
26
|
+
*
|
|
27
|
+
*/
|
|
28
|
+
getResponse(headers?: Record<string, string>): Promise<Response>;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Specialized HTML template that can render ´OINODbApiResult´.
|
|
32
|
+
*
|
|
33
|
+
*/
|
|
34
|
+
export declare class OINODbHtmlTemplate extends OINOHtmlTemplate {
|
|
35
|
+
/**
|
|
36
|
+
* Creates HTML Response from API modelset.
|
|
37
|
+
*
|
|
38
|
+
* @param modelset OINO API dataset
|
|
39
|
+
* @param overrideValues values to override in the data
|
|
40
|
+
*
|
|
41
|
+
*/
|
|
42
|
+
renderFromDbData(modelset: OINODbModelSet, overrideValues?: any): Promise<OINOHttpResult>;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* API class with method to process HTTP REST requests.
|
|
46
|
+
*
|
|
47
|
+
*/
|
|
48
|
+
export declare class OINODbApi {
|
|
49
|
+
/** API database reference */
|
|
50
|
+
readonly db: OINODb;
|
|
51
|
+
/** API datamodel */
|
|
52
|
+
readonly datamodel: OINODbDataModel;
|
|
53
|
+
/** API parameters */
|
|
54
|
+
readonly params: OINODbApiParams;
|
|
55
|
+
/** API hashid */
|
|
56
|
+
readonly hashid: OINOHashid | null;
|
|
57
|
+
/**
|
|
58
|
+
* Constructor of API object.
|
|
59
|
+
* NOTE! OINODb.initDatamodel must be called if created manually instead of the factory.
|
|
60
|
+
*
|
|
61
|
+
* @param db database for the API
|
|
62
|
+
* @param params parameters for the API
|
|
63
|
+
*
|
|
64
|
+
*/
|
|
65
|
+
constructor(db: OINODb, params: OINODbApiParams);
|
|
66
|
+
private _validateRowValues;
|
|
67
|
+
private _doGet;
|
|
68
|
+
private _doPost;
|
|
69
|
+
private _doPut;
|
|
70
|
+
private _doDelete;
|
|
71
|
+
/**
|
|
72
|
+
* Method for handlind a HTTP REST request with GET, POST, PUT, DELETE corresponding to
|
|
73
|
+
* SQL select, insert, update and delete.
|
|
74
|
+
*
|
|
75
|
+
* @param method HTTP verb (uppercase)
|
|
76
|
+
* @param id URL id of the REST request
|
|
77
|
+
* @param body HTTP body data as either serialized string or unserialized JS object / OINODataRow-array
|
|
78
|
+
* @param params HTTP URL parameters as key-value-pairs
|
|
79
|
+
*
|
|
80
|
+
*/
|
|
81
|
+
doRequest(method: string, id: string, body: string | OINODataRow[] | Buffer | any, params?: OINODbApiRequestParams): Promise<OINODbApiResult>;
|
|
82
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/** Set the name of the OINO ID field (default \_OINOID\_) */
|
|
2
|
+
export declare class OINODbConfig {
|
|
3
|
+
/** Name of the synthetic OINO ID field */
|
|
4
|
+
static OINODB_ID_FIELD: string;
|
|
5
|
+
/** Private key separator of the synthetic OINO ID field */
|
|
6
|
+
static OINODB_ID_SEPARATOR: string;
|
|
7
|
+
private static OINODB_ID_SEPARATOR_ESCAPED;
|
|
8
|
+
/** Name of the OINODbSqlFilter-parameter in request */
|
|
9
|
+
static OINODB_SQL_FILTER_PARAM: string;
|
|
10
|
+
/** Name of the OINODbSqlOrder-parameter in request */
|
|
11
|
+
static OINODB_SQL_ORDER_PARAM: string;
|
|
12
|
+
/** Name of the OINODbSqlLimit-parameter in request */
|
|
13
|
+
static OINODB_SQL_LIMIT_PARAM: string;
|
|
14
|
+
/**
|
|
15
|
+
* Set the name of the OINO ID field
|
|
16
|
+
* @param idField name of the OINO ID field
|
|
17
|
+
*/
|
|
18
|
+
static setOinoIdField(idField: string): void;
|
|
19
|
+
/**
|
|
20
|
+
* Set the separator character of the OINO ID field
|
|
21
|
+
* @param idSeparator character to use as separator of id parts
|
|
22
|
+
*/
|
|
23
|
+
static setOinoIdSeparator(idSeparator: string): void;
|
|
24
|
+
/**
|
|
25
|
+
* Print OINO ID for primary key values.
|
|
26
|
+
*
|
|
27
|
+
* @param primaryKeys an array of primary key values.
|
|
28
|
+
*
|
|
29
|
+
*/
|
|
30
|
+
static printOINOId(primaryKeys: string[]): string;
|
|
31
|
+
/**
|
|
32
|
+
* Set the name of the OINODbSqlFilter-param field
|
|
33
|
+
*
|
|
34
|
+
* @param sqlFilterParam name of the http parameter with `OINODbSqlFilter` definition
|
|
35
|
+
*
|
|
36
|
+
*/
|
|
37
|
+
static setOinoSqlFilterParam(sqlFilterParam: string): void;
|
|
38
|
+
/**
|
|
39
|
+
* Set the name of the OINODbSqlOrder-param field
|
|
40
|
+
*
|
|
41
|
+
* @param sqlOrderParam name of the http parameter with `OINODbSqlOrder` definition
|
|
42
|
+
*
|
|
43
|
+
*/
|
|
44
|
+
static setOinoSqlOrderParam(sqlOrderParam: string): void;
|
|
45
|
+
/**
|
|
46
|
+
* Set the name of the OINODbSqlLimit-param field
|
|
47
|
+
*
|
|
48
|
+
* @param sqlLimitParam name of the http parameter with `OINODbSqlLimit` definition
|
|
49
|
+
*
|
|
50
|
+
*/
|
|
51
|
+
static setOinoSqlLimitParam(sqlLimitParam: string): void;
|
|
52
|
+
}
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import { OINODbDataFieldParams, OINODataCell, OINODb } from "./index.js";
|
|
2
|
+
/**
|
|
3
|
+
* Base class for a column of data responsible for appropriatelly serializing/deserializing the data.
|
|
4
|
+
*
|
|
5
|
+
*/
|
|
6
|
+
export declare class OINODbDataField {
|
|
7
|
+
/** OINODB reference*/
|
|
8
|
+
readonly db: OINODb;
|
|
9
|
+
/** Name of the field */
|
|
10
|
+
readonly name: string;
|
|
11
|
+
/** Internal type of field*/
|
|
12
|
+
readonly type: string;
|
|
13
|
+
/** SQL type of the field */
|
|
14
|
+
readonly sqlType: string;
|
|
15
|
+
/** Maximum length of the field (or 0) */
|
|
16
|
+
readonly maxLength: number;
|
|
17
|
+
/** Parameters for the field */
|
|
18
|
+
readonly fieldParams: OINODbDataFieldParams;
|
|
19
|
+
/**
|
|
20
|
+
* Constructor for a data field
|
|
21
|
+
*
|
|
22
|
+
* @param db OINODb reference
|
|
23
|
+
* @param name name of the field
|
|
24
|
+
* @param type internal type of the field
|
|
25
|
+
* @param sqlType column type in database
|
|
26
|
+
* @param fieldParams parameters of the field
|
|
27
|
+
* @param maxLength maximum length of the field (or 0)
|
|
28
|
+
*
|
|
29
|
+
*/
|
|
30
|
+
constructor(db: OINODb, name: string, type: string, sqlType: string, fieldParams: OINODbDataFieldParams, maxLength?: number);
|
|
31
|
+
/**
|
|
32
|
+
* Pring debug information for the field
|
|
33
|
+
*
|
|
34
|
+
* @param length length of the debug output (or 0 for as long as needed)
|
|
35
|
+
*
|
|
36
|
+
*/
|
|
37
|
+
printColumnDebug(length?: number): string;
|
|
38
|
+
/**
|
|
39
|
+
* Serialize cell value in the given content format.
|
|
40
|
+
*
|
|
41
|
+
* @param cellVal cell value
|
|
42
|
+
*
|
|
43
|
+
*/
|
|
44
|
+
serializeCell(cellVal: OINODataCell): string | null | undefined;
|
|
45
|
+
/**
|
|
46
|
+
* Parce cell value from string using field type specific formatting rules.
|
|
47
|
+
*
|
|
48
|
+
* @param value string value
|
|
49
|
+
*
|
|
50
|
+
*/
|
|
51
|
+
deserializeCell(value: string | null | undefined): OINODataCell;
|
|
52
|
+
/**
|
|
53
|
+
* Print data cell (from deserialization) as SQL-string.
|
|
54
|
+
*
|
|
55
|
+
* @param cellVal cell value
|
|
56
|
+
*
|
|
57
|
+
*/
|
|
58
|
+
printCellAsSqlValue(cellVal: OINODataCell): string;
|
|
59
|
+
/**
|
|
60
|
+
* Print name of column as SQL.
|
|
61
|
+
*
|
|
62
|
+
*/
|
|
63
|
+
printSqlColumnName(): string;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Specialised class for a string column.
|
|
67
|
+
*
|
|
68
|
+
*/
|
|
69
|
+
export declare class OINOStringDataField extends OINODbDataField {
|
|
70
|
+
/**
|
|
71
|
+
* Constructor for a string data field
|
|
72
|
+
*
|
|
73
|
+
* @param db OINODb reference
|
|
74
|
+
* @param name name of the field
|
|
75
|
+
* @param sqlType column type in database
|
|
76
|
+
* @param fieldParams parameters of the field
|
|
77
|
+
* @param maxLength maximum length of the field (or 0)
|
|
78
|
+
*
|
|
79
|
+
*/
|
|
80
|
+
constructor(db: OINODb, name: string, sqlType: string, fieldParams: OINODbDataFieldParams, maxLength: number);
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Specialised class for a boolean column.
|
|
84
|
+
*
|
|
85
|
+
*/
|
|
86
|
+
export declare class OINOBooleanDataField extends OINODbDataField {
|
|
87
|
+
/**
|
|
88
|
+
* Constructor for a boolean data field
|
|
89
|
+
*
|
|
90
|
+
* @param db OINODb reference
|
|
91
|
+
* @param name name of the field
|
|
92
|
+
* @param sqlType column type in database
|
|
93
|
+
* @param fieldParams parameters of the field
|
|
94
|
+
*
|
|
95
|
+
*/
|
|
96
|
+
constructor(db: OINODb, name: string, sqlType: string, fieldParams: OINODbDataFieldParams);
|
|
97
|
+
/**
|
|
98
|
+
* Serialize cell value in the given content format.
|
|
99
|
+
*
|
|
100
|
+
* @param cellVal cell value
|
|
101
|
+
*
|
|
102
|
+
*/
|
|
103
|
+
serializeCell(cellVal: OINODataCell): string | null | undefined;
|
|
104
|
+
/**
|
|
105
|
+
* Parce cell value from string using field type specific formatting rules.
|
|
106
|
+
*
|
|
107
|
+
* @param value string value
|
|
108
|
+
*
|
|
109
|
+
*/
|
|
110
|
+
deserializeCell(value: string | null | undefined): OINODataCell;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Specialised class for a number column.
|
|
114
|
+
*
|
|
115
|
+
*/
|
|
116
|
+
export declare class OINONumberDataField extends OINODbDataField {
|
|
117
|
+
/**
|
|
118
|
+
* Constructor for a string data field
|
|
119
|
+
*
|
|
120
|
+
* @param db OINODb reference
|
|
121
|
+
* @param name name of the field
|
|
122
|
+
* @param sqlType column type in database
|
|
123
|
+
* @param fieldParams parameters of the field
|
|
124
|
+
*
|
|
125
|
+
*/
|
|
126
|
+
constructor(db: OINODb, name: string, sqlType: string, fieldParams: OINODbDataFieldParams);
|
|
127
|
+
/**
|
|
128
|
+
* Serialize cell value in the given content format.
|
|
129
|
+
*
|
|
130
|
+
* @param cellVal cell value
|
|
131
|
+
*
|
|
132
|
+
*/
|
|
133
|
+
serializeCell(cellVal: OINODataCell): string | null | undefined;
|
|
134
|
+
/**
|
|
135
|
+
* Parce cell value from string using field type specific formatting rules.
|
|
136
|
+
*
|
|
137
|
+
* @param value string value
|
|
138
|
+
*
|
|
139
|
+
*/
|
|
140
|
+
deserializeCell(value: string | null | undefined): OINODataCell;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Specialised class for a blob column.
|
|
144
|
+
*
|
|
145
|
+
*/
|
|
146
|
+
export declare class OINOBlobDataField extends OINODbDataField {
|
|
147
|
+
/**
|
|
148
|
+
* Constructor for a blob data field
|
|
149
|
+
*
|
|
150
|
+
* @param db OINODb reference
|
|
151
|
+
* @param name name of the field
|
|
152
|
+
* @param sqlType column type in database
|
|
153
|
+
* @param fieldParams parameters of the field
|
|
154
|
+
* @param maxLength maximum length of the field (or 0)
|
|
155
|
+
*
|
|
156
|
+
*/
|
|
157
|
+
constructor(db: OINODb, name: string, sqlType: string, fieldParams: OINODbDataFieldParams, maxLength: number);
|
|
158
|
+
/**
|
|
159
|
+
* Serialize cell value in the given content format.
|
|
160
|
+
*
|
|
161
|
+
* @param cellVal cell value
|
|
162
|
+
*
|
|
163
|
+
*/
|
|
164
|
+
serializeCell(cellVal: OINODataCell): string | null | undefined;
|
|
165
|
+
/**
|
|
166
|
+
* Parce cell value from string using field type specific formatting rules.
|
|
167
|
+
*
|
|
168
|
+
* @param value string value
|
|
169
|
+
*
|
|
170
|
+
*/
|
|
171
|
+
deserializeCell(value: string | null | undefined): OINODataCell;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Specialised class for a datetime column.
|
|
175
|
+
*
|
|
176
|
+
*/
|
|
177
|
+
export declare class OINODatetimeDataField extends OINODbDataField {
|
|
178
|
+
/**
|
|
179
|
+
* Constructor for a string data field
|
|
180
|
+
*
|
|
181
|
+
* @param db OINODb reference
|
|
182
|
+
* @param name name of the field
|
|
183
|
+
* @param sqlType column type in database
|
|
184
|
+
* @param fieldParams parameters of the field
|
|
185
|
+
*
|
|
186
|
+
*/
|
|
187
|
+
constructor(db: OINODb, name: string, sqlType: string, fieldParams: OINODbDataFieldParams);
|
|
188
|
+
/**
|
|
189
|
+
* Serialize cell value in the given content format.
|
|
190
|
+
*
|
|
191
|
+
* @param cellVal cell value
|
|
192
|
+
*
|
|
193
|
+
*/
|
|
194
|
+
serializeCell(cellVal: OINODataCell): string | null | undefined;
|
|
195
|
+
/**
|
|
196
|
+
* Parce cell value from string using field type specific formatting rules.
|
|
197
|
+
*
|
|
198
|
+
* @param value string value
|
|
199
|
+
*
|
|
200
|
+
*/
|
|
201
|
+
deserializeCell(value: string | null | undefined): OINODataCell;
|
|
202
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { OINODbDataField, OINODbApi, OINODataRow, OINODbDataFieldFilter, OINODbSqlParams } from "./index.js";
|
|
2
|
+
/**
|
|
3
|
+
* OINO Datamodel object for representing one database table and it's columns.
|
|
4
|
+
*
|
|
5
|
+
*/
|
|
6
|
+
export declare class OINODbDataModel {
|
|
7
|
+
private _columnLookup;
|
|
8
|
+
/** Database refererence of the table */
|
|
9
|
+
readonly api: OINODbApi;
|
|
10
|
+
/** Field refererences of the API */
|
|
11
|
+
readonly fields: OINODbDataField[];
|
|
12
|
+
/**
|
|
13
|
+
* Constructor of the data model.
|
|
14
|
+
* NOTE! OINODbDataModel.initialize must be called after constructor to populate fields.
|
|
15
|
+
*
|
|
16
|
+
* @param api api of the data model
|
|
17
|
+
*
|
|
18
|
+
*/
|
|
19
|
+
constructor(api: OINODbApi);
|
|
20
|
+
/**
|
|
21
|
+
* Initialize datamodel from SQL schema.
|
|
22
|
+
*
|
|
23
|
+
*/
|
|
24
|
+
initialize(): Promise<void>;
|
|
25
|
+
private _printSqlColumnNames;
|
|
26
|
+
private _printSqlInsertColumnsAndValues;
|
|
27
|
+
private _printSqlUpdateValues;
|
|
28
|
+
private _printSqlPrimaryKeyCondition;
|
|
29
|
+
/**
|
|
30
|
+
* Add a field to the datamodel.
|
|
31
|
+
*
|
|
32
|
+
* @param field dataset field
|
|
33
|
+
*
|
|
34
|
+
*/
|
|
35
|
+
addField(field: OINODbDataField): void;
|
|
36
|
+
/**
|
|
37
|
+
* Find a field of a given name if any.
|
|
38
|
+
*
|
|
39
|
+
* @param name name of the field to find
|
|
40
|
+
*
|
|
41
|
+
*/
|
|
42
|
+
findFieldByName(name: string): OINODbDataField | null;
|
|
43
|
+
/**
|
|
44
|
+
* Find index of a field of a given name if any.
|
|
45
|
+
*
|
|
46
|
+
* @param name name of the field to find
|
|
47
|
+
*
|
|
48
|
+
*/
|
|
49
|
+
findFieldIndexByName(name: string): number;
|
|
50
|
+
/**
|
|
51
|
+
* Find all fields based of given filter callback criteria (e.g. fields of certain data type, primary keys etc.)
|
|
52
|
+
*
|
|
53
|
+
* @param filter callback called for each field to include or not
|
|
54
|
+
*
|
|
55
|
+
*/
|
|
56
|
+
filterFields(filter: OINODbDataFieldFilter): OINODbDataField[];
|
|
57
|
+
/**
|
|
58
|
+
* Return the primary key values of one row in order of the data model
|
|
59
|
+
*
|
|
60
|
+
* @param row data row
|
|
61
|
+
* @param hashidValues apply hashid when applicable
|
|
62
|
+
*
|
|
63
|
+
*/
|
|
64
|
+
getRowPrimarykeyValues(row: OINODataRow, hashidValues?: boolean): string[];
|
|
65
|
+
/**
|
|
66
|
+
* Print debug information about the fields.
|
|
67
|
+
*
|
|
68
|
+
* @param separator string to separate field prints
|
|
69
|
+
*
|
|
70
|
+
*/
|
|
71
|
+
printDebug(separator?: string): string;
|
|
72
|
+
/**
|
|
73
|
+
* Print all public properties (db, table name, fields) of the datamodel. Used
|
|
74
|
+
* in automated testing validate schema has stayed the same.
|
|
75
|
+
*
|
|
76
|
+
*/
|
|
77
|
+
printFieldPublicPropertiesJson(): string;
|
|
78
|
+
/**
|
|
79
|
+
* Print SQL select statement using optional id and filter.
|
|
80
|
+
*
|
|
81
|
+
* @param id OINO ID (i.e. combined primary key values)
|
|
82
|
+
* @param params OINO reqest params
|
|
83
|
+
*
|
|
84
|
+
*/
|
|
85
|
+
printSqlSelect(id: string, params: OINODbSqlParams): string;
|
|
86
|
+
/**
|
|
87
|
+
* Print SQL insert statement from one data row.
|
|
88
|
+
*
|
|
89
|
+
* @param row one row of data in the data model
|
|
90
|
+
*
|
|
91
|
+
*/
|
|
92
|
+
printSqlInsert(row: OINODataRow): string;
|
|
93
|
+
/**
|
|
94
|
+
* Print SQL insert statement from one data row.
|
|
95
|
+
*
|
|
96
|
+
* @param id OINO ID (i.e. combined primary key values)
|
|
97
|
+
* @param row one row of data in the data model
|
|
98
|
+
*
|
|
99
|
+
*/
|
|
100
|
+
printSqlUpdate(id: string, row: OINODataRow): string;
|
|
101
|
+
/**
|
|
102
|
+
* Print SQL delete statement for id.
|
|
103
|
+
*
|
|
104
|
+
* @param id OINO ID (i.e. combined primary key values)
|
|
105
|
+
*
|
|
106
|
+
*/
|
|
107
|
+
printSqlDelete(id: string): string;
|
|
108
|
+
}
|