query-core 0.3.0 → 0.5.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.
- package/lib/query.js +11 -25
- package/package.json +1 -1
- package/src/metadata.ts +2 -2
- package/src/query.ts +11 -22
package/lib/query.js
CHANGED
|
@@ -99,37 +99,23 @@ function buildQuery(filter, param, sort, buildSort3, attrs, table, fields, sq, s
|
|
|
99
99
|
if (attr.q) {
|
|
100
100
|
ex.push(key);
|
|
101
101
|
}
|
|
102
|
-
if (attr.
|
|
102
|
+
if (attr.operator === "=") {
|
|
103
103
|
filters.push(field + " = " + param(i++));
|
|
104
104
|
args.push(v);
|
|
105
105
|
}
|
|
106
|
-
else if (attr.
|
|
106
|
+
else if (attr.operator === "like") {
|
|
107
107
|
filters.push(field + " " + like + " " + param(i++));
|
|
108
|
-
args.push(v + "%");
|
|
108
|
+
args.push("%" + v + "%");
|
|
109
109
|
}
|
|
110
110
|
else {
|
|
111
111
|
filters.push(field + " " + like + " " + param(i++));
|
|
112
|
-
args.push(
|
|
112
|
+
args.push(v + "%");
|
|
113
113
|
}
|
|
114
114
|
}
|
|
115
115
|
}
|
|
116
|
-
else if (v instanceof Date) {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
args.push(v);
|
|
120
|
-
}
|
|
121
|
-
else {
|
|
122
|
-
filters.push(field + " >= " + param(i++));
|
|
123
|
-
args.push(v);
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
else if (typeof v === "number") {
|
|
127
|
-
if (attr.match === "max") {
|
|
128
|
-
filters.push(field + " <= " + v);
|
|
129
|
-
}
|
|
130
|
-
else {
|
|
131
|
-
filters.push(field + " >= " + v);
|
|
132
|
-
}
|
|
116
|
+
else if (typeof v === "number" || v instanceof Date) {
|
|
117
|
+
var operator = attr.operator ? attr.operator : ">=";
|
|
118
|
+
filters.push(field + " " + operator + " " + param(i++));
|
|
133
119
|
}
|
|
134
120
|
else if (attr.type === "ObjectId") {
|
|
135
121
|
filters.push(field + " = " + param(i++));
|
|
@@ -236,17 +222,17 @@ function buildQuery(filter, param, sort, buildSort3, attrs, table, fields, sq, s
|
|
|
236
222
|
var attr = attrs[field];
|
|
237
223
|
if (attr.q && (attr.type === undefined || attr.type === "string") && !ex.includes(field)) {
|
|
238
224
|
var column = attr.column ? attr.column : field;
|
|
239
|
-
if (attr.
|
|
225
|
+
if (attr.operator === "=") {
|
|
240
226
|
qfilters.push(column + " = " + param(i++));
|
|
241
227
|
args.push(q);
|
|
242
228
|
}
|
|
243
|
-
else if (attr.
|
|
229
|
+
else if (attr.operator === "like") {
|
|
244
230
|
qfilters.push(column + " " + like + " " + param(i++));
|
|
245
|
-
args.push(q + "%");
|
|
231
|
+
args.push("%" + q + "%");
|
|
246
232
|
}
|
|
247
233
|
else {
|
|
248
234
|
qfilters.push(column + " " + like + " " + param(i++));
|
|
249
|
-
args.push(
|
|
235
|
+
args.push(q + "%");
|
|
250
236
|
}
|
|
251
237
|
}
|
|
252
238
|
}
|
package/package.json
CHANGED
package/src/metadata.ts
CHANGED
|
@@ -40,7 +40,7 @@ export type DataType =
|
|
|
40
40
|
| "datetimes"
|
|
41
41
|
| "times"
|
|
42
42
|
export type FormatType = "currency" | "percentage" | "email" | "url" | "phone" | "fax" | "ipv4" | "ipv6"
|
|
43
|
-
export type
|
|
43
|
+
export type Operator = "=" | "like" | "!=" | "<>" | ">" | ">=" | "<" | "<="
|
|
44
44
|
|
|
45
45
|
export interface Model {
|
|
46
46
|
name?: string
|
|
@@ -55,7 +55,7 @@ export interface Attribute {
|
|
|
55
55
|
name?: string
|
|
56
56
|
column?: string
|
|
57
57
|
type?: DataType
|
|
58
|
-
|
|
58
|
+
operator?: Operator
|
|
59
59
|
default?: string | number | Date | boolean
|
|
60
60
|
key?: boolean
|
|
61
61
|
q?: boolean
|
package/src/query.ts
CHANGED
|
@@ -106,31 +106,20 @@ export function buildQuery<S>(
|
|
|
106
106
|
if (attr.q) {
|
|
107
107
|
ex.push(key)
|
|
108
108
|
}
|
|
109
|
-
if (attr.
|
|
109
|
+
if (attr.operator === "=") {
|
|
110
110
|
filters.push(`${field} = ${param(i++)}`)
|
|
111
111
|
args.push(v)
|
|
112
|
-
} else if (attr.
|
|
112
|
+
} else if (attr.operator === "like") {
|
|
113
113
|
filters.push(`${field} ${like} ${param(i++)}`)
|
|
114
|
-
args.push(v + "%")
|
|
114
|
+
args.push("%" + v + "%")
|
|
115
115
|
} else {
|
|
116
116
|
filters.push(`${field} ${like} ${param(i++)}`)
|
|
117
|
-
args.push(
|
|
117
|
+
args.push(v + "%")
|
|
118
118
|
}
|
|
119
119
|
}
|
|
120
|
-
} else if (v instanceof Date) {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
args.push(v)
|
|
124
|
-
} else {
|
|
125
|
-
filters.push(`${field} >= ${param(i++)}`)
|
|
126
|
-
args.push(v)
|
|
127
|
-
}
|
|
128
|
-
} else if (typeof v === "number") {
|
|
129
|
-
if (attr.match === "max") {
|
|
130
|
-
filters.push(`${field} <= ${v}`)
|
|
131
|
-
} else {
|
|
132
|
-
filters.push(`${field} >= ${v}`)
|
|
133
|
-
}
|
|
120
|
+
} else if (typeof v === "number" || v instanceof Date) {
|
|
121
|
+
const operator = attr.operator ? attr.operator : ">="
|
|
122
|
+
filters.push(`${field} ${operator} ${param(i++)}`)
|
|
134
123
|
} else if (attr.type === "ObjectId") {
|
|
135
124
|
filters.push(`${field} = ${param(i++)}`)
|
|
136
125
|
args.push(v)
|
|
@@ -219,15 +208,15 @@ export function buildQuery<S>(
|
|
|
219
208
|
const attr = attrs[field]
|
|
220
209
|
if (attr.q && (attr.type === undefined || attr.type === "string") && !ex.includes(field)) {
|
|
221
210
|
const column = attr.column ? attr.column : field
|
|
222
|
-
if (attr.
|
|
211
|
+
if (attr.operator === "=") {
|
|
223
212
|
qfilters.push(`${column} = ${param(i++)}`)
|
|
224
213
|
args.push(q)
|
|
225
|
-
} else if (attr.
|
|
214
|
+
} else if (attr.operator === "like") {
|
|
226
215
|
qfilters.push(`${column} ${like} ${param(i++)}`)
|
|
227
|
-
args.push(q + "%")
|
|
216
|
+
args.push("%" + q + "%")
|
|
228
217
|
} else {
|
|
229
218
|
qfilters.push(`${column} ${like} ${param(i++)}`)
|
|
230
|
-
args.push(
|
|
219
|
+
args.push(q + "%")
|
|
231
220
|
}
|
|
232
221
|
}
|
|
233
222
|
}
|