( toDrizzle: (col: AnyColumn) => ColumnType, condition: Condition )
| 23 | const CREATE_MANY_BATCH_SIZE = 500; |
| 24 | |
| 25 | function buildWhere( |
| 26 | toDrizzle: (col: AnyColumn) => ColumnType, |
| 27 | condition: Condition |
| 28 | ): Drizzle.SQL | undefined { |
| 29 | if (condition.type === ConditionType.Compare) { |
| 30 | const left = toDrizzle(condition.a); |
| 31 | const op = condition.operator; |
| 32 | let right = condition.b; |
| 33 | if (right instanceof Column) right = toDrizzle(right); |
| 34 | let inverse = false; |
| 35 | |
| 36 | switch (op) { |
| 37 | case "=": |
| 38 | return Drizzle.eq(left, right); |
| 39 | case "!=": |
| 40 | return Drizzle.ne(left, right); |
| 41 | case ">": |
| 42 | return Drizzle.gt(left, right); |
| 43 | case ">=": |
| 44 | return Drizzle.gte(left, right); |
| 45 | case "<": |
| 46 | return Drizzle.lt(left, right); |
| 47 | case "<=": |
| 48 | return Drizzle.lte(left, right); |
| 49 | case "in": { |
| 50 | // @ts-expect-error -- skip type check |
| 51 | return Drizzle.inArray(left, right); |
| 52 | } |
| 53 | case "not in": |
| 54 | // @ts-expect-error -- skip type check |
| 55 | return Drizzle.notInArray(left, right); |
| 56 | case "is": |
| 57 | return right === null ? Drizzle.isNull(left) : Drizzle.eq(left, right); |
| 58 | case "is not": |
| 59 | return right === null |
| 60 | ? Drizzle.isNotNull(left) |
| 61 | : Drizzle.ne(left, right); |
| 62 | case "not contains": |
| 63 | inverse = true; |
| 64 | case "contains": |
| 65 | right = |
| 66 | typeof right === "string" |
| 67 | ? `%${right}%` |
| 68 | : Drizzle.sql`concat('%', ${right}, '%')`; |
| 69 | |
| 70 | return inverse |
| 71 | ? // @ts-expect-error -- skip type check |
| 72 | Drizzle.notLike(left, right) |
| 73 | : // @ts-expect-error -- skip type check |
| 74 | Drizzle.like(left, right); |
| 75 | case "not ends with": |
| 76 | inverse = true; |
| 77 | case "ends with": |
| 78 | right = |
| 79 | typeof right === "string" |
| 80 | ? `%${right}` |
| 81 | : Drizzle.sql`concat('%', ${right})`; |
| 82 |
no test coverage detected