| 156 | } |
| 157 | |
| 158 | public buildCondition( |
| 159 | column: string, |
| 160 | operator: Operator, |
| 161 | value?: SqlParam |
| 162 | ): string { |
| 163 | switch (operator) { |
| 164 | case 'IS NULL': |
| 165 | return `${column} IS NULL`; |
| 166 | case 'IS NOT NULL': |
| 167 | return `${column} IS NOT NULL`; |
| 168 | case 'BETWEEN': |
| 169 | if (Array.isArray(value) && value.length === 2) { |
| 170 | return `${column} BETWEEN ${this.escapeValue(value[0]!)} AND ${this.escapeValue(value[1]!)}`; |
| 171 | } |
| 172 | throw new Error('BETWEEN operator requires an array of two values'); |
| 173 | case 'IN': |
| 174 | case 'NOT IN': |
| 175 | if (!(Array.isArray(value) || value instanceof Expression)) { |
| 176 | throw new Error(`${operator} operator requires an array value`); |
| 177 | } |
| 178 | return `${column} ${operator} ${this.escapeValue(value)}`; |
| 179 | default: |
| 180 | return `${column} ${operator} ${this.escapeValue(value!)}`; |
| 181 | } |
| 182 | } |
| 183 | |
| 184 | andWhere(column: string, operator: Operator, value?: SqlParam): this { |
| 185 | const condition = this.buildCondition(column, operator, value); |