MCPcopy
hub / github.com/Effect-TS/effect / compile

Method compile

packages/sql/src/internal/statement.ts:536–752  ·  view source on GitHub ↗
(
    statement: Statement.Fragment,
    withoutTransform = false,
    placeholderOverride?: (u: unknown) => string
  )

Source from the content-addressed store, hash-verified

534 ) {}
535
536 compile(
537 statement: Statement.Fragment,
538 withoutTransform = false,
539 placeholderOverride?: (u: unknown) => string
540 ): readonly [sql: string, binds: ReadonlyArray<unknown>] {
541 withoutTransform = withoutTransform || this.disableTransforms
542 const cacheSymbol = withoutTransform ? statementCacheNoTransformSymbol : statementCacheSymbol
543 if (cacheSymbol in statement) {
544 return (statement as any)[cacheSymbol]
545 }
546
547 const segments = statement.segments
548 const len = segments.length
549
550 let sql = ""
551 const binds: Array<unknown> = []
552 let placeholderCount = 0
553 const placeholder = placeholderOverride ?? ((u: unknown) => this.parameterPlaceholder(++placeholderCount, u))
554 const placeholderNoIncrement = (u: unknown) => this.parameterPlaceholder(placeholderCount, u)
555 const placeholders = makePlaceholdersArray(placeholder)
556
557 for (let i = 0; i < len; i++) {
558 const segment = segments[i]
559
560 switch (segment._tag) {
561 case "Literal": {
562 sql += segment.value
563 if (segment.params) {
564 binds.push.apply(binds, segment.params as any)
565 }
566 break
567 }
568
569 case "Identifier": {
570 sql += this.onIdentifier(segment.value, withoutTransform)
571 break
572 }
573
574 case "Parameter": {
575 sql += placeholder(segment.value)
576 binds.push(segment.value)
577 break
578 }
579
580 case "ArrayHelper": {
581 sql += `(${placeholders(segment.value)})`
582 binds.push.apply(binds, segment.value as any)
583 break
584 }
585
586 case "RecordInsertHelper": {
587 const keys = Object.keys(segment.value[0])
588
589 if (this.onInsert) {
590 const values: Array<ReadonlyArray<unknown>> = new Array(segment.value.length)
591 let placeholders = ""
592 for (let i = 0; i < segment.value.length; i++) {
593 const row: Array<unknown> = new Array(keys.length)

Callers 15

Kysely.test.tsFile · 0.45
makeSqlCommitFunction · 0.45
executeCommitFunction · 0.45
withConnectionMethod · 0.45
streamMethod · 0.45
compileMethod · 0.45
Client.test.tsFile · 0.45
getAjvValidateFunction · 0.45
getAjvValidateFunction · 0.45
Client.test.tsFile · 0.45
Client.test.tsFile · 0.45

Calls 6

makePlaceholdersArrayFunction · 0.85
extractPrimitiveFunction · 0.85
generateColumnsFunction · 0.85
keysMethod · 0.80
placeholderFunction · 0.70
mapMethod · 0.65

Tested by 2

getAjvValidateFunction · 0.36
getAjvValidateFunction · 0.36