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

Function extractPrimitive

packages/effect/src/sql/Statement.ts:1781–1804  ·  view source on GitHub ↗
(
  value: unknown,
  onCustom: (
    type: Custom<string, unknown, unknown>,
    placeholder: (u: unknown) => string,
    withoutTransform: boolean
  ) => readonly [sql: string, binds: ReadonlyArray<unknown>],
  placeholder: (u: unknown) => string,
  withoutTransform: boolean
)

Source from the content-addressed store, hash-verified

1779}
1780
1781const extractPrimitive = (
1782 value: unknown,
1783 onCustom: (
1784 type: Custom<string, unknown, unknown>,
1785 placeholder: (u: unknown) => string,
1786 withoutTransform: boolean
1787 ) => readonly [sql: string, binds: ReadonlyArray<unknown>],
1788 placeholder: (u: unknown) => string,
1789 withoutTransform: boolean
1790): unknown => {
1791 if (value === undefined) {
1792 return null
1793 } else if (isFragment(value)) {
1794 const head = value.segments[0]
1795 if (head._tag === "Custom") {
1796 const compiled = onCustom(head, placeholder, withoutTransform)
1797 return compiled[1][0] ?? null
1798 } else if (head._tag === "Parameter") {
1799 return head.value
1800 }
1801 return null
1802 }
1803 return value
1804}
1805
1806const escapeSqlite = defaultEscape("\"")
1807

Callers 1

compileFunction · 0.85

Calls 2

isFragmentFunction · 0.85
onCustomFunction · 0.70

Tested by

no test coverage detected