( toDrizzle: (col: AnyColumn) => ColumnType, condition: Condition )
| 94 | let savepointSequence = 0; |
| 95 | |
| 96 | function buildWhere( |
| 97 | toDrizzle: (col: AnyColumn) => ColumnType, |
| 98 | condition: Condition |
| 99 | ): Drizzle.SQL | undefined { |
| 100 | if (condition.type === ConditionType.Compare) { |
| 101 | const left = toDrizzle(condition.a); |
| 102 | const op = condition.operator; |
| 103 | let right = condition.b; |
| 104 | if (right instanceof Column) right = toDrizzle(right); |
| 105 | let inverse = false; |
| 106 | |
| 107 | switch (op) { |
| 108 | case "=": |
| 109 | return Drizzle.eq(left, right); |
| 110 | case "!=": |
| 111 | return Drizzle.ne(left, right); |
| 112 | case ">": |
| 113 | return Drizzle.gt(left, right); |
| 114 | case ">=": |
| 115 | return Drizzle.gte(left, right); |
| 116 | case "<": |
| 117 | return Drizzle.lt(left, right); |
| 118 | case "<=": |
| 119 | return Drizzle.lte(left, right); |
| 120 | case "in": { |
| 121 | // @ts-expect-error -- skip type check |
| 122 | return Drizzle.inArray(left, right); |
| 123 | } |
| 124 | case "not in": |
| 125 | // @ts-expect-error -- skip type check |
| 126 | return Drizzle.notInArray(left, right); |
| 127 | case "is": |
| 128 | return right === null ? Drizzle.isNull(left) : Drizzle.eq(left, right); |
| 129 | case "is not": |
| 130 | return right === null |
| 131 | ? Drizzle.isNotNull(left) |
| 132 | : Drizzle.ne(left, right); |
| 133 | case "not contains": |
| 134 | inverse = true; |
| 135 | case "contains": |
| 136 | right = |
| 137 | typeof right === "string" |
| 138 | ? `%${right}%` |
| 139 | : Drizzle.sql`concat('%', ${right}, '%')`; |
| 140 | |
| 141 | return inverse |
| 142 | ? // @ts-expect-error -- skip type check |
| 143 | Drizzle.notLike(left, right) |
| 144 | : // @ts-expect-error -- skip type check |
| 145 | Drizzle.like(left, right); |
| 146 | case "not ends with": |
| 147 | inverse = true; |
| 148 | case "ends with": |
| 149 | right = |
| 150 | typeof right === "string" |
| 151 | ? `%${right}` |
| 152 | : Drizzle.sql`concat('%', ${right})`; |
| 153 |
no test coverage detected