@oino-ts/db-mssql 0.2.0 → 0.3.0

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.
@@ -249,9 +249,10 @@ class OINODbMsSql extends db_1.OINODb {
249
249
  * @param whereCondition - The WHERE clause to filter the results.
250
250
  * @param orderCondition - The ORDER BY clause to sort the results.
251
251
  * @param limitCondition - The LIMIT clause to limit the number of results.
252
+ * @param groupByCondition - The GROUP BY clause to group the results.
252
253
  *
253
254
  */
254
- printSqlSelect(tableName, columnNames, whereCondition, orderCondition, limitCondition) {
255
+ printSqlSelect(tableName, columnNames, whereCondition, orderCondition, limitCondition, groupByCondition) {
255
256
  const limit_parts = limitCondition.split(" OFFSET ");
256
257
  let result = "SELECT ";
257
258
  if ((limitCondition != "") && (limit_parts.length == 1)) {
@@ -273,6 +274,9 @@ class OINODbMsSql extends db_1.OINODb {
273
274
  result += " OFFSET " + limit_parts[1] + " ROWS FETCH NEXT " + limit_parts[0] + " ROWS ONLY";
274
275
  }
275
276
  }
277
+ if (groupByCondition != "") {
278
+ result += " GROUP BY " + groupByCondition;
279
+ }
276
280
  result += ";";
277
281
  // OINOLog.debug("OINODb.printSqlSelect", {result:result})
278
282
  return result;
@@ -380,8 +384,11 @@ ORDER BY C.ORDINAL_POSITION;`;
380
384
  isAutoInc: row[7] == 1,
381
385
  isNotNull: row[1] == "NO"
382
386
  };
383
- if (((api.params.excludeFieldPrefix) && field_name.startsWith(api.params.excludeFieldPrefix)) || ((api.params.excludeFields) && (api.params.excludeFields.indexOf(field_name) < 0))) {
387
+ if (api.isFieldIncluded(field_name) == false) {
384
388
  db_1.OINOLog.info("OINODbMsSql.initializeApiDatamodel: field excluded in API parameters.", { field: field_name });
389
+ if (field_params.isPrimaryKey) {
390
+ throw new Error(db_1.OINO_ERROR_PREFIX + "Primary key field excluded in API parameters: " + field_name);
391
+ }
385
392
  }
386
393
  else {
387
394
  // OINOLog.debug("OINODbMsSql.initializeApiDatamodel: next field ", {field_name: field_name, sql_type:sql_type, char_field_length:char_field_length, numeric_field_length1:numeric_field_length1, numeric_field_length2:numeric_field_length2, field_params:field_params })
@@ -246,9 +246,10 @@ export class OINODbMsSql extends OINODb {
246
246
  * @param whereCondition - The WHERE clause to filter the results.
247
247
  * @param orderCondition - The ORDER BY clause to sort the results.
248
248
  * @param limitCondition - The LIMIT clause to limit the number of results.
249
+ * @param groupByCondition - The GROUP BY clause to group the results.
249
250
  *
250
251
  */
251
- printSqlSelect(tableName, columnNames, whereCondition, orderCondition, limitCondition) {
252
+ printSqlSelect(tableName, columnNames, whereCondition, orderCondition, limitCondition, groupByCondition) {
252
253
  const limit_parts = limitCondition.split(" OFFSET ");
253
254
  let result = "SELECT ";
254
255
  if ((limitCondition != "") && (limit_parts.length == 1)) {
@@ -270,6 +271,9 @@ export class OINODbMsSql extends OINODb {
270
271
  result += " OFFSET " + limit_parts[1] + " ROWS FETCH NEXT " + limit_parts[0] + " ROWS ONLY";
271
272
  }
272
273
  }
274
+ if (groupByCondition != "") {
275
+ result += " GROUP BY " + groupByCondition;
276
+ }
273
277
  result += ";";
274
278
  // OINOLog.debug("OINODb.printSqlSelect", {result:result})
275
279
  return result;
@@ -377,8 +381,11 @@ ORDER BY C.ORDINAL_POSITION;`;
377
381
  isAutoInc: row[7] == 1,
378
382
  isNotNull: row[1] == "NO"
379
383
  };
380
- if (((api.params.excludeFieldPrefix) && field_name.startsWith(api.params.excludeFieldPrefix)) || ((api.params.excludeFields) && (api.params.excludeFields.indexOf(field_name) < 0))) {
384
+ if (api.isFieldIncluded(field_name) == false) {
381
385
  OINOLog.info("OINODbMsSql.initializeApiDatamodel: field excluded in API parameters.", { field: field_name });
386
+ if (field_params.isPrimaryKey) {
387
+ throw new Error(OINO_ERROR_PREFIX + "Primary key field excluded in API parameters: " + field_name);
388
+ }
382
389
  }
383
390
  else {
384
391
  // OINOLog.debug("OINODbMsSql.initializeApiDatamodel: next field ", {field_name: field_name, sql_type:sql_type, char_field_length:char_field_length, numeric_field_length1:numeric_field_length1, numeric_field_length2:numeric_field_length2, field_params:field_params })
@@ -52,9 +52,10 @@ export declare class OINODbMsSql extends OINODb {
52
52
  * @param whereCondition - The WHERE clause to filter the results.
53
53
  * @param orderCondition - The ORDER BY clause to sort the results.
54
54
  * @param limitCondition - The LIMIT clause to limit the number of results.
55
+ * @param groupByCondition - The GROUP BY clause to group the results.
55
56
  *
56
57
  */
57
- printSqlSelect(tableName: string, columnNames: string, whereCondition: string, orderCondition: string, limitCondition: string): string;
58
+ printSqlSelect(tableName: string, columnNames: string, whereCondition: string, orderCondition: string, limitCondition: string, groupByCondition: string): string;
58
59
  /**
59
60
  * Connect to database.
60
61
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oino-ts/db-mssql",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "OINO TS package for using Microsoft Sql databases.",
5
5
  "author": "Matias Kiviniemi (pragmatta)",
6
6
  "license": "MPL-2.0",
@@ -22,7 +22,7 @@
22
22
  "module": "./dist/esm/index.js",
23
23
  "types": "./dist/types/index.d.ts",
24
24
  "dependencies": {
25
- "@oino-ts/db": "0.2.0",
25
+ "@oino-ts/db": "0.3.0",
26
26
  "mssql": "^11.0.1"
27
27
  },
28
28
  "devDependencies": {
@@ -264,9 +264,10 @@ export class OINODbMsSql extends OINODb {
264
264
  * @param whereCondition - The WHERE clause to filter the results.
265
265
  * @param orderCondition - The ORDER BY clause to sort the results.
266
266
  * @param limitCondition - The LIMIT clause to limit the number of results.
267
+ * @param groupByCondition - The GROUP BY clause to group the results.
267
268
  *
268
269
  */
269
- printSqlSelect(tableName:string, columnNames:string, whereCondition:string, orderCondition:string, limitCondition:string): string {
270
+ printSqlSelect(tableName:string, columnNames:string, whereCondition:string, orderCondition:string, limitCondition:string, groupByCondition: string): string {
270
271
  const limit_parts = limitCondition.split(" OFFSET ")
271
272
  let result:string = "SELECT "
272
273
  if ((limitCondition != "") && (limit_parts.length == 1)) {
@@ -287,6 +288,9 @@ export class OINODbMsSql extends OINODb {
287
288
  result += " OFFSET " + limit_parts[1] + " ROWS FETCH NEXT " + limit_parts[0] + " ROWS ONLY"
288
289
  }
289
290
  }
291
+ if (groupByCondition != "") {
292
+ result += " GROUP BY " + groupByCondition
293
+ }
290
294
  result += ";"
291
295
  // OINOLog.debug("OINODb.printSqlSelect", {result:result})
292
296
  return result;
@@ -399,8 +403,12 @@ ORDER BY C.ORDINAL_POSITION;`
399
403
  isAutoInc: row[7] == 1,
400
404
  isNotNull: row[1] == "NO"
401
405
  }
402
- if (((api.params.excludeFieldPrefix) && field_name.startsWith(api.params.excludeFieldPrefix)) || ((api.params.excludeFields) && (api.params.excludeFields.indexOf(field_name) < 0))) {
406
+ if (api.isFieldIncluded(field_name) == false) {
403
407
  OINOLog.info("OINODbMsSql.initializeApiDatamodel: field excluded in API parameters.", {field:field_name})
408
+ if (field_params.isPrimaryKey) {
409
+ throw new Error(OINO_ERROR_PREFIX + "Primary key field excluded in API parameters: " + field_name)
410
+ }
411
+
404
412
  } else {
405
413
  // OINOLog.debug("OINODbMsSql.initializeApiDatamodel: next field ", {field_name: field_name, sql_type:sql_type, char_field_length:char_field_length, numeric_field_length1:numeric_field_length1, numeric_field_length2:numeric_field_length2, field_params:field_params })
406
414
  if ((sql_type == "tinyint") || (sql_type == "smallint") || (sql_type == "int") || (sql_type == "bigint") || (sql_type == "float") || (sql_type == "real")) {