taon-type-sql 21.0.23 → 21.0.24
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.
- package/browser/package.json +1 -1
- package/browser-prod/package.json +1 -1
- package/lib/build-info._auto-generated_.d.ts +1 -1
- package/lib/build-info._auto-generated_.js +1 -1
- package/lib/package.json +1 -1
- package/lib-prod/build-info._auto-generated_.js +26 -14
- package/lib-prod/builder/column/basic-column.js +8 -10
- package/lib-prod/builder/column/boolean-column.js +8 -11
- package/lib-prod/builder/column/comparable-column.js +35 -38
- package/lib-prod/builder/column/date-column.js +8 -11
- package/lib-prod/builder/column/number-column.js +14 -17
- package/lib-prod/builder/column/query-column.js +15 -21
- package/lib-prod/builder/column/string-column.js +29 -32
- package/lib-prod/builder/column/value-column.js +20 -22
- package/lib-prod/builder/condition/query-column-condition.js +13 -19
- package/lib-prod/builder/condition/query-condition-chain.js +24 -31
- package/lib-prod/builder/condition/query-condition.js +2 -4
- package/lib-prod/builder/condition/query-join-condition.js +13 -19
- package/lib-prod/builder/helpers/generics-helper.js +2 -4
- package/lib-prod/builder/helpers/internal-types.js +1 -0
- package/lib-prod/builder/join/joined-tables-chain.js +9 -12
- package/lib-prod/builder/join/joined-tables.js +17 -20
- package/lib-prod/builder/other/query-ordering.js +13 -19
- package/lib-prod/builder/query/select-query.js +44 -50
- package/lib-prod/builder/query/table-condition-query.js +21 -26
- package/lib-prod/builder/query/table-query.js +49 -51
- package/lib-prod/builder/query-source.js +15 -16
- package/lib-prod/builder/query-table.js +18 -23
- package/lib-prod/client/mysql.js +4 -7
- package/lib-prod/client/pg.js +4 -7
- package/lib-prod/client/query-processor.js +64 -39
- package/lib-prod/converter/param-converter.js +24 -21
- package/lib-prod/converter/parameterized-converter.js +10 -13
- package/lib-prod/converter/query-converter.js +256 -244
- package/lib-prod/converter/result-converter.js +70 -62
- package/lib-prod/converter/sql-converter.js +3 -6
- package/lib-prod/converter/type-converter.js +32 -28
- package/lib-prod/converter/types.js +1 -0
- package/lib-prod/env/env.angular-node-app.js +66 -130
- package/lib-prod/env/env.docs-webapp.js +66 -130
- package/lib-prod/env/env.electron-app.js +66 -130
- package/lib-prod/env/env.mobile-app.js +66 -130
- package/lib-prod/env/env.npm-lib-and-cli-tool.js +66 -130
- package/lib-prod/env/env.vscode-plugin.js +66 -130
- package/lib-prod/env/index.js +6 -6
- package/lib-prod/index._auto-generated_.js +5 -0
- package/lib-prod/index.js +25 -46
- package/lib-prod/migrations/index.js +2 -1
- package/lib-prod/migrations/migrations_index._auto-generated_.js +3 -0
- package/lib-prod/package.json +1 -1
- package/package.json +1 -1
- package/websql/package.json +1 -1
- package/websql-prod/package.json +1 -1
|
@@ -1,268 +1,280 @@
|
|
|
1
|
-
import { string, number, date, boolean } from
|
|
2
|
-
function createQueryConverter(paramConverter, options, engine) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
return s;
|
|
15
|
-
}
|
|
16
|
-
function convertUpdateQuery(query) {
|
|
17
|
-
let s = "UPDATE " + convertTable(query._table) + " SET ";
|
|
18
|
-
s += convertUpdateSetters(query._table, query._entity);
|
|
19
|
-
s += convertConditions(query._conditions);
|
|
20
|
-
return s;
|
|
21
|
-
}
|
|
22
|
-
function convertUpdateSetters(table, entity) {
|
|
23
|
-
return Object.keys(entity).sort().map((key) => {
|
|
24
|
-
let value = entity[key];
|
|
25
|
-
let column = table[key];
|
|
26
|
-
return convertColumnName(column) + " = " + convertParam(column, value);
|
|
27
|
-
}).join(", ");
|
|
28
|
-
}
|
|
29
|
-
function convertInsertQuery(query) {
|
|
30
|
-
let items = Array.isArray(query._entity) ? query._entity : [query._entity];
|
|
31
|
-
let keySet = items.reduce((set, item) => {
|
|
32
|
-
Object.keys(item).forEach((key) => set.add(key));
|
|
33
|
-
return set;
|
|
34
|
-
}, /* @__PURE__ */ new Set());
|
|
35
|
-
let keys = Array.from(keySet).sort();
|
|
36
|
-
let s = "INSERT INTO " + convertTable(query._table) + " ";
|
|
37
|
-
s += "(" + keys.map((key) => convertColumnName(query._table[key])).join(", ") + ")";
|
|
38
|
-
s += options.lineBreak + "VALUES ";
|
|
39
|
-
s += items.map((item) => convertInsertItem(query._table, item, keys)).map((row) => "(" + row + ")").join(", ");
|
|
40
|
-
s += getPgInsertReturningIfNeeded(query);
|
|
41
|
-
return s;
|
|
42
|
-
}
|
|
43
|
-
function getPgInsertReturningIfNeeded(query) {
|
|
44
|
-
if (engine === "pg" && query._action === "insert" && !Array.isArray(query._entity) && query._table.$id && query._table.$id._table && query._table.$id._name) {
|
|
45
|
-
return " RETURNING " + convertColumnName(query._table.$id);
|
|
1
|
+
import { string, number, date, boolean } from './type-converter';
|
|
2
|
+
export function createQueryConverter(paramConverter, options, engine) {
|
|
3
|
+
return convertQuery;
|
|
4
|
+
function convertQuery(query) {
|
|
5
|
+
if (query._action === 'select')
|
|
6
|
+
return convertSelectQuery(query);
|
|
7
|
+
if (query._action === 'delete')
|
|
8
|
+
return convertDeleteQuery(query);
|
|
9
|
+
if (query._action === 'update')
|
|
10
|
+
return convertUpdateQuery(query);
|
|
11
|
+
if (query._action === 'insert')
|
|
12
|
+
return convertInsertQuery(query);
|
|
13
|
+
throw new Error('Unknown query type:' + query._action);
|
|
46
14
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
let value = entity[key];
|
|
52
|
-
let column = table[key];
|
|
53
|
-
return convertParam(column, value);
|
|
54
|
-
}).join(", ");
|
|
55
|
-
}
|
|
56
|
-
function convertSelectQuery(query) {
|
|
57
|
-
let s = "SELECT ";
|
|
58
|
-
if (query._distinct) {
|
|
59
|
-
s += "DISTINCT ";
|
|
15
|
+
function convertDeleteQuery(query) {
|
|
16
|
+
let s = 'DELETE FROM ' + convertTable(query._table);
|
|
17
|
+
s += convertConditions(query._conditions);
|
|
18
|
+
return s;
|
|
60
19
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
20
|
+
function convertUpdateQuery(query) {
|
|
21
|
+
let s = 'UPDATE ' + convertTable(query._table) + ' SET ';
|
|
22
|
+
s += convertUpdateSetters(query._table, query._entity);
|
|
23
|
+
s += convertConditions(query._conditions);
|
|
24
|
+
return s;
|
|
65
25
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
26
|
+
function convertUpdateSetters(table, entity) {
|
|
27
|
+
return Object.keys(entity).sort().map(key => {
|
|
28
|
+
let value = entity[key];
|
|
29
|
+
let column = table[key];
|
|
30
|
+
return convertColumnName(column) + ' = ' + convertParam(column, value);
|
|
31
|
+
}).join(', ');
|
|
71
32
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
33
|
+
function convertInsertQuery(query) {
|
|
34
|
+
let items = Array.isArray(query._entity) ? query._entity : [query._entity];
|
|
35
|
+
let keySet = items.reduce((set, item) => {
|
|
36
|
+
Object.keys(item).forEach(key => set.add(key));
|
|
37
|
+
return set;
|
|
38
|
+
}, new Set());
|
|
39
|
+
let keys = Array.from(keySet).sort();
|
|
40
|
+
let s = 'INSERT INTO ' + convertTable(query._table) + ' ';
|
|
41
|
+
s += '(' + keys.map(key => convertColumnName(query._table[key])).join(', ') + ')';
|
|
42
|
+
s += options.lineBreak + 'VALUES ';
|
|
43
|
+
s += items.map(item => convertInsertItem(query._table, item, keys))
|
|
44
|
+
.map((row) => '(' + row + ')').join(', ');
|
|
45
|
+
s += getPgInsertReturningIfNeeded(query);
|
|
46
|
+
return s;
|
|
76
47
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
48
|
+
function getPgInsertReturningIfNeeded(query) {
|
|
49
|
+
if (engine === 'pg' && query._action === 'insert' && !Array.isArray(query._entity) &&
|
|
50
|
+
query._table.$id && query._table.$id._table && query._table.$id._name) {
|
|
51
|
+
return ' RETURNING ' + convertColumnName(query._table.$id);
|
|
52
|
+
}
|
|
53
|
+
return '';
|
|
81
54
|
}
|
|
82
|
-
|
|
83
|
-
|
|
55
|
+
function convertInsertItem(table, entity, keys) {
|
|
56
|
+
return keys.map(key => {
|
|
57
|
+
let value = entity[key];
|
|
58
|
+
let column = table[key];
|
|
59
|
+
return convertParam(column, value);
|
|
60
|
+
}).join(', ');
|
|
84
61
|
}
|
|
85
|
-
|
|
86
|
-
|
|
62
|
+
function convertSelectQuery(query) {
|
|
63
|
+
let s = 'SELECT ';
|
|
64
|
+
if (query._distinct) {
|
|
65
|
+
s += 'DISTINCT ';
|
|
66
|
+
}
|
|
67
|
+
if (query._columns == null || query._columns.length === 0) {
|
|
68
|
+
s += '*';
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
s += query._columns.map((column) => convertColumn(column)).join(', ');
|
|
72
|
+
}
|
|
73
|
+
s += options.lineBreak + 'FROM ';
|
|
74
|
+
if (query._tables) {
|
|
75
|
+
s += query._tables.map((table) => table._parent ? convertJoin(table) : convertTable(table)).join(', ');
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
s += convertTable(query._table);
|
|
79
|
+
}
|
|
80
|
+
s += convertConditions(query._conditions);
|
|
81
|
+
if (query._groupBy && query._groupBy.length > 0) {
|
|
82
|
+
s += options.lineBreak + 'GROUP BY ';
|
|
83
|
+
s += query._groupBy.map((column) => convertColumn(column)).join(', ');
|
|
84
|
+
}
|
|
85
|
+
s += convertConditions(query._having, 'HAVING');
|
|
86
|
+
if (query._orderings && query._orderings.length > 0) {
|
|
87
|
+
s += options.lineBreak + 'ORDER BY ';
|
|
88
|
+
s += query._orderings.map((ordering) => convertOrdering(ordering)).join(', ');
|
|
89
|
+
}
|
|
90
|
+
if (query._limit != null) {
|
|
91
|
+
s += options.lineBreak + 'LIMIT ' + number(query._limit);
|
|
92
|
+
}
|
|
93
|
+
if (query._offset != null) {
|
|
94
|
+
s += options.lineBreak + 'OFFSET ' + number(query._offset);
|
|
95
|
+
}
|
|
96
|
+
return s;
|
|
87
97
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
98
|
+
function convertConditions(conditions, keyword = 'WHERE') {
|
|
99
|
+
let s = '';
|
|
100
|
+
if (conditions && conditions.length > 0) {
|
|
101
|
+
s += options.lineBreak + keyword + ' ';
|
|
102
|
+
preprocessConditions(conditions);
|
|
103
|
+
s += conditions.map(condition => convertCondition(condition, true)).join(' AND ');
|
|
104
|
+
}
|
|
105
|
+
return s;
|
|
96
106
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
107
|
+
function convertJoin(joinChain) {
|
|
108
|
+
let items = [];
|
|
109
|
+
while (joinChain) {
|
|
110
|
+
items.push(joinChain);
|
|
111
|
+
joinChain = joinChain._parent;
|
|
112
|
+
}
|
|
113
|
+
let root = items[items.length - 1];
|
|
114
|
+
let s = convertTable(root);
|
|
115
|
+
for (let i = items.length - 2; i >= 0; i -= 2) {
|
|
116
|
+
let table = items[i]._table;
|
|
117
|
+
let modifier = items[i]._modifier;
|
|
118
|
+
let condition = items[i - 1]._condition;
|
|
119
|
+
let param = convertColumn(condition._otherColumn);
|
|
120
|
+
s += ' ' + modifier.toUpperCase() + ' JOIN ' + convertTable(table) + ' ON ' +
|
|
121
|
+
convertColumnCondition(condition, param);
|
|
122
|
+
}
|
|
123
|
+
return s;
|
|
104
124
|
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
125
|
+
function convertOrdering(ordering) {
|
|
126
|
+
if (ordering._column) {
|
|
127
|
+
let s = convertColumn(ordering._column);
|
|
128
|
+
if (ordering._nullsPosition != null) { // "NULLS FIRST" only exists in PG, this is the general solution
|
|
129
|
+
s += ' IS NULL ' + (ordering._nullsPosition === 'FIRST' ? 'DESC' : 'ASC') + ', ' + s;
|
|
130
|
+
}
|
|
131
|
+
if (ordering._direction === 'ASC')
|
|
132
|
+
s += ' ASC';
|
|
133
|
+
if (ordering._direction === 'DESC')
|
|
134
|
+
s += ' DESC';
|
|
135
|
+
return s;
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
return convertColumn(ordering);
|
|
139
|
+
}
|
|
113
140
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
function convertOrdering(ordering) {
|
|
117
|
-
if (ordering._column) {
|
|
118
|
-
let s = convertColumn(ordering._column);
|
|
119
|
-
if (ordering._nullsPosition != null) {
|
|
120
|
-
s += " IS NULL " + (ordering._nullsPosition === "FIRST" ? "DESC" : "ASC") + ", " + s;
|
|
121
|
-
}
|
|
122
|
-
if (ordering._direction === "ASC") s += " ASC";
|
|
123
|
-
if (ordering._direction === "DESC") s += " DESC";
|
|
124
|
-
return s;
|
|
125
|
-
} else {
|
|
126
|
-
return convertColumn(ordering);
|
|
141
|
+
function convertTable(table) {
|
|
142
|
+
return options.nameEscape + table._$name + options.nameEscape;
|
|
127
143
|
}
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
s += convertTable(column._table) + ".";
|
|
144
|
+
function convertColumn(column) {
|
|
145
|
+
let s = '';
|
|
146
|
+
if (!(column._name === '*' && column._modifiers.length > 0 && column._modifiers[0].name === 'count')) {
|
|
147
|
+
s += convertTable(column._table) + '.';
|
|
148
|
+
}
|
|
149
|
+
s += convertColumnName(column);
|
|
150
|
+
return convertColumnModifiers(s, column);
|
|
136
151
|
}
|
|
137
|
-
s
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
152
|
+
function convertColumnModifiers(s, column) {
|
|
153
|
+
if (column._modifiers) {
|
|
154
|
+
column._modifiers.forEach((modifier) => {
|
|
155
|
+
let name = modifier.name;
|
|
156
|
+
if (name === 'lower')
|
|
157
|
+
s = 'LOWER(' + s + ')';
|
|
158
|
+
else if (name === 'upper')
|
|
159
|
+
s = 'UPPER(' + s + ')';
|
|
160
|
+
else if (name === 'count')
|
|
161
|
+
s = 'COUNT(' + s + ')';
|
|
162
|
+
else if (name === 'sum')
|
|
163
|
+
s = 'SUM(' + s + ')';
|
|
164
|
+
else if (name === 'avg')
|
|
165
|
+
s = 'AVG(' + s + ')';
|
|
166
|
+
else if (name === 'min')
|
|
167
|
+
s = 'MIN(' + s + ')';
|
|
168
|
+
else if (name === 'max')
|
|
169
|
+
s = 'MAX(' + s + ')';
|
|
170
|
+
else if (name === 'as')
|
|
171
|
+
s = s + ' AS ' + options.nameEscape + modifier.params + options.nameEscape;
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
return s + '';
|
|
153
175
|
}
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
return options.nameEscape + name + options.nameEscape;
|
|
160
|
-
}
|
|
161
|
-
function preprocessConditions(conditions) {
|
|
162
|
-
conditions.forEach((condition) => {
|
|
163
|
-
if (conditions.length > 1 && condition._sibling) {
|
|
164
|
-
condition._parenthesis = true;
|
|
165
|
-
}
|
|
166
|
-
preprocessParams(condition);
|
|
167
|
-
});
|
|
168
|
-
}
|
|
169
|
-
function preprocessParams(condition) {
|
|
170
|
-
if (condition._sibling) {
|
|
171
|
-
preprocessParams(condition._sibling);
|
|
176
|
+
function convertColumnName(column) {
|
|
177
|
+
if (column._name === '*')
|
|
178
|
+
return column._name;
|
|
179
|
+
let name = typeof column._name === 'string' ? column._name : column._name.name;
|
|
180
|
+
return options.nameEscape + name + options.nameEscape;
|
|
172
181
|
}
|
|
173
|
-
|
|
174
|
-
|
|
182
|
+
function preprocessConditions(conditions) {
|
|
183
|
+
conditions.forEach(condition => {
|
|
184
|
+
if (conditions.length > 1 && condition._sibling) {
|
|
185
|
+
condition._parenthesis = true;
|
|
186
|
+
}
|
|
187
|
+
preprocessParams(condition);
|
|
188
|
+
});
|
|
175
189
|
}
|
|
176
|
-
|
|
177
|
-
|
|
190
|
+
// this is only needed, so that the $1, $2... numbering is not reversed
|
|
191
|
+
function preprocessParams(condition) {
|
|
192
|
+
if (condition._sibling) {
|
|
193
|
+
preprocessParams(condition._sibling);
|
|
194
|
+
}
|
|
195
|
+
if (!condition._sibling && !condition._child) {
|
|
196
|
+
condition.__param = getConditionParam(condition);
|
|
197
|
+
}
|
|
198
|
+
if (condition._child) {
|
|
199
|
+
preprocessParams(condition._child);
|
|
200
|
+
}
|
|
178
201
|
}
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
202
|
+
function convertCondition(condition, root = false) {
|
|
203
|
+
if (!condition._sibling && !condition._child) {
|
|
204
|
+
return convertColumnCondition(condition, condition.__param);
|
|
205
|
+
}
|
|
206
|
+
let s = '';
|
|
207
|
+
if (condition._child) {
|
|
208
|
+
s += convertCondition(condition._child);
|
|
209
|
+
}
|
|
210
|
+
if (condition._sibling) {
|
|
211
|
+
s = convertCondition(condition._sibling, root) + ' ' + condition._chainType.toUpperCase() + ' ' + s;
|
|
212
|
+
}
|
|
213
|
+
if (condition._parenthesis || ((!root || condition._negation) && condition._child)) {
|
|
214
|
+
s = '( ' + s + ' )';
|
|
215
|
+
}
|
|
216
|
+
if (condition._negation) {
|
|
217
|
+
s = 'NOT ' + s;
|
|
218
|
+
}
|
|
219
|
+
return s;
|
|
183
220
|
}
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
221
|
+
function convertColumnCondition(condition, param) {
|
|
222
|
+
let s = convertColumn(condition._column);
|
|
223
|
+
s += getConditionString(condition, param);
|
|
224
|
+
return s;
|
|
187
225
|
}
|
|
188
|
-
|
|
189
|
-
|
|
226
|
+
function getConditionString(condition, param) {
|
|
227
|
+
switch (condition._type) {
|
|
228
|
+
case 'eq': return ' = ' + param;
|
|
229
|
+
case 'ne': return ' <> ' + param;
|
|
230
|
+
case 'lt': return ' < ' + param;
|
|
231
|
+
case 'gt': return ' > ' + param;
|
|
232
|
+
case 'lte': return ' <= ' + param;
|
|
233
|
+
case 'gte': return ' >= ' + param;
|
|
234
|
+
case 'is-null': return ' IS NULL';
|
|
235
|
+
case 'is-not-null': return ' IS NOT NULL';
|
|
236
|
+
case 'like': return ' LIKE ' + param;
|
|
237
|
+
case 'not-like': return ' NOT LIKE ' + param;
|
|
238
|
+
case 'in': return ' IN (' + param + ')';
|
|
239
|
+
case 'not-in': return ' NOT IN (' + param + ')';
|
|
240
|
+
case 'between': return ' BETWEEN ' + param;
|
|
241
|
+
case 'not-between': return ' NOT BETWEEN ' + param;
|
|
242
|
+
default: return '';
|
|
243
|
+
}
|
|
190
244
|
}
|
|
191
|
-
|
|
192
|
-
|
|
245
|
+
function getConditionParam(condition) {
|
|
246
|
+
let param = '';
|
|
247
|
+
if (condition._otherColumn) {
|
|
248
|
+
param = convertColumn(condition._otherColumn);
|
|
249
|
+
}
|
|
250
|
+
else {
|
|
251
|
+
let _convertParam = (param) => convertParam(condition._column, param);
|
|
252
|
+
if (condition._type === 'in' || condition._type === 'not-in') {
|
|
253
|
+
param = condition._values.map((value) => _convertParam(value)).join(', ');
|
|
254
|
+
}
|
|
255
|
+
else if (condition._type === 'between' || condition._type === 'not-between') {
|
|
256
|
+
param = _convertParam(condition._values[0]) + ' AND ' + _convertParam(condition._values[1]);
|
|
257
|
+
}
|
|
258
|
+
else if (condition._type !== 'is-null' && condition._type !== 'is-not-null') {
|
|
259
|
+
param = _convertParam(condition._values[0]);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
return param;
|
|
193
263
|
}
|
|
194
|
-
|
|
195
|
-
|
|
264
|
+
function convertParam(column, param) {
|
|
265
|
+
if (param == null)
|
|
266
|
+
return 'NULL';
|
|
267
|
+
return paramConverter(getTypedParam(column._type, param));
|
|
196
268
|
}
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
return " = " + param;
|
|
208
|
-
case "ne":
|
|
209
|
-
return " <> " + param;
|
|
210
|
-
case "lt":
|
|
211
|
-
return " < " + param;
|
|
212
|
-
case "gt":
|
|
213
|
-
return " > " + param;
|
|
214
|
-
case "lte":
|
|
215
|
-
return " <= " + param;
|
|
216
|
-
case "gte":
|
|
217
|
-
return " >= " + param;
|
|
218
|
-
case "is-null":
|
|
219
|
-
return " IS NULL";
|
|
220
|
-
case "is-not-null":
|
|
221
|
-
return " IS NOT NULL";
|
|
222
|
-
case "like":
|
|
223
|
-
return " LIKE " + param;
|
|
224
|
-
case "not-like":
|
|
225
|
-
return " NOT LIKE " + param;
|
|
226
|
-
case "in":
|
|
227
|
-
return " IN (" + param + ")";
|
|
228
|
-
case "not-in":
|
|
229
|
-
return " NOT IN (" + param + ")";
|
|
230
|
-
case "between":
|
|
231
|
-
return " BETWEEN " + param;
|
|
232
|
-
case "not-between":
|
|
233
|
-
return " NOT BETWEEN " + param;
|
|
234
|
-
default:
|
|
235
|
-
return "";
|
|
269
|
+
function getTypedParam(type, param) {
|
|
270
|
+
if (type === 'number')
|
|
271
|
+
return number(param);
|
|
272
|
+
else if (type === 'boolean')
|
|
273
|
+
return boolean(param);
|
|
274
|
+
else if (type === 'date')
|
|
275
|
+
return date(param);
|
|
276
|
+
else if (type === 'string')
|
|
277
|
+
return string(param);
|
|
278
|
+
return param;
|
|
236
279
|
}
|
|
237
|
-
}
|
|
238
|
-
function getConditionParam(condition) {
|
|
239
|
-
let param = "";
|
|
240
|
-
if (condition._otherColumn) {
|
|
241
|
-
param = convertColumn(condition._otherColumn);
|
|
242
|
-
} else {
|
|
243
|
-
let _convertParam = (param2) => convertParam(condition._column, param2);
|
|
244
|
-
if (condition._type === "in" || condition._type === "not-in") {
|
|
245
|
-
param = condition._values.map((value) => _convertParam(value)).join(", ");
|
|
246
|
-
} else if (condition._type === "between" || condition._type === "not-between") {
|
|
247
|
-
param = _convertParam(condition._values[0]) + " AND " + _convertParam(condition._values[1]);
|
|
248
|
-
} else if (condition._type !== "is-null" && condition._type !== "is-not-null") {
|
|
249
|
-
param = _convertParam(condition._values[0]);
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
return param;
|
|
253
|
-
}
|
|
254
|
-
function convertParam(column, param) {
|
|
255
|
-
if (param == null) return "NULL";
|
|
256
|
-
return paramConverter(getTypedParam(column._type, param));
|
|
257
|
-
}
|
|
258
|
-
function getTypedParam(type, param) {
|
|
259
|
-
if (type === "number") return number(param);
|
|
260
|
-
else if (type === "boolean") return boolean(param);
|
|
261
|
-
else if (type === "date") return date(param);
|
|
262
|
-
else if (type === "string") return string(param);
|
|
263
|
-
return param;
|
|
264
|
-
}
|
|
265
280
|
}
|
|
266
|
-
export {
|
|
267
|
-
createQueryConverter
|
|
268
|
-
};
|