@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.
Files changed (39) hide show
  1. package/dist/cjs/OINODb.js +6 -144
  2. package/dist/cjs/OINODbApi.js +50 -318
  3. package/dist/cjs/OINODbConfig.js +10 -10
  4. package/dist/cjs/OINODbConstants.js +10 -0
  5. package/dist/cjs/OINODbDataField.js +28 -70
  6. package/dist/cjs/OINODbDataModel.js +30 -144
  7. package/dist/cjs/OINODbFactory.js +2 -2
  8. package/dist/cjs/OINODbModelSet.js +23 -23
  9. package/dist/cjs/OINODbQueryParams.js +201 -0
  10. package/dist/cjs/index.js +12 -41
  11. package/dist/esm/OINODb.js +6 -142
  12. package/dist/esm/OINODbApi.js +49 -314
  13. package/dist/esm/OINODbConstants.js +7 -0
  14. package/dist/esm/OINODbDataModel.js +31 -145
  15. package/dist/esm/OINODbFactory.js +1 -1
  16. package/dist/esm/OINODbQueryParams.js +194 -0
  17. package/dist/esm/index.js +4 -14
  18. package/dist/types/OINODb.d.ts +6 -173
  19. package/dist/types/OINODbApi.d.ts +18 -104
  20. package/dist/types/OINODbConstants.d.ts +23 -0
  21. package/dist/types/OINODbDataModel.d.ts +7 -61
  22. package/dist/types/OINODbFactory.d.ts +5 -2
  23. package/dist/types/OINODbQueryParams.d.ts +72 -0
  24. package/dist/types/index.d.ts +4 -108
  25. package/package.json +37 -37
  26. package/src/OINODb.ts +99 -348
  27. package/src/OINODbApi.test.ts +507 -498
  28. package/src/OINODbApi.ts +389 -667
  29. package/src/OINODbConstants.ts +32 -0
  30. package/src/OINODbDataModel.ts +191 -307
  31. package/src/OINODbFactory.ts +73 -68
  32. package/src/OINODbQueryParams.ts +203 -0
  33. package/src/index.ts +6 -118
  34. package/src/OINODbConfig.ts +0 -98
  35. package/src/OINODbDataField.ts +0 -405
  36. package/src/OINODbModelSet.ts +0 -353
  37. package/src/OINODbParser.ts +0 -438
  38. package/src/OINODbSqlParams.ts +0 -593
  39. package/src/OINODbSwagger.ts +0 -209
@@ -1,69 +1,74 @@
1
- /*
2
- * This Source Code Form is subject to the terms of the Mozilla Public
3
- * License, v. 2.0. If a copy of the MPL was not distributed with this
4
- * file, You can obtain one at https://mozilla.org/MPL/2.0/.
5
- */
6
-
7
- import { OINODbApi, OINODbApiParams, OINODbParams, OINODb, OINODbConstructor } from "./index.js"
8
-
9
- /**
10
- * Static factory class for easily creating things based on data
11
- *
12
- */
13
- export class OINODbFactory {
14
- private static _dbRegistry:Record<string, OINODbConstructor> = {}
15
-
16
- /**
17
- * Register a supported database class. Used to enable those that are installed in the factory
18
- * instead of forcing everyone to install all database libraries.
19
- *
20
- * @param dbName name of the database implementation class
21
- * @param dbTypeClass constructor for creating a database of that type
22
- */
23
- static registerDb(dbName:string, dbTypeClass: OINODbConstructor):void {
24
- this._dbRegistry[dbName] = dbTypeClass
25
- }
26
-
27
- /**
28
- * Create database from parameters from the registered classes.
29
- *
30
- * @param params database connection parameters
31
- * @param connect if true, connects to the database
32
- * @param validate if true, validates the database connection
33
- */
34
- static async createDb(params:OINODbParams, connect:boolean = true, validate:boolean = true):Promise<OINODb> {
35
- let result:OINODb
36
- let db_type = this._dbRegistry[params.type]
37
- if (db_type) {
38
- result = new db_type(params)
39
- } else {
40
- throw new Error("Unsupported database type: " + params.type)
41
- }
42
- if (connect) {
43
- const connect_res = await result.connect()
44
- if (connect_res.success == false) {
45
- throw new Error("Database connection failed: " + connect_res.statusText)
46
- }
47
- }
48
- if (validate) {
49
- const validate_res = await result.validate()
50
- if (validate_res.success == false) {
51
- throw new Error("Database validation failed: " + validate_res.statusText)
52
- }
53
- }
54
- return result
55
- }
56
-
57
-
58
- /**
59
- * Create API from parameters and calls initDatamodel on the datamodel.
60
- *
61
- * @param db databased used in API
62
- * @param params parameters of the API
63
- */
64
- static async createApi(db: OINODb, params: OINODbApiParams):Promise<OINODbApi> {
65
- let result:OINODbApi = new OINODbApi(db, params)
66
- await db.initializeApiDatamodel(result)
67
- return result
68
- }
1
+ /*
2
+ * This Source Code Form is subject to the terms of the Mozilla Public
3
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
4
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/.
5
+ */
6
+
7
+ import { OINOApiParams } from "@oino-ts/common"
8
+
9
+ import { OINODbParams, OINODbConstructor } from "./OINODbConstants.js"
10
+ import { OINODbApi } from "./OINODbApi.js"
11
+ import { OINODb } from "./OINODb.js"
12
+ import { OINODbDataModel } from "./OINODbDataModel.js"
13
+
14
+ /**
15
+ * Static factory class for easily creating things based on data
16
+ *
17
+ */
18
+ export class OINODbFactory {
19
+ private static _dbRegistry:Record<string, OINODbConstructor> = {}
20
+
21
+ /**
22
+ * Register a supported database class. Used to enable those that are installed in the factory
23
+ * instead of forcing everyone to install all database libraries.
24
+ *
25
+ * @param dbName name of the database implementation class
26
+ * @param dbTypeClass constructor for creating a database of that type
27
+ */
28
+ static registerDb(dbName:string, dbTypeClass: OINODbConstructor):void {
29
+ this._dbRegistry[dbName] = dbTypeClass
30
+ }
31
+
32
+ /**
33
+ * Create database from parameters from the registered classes.
34
+ *
35
+ * @param params database connection parameters
36
+ * @param connect if true, connects to the database
37
+ * @param validate if true, validates the database connection
38
+ */
39
+ static async createDb(params:OINODbParams, connect:boolean = true, validate:boolean = true):Promise<OINODb> {
40
+ let result:OINODb
41
+ let db_type = this._dbRegistry[params.type]
42
+ if (db_type) {
43
+ result = new db_type(params)
44
+ } else {
45
+ throw new Error("Unsupported database type: " + params.type)
46
+ }
47
+ if (connect) {
48
+ const connect_res = await result.connect()
49
+ if (connect_res.success == false) {
50
+ throw new Error("Database connection failed: " + connect_res.statusText)
51
+ }
52
+ }
53
+ if (validate) {
54
+ const validate_res = await result.validate()
55
+ if (validate_res.success == false) {
56
+ throw new Error("Database validation failed: " + validate_res.statusText)
57
+ }
58
+ }
59
+ return result
60
+ }
61
+
62
+
63
+ /**
64
+ * Create API from parameters and calls initDatamodel on the datamodel.
65
+ *
66
+ * @param db databased used in API
67
+ * @param params parameters of the API
68
+ */
69
+ static async createApi(db: OINODb, params: OINOApiParams):Promise<OINODbApi> {
70
+ let result:OINODbApi = new OINODbApi(db, params)
71
+ await db.initializeApiDatamodel(result)
72
+ return result
73
+ }
69
74
  }
@@ -0,0 +1,203 @@
1
+ /*
2
+ * This Source Code Form is subject to the terms of the Mozilla Public
3
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
4
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/.
5
+ */
6
+
7
+ import { OINO_ERROR_PREFIX, OINOLog, OINODataField, OINOQueryNullCheck, OINOQueryFilter, OINOQueryOrder, OINOQueryLimit, OINOQueryAggregate, OINOQueryAggregateFunctions, OINOQuerySelect, OINODataModel } from "@oino-ts/common"
8
+
9
+ import { OINODbDataModel } from "./OINODbDataModel.js"
10
+
11
+ /**
12
+ * Class for recursively parsing of filters and printing them as SQL conditions.
13
+ * Supports three types of statements
14
+ * - comparison: (field)-lt|le|eq|ge|gt|like(value)
15
+ * - negation: -not(filter)
16
+ * - conjunction/disjunction: (filter)-and|or(filter)
17
+ * Supported conditions are comparisons (<, <=, =, >=, >) and substring match (LIKE).
18
+ *
19
+ */
20
+ export class OINODbQueryFilter extends OINOQueryFilter {
21
+
22
+ private static operatorToSql(filter: OINOQueryFilter):string {
23
+ switch (filter.operator) {
24
+ case "and": return " AND "
25
+ case "or": return " OR "
26
+ case "not": return "NOT "
27
+ case "lt": return " < "
28
+ case "le": return " <= "
29
+ case "eq": return " = "
30
+ case "ne": return " != "
31
+ case "ge": return " >= "
32
+ case "gt": return " > "
33
+ case "like": return " LIKE "
34
+ case "isnull": return " IS NULL"
35
+ case "isNotNull": return " IS NOT NULL"
36
+ }
37
+ return " "
38
+ }
39
+
40
+ /**
41
+ * Print filter as SQL condition based on the datamodel of the API.
42
+ *
43
+ * @param dataModel data model (and database) to use for formatting of values
44
+ *
45
+ */
46
+ static printSql(filter: OINOQueryFilter, dataModel:OINODbDataModel):string {
47
+ if (filter.isEmpty()) {
48
+ return ""
49
+ }
50
+ let result:string = ""
51
+ let field:OINODataField|null = null
52
+ if (filter.leftSide instanceof OINOQueryFilter) {
53
+ result += OINODbQueryFilter.printSql(filter.leftSide, dataModel)
54
+ } else {
55
+ field = dataModel.findFieldByName(filter.leftSide as string)
56
+ if (!field) {
57
+ OINOLog.error("@oino-ts/db", "OINODbQueryFilter", "toSql", "Invalid field!", {field:filter.leftSide})
58
+ throw new Error(OINO_ERROR_PREFIX + ": OINODbQueryFilter.toSql - Invalid field '" + filter.leftSide + "'") // invalid field name could be a security risk, stop processing
59
+ }
60
+ result += dataModel.api.datasource.printColumnName(field.name)
61
+ }
62
+ result += OINODbQueryFilter.operatorToSql(filter)
63
+ if (filter.rightSide instanceof OINOQueryFilter) {
64
+ result += OINODbQueryFilter.printSql(filter.rightSide, dataModel)
65
+
66
+ } else if (filter.operator == OINOQueryNullCheck.isnull || filter.operator == OINOQueryNullCheck.isNotNull) {
67
+ // nothing to do, IS NULL and IS NOT NULL do not have a right side
68
+ } else {
69
+ const value = field!.deserializeCell(filter.rightSide as string)
70
+ if ((value == null) || (value === "")) {
71
+ OINOLog.error("@oino-ts/db", "OINODbQueryFilter", "toSql", "Invalid value!", {value:value})
72
+ throw new Error(OINO_ERROR_PREFIX + ": OINODbQueryFilter.toSql - Invalid value '" + value + "'") // invalid value could be a security risk, stop processing
73
+ }
74
+ result += field!.printCellAsValue(value)
75
+ }
76
+ result = "(" + result + ")"
77
+ OINOLog.debug("@oino-ts/db", "OINODbQueryFilter", "toSql", "Result", {sql:result})
78
+ return result
79
+ }
80
+ }
81
+
82
+ /**
83
+ * Class for ordering select results on a number of columns.
84
+ *
85
+ */
86
+ export class OINODbQueryOrder extends OINOQueryOrder {
87
+
88
+ /**
89
+ * Print order as SQL condition based on the datamodel of the API.
90
+ *
91
+ * @param order order instance
92
+ * @param dataModel data model (and database) to use for formatting of values
93
+ *
94
+ */
95
+ static printSql(order: OINOQueryOrder, dataModel:OINODbDataModel):string {
96
+ if (order.isEmpty()) {
97
+ return ""
98
+ }
99
+ let result:string = ""
100
+ for (let i=0; i<order.columns.length; i++) {
101
+ const field:OINODataField|null = dataModel.findFieldByName(order.columns[i])
102
+ if (!field) {
103
+ OINOLog.error("@oino-ts/db", "OINODbQueryOrder", "toSql", "Invalid field!", {field:order.columns[i]})
104
+ throw new Error(OINO_ERROR_PREFIX + ": OINODbQueryOrder.toSql - Invalid field '" + order.columns[i] + "'") // invalid field name could be a security risk, stop processing
105
+ }
106
+ if (result) {
107
+ result += ","
108
+ }
109
+ result += dataModel.api.datasource.printColumnName(field.name) + " "
110
+ if (order.descending[i]) {
111
+ result += "DESC"
112
+ } else {
113
+ result += "ASC"
114
+ }
115
+ }
116
+ OINOLog.debug("@oino-ts/db", "OINODbQueryOrder", "toSql", "Result", {sql:result})
117
+ return result
118
+ }
119
+ }
120
+
121
+ /**
122
+ * Class for limiting the number of results.
123
+ *
124
+ */
125
+ export class OINODbQueryLimit extends OINOQueryLimit {
126
+
127
+ /**
128
+ * Print order as SQL condition based on the datamodel of the API.
129
+ *
130
+ * @param limit limit instance
131
+ * @param dataModel data model (and database) to use for formatting of values
132
+ *
133
+ */
134
+ static printSql(limit: OINOQueryLimit, dataModel:OINODbDataModel):string {
135
+ if (limit.isEmpty()) {
136
+ return ""
137
+ }
138
+ let result:string = limit.limit.toString()
139
+ if (limit.page > 0) {
140
+ result += " OFFSET " + (limit.limit * (limit.page-1) + 1).toString()
141
+ }
142
+ OINOLog.debug("@oino-ts/db", "OINODbQueryLimit", "toSql", "Result", {sql:result})
143
+ return result
144
+ }
145
+ }
146
+
147
+ /**
148
+ * Class for limiting the number of results.
149
+ *
150
+ */
151
+ export class OINODbQueryAggregate extends OINOQueryAggregate {
152
+
153
+ /**
154
+ * Print non-aggregated fields as SQL GROUP BY-condition based on the datamodel of the API.
155
+ *
156
+ * @param aggregate aggregate instance
157
+ * @param dataModel data model (and database) to use for formatting of values
158
+ * @param select what fields to select
159
+ *
160
+ */
161
+ static printSql(aggregate: OINOQueryAggregate, dataModel:OINODataModel, select?:OINOQuerySelect):string {
162
+ if (aggregate.isEmpty()) {
163
+ return ""
164
+ }
165
+ let result:string = ""
166
+ for (let i=0; i<dataModel.fields.length; i++) {
167
+ const f = dataModel.fields[i]
168
+ if ((select?.isSelected(f.name) || (f.fieldParams.isPrimaryKey == true)) && (aggregate.fields.includes(f.name) == false)) {
169
+ result += f.printColumnName() + ","
170
+ }
171
+ }
172
+ result = result.substring(0, result.length-1)
173
+ OINOLog.debug("@oino-ts/db", "OINODbQueryAggregate", "toSql", "Result", {sql:result})
174
+ return result
175
+ }
176
+
177
+ /**
178
+ * Print non-aggregated fields as SQL GROUP BY-condition based on the datamodel of the API.
179
+ *
180
+ * @param dataModel data model (and database) to use for formatting of values
181
+ * @param select what fields to select
182
+ *
183
+ */
184
+ static printColumnNames(aggregate: OINOQueryAggregate, dataModel:OINODataModel, select?:OINOQuerySelect):string {
185
+ let result:string = ""
186
+ for (let i=0; i<dataModel.fields.length; i++) {
187
+ const f:OINODataField = dataModel.fields[i]
188
+ if ((select?.isSelected(f.name) === false) && (f.fieldParams.isPrimaryKey == false)) { // if a field is not selected, we include an aggregated constant (min of const string) and correct fieldname instead so that dimensions of the data don't change, it does not need a group by but no unnecessary data is fetched
189
+ result += OINOQueryAggregateFunctions.min + "(" + f.datasource.printStringValue("") + ") as " + f.printColumnName()+","
190
+
191
+ } else {
192
+ const aggregate_index = aggregate.fields.indexOf(f.name)
193
+ const col_name = f.printColumnName()
194
+ if (aggregate_index >= 0) {
195
+ result += aggregate.functions[aggregate_index] + "(" + col_name + ") as " + col_name + ","
196
+ } else {
197
+ result += col_name + ","
198
+ }
199
+ }
200
+ }
201
+ return result.substring(0, result.length-1)
202
+ }
203
+ }
package/src/index.ts CHANGED
@@ -1,118 +1,6 @@
1
- import { Buffer } from "node:buffer";
2
- import { OINODb } from "./OINODb.js"
3
- import { OINODbDataField } from "./OINODbDataField.js"
4
- import { OINODbSqlAggregate, OINODbSqlFilter, OINODbSqlLimit, OINODbSqlOrder, OINODbSqlSelect } from "./OINODbSqlParams.js"
5
-
6
- export { OINODbApiResult, OINODbHtmlTemplate, OINODbApi, OINODbApiRequest, type OINODbApiRequestInit, type OINODbApiData } from "./OINODbApi.js"
7
- export { OINODbDataModel } from "./OINODbDataModel.js"
8
- export { OINODbModelSet } from "./OINODbModelSet.js"
9
- export { OINODbDataField, OINOBooleanDataField, OINONumberDataField, OINOStringDataField, OINOBlobDataField, OINODatetimeDataField } from "./OINODbDataField.js"
10
- export { OINODbDataSet, OINODbMemoryDataSet, OINODb } from "./OINODb.js"
11
- export { OINODbSqlFilter, OINODbSqlOrder, OINODbSqlComparison, OINODbSqlLimit, OINODbSqlBooleanOperation, OINODbSqlAggregate, OINODbSqlAggregateFunctions, OINODbSqlSelect, OINODbSqlNullCheck } from "./OINODbSqlParams.js"
12
- export { OINODbConfig } from "./OINODbConfig.js"
13
- export { OINODbFactory } from "./OINODbFactory.js"
14
- export { OINODbSwagger } from "./OINODbSwagger.js"
15
- export { OINODbParser } from "./OINODbParser.js"
16
-
17
- /** API parameters */
18
- export type OINODbApiParams = {
19
- /** Name of the api */
20
- apiName: string
21
- /** Name of the database table */
22
- tableName: string
23
- /** Reject values that exceed field max length (behaviour on such is platform dependent) */
24
- failOnOversizedValues?: Boolean
25
- /** Reject PUT-requests that contain values for autoinc-type fields */
26
- failOnUpdateOnAutoinc?: boolean
27
- /** Reject POST-requests without primary key value (can work if DB-side ) */
28
- failOnInsertWithoutKey?: boolean
29
- /** Reject POST-requests without primary key value (can work if DB-side ) */
30
- failOnAnyInvalidRows?: boolean
31
- /** Treat date type fields as just strings and use the native formatting instead of the ISO 8601 format */
32
- useDatesAsString?: Boolean
33
- /** Include given fields from the API and exclude rest (if defined) */
34
- includeFields?:string[],
35
- /** Exclude all fields with this prefix from the API */
36
- excludeFieldPrefix?:string
37
- /** Exclude given fields from the API and include rest (if defined) */
38
- excludeFields?:string[],
39
- /** Enable hashids for numeric primarykeys by adding a 32 char key */
40
- hashidKey?:string,
41
- /** Set (minimum) length (12-32 chars) of the hashids */
42
- hashidLength?:number,
43
- /** Make hashids static per row/table */
44
- hashidStaticIds?: boolean,
45
- /** Name of field that has the modified field */
46
- cacheModifiedField?:string,
47
- /** Return inserted id values */
48
- returnInsertedIds?: boolean
49
- }
50
-
51
- /**
52
- * Database class (constructor) type
53
- * @param dbParams database parameters
54
- */
55
- export type OINODbConstructor = new (dbParams:OINODbParams) => OINODb
56
-
57
- /** Database parameters */
58
- export type OINODbParams = {
59
- /** Name of the database class (e.g. OINODbPostgresql) */
60
- type: string
61
- /** Connection URL, either file://-path or an IP-address or an HTTP-url */
62
- url: string
63
- /** Name of the database */
64
- database: string
65
- /** TCP port of the database */
66
- port?: number
67
- /** Username used to authenticate */
68
- user?: string
69
- /** Password used to authenticate */
70
- password?: string
71
- }
72
-
73
- /** Field parameters in database */
74
- export type OINODbDataFieldParams = {
75
- /** Is the field a primary key */
76
- isPrimaryKey: Boolean
77
- /** Is the field a primary key */
78
- isForeignKey: Boolean
79
- /** Is the field an auto inc type */
80
- isAutoInc: Boolean
81
- /** Is the field allowed to have null values */
82
- isNotNull: Boolean
83
- }
84
-
85
- /**
86
- * Callback to filter data fields
87
- * @param field fields to filter
88
- */
89
- export type OINODbDataFieldFilter = (field:OINODbDataField) => Boolean
90
-
91
- /** Request options */
92
- export type OINODbSqlParams = {
93
- /** Additional SQL select where-conditions */
94
- filter?:OINODbSqlFilter,
95
- /** SQL result ordering conditions */
96
- order?:OINODbSqlOrder
97
- /** SQL result limit condition */
98
- limit?:OINODbSqlLimit
99
- /** SQL aggregation functions */
100
- aggregate?:OINODbSqlAggregate
101
- /** SQL select condition */
102
- select?:OINODbSqlSelect
103
- }
104
-
105
- /** A single column value of a data row */
106
- export type OINODataCell = string | bigint | number | boolean | Date | Uint8Array | Buffer | null | undefined
107
- /** A single data row */
108
- export type OINODataRow = Array<OINODataCell>
109
- /** Empty row instance */
110
- export const OINODB_EMPTY_ROW:OINODataRow = []
111
- /** Empty row array instance */
112
- export const OINODB_EMPTY_ROWS:OINODataRow[] = []
113
- /** Constant for undefined values */
114
- export const OINODB_UNDEFINED = "" // original idea was to have a defined literal that get's swapped back to undefined, but current implementation just leaves it out at serialization (so value does not matter)
115
-
116
- /** Key-value collection */
117
- export type OINOValues = Record<string, string>
118
-
1
+ export { OINODb } from "./OINODb.js"
2
+ export { OINODbDataModel } from "./OINODbDataModel.js"
3
+ export { OINODbFactory } from "./OINODbFactory.js"
4
+ export { OINODbApi } from "./OINODbApi.js"
5
+ export { OINODbQueryFilter, OINODbQueryOrder, OINODbQueryLimit, OINODbQueryAggregate } from "./OINODbQueryParams.js"
6
+ export { type OINODbConstructor, type OINODbParams, OINODB_UNDEFINED } from "./OINODbConstants.js"
@@ -1,98 +0,0 @@
1
- /** Set the name of the OINO ID field (default \_OINOID\_) */
2
-
3
- export class OINODbConfig {
4
- /** Name of the synthetic OINO ID field */
5
- static OINODB_ID_FIELD:string = "_OINOID_"
6
- /** Private key separator of the synthetic OINO ID field */
7
- static OINODB_ID_SEPARATOR:string = "_"
8
- private static OINODB_ID_SEPARATOR_ESCAPED:string = "%"
9
-
10
- /** Name of the OINODbSqlFilter-parameter in request */
11
- static OINODB_SQL_FILTER_PARAM:string = "oinosqlfilter"
12
-
13
- /** Name of the OINODbSqlOrder-parameter in request */
14
- static OINODB_SQL_ORDER_PARAM:string = "oinosqlorder"
15
-
16
- /** Name of the OINODbSqlLimit-parameter in request */
17
- static OINODB_SQL_LIMIT_PARAM:string = "oinosqllimit"
18
-
19
- /** Name of the OINODbSqlAggregate-parameter in request */
20
- static OINODB_SQL_AGGREGATE_PARAM:string = "oinosqlaggregate"
21
-
22
- /** Name of the OINODbSqlSelect-parameter in request */
23
- static OINODB_SQL_SELECT_PARAM:string = "oinosqlselect"
24
-
25
- /**
26
- * Set the name of the OINO ID field
27
- * @param idField name of the OINO ID field
28
- */
29
- static setOinoIdField(idField: string) {
30
- if (idField) {
31
- OINODbConfig.OINODB_ID_FIELD = idField;
32
- }
33
- }
34
-
35
- /**
36
- * Set the separator character of the OINO ID field
37
- * @param idSeparator character to use as separator of id parts
38
- */
39
- static setOinoIdSeparator(idSeparator: string) {
40
- if (idSeparator && (idSeparator.length == 1)) {
41
- OINODbConfig.OINODB_ID_SEPARATOR = idSeparator;
42
- OINODbConfig.OINODB_ID_SEPARATOR_ESCAPED = '%' + idSeparator.charCodeAt(0).toString(16);
43
- }
44
- }
45
-
46
- /**
47
- * Print OINO ID for primary key values.
48
- *
49
- * @param primaryKeys an array of primary key values.
50
- *
51
- */
52
- static printOINOId(primaryKeys:string[]):string {
53
- let result:string = ""
54
- for (let i=0; i< primaryKeys.length; i++) {
55
- if (i > 0) {
56
- result += OINODbConfig.OINODB_ID_SEPARATOR
57
- }
58
- result += encodeURIComponent(primaryKeys[i] as string).replaceAll(OINODbConfig.OINODB_ID_SEPARATOR, OINODbConfig.OINODB_ID_SEPARATOR_ESCAPED)
59
- }
60
- return result
61
- }
62
-
63
- /**
64
- * Set the name of the OINODbSqlFilter-param field
65
- *
66
- * @param sqlFilterParam name of the http parameter with `OINODbSqlFilter` definition
67
- *
68
- */
69
- static setOinoSqlFilterParam(sqlFilterParam: string) {
70
- if (sqlFilterParam) {
71
- OINODbConfig.OINODB_SQL_FILTER_PARAM = sqlFilterParam;
72
- }
73
- }
74
-
75
- /**
76
- * Set the name of the OINODbSqlOrder-param field
77
- *
78
- * @param sqlOrderParam name of the http parameter with `OINODbSqlOrder` definition
79
- *
80
- */
81
- static setOinoSqlOrderParam(sqlOrderParam: string) {
82
- if (sqlOrderParam) {
83
- OINODbConfig.OINODB_SQL_ORDER_PARAM = sqlOrderParam;
84
- }
85
- }
86
-
87
- /**
88
- * Set the name of the OINODbSqlLimit-param field
89
- *
90
- * @param sqlLimitParam name of the http parameter with `OINODbSqlLimit` definition
91
- *
92
- */
93
- static setOinoSqlLimitParam(sqlLimitParam: string) {
94
- if (sqlLimitParam) {
95
- OINODbConfig.OINODB_SQL_LIMIT_PARAM = sqlLimitParam;
96
- }
97
- }
98
- }