MCPcopy
hub / github.com/simstudioai/sim / renderSql

Function renderSql

apps/sim/lib/table/__tests__/sql.test.ts:53–72  ·  view source on GitHub ↗

Recursively render a mock SQL node into its generated SQL string.

(node: SqlNode | unknown)

Source from the content-addressed store, hash-verified

51
52/** Recursively render a mock SQL node into its generated SQL string. */
53function renderSql(node: SqlNode | unknown): string {
54 if (node == null) return String(node)
55 if (isRawNode(node)) return node.rawSql
56 if (isJoinNode(node)) {
57 const sep = isRawNode(node.separator) ? node.separator.rawSql : ', '
58 return node.fragments.map(renderSql).join(sep)
59 }
60 if (isTemplateNode(node)) {
61 const parts: string[] = []
62 for (let i = 0; i < node.strings.length; i++) {
63 parts.push(node.strings[i])
64 if (i < node.values.length) {
65 parts.push(renderSql(node.values[i]))
66 }
67 }
68 return parts.join('')
69 }
70 if (typeof node === 'string') return `'${node}'`
71 return String(node)
72}
73
74function render(node: unknown): string {
75 return renderSql(node)

Callers 1

renderFunction · 0.85

Calls 5

isRawNodeFunction · 0.85
isJoinNodeFunction · 0.85
isTemplateNodeFunction · 0.85
joinMethod · 0.80
pushMethod · 0.45

Tested by

no test coverage detected