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

Function makeCompiler

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

Source from the content-addressed store, hash-verified

835 * @since 4.0.0
836 */
837export const makeCompiler = (
838 transform?: (_: string) => string,
839 transformJson = true
840): Statement.Compiler => {
841 const transformValue = transformJson && transform
842 ? Statement.defaultTransforms(transform).value
843 : undefined
844
845 return Statement.makeCompiler<PgCustom>({
846 dialect: "pg",
847 placeholder(_) {
848 return `$${_}`
849 },
850 onIdentifier: transform ?
851 function(value, withoutTransform) {
852 return withoutTransform ? escape(value) : escape(transform(value))
853 } :
854 escape,
855 onRecordUpdate(placeholders, valueAlias, valueColumns, values, returning) {
856 return [
857 `(values ${placeholders}) AS ${valueAlias}${valueColumns}${returning ? ` RETURNING ${returning[0]}` : ""}`,
858 returning ?
859 values.flat().concat(returning[1]) :
860 values.flat()
861 ]
862 },
863 onCustom(type, placeholder, withoutTransform) {
864 switch (type.kind) {
865 case "PgJson": {
866 return [
867 placeholder(undefined),
868 [
869 withoutTransform || transformValue === undefined
870 ? type.paramA
871 : transformValue(type.paramA)
872 ]
873 ]
874 }
875 }
876 }
877 })
878}
879
880const escape = Statement.defaultEscape("\"")
881

Callers 1

PgClient.tsFile · 0.70

Calls 2

escapeFunction · 0.50
transformFunction · 0.50

Tested by

no test coverage detected