forked from GerbenAaltink/alopex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
key.js
34 lines (33 loc) · 815 Bytes
/
key.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
class Key {
constructor (name, value) {
this.filters = {
eq: '=',
lt: '<',
lte: '<=',
gt: '>',
gte: '>=',
like: 'LIKE',
isnull: null
}
const parts = name.split('__')
this.name = parts[0]
this.value = value
this.filter = (parts.length > 1 ? parts[1] : 'eq').toLowerCase()
this.isParameter = this.filter !== 'isnull'
this.operator = this.filters[this.filter]
if (this.operator === undefined) {
this.operator = '='
this.filter = 'eq'
}
if (this.isParameter) {
this.string = `"${this.name}" ${this.operator} ?`
} else {
if (this.value === false) {
this.string = `"${this.name}" IS NOT NULL`
} else {
this.string = `"${this.name}" IS NULL`
}
}
}
}
module.exports = Key