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

Function makeCompiler

repos/effect/packages/sql/pglite/src/PgliteClient.ts:390–431  ·  view source on GitHub ↗
(
  transform?: (_: string) => string,
  transformJson = true
)

Source from the content-addressed store, hash-verified

388 * @since 4.0.0
389 */
390export const makeCompiler = (
391 transform?: (_: string) => string,
392 transformJson = true
393): Statement.Compiler => {
394 const transformValue = transformJson && transform
395 ? Statement.defaultTransforms(transform).value
396 : undefined
397
398 return Statement.makeCompiler<PgCustom>({
399 dialect: "pg",
400 placeholder(_) {
401 return `$${_}`
402 },
403 onIdentifier: transform ?
404 function(value, withoutTransform) {
405 return withoutTransform ? escape(value) : escape(transform(value))
406 } :
407 escape,
408 onRecordUpdate(placeholders, valueAlias, valueColumns, values, returning) {
409 return [
410 `(values ${placeholders}) AS ${valueAlias}${valueColumns}${returning ? ` RETURNING ${returning[0]}` : ""}`,
411 returning ?
412 values.flat().concat(returning[1]) :
413 values.flat()
414 ]
415 },
416 onCustom(type, placeholder, withoutTransform) {
417 switch (type.kind) {
418 case "PgJson": {
419 return [
420 placeholder(undefined),
421 [
422 withoutTransform || transformValue === undefined
423 ? type.paramA
424 : transformValue(type.paramA)
425 ]
426 ]
427 }
428 }
429 }
430 })
431}
432
433const escape = Statement.defaultEscape("\"")
434const escapeLiteral = (value: string) => `'${value.replace(/'/g, "''")}'`

Callers 1

fromClientFunction · 0.70

Calls 2

escapeFunction · 0.50
transformFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…