| 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) |