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

Function makeCompiler

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

Source from the content-addressed store, hash-verified

469 * @since 1.0.0
470 */
471export const makeCompiler = (transform?: (_: string) => string) =>
472 Statement.makeCompiler<MssqlCustom>({
473 dialect: "mssql",
474 placeholder(_) {
475 return `@${numberToParamName(_ - 1)}`
476 },
477 onIdentifier: transform ?
478 function(value, withoutTransform) {
479 return withoutTransform ? escape(value) : escape(transform(value))
480 } :
481 escape,
482 onRecordUpdate(placeholders, valueAlias, valueColumns, values, returning) {
483 const returningSql = returning ? returning[0] === "*" ? "OUTPUT INSERTED.* " : `OUTPUT ${returning[0]} ` : ""
484 return [
485 `${returningSql}FROM (values ${placeholders}) AS ${valueAlias}${valueColumns}`,
486 returning ?
487 returning[1].concat(values.flat()) :
488 values.flat()
489 ]
490 },
491 onCustom(type, placeholder) {
492 switch (type.kind) {
493 case "MssqlParam": {
494 return [placeholder(undefined), [type] as any]
495 }
496 }
497 },
498 onInsert(columns, placeholders, values, returning) {
499 const returningSql = returning ? returning[0] === "*" ? " OUTPUT INSERTED.*" : ` OUTPUT ${returning[0]}` : ""
500 return [
501 `(${columns.join(",")})${returningSql} VALUES ${placeholders}`,
502 returning ?
503 returning[1].concat(values.flat()) :
504 values.flat()
505 ]
506 }
507 })
508
509// compiler helpers
510

Callers 1

makeFunction · 0.70

Calls 2

escapeFunction · 0.70
transformInterface · 0.50

Tested by

no test coverage detected