@dascompany/database 2.1.2 → 2.1.4
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.
|
@@ -3,10 +3,10 @@ import Filters from "../utils/Filters";
|
|
|
3
3
|
import Parameters from "../utils/Parameters";
|
|
4
4
|
export default class QueryOptions {
|
|
5
5
|
static correctingSorting(querySortBy) {
|
|
6
|
-
const
|
|
6
|
+
const orderBy = Parameters.correct(querySortBy, { type: ParameterType.arrayObject });
|
|
7
7
|
const table = [];
|
|
8
|
-
if (
|
|
9
|
-
|
|
8
|
+
if (orderBy[0]) {
|
|
9
|
+
orderBy.forEach((element) => {
|
|
10
10
|
const key = Parameters.correct(element.key, { type: ParameterType.string, filter: Filters.databaseColumn });
|
|
11
11
|
const order = Parameters.correct(element.order, { type: ParameterType.string });
|
|
12
12
|
table.push({ key, order });
|
|
@@ -61,7 +61,9 @@ export default class QueryParamCreator {
|
|
|
61
61
|
}
|
|
62
62
|
static getBaseTypeForComplexType(paramType) {
|
|
63
63
|
switch (paramType) {
|
|
64
|
-
case ParameterType.arrayNumber
|
|
64
|
+
case ParameterType.arrayNumber:
|
|
65
|
+
return ParameterType.number;
|
|
66
|
+
case ParameterType.betweenNumber:
|
|
65
67
|
return ParameterType.number;
|
|
66
68
|
case ParameterType.arrayString:
|
|
67
69
|
return ParameterType.string;
|
|
@@ -3,7 +3,7 @@ import QueryOptionsI from '../types/QueryOptionsI';
|
|
|
3
3
|
export default class QueryParams {
|
|
4
4
|
private static where;
|
|
5
5
|
private static params;
|
|
6
|
-
private static
|
|
6
|
+
private static orderBy;
|
|
7
7
|
private static limit;
|
|
8
8
|
private static values;
|
|
9
9
|
private static paramConnector;
|
|
@@ -3,15 +3,15 @@ import QueryParamsCreator from './QueryParamCreator';
|
|
|
3
3
|
export default class QueryParams {
|
|
4
4
|
static where = '$WHERE';
|
|
5
5
|
static params = '$PARAMS';
|
|
6
|
-
static
|
|
6
|
+
static orderBy = '$ORDERBY';
|
|
7
7
|
static limit = '$LIMIT';
|
|
8
8
|
static values = '$VALUES';
|
|
9
9
|
static paramConnector = 'AND';
|
|
10
10
|
static createParams(queryString, options) {
|
|
11
11
|
if (options.where && (queryString.includes(this.where) || queryString.includes(this.params)))
|
|
12
12
|
queryString = QueryParams.createWhereParams(queryString, options.where);
|
|
13
|
-
if (options && queryString.includes(this.
|
|
14
|
-
queryString = QueryParams.createOrderParams(queryString, options.
|
|
13
|
+
if (options && queryString.includes(this.orderBy))
|
|
14
|
+
queryString = QueryParams.createOrderParams(queryString, options.orderBy);
|
|
15
15
|
if (options && queryString.includes(this.limit))
|
|
16
16
|
queryString = QueryParams.createLimitParams(queryString, options.limit);
|
|
17
17
|
if (options.values && queryString.includes(this.values))
|
|
@@ -63,16 +63,16 @@ export default class QueryParams {
|
|
|
63
63
|
throw new Error(`Brak zmiennej: ${this.where} lub ${this.params} w zapytaniu sql`);
|
|
64
64
|
return sqlWithParams;
|
|
65
65
|
}
|
|
66
|
-
static createOrderParams(sql,
|
|
67
|
-
if (
|
|
66
|
+
static createOrderParams(sql, orderBy) {
|
|
67
|
+
if (orderBy) {
|
|
68
68
|
let strToReplace = `ORDER BY `;
|
|
69
|
-
|
|
69
|
+
orderBy.forEach(item => {
|
|
70
70
|
strToReplace += `${item.key} ${item.order} `;
|
|
71
71
|
});
|
|
72
|
-
sql = sql.replaceAll(this.
|
|
72
|
+
sql = sql.replaceAll(this.orderBy, strToReplace);
|
|
73
73
|
}
|
|
74
74
|
else
|
|
75
|
-
sql = sql.replaceAll(this.
|
|
75
|
+
sql = sql.replaceAll(this.orderBy, '');
|
|
76
76
|
return sql;
|
|
77
77
|
}
|
|
78
78
|
static createLimitParams(sql, resultLimitation) {
|
|
@@ -4,7 +4,7 @@ import ResultLimitationI from "./ResultLimitationI";
|
|
|
4
4
|
import WhereOptionI from "./WhereOptionI";
|
|
5
5
|
export default interface QueryOptionsI {
|
|
6
6
|
where?: WhereOptionI;
|
|
7
|
-
|
|
7
|
+
orderBy?: OrderByI[];
|
|
8
8
|
limit?: ResultLimitationI;
|
|
9
9
|
values?: ParameterI[];
|
|
10
10
|
}
|