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

Function join

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

Source from the content-addressed store, hash-verified

787 * @since 4.0.0
788 */
789export function join(lit: string, addParens = true, fallback = "") {
790 const literalStatement = literal(lit)
791 const fallbackFragment = fragment([literal(fallback)])
792
793 return (clauses: ReadonlyArray<string | Fragment>): Fragment => {
794 if (clauses.length === 0) {
795 return fallbackFragment
796 } else if (clauses.length === 1) {
797 return fragment(convertLiteralOrFragment(clauses[0]))
798 }
799
800 const segments: Array<Segment> = []
801
802 if (addParens) {
803 segments.push(literal("("))
804 }
805
806 segments.push.apply(segments, convertLiteralOrFragment(clauses[0]))
807
808 for (let i = 1; i < clauses.length; i++) {
809 segments.push(literalStatement)
810 segments.push.apply(segments, convertLiteralOrFragment(clauses[i]))
811 }
812
813 if (addParens) {
814 segments.push(literal(")"))
815 }
816
817 return fragment(segments)
818 }
819}
820
821/**
822 * Combines clauses with `AND`, parenthesizing multiple clauses and returning

Callers 2

Statement.tsFile · 0.70
flushMethod · 0.50

Calls 5

fragmentFunction · 0.85
convertLiteralOrFragmentFunction · 0.85
literalFunction · 0.70
pushMethod · 0.65
applyMethod · 0.45

Tested by

no test coverage detected