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

Function compile

packages/effect/src/unstable/sql/Statement.ts:822–1042  ·  view source on GitHub ↗
(
    this: CompilerImpl,
    statement: Fragment,
    withoutTransform = false,
    placeholderOverride?: (u: unknown) => string
  )

Source from the content-addressed store, hash-verified

820
821const CompilerProto = {
822 compile(
823 this: CompilerImpl,
824 statement: Fragment,
825 withoutTransform = false,
826 placeholderOverride?: (u: unknown) => string
827 ): readonly [sql: string, binds: ReadonlyArray<unknown>] {
828 const opts = this.options
829 withoutTransform = withoutTransform || this.disableTransforms
830 const cache = withoutTransform ? this.statementCacheNoTransform : this.statementCache
831 const cached = cache.get(statement)
832 if (cached !== undefined) {
833 return cached
834 }
835
836 const segments = statement.segments
837 const len = segments.length
838
839 let sql = ""
840 const binds: Array<unknown> = []
841 let placeholderCount = 0
842 const placeholder = placeholderOverride ?? ((u: unknown) => opts.placeholder(++placeholderCount, u))
843 const placeholderNoIncrement = (u: unknown) => opts.placeholder(placeholderCount, u)
844 const placeholders = makePlaceholdersArray(placeholder)
845
846 for (let i = 0; i < len; i++) {
847 const segment = segments[i]
848
849 switch (segment._tag) {
850 case "Literal": {
851 sql += segment.value
852 if (segment.params) {
853 binds.push.apply(binds, segment.params as any)
854 }
855 break
856 }
857
858 case "Identifier": {
859 sql += opts.onIdentifier(segment.value, withoutTransform)
860 break
861 }
862
863 case "Parameter": {
864 sql += placeholder(segment.value)
865 binds.push(segment.value)
866 break
867 }
868
869 case "ArrayHelper": {
870 sql += `(${placeholders(segment.value)})`
871 binds.push.apply(binds, segment.value as any)
872 break
873 }
874
875 case "RecordInsertHelper": {
876 const keys = Object.keys(segment.value[0])
877
878 if (opts.onInsert) {
879 const values: Array<ReadonlyArray<unknown>> = new Array(segment.value.length)

Callers 6

getParserMethod · 0.50
getParserMethod · 0.50
getParserMethod · 0.50
getParserMethod · 0.50
makeConstructorParserFunction · 0.50
makeParserFunction · 0.50

Calls 10

makePlaceholdersArrayFunction · 0.85
extractPrimitiveFunction · 0.85
generateColumnsFunction · 0.85
pushMethod · 0.80
compileMethod · 0.80
filterMethod · 0.80
placeholderFunction · 0.70
getMethod · 0.65
setMethod · 0.65
mapMethod · 0.45

Tested by

no test coverage detected