@oino-ts/db 1.0.1 → 1.0.2

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.
@@ -35,10 +35,10 @@ class OINODbDataModel extends common_1.OINODataModel {
35
35
  for (let i = 0; i < this.fields.length; i++) {
36
36
  const f = this.fields[i];
37
37
  if ((select?.isSelected(f.name) === false) && (f.fieldParams.isPrimaryKey == false)) { // if a field is not selected, we include a constant and correct fieldname instead so that dimensions of the data don't change but no unnecessary data is fetched
38
- result += f.datasource.printStringValue(OINODbConstants_js_1.OINODB_UNDEFINED) + " as " + f.printColumnName() + ",";
38
+ result += f.datasource.printStringValue(OINODbConstants_js_1.OINODB_UNDEFINED) + " as " + f.printFieldName() + ",";
39
39
  }
40
40
  else {
41
- result += f.printColumnName() + ",";
41
+ result += f.printFieldName() + ",";
42
42
  }
43
43
  }
44
44
  return result.substring(0, result.length - 1);
@@ -55,7 +55,7 @@ class OINODbDataModel extends common_1.OINODataModel {
55
55
  columns += ",";
56
56
  values += ",";
57
57
  }
58
- columns += f.printColumnName();
58
+ columns += f.printFieldName();
59
59
  values += f.printCellAsValue(val);
60
60
  }
61
61
  }
@@ -71,7 +71,7 @@ class OINODbDataModel extends common_1.OINODataModel {
71
71
  if (result != "") {
72
72
  result += ",";
73
73
  }
74
- result += f.printColumnName() + "=" + f.printCellAsValue(val);
74
+ result += f.printFieldName() + "=" + f.printCellAsValue(val);
75
75
  }
76
76
  }
77
77
  if (result == "") {
@@ -94,9 +94,9 @@ class OINODbDataModel extends common_1.OINODataModel {
94
94
  }
95
95
  value = f.printCellAsValue(value);
96
96
  if (value == "") { // ids are user input and could be specially crafted to be empty
97
- throw new Error(common_1.OINO_ERROR_PREFIX + ": empty condition for id '" + id_value + "' for table " + this.api.params.tableName);
97
+ throw new Error(common_1.OINO_ERROR_PREFIX + ": invalid id value '" + id_value + "' for table " + this.api.params.tableName);
98
98
  }
99
- result += f.printColumnName() + "=" + value;
99
+ result += f.printFieldName() + "=" + value;
100
100
  i = i + 1;
101
101
  }
102
102
  }
@@ -55,7 +55,7 @@ class OINODbQueryFilter extends common_1.OINOQueryFilter {
55
55
  common_1.OINOLog.error("@oino-ts/db", "OINODbQueryFilter", "toSql", "Invalid field!", { field: filter.leftSide });
56
56
  throw new Error(common_1.OINO_ERROR_PREFIX + ": OINODbQueryFilter.toSql - Invalid field '" + filter.leftSide + "'"); // invalid field name could be a security risk, stop processing
57
57
  }
58
- result += dataModel.api.datasource.printColumnName(field.name);
58
+ result += dataModel.dbApi.db.printColumnName(field.name);
59
59
  }
60
60
  result += OINODbQueryFilter.operatorToSql(filter);
61
61
  if (filter.rightSide instanceof common_1.OINOQueryFilter) {
@@ -104,7 +104,7 @@ class OINODbQueryOrder extends common_1.OINOQueryOrder {
104
104
  if (result) {
105
105
  result += ",";
106
106
  }
107
- result += dataModel.api.datasource.printColumnName(field.name) + " ";
107
+ result += dataModel.dbApi.db.printColumnName(field.name) + " ";
108
108
  if (order.descending[i]) {
109
109
  result += "DESC";
110
110
  }
@@ -163,7 +163,7 @@ class OINODbQueryAggregate extends common_1.OINOQueryAggregate {
163
163
  for (let i = 0; i < dataModel.fields.length; i++) {
164
164
  const f = dataModel.fields[i];
165
165
  if ((select?.isSelected(f.name) || (f.fieldParams.isPrimaryKey == true)) && (aggregate.fields.includes(f.name) == false)) {
166
- result += f.printColumnName() + ",";
166
+ result += f.printFieldName() + ",";
167
167
  }
168
168
  }
169
169
  result = result.substring(0, result.length - 1);
@@ -182,11 +182,11 @@ class OINODbQueryAggregate extends common_1.OINOQueryAggregate {
182
182
  for (let i = 0; i < dataModel.fields.length; i++) {
183
183
  const f = dataModel.fields[i];
184
184
  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
185
- result += common_1.OINOQueryAggregateFunctions.min + "(" + f.datasource.printStringValue("") + ") as " + f.printColumnName() + ",";
185
+ result += common_1.OINOQueryAggregateFunctions.min + "(" + f.datasource.printStringValue("") + ") as " + f.printFieldName() + ",";
186
186
  }
187
187
  else {
188
188
  const aggregate_index = aggregate.fields.indexOf(f.name);
189
- const col_name = f.printColumnName();
189
+ const col_name = f.printFieldName();
190
190
  if (aggregate_index >= 0) {
191
191
  result += aggregate.functions[aggregate_index] + "(" + col_name + ") as " + col_name + ",";
192
192
  }
@@ -32,10 +32,10 @@ export class OINODbDataModel extends OINODataModel {
32
32
  for (let i = 0; i < this.fields.length; i++) {
33
33
  const f = this.fields[i];
34
34
  if ((select?.isSelected(f.name) === false) && (f.fieldParams.isPrimaryKey == false)) { // if a field is not selected, we include a constant and correct fieldname instead so that dimensions of the data don't change but no unnecessary data is fetched
35
- result += f.datasource.printStringValue(OINODB_UNDEFINED) + " as " + f.printColumnName() + ",";
35
+ result += f.datasource.printStringValue(OINODB_UNDEFINED) + " as " + f.printFieldName() + ",";
36
36
  }
37
37
  else {
38
- result += f.printColumnName() + ",";
38
+ result += f.printFieldName() + ",";
39
39
  }
40
40
  }
41
41
  return result.substring(0, result.length - 1);
@@ -52,7 +52,7 @@ export class OINODbDataModel extends OINODataModel {
52
52
  columns += ",";
53
53
  values += ",";
54
54
  }
55
- columns += f.printColumnName();
55
+ columns += f.printFieldName();
56
56
  values += f.printCellAsValue(val);
57
57
  }
58
58
  }
@@ -68,7 +68,7 @@ export class OINODbDataModel extends OINODataModel {
68
68
  if (result != "") {
69
69
  result += ",";
70
70
  }
71
- result += f.printColumnName() + "=" + f.printCellAsValue(val);
71
+ result += f.printFieldName() + "=" + f.printCellAsValue(val);
72
72
  }
73
73
  }
74
74
  if (result == "") {
@@ -91,9 +91,9 @@ export class OINODbDataModel extends OINODataModel {
91
91
  }
92
92
  value = f.printCellAsValue(value);
93
93
  if (value == "") { // ids are user input and could be specially crafted to be empty
94
- throw new Error(OINO_ERROR_PREFIX + ": empty condition for id '" + id_value + "' for table " + this.api.params.tableName);
94
+ throw new Error(OINO_ERROR_PREFIX + ": invalid id value '" + id_value + "' for table " + this.api.params.tableName);
95
95
  }
96
- result += f.printColumnName() + "=" + value;
96
+ result += f.printFieldName() + "=" + value;
97
97
  i = i + 1;
98
98
  }
99
99
  }
@@ -52,7 +52,7 @@ export class OINODbQueryFilter extends OINOQueryFilter {
52
52
  OINOLog.error("@oino-ts/db", "OINODbQueryFilter", "toSql", "Invalid field!", { field: filter.leftSide });
53
53
  throw new Error(OINO_ERROR_PREFIX + ": OINODbQueryFilter.toSql - Invalid field '" + filter.leftSide + "'"); // invalid field name could be a security risk, stop processing
54
54
  }
55
- result += dataModel.api.datasource.printColumnName(field.name);
55
+ result += dataModel.dbApi.db.printColumnName(field.name);
56
56
  }
57
57
  result += OINODbQueryFilter.operatorToSql(filter);
58
58
  if (filter.rightSide instanceof OINOQueryFilter) {
@@ -100,7 +100,7 @@ export class OINODbQueryOrder extends OINOQueryOrder {
100
100
  if (result) {
101
101
  result += ",";
102
102
  }
103
- result += dataModel.api.datasource.printColumnName(field.name) + " ";
103
+ result += dataModel.dbApi.db.printColumnName(field.name) + " ";
104
104
  if (order.descending[i]) {
105
105
  result += "DESC";
106
106
  }
@@ -157,7 +157,7 @@ export class OINODbQueryAggregate extends OINOQueryAggregate {
157
157
  for (let i = 0; i < dataModel.fields.length; i++) {
158
158
  const f = dataModel.fields[i];
159
159
  if ((select?.isSelected(f.name) || (f.fieldParams.isPrimaryKey == true)) && (aggregate.fields.includes(f.name) == false)) {
160
- result += f.printColumnName() + ",";
160
+ result += f.printFieldName() + ",";
161
161
  }
162
162
  }
163
163
  result = result.substring(0, result.length - 1);
@@ -176,11 +176,11 @@ export class OINODbQueryAggregate extends OINOQueryAggregate {
176
176
  for (let i = 0; i < dataModel.fields.length; i++) {
177
177
  const f = dataModel.fields[i];
178
178
  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
179
- result += OINOQueryAggregateFunctions.min + "(" + f.datasource.printStringValue("") + ") as " + f.printColumnName() + ",";
179
+ result += OINOQueryAggregateFunctions.min + "(" + f.datasource.printStringValue("") + ") as " + f.printFieldName() + ",";
180
180
  }
181
181
  else {
182
182
  const aggregate_index = aggregate.fields.indexOf(f.name);
183
- const col_name = f.printColumnName();
183
+ const col_name = f.printFieldName();
184
184
  if (aggregate_index >= 0) {
185
185
  result += aggregate.functions[aggregate_index] + "(" + col_name + ") as " + col_name + ",";
186
186
  }
@@ -30,6 +30,13 @@ export declare abstract class OINODb extends OINODataSource {
30
30
  *
31
31
  */
32
32
  abstract sqlExec(sql: string): Promise<OINODataSet>;
33
+ /**
34
+ * Print a table name using database specific SQL escaping.
35
+ *
36
+ * @param sqlTable name of the table
37
+ *
38
+ */
39
+ abstract printTableName(sqlTable: string): string;
33
40
  /**
34
41
  * Print SQL select statement with DB specific formatting.
35
42
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oino-ts/db",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
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,13 +19,13 @@
19
19
  "module": "./dist/esm/index.js",
20
20
  "types": "./dist/types/index.d.ts",
21
21
  "dependencies": {
22
- "@oino-ts/common": "1.0.1",
22
+ "@oino-ts/common": "1.0.2",
23
23
  "oino-ts": "file:.."
24
24
  },
25
25
  "devDependencies": {
26
- "@oino-ts/types": "1.0.1",
26
+ "@oino-ts/types": "1.0.2",
27
27
  "@types/bun": "^1.1.14",
28
- "@types/node": "^21.0.10",
28
+ "@types/node": "^21.0.20",
29
29
  "typescript": "~5.9.0"
30
30
  },
31
31
  "files": [
package/src/OINODb.ts CHANGED
@@ -48,6 +48,14 @@ export abstract class OINODb extends OINODataSource {
48
48
  */
49
49
  abstract sqlExec(sql:string): Promise<OINODataSet>
50
50
 
51
+ /**
52
+ * Print a table name using database specific SQL escaping.
53
+ *
54
+ * @param sqlTable name of the table
55
+ *
56
+ */
57
+ abstract printTableName(sqlTable:string): string
58
+
51
59
  /**
52
60
  * Print SQL select statement with DB specific formatting.
53
61
  *
@@ -39,9 +39,9 @@ export class OINODbDataModel extends OINODataModel {
39
39
  for (let i=0; i < this.fields.length; i++) {
40
40
  const f:OINODataField = this.fields[i]
41
41
  if ((select?.isSelected(f.name) === false) && (f.fieldParams.isPrimaryKey == false)) { // if a field is not selected, we include a constant and correct fieldname instead so that dimensions of the data don't change but no unnecessary data is fetched
42
- result += f.datasource.printStringValue(OINODB_UNDEFINED) + " as " + f.printColumnName()+","
42
+ result += f.datasource.printStringValue(OINODB_UNDEFINED) + " as " + f.printFieldName()+","
43
43
  } else {
44
- result += f.printColumnName()+","
44
+ result += f.printFieldName()+","
45
45
  }
46
46
  }
47
47
  return result.substring(0, result.length-1)
@@ -59,7 +59,7 @@ export class OINODbDataModel extends OINODataModel {
59
59
  columns += ",";
60
60
  values += ",";
61
61
  }
62
- columns += f.printColumnName();
62
+ columns += f.printFieldName();
63
63
  values += f.printCellAsValue(val);
64
64
  }
65
65
  }
@@ -76,7 +76,7 @@ export class OINODbDataModel extends OINODataModel {
76
76
  if (result != "") {
77
77
  result += ",";
78
78
  }
79
- result += f.printColumnName() + "=" + f.printCellAsValue(val);
79
+ result += f.printFieldName() + "=" + f.printCellAsValue(val);
80
80
  }
81
81
  }
82
82
  if (result == "") {
@@ -100,9 +100,9 @@ export class OINODbDataModel extends OINODataModel {
100
100
  }
101
101
  value = f.printCellAsValue(value)
102
102
  if (value == "") { // ids are user input and could be specially crafted to be empty
103
- throw new Error(OINO_ERROR_PREFIX + ": empty condition for id '" + id_value + "' for table " + this.api.params.tableName)
103
+ throw new Error(OINO_ERROR_PREFIX + ": invalid id value '" + id_value + "' for table " + this.api.params.tableName)
104
104
  }
105
- result += f.printColumnName() + "=" + value;
105
+ result += f.printFieldName() + "=" + value;
106
106
  i = i + 1
107
107
  }
108
108
  }
@@ -57,7 +57,7 @@ export class OINODbQueryFilter extends OINOQueryFilter {
57
57
  OINOLog.error("@oino-ts/db", "OINODbQueryFilter", "toSql", "Invalid field!", {field:filter.leftSide})
58
58
  throw new Error(OINO_ERROR_PREFIX + ": OINODbQueryFilter.toSql - Invalid field '" + filter.leftSide + "'") // invalid field name could be a security risk, stop processing
59
59
  }
60
- result += dataModel.api.datasource.printColumnName(field.name)
60
+ result += dataModel.dbApi.db.printColumnName(field.name)
61
61
  }
62
62
  result += OINODbQueryFilter.operatorToSql(filter)
63
63
  if (filter.rightSide instanceof OINOQueryFilter) {
@@ -106,7 +106,7 @@ export class OINODbQueryOrder extends OINOQueryOrder {
106
106
  if (result) {
107
107
  result += ","
108
108
  }
109
- result += dataModel.api.datasource.printColumnName(field.name) + " "
109
+ result += dataModel.dbApi.db.printColumnName(field.name) + " "
110
110
  if (order.descending[i]) {
111
111
  result += "DESC"
112
112
  } else {
@@ -166,7 +166,7 @@ export class OINODbQueryAggregate extends OINOQueryAggregate {
166
166
  for (let i=0; i<dataModel.fields.length; i++) {
167
167
  const f = dataModel.fields[i]
168
168
  if ((select?.isSelected(f.name) || (f.fieldParams.isPrimaryKey == true)) && (aggregate.fields.includes(f.name) == false)) {
169
- result += f.printColumnName() + ","
169
+ result += f.printFieldName() + ","
170
170
  }
171
171
  }
172
172
  result = result.substring(0, result.length-1)
@@ -186,11 +186,11 @@ export class OINODbQueryAggregate extends OINOQueryAggregate {
186
186
  for (let i=0; i<dataModel.fields.length; i++) {
187
187
  const f:OINODataField = dataModel.fields[i]
188
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()+","
189
+ result += OINOQueryAggregateFunctions.min + "(" + f.datasource.printStringValue("") + ") as " + f.printFieldName()+","
190
190
 
191
191
  } else {
192
192
  const aggregate_index = aggregate.fields.indexOf(f.name)
193
- const col_name = f.printColumnName()
193
+ const col_name = f.printFieldName()
194
194
  if (aggregate_index >= 0) {
195
195
  result += aggregate.functions[aggregate_index] + "(" + col_name + ") as " + col_name + ","
196
196
  } else {