Home / Function/ splitSqlStatements() — supabase Function Reference

splitSqlStatements() — supabase Function Reference

Architecture documentation for the splitSqlStatements() function in ExplainVisualizer.utils.ts from the supabase codebase.

Entity Profile

Relationship Graph

Source Code

apps/studio/components/interfaces/ExplainVisualizer/ExplainVisualizer.utils.ts lines 200–230

export function splitSqlStatements(sql: string): string[] {
  // Enhanced tokenizer that handles:
  // - Single-quoted strings: '...' (with '' escaping)
  // - Double-quoted strings: "..." (with "" escaping)
  // - Dollar-quoted strings: $tag$...$tag$
  // - Line comments: -- (until end of line)
  // - Block comments: /* ... */ (may be multiline)
  // - Semicolons: ;
  const tokens =
    sql.match(
      /'([^']|'')*'|"([^"]|"")*"|\$[a-zA-Z0-9_]*\$[\s\S]*?\$[a-zA-Z0-9_]*\$|--[^\r\n]*|\/\*[\s\S]*?\*\/|;|[^'"$;\-\/]+|./g
    ) || []

  const statements: string[] = []
  let current = ''

  for (const token of tokens) {
    if (token === ';') {
      if (current.trim()) statements.push(current.trim())
      current = ''
    } else {
      current += token
    }
  }

  if (current.trim()) {
    statements.push(current.trim())
  }

  return statements
}

Subdomains

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free