MCPcopy Create free account
hub / github.com/effect-app/libs / fieldExpr

Function fieldExpr

packages/infra/src/Store/SQL/query.ts:188–209  ·  view source on GitHub ↗
(path: string, relation?: string)

Source from the content-addressed store, hash-verified

186 }
187
188 const fieldExpr = (path: string, relation?: string): string => {
189 if (path === idKey || path === "id") return "id"
190 if (relation && path.includes(".-1.")) {
191 const subPath = path.split(".-1.")[1]!
192 if (subPath.endsWith(".length")) {
193 // TODO: array length inside relation element
194 return dialect.jsonExtractElement(`_${relation}`, subPath.slice(0, -".length".length))
195 }
196 return dialect.jsonExtractElement(`_${relation}`, subPath)
197 }
198 if (path.endsWith(".length")) {
199 const arrPath = dottedToJsonPath(path.slice(0, -".length".length))
200 return dialect.arrayLength(arrPath)
201 }
202 const jsonPath = dottedToJsonPath(path)
203 const expr = dialect.jsonExtract(jsonPath)
204 const topKey = path.split(".")[0]
205 if (topKey in defaultValues) {
206 return `COALESCE(${expr}, ${addParam(defaultValues[topKey])})`
207 }
208 return expr
209 }
210
211 const statement = (x: FilterR, relation?: string): string => {
212 const resolvedPath = x.path === idKey ? "id" : x.path

Callers 4

statementFunction · 0.85
aggregateSelectExprFunction · 0.85
getSelectExprFunction · 0.85
buildWhereSQLQueryFunction · 0.85

Calls 3

dottedToJsonPathFunction · 0.85
addParamFunction · 0.85
splitMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…