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

Function makeCompiler

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

Source from the content-addressed store, hash-verified

819 ))
820
821/**
822 * Creates a layer from a concrete PostgreSQL pool configuration, providing both `PgClient` and `SqlClient`.
823 *
824 * @category layers
825 * @since 4.0.0
826 */
827export const layer = (
828 config: PgPoolConfig
829): Layer.Layer<PgClient | Client.SqlClient, SqlError> => layerFrom(make(config))
830
831/**
832 * Creates the PostgreSQL statement compiler, using `$1` placeholders, double-quoted identifiers, PostgreSQL returning clauses, and optional JSON value transformation.
833 *
834 * @category constructors
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": {

Callers 1

PgClient.tsFile · 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…