MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / buildWhere

Function buildWhere

packages/core/fumadb/src/adapters/kysely/query.ts:35–100  ·  view source on GitHub ↗
(
  condition: Condition,
  eb: ExpressionBuilder<any, any>,
  provider: SQLProvider
)

Source from the content-addressed store, hash-verified

33}
34
35export function buildWhere(
36 condition: Condition,
37 eb: ExpressionBuilder<any, any>,
38 provider: SQLProvider
39): ExpressionWrapper<any, any, SqlBool> {
40 if (condition.type === ConditionType.Compare) {
41 const left = condition.a;
42 const op = condition.operator;
43 let val = condition.b;
44
45 if (!(val instanceof Column)) {
46 val = serialize(val, left, provider);
47 }
48
49 let v: BinaryOperator;
50 let rhs: unknown;
51
52 switch (op) {
53 case "contains":
54 v = "like";
55 case "not contains":
56 v ??= "not like";
57 rhs =
58 val instanceof Column
59 ? sql`concat('%', ${eb.ref(fullSQLName(val))}, '%')`
60 : `%${val}%`;
61
62 break;
63 case "starts with":
64 v = "like";
65 case "not starts with":
66 v ??= "not like";
67 rhs =
68 val instanceof Column
69 ? sql`concat(${eb.ref(fullSQLName(val))}, '%')`
70 : `${val}%`;
71
72 break;
73 case "ends with":
74 v = "like";
75 case "not ends with":
76 v ??= "not like";
77 rhs =
78 val instanceof Column
79 ? sql`concat('%', ${eb.ref(fullSQLName(val))})`
80 : `%${val}`;
81 break;
82 default:
83 v = op;
84 rhs = val instanceof Column ? eb.ref(fullSQLName(val)) : val;
85 }
86
87 return eb(fullSQLName(left), v, rhs);
88 }
89
90 // Nested conditions
91 if (condition.type === ConditionType.And) {
92 return eb.and(condition.items.map((v) => buildWhere(v, eb, provider)));

Callers 5

findManyFunction · 0.70
countFunction · 0.70
updateManyFunction · 0.70
upsertFunction · 0.70
deleteManyFunction · 0.70

Calls 2

serializeFunction · 0.90
fullSQLNameFunction · 0.85

Tested by

no test coverage detected