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

Function makeCompiler

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

Source from the content-addressed store, hash-verified

661 * @since 4.0.0
662 */
663export const makeCompiler = (transform?: (_: string) => string) =>
664 Statement.makeCompiler<MssqlCustom>({
665 dialect: "mssql",
666 placeholder(_) {
667 return `@${numberToParamName(_ - 1)}`
668 },
669 onIdentifier: transform ?
670 function(value, withoutTransform) {
671 return withoutTransform ? escape(value) : escape(transform(value))
672 } :
673 escape,
674 onRecordUpdate(placeholders, valueAlias, valueColumns, values, returning) {
675 const returningSql = returning ? returning[0] === "*" ? "OUTPUT INSERTED.* " : `OUTPUT ${returning[0]} ` : ""
676 return [
677 `${returningSql}FROM (values ${placeholders}) AS ${valueAlias}${valueColumns}`,
678 returning ?
679 returning[1].concat(values.flat()) :
680 values.flat()
681 ]
682 },
683 onCustom(type, placeholder) {
684 switch (type.kind) {
685 case "MssqlParam": {
686 return [placeholder(undefined), [type] as any]
687 }
688 }
689 },
690 onInsert(columns, placeholders, values, returning) {
691 const returningSql = returning ? returning[0] === "*" ? " OUTPUT INSERTED.*" : ` OUTPUT ${returning[0]}` : ""
692 return [
693 `(${columns.join(",")})${returningSql} VALUES ${placeholders}`,
694 returning ?
695 returning[1].concat(values.flat()) :
696 values.flat()
697 ]
698 }
699 })
700
701// compiler helpers
702

Callers 1

makeFunction · 0.70

Calls 2

escapeFunction · 0.70
transformFunction · 0.50

Tested by

no test coverage detected