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

Function join

packages/effect/src/unstable/sql/Statement.ts:655–685  ·  view source on GitHub ↗
(lit: string, addParens = true, fallback = "")

Source from the content-addressed store, hash-verified

653 * @since 4.0.0
654 */
655export function join(lit: string, addParens = true, fallback = "") {
656 const literalStatement = literal(lit)
657 const fallbackFragment = fragment([literal(fallback)])
658
659 return (clauses: ReadonlyArray<string | Fragment>): Fragment => {
660 if (clauses.length === 0) {
661 return fallbackFragment
662 } else if (clauses.length === 1) {
663 return fragment(convertLiteralOrFragment(clauses[0]))
664 }
665
666 const segments: Array<Segment> = []
667
668 if (addParens) {
669 segments.push(literal("("))
670 }
671
672 segments.push.apply(segments, convertLiteralOrFragment(clauses[0]))
673
674 for (let i = 1; i < clauses.length; i++) {
675 segments.push(literalStatement)
676 segments.push.apply(segments, convertLiteralOrFragment(clauses[i]))
677 }
678
679 if (addParens) {
680 segments.push(literal(")"))
681 }
682
683 return fragment(segments)
684 }
685}
686
687/**
688 * Combines clauses with `AND`, parenthesizing multiple clauses and returning

Callers 1

Statement.tsFile · 0.70

Calls 4

fragmentFunction · 0.85
convertLiteralOrFragmentFunction · 0.85
pushMethod · 0.80
literalFunction · 0.70

Tested by

no test coverage detected