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

Function makeCompiler

packages/sql/mssql/src/MssqlClient.ts:768–804  ·  view source on GitHub ↗
(transform?: (_: string) => string)

Source from the content-addressed store, hash-verified

766 * @since 4.0.0
767 */
768export const makeCompiler = (transform?: (_: string) => string) =>
769 Statement.makeCompiler<MssqlCustom>({
770 dialect: "mssql",
771 placeholder(_) {
772 return `@${numberToParamName(_ - 1)}`
773 },
774 onIdentifier: transform ?
775 function(value, withoutTransform) {
776 return withoutTransform ? escape(value) : escape(transform(value))
777 } :
778 escape,
779 onRecordUpdate(placeholders, valueAlias, valueColumns, values, returning) {
780 const returningSql = returning ? returning[0] === "*" ? "OUTPUT INSERTED.* " : `OUTPUT ${returning[0]} ` : ""
781 return [
782 `${returningSql}FROM (values ${placeholders}) AS ${valueAlias}${valueColumns}`,
783 returning ?
784 values.flat().concat(returning[1]) :
785 values.flat()
786 ]
787 },
788 onCustom(type, placeholder) {
789 switch (type.kind) {
790 case "MssqlParam": {
791 return [placeholder(undefined), [type] as any]
792 }
793 }
794 },
795 onInsert(columns, placeholders, values, returning) {
796 const returningSql = returning ? returning[0] === "*" ? " OUTPUT INSERTED.*" : ` OUTPUT ${returning[0]}` : ""
797 return [
798 `(${columns.join(",")})${returningSql} VALUES ${placeholders}`,
799 returning ?
800 values.flat().concat(returning[1]) :
801 values.flat()
802 ]
803 }
804 })
805
806// compiler helpers
807

Callers 1

makeFunction · 0.70

Calls 2

escapeFunction · 0.70
transformFunction · 0.50

Tested by

no test coverage detected