MCPcopy
hub / github.com/Effect-TS/effect / makeCompiler

Function makeCompiler

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

Source from the content-addressed store, hash-verified

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

Callers 1

makeClientFunction · 0.70

Calls 2

escapeFunction · 0.50
transformInterface · 0.50

Tested by

no test coverage detected