MCPcopy Create free account
hub / github.com/Effect-TS/effect / makeCompiler

Function makeCompiler

packages/sql-pg/src/PgClient.ts:602–643  ·  view source on GitHub ↗
(
  transform?: (_: string) => string,
  transformJson = true
)

Source from the content-addressed store, hash-verified

600 * @since 1.0.0
601 */
602export const makeCompiler = (
603 transform?: (_: string) => string,
604 transformJson = true
605): Statement.Compiler => {
606 const transformValue = transformJson && transform
607 ? Statement.defaultTransforms(transform).value
608 : undefined
609
610 return Statement.makeCompiler<PgCustom>({
611 dialect: "pg",
612 placeholder(_) {
613 return `$${_}`
614 },
615 onIdentifier: transform ?
616 function(value, withoutTransform) {
617 return withoutTransform ? escape(value) : escape(transform(value))
618 } :
619 escape,
620 onRecordUpdate(placeholders, valueAlias, valueColumns, values, returning) {
621 return [
622 `(values ${placeholders}) AS ${valueAlias}${valueColumns}${returning ? ` RETURNING ${returning[0]}` : ""}`,
623 returning ?
624 values.flat().concat(returning[1]) :
625 values.flat()
626 ]
627 },
628 onCustom(type, placeholder, withoutTransform) {
629 switch (type.kind) {
630 case "PgJson": {
631 return [
632 placeholder(undefined),
633 [
634 withoutTransform || transformValue === undefined
635 ? type.i0
636 : transformValue(type.i0)
637 ]
638 ]
639 }
640 }
641 }
642 })
643}
644
645const escape = Statement.defaultEscape("\"")
646

Callers 1

makeClientFunction · 0.70

Calls 2

escapeFunction · 0.50
transformInterface · 0.50

Tested by

no test coverage detected