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

Function doc

packages/core/fumadb/src/adapters/mongodb/query.ts:29–68  ·  view source on GitHub ↗
(name: string, op: Operator, value: unknown)

Source from the content-addressed store, hash-verified

27
28function buildWhere(condition: Condition): Filter<Document> {
29 function doc(name: string, op: Operator, value: unknown): Filter<Document> {
30 switch (op) {
31 case "=":
32 case "is":
33 if (value == null) return { [name]: { $exists: false } };
34
35 return { [name]: value };
36 case "!=":
37 case "is not":
38 if (value == null) return { [name]: { $exists: true } };
39
40 return { [name]: { $ne: value } };
41 case ">":
42 return { [name]: { $gt: value } };
43 case ">=":
44 return { [name]: { $gte: value } };
45 case "<":
46 return { [name]: { $lt: value } };
47 case "<=":
48 return { [name]: { $lte: value } };
49 case "in":
50 return { [name]: { $in: value } };
51 case "not in":
52 return { [name]: { $nin: value } };
53 case "starts with":
54 return { [name]: { $regex: `^${value}`, $options: "i" } };
55 case "not starts with":
56 return { [name]: { $not: { $regex: `^${value}`, $options: "i" } } };
57 case "contains":
58 return { [name]: { $regex: value, $options: "i" } };
59 case "not contains":
60 return { [name]: { $not: { $regex: value, $options: "i" } } };
61 case "ends with":
62 return { [name]: { $regex: `${value}$`, $options: "i" } };
63 case "not ends with":
64 return { [name]: { $not: { $regex: `${value}$`, $options: "i" } } };
65 default:
66 throw new Error(`Unsupported operator: ${op}`);
67 }
68 }
69
70 function expr(exp1: string, op: Operator, exp2: string): Filter<Document> {
71 switch (op) {

Callers 1

buildWhereFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected