@oino-ts/types 0.2.0 → 0.3.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.
@@ -84,5 +84,5 @@ export declare class OINOHtmlTemplate {
84
84
  * @param includeDebugMessages include debug messages in result
85
85
  *
86
86
  */
87
- renderFromResult(result: OINOResult, removeUnusedTags: boolean | undefined, messageSeparator: string, includeErrorMessages?: boolean, includeWarningMessages?: boolean, includeInfoMessages?: boolean, includeDebugMessages?: boolean): OINOHttpResult;
87
+ renderFromResult(result: OINOResult, removeUnusedTags?: boolean, messageSeparator?: string, includeErrorMessages?: boolean, includeWarningMessages?: boolean, includeInfoMessages?: boolean, includeDebugMessages?: boolean): OINOHttpResult;
88
88
  }
@@ -80,9 +80,10 @@ export declare abstract class OINODb {
80
80
  * @param whereCondition - The WHERE clause to filter the results.
81
81
  * @param orderCondition - The ORDER BY clause to sort the results.
82
82
  * @param limitCondition - The LIMIT clause to limit the number of results.
83
+ * @param groupByCondition - The GROUP BY clause to group the results.
83
84
  *
84
85
  */
85
- printSqlSelect(tableName: string, columnNames: string, whereCondition: string, orderCondition: string, limitCondition: string): string;
86
+ printSqlSelect(tableName: string, columnNames: string, whereCondition: string, orderCondition: string, limitCondition: string, groupByCondition: string): string;
86
87
  }
87
88
  /**
88
89
  * Base class for SQL results that can be asynchronously iterated (but
@@ -79,4 +79,11 @@ export declare class OINODbApi {
79
79
  *
80
80
  */
81
81
  doRequest(method: string, id: string, body: string | OINODataRow[] | Buffer | any, params?: OINODbApiRequestParams): Promise<OINODbApiResult>;
82
+ /**
83
+ * Method to check if a field is included in the API params.
84
+ *
85
+ * @param fieldName name of the field
86
+ *
87
+ */
88
+ isFieldIncluded(fieldName: string): boolean;
82
89
  }
@@ -11,6 +11,8 @@ export declare class OINODbConfig {
11
11
  static OINODB_SQL_ORDER_PARAM: string;
12
12
  /** Name of the OINODbSqlLimit-parameter in request */
13
13
  static OINODB_SQL_LIMIT_PARAM: string;
14
+ /** Name of the OINODbSqlAggregate-parameter in request */
15
+ static OINODB_SQL_AGGREGATE_PARAM: string;
14
16
  /**
15
17
  * Set the name of the OINO ID field
16
18
  * @param idField name of the OINO ID field
@@ -44,14 +44,14 @@ export declare class OINODbSqlFilter {
44
44
  */
45
45
  constructor(leftSide: OINODbSqlFilter | string, operation: OINODbSqlComparison | OINODbSqlBooleanOperation | null, rightSide: OINODbSqlFilter | string);
46
46
  /**
47
- * Constructor for `OINOFilter` as parser of http parameter.
47
+ * Constructor for `OINODbSqlFilter` as parser of http parameter.
48
48
  *
49
49
  * @param filterString string representation of filter from HTTP-request
50
50
  *
51
51
  */
52
52
  static parse(filterString: string): OINODbSqlFilter;
53
53
  /**
54
- * Construct a new `OINOFilter` as combination of (boolean and/or) of two filters.
54
+ * Construct a new `OINODbSqlFilter` as combination of (boolean and/or) of two filters.
55
55
  *
56
56
  * @param leftSide left side to combine
57
57
  * @param operation boolean operation to use in combination
@@ -145,3 +145,57 @@ export declare class OINODbSqlLimit {
145
145
  */
146
146
  toSql(dataModel: OINODbDataModel): string;
147
147
  }
148
+ /**
149
+ * Supported aggregation functions in OINODbSqlAggregate.
150
+ * @enum
151
+ */
152
+ export declare enum OINODbSqlAggregateFunctions {
153
+ count = "count",
154
+ sum = "sum",
155
+ avg = "avg",
156
+ min = "min",
157
+ max = "max"
158
+ }
159
+ /**
160
+ * Class for limiting the number of results.
161
+ *
162
+ */
163
+ export declare class OINODbSqlAggregate {
164
+ private static _aggregateRegex;
165
+ private _functions;
166
+ private _fields;
167
+ /**
168
+ * Constructor for `OINODbSqlAggregate`.
169
+ *
170
+ * @param function aggregate function to use
171
+ * @param fields fields to aggregate
172
+ *
173
+ */
174
+ constructor(func: OINODbSqlAggregateFunctions[], fields: string[]);
175
+ /**
176
+ * Constructor for `OINODbSqlAggregate` as parser of http parameter.
177
+ *
178
+ * @param aggregatorString string representation of limit from HTTP-request
179
+ *
180
+ */
181
+ static parse(aggregatorString: string): OINODbSqlAggregate;
182
+ /**
183
+ * Does filter contain any valid conditions.
184
+ *
185
+ */
186
+ isEmpty(): boolean;
187
+ /**
188
+ * Print non-aggregated fields as SQL GROUP BY-condition based on the datamodel of the API.
189
+ *
190
+ * @param dataModel data model (and database) to use for formatting of values
191
+ *
192
+ */
193
+ toSql(dataModel: OINODbDataModel): string;
194
+ /**
195
+ * Print non-aggregated fields as SQL GROUP BY-condition based on the datamodel of the API.
196
+ *
197
+ * @param dataModel data model (and database) to use for formatting of values
198
+ *
199
+ */
200
+ printSqlColumnNames(dataModel: OINODbDataModel): string;
201
+ }
package/db/src/index.d.ts CHANGED
@@ -3,7 +3,7 @@ export { OINOContentType };
3
3
  export { OINO_ERROR_PREFIX, OINO_WARNING_PREFIX, OINO_INFO_PREFIX, OINO_DEBUG_PREFIX, OINOStr, OINOBenchmark, OINOLog, OINOLogLevel, OINOConsoleLog, OINOResult, OINOHttpResult, OINOHtmlTemplate } from "@oino-ts/common";
4
4
  import { OINODb } from "./OINODb.js";
5
5
  import { OINODbDataField } from "./OINODbDataField.js";
6
- import { OINODbSqlFilter, OINODbSqlLimit, OINODbSqlOrder } from "./OINODbSqlParams.js";
6
+ import { OINODbSqlAggregate, OINODbSqlFilter, OINODbSqlLimit, OINODbSqlOrder } from "./OINODbSqlParams.js";
7
7
  export { OINODbApiResult, OINODbHtmlTemplate, OINODbApi } from "./OINODbApi.js";
8
8
  export { OINODbDataModel } from "./OINODbDataModel.js";
9
9
  export { OINODbModelSet } from "./OINODbModelSet.js";
@@ -16,6 +16,8 @@ export { OINODbSwagger } from "./OINODbSwagger.js";
16
16
  export { OINODbParser } from "./OINODbParser.js";
17
17
  /** API parameters */
18
18
  export type OINODbApiParams = {
19
+ /** Name of the api */
20
+ apiName: string;
19
21
  /** Name of the database table */
20
22
  tableName: string;
21
23
  /** Reject values that exceed field max length (behaviour on such is platform dependent) */
@@ -26,9 +28,11 @@ export type OINODbApiParams = {
26
28
  failOnInsertWithoutKey?: boolean;
27
29
  /** Treat date type fields as just strings and use the native formatting instead of the ISO 8601 format */
28
30
  useDatesAsString?: Boolean;
31
+ /** Include given fields from the API and exclude rest (if defined) */
32
+ includeFields?: string[];
29
33
  /** Exclude all fields with this prefix from the API */
30
34
  excludeFieldPrefix?: string;
31
- /** Exclude given fields from the API */
35
+ /** Exclude given fields from the API and include rest (if defined) */
32
36
  excludeFields?: string[];
33
37
  /** Enable hashids for numeric primarykeys by adding a 32 char key */
34
38
  hashidKey?: string;
@@ -83,6 +87,8 @@ export type OINODbSqlParams = {
83
87
  order?: OINODbSqlOrder;
84
88
  /** SQL result limit condition */
85
89
  limit?: OINODbSqlLimit;
90
+ /** SQL aggregation functions */
91
+ aggregate?: OINODbSqlAggregate;
86
92
  };
87
93
  /** Request options */
88
94
  export type OINODbApiRequestParams = {
@@ -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/types",
3
- "version": "0.2.0",
3
+ "version": "0.3.1",
4
4
  "description": "OINO TS package for types.",
5
5
  "author": "Matias Kiviniemi (pragmatta)",
6
6
  "license": "MPL-2.0",