(condition: Condition)
| 17 | |
| 18 | // TODO: implement comparing values with another table's columns |
| 19 | function buildWhere(condition: Condition): object { |
| 20 | if (condition.type === ConditionType.Compare) { |
| 21 | const column = condition.a; |
| 22 | const value = condition.b; |
| 23 | const name = column.names.prisma; |
| 24 | |
| 25 | if (value instanceof Column) { |
| 26 | throw new Error( |
| 27 | "Prisma adapter does not support comparing against another column at the moment.", |
| 28 | ); |
| 29 | } |
| 30 | |
| 31 | switch (condition.operator) { |
| 32 | case "=": |
| 33 | case "is": |
| 34 | return { [name]: value }; |
| 35 | case "!=": |
| 36 | case "is not": |
| 37 | return { [name]: { not: value } }; |
| 38 | case ">": |
| 39 | return { [name]: { gt: value } }; |
| 40 | case ">=": |
| 41 | return { [name]: { gte: value } }; |
| 42 | case "<": |
| 43 | return { [name]: { lt: value } }; |
| 44 | case "<=": |
| 45 | return { [name]: { lte: value } }; |
| 46 | case "in": |
| 47 | return { [name]: { in: value } }; |
| 48 | case "not in": |
| 49 | return { [name]: { notIn: value } }; |
| 50 | case "starts with": |
| 51 | return { [name]: { startsWith: value } }; |
| 52 | case "not starts with": |
| 53 | return { NOT: { [name]: { startsWith: value } } }; |
| 54 | case "contains": |
| 55 | return { [name]: { contains: value } }; |
| 56 | case "not contains": |
| 57 | return { NOT: { [name]: { contains: value } } }; |
| 58 | case "ends with": |
| 59 | return { [name]: { endsWith: value } }; |
| 60 | case "not ends with": |
| 61 | return { NOT: { [name]: { endsWith: value } } }; |
| 62 | default: |
| 63 | throw new Error(`Unsupported operator: ${condition.operator}`); |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | if (condition.type === ConditionType.And) { |
| 68 | return { |
| 69 | AND: condition.items.map(buildWhere), |
| 70 | }; |
| 71 | } |
| 72 | |
| 73 | if (condition.type === ConditionType.Not) { |
| 74 | return { |
| 75 | NOT: buildWhere(condition.item), |
| 76 | }; |
no outgoing calls
no test coverage detected