Help us shape the future of Go! Take the 2026 Go Developer Survey

sqlddl

package
v2.6.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 30, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package sqlddl ingests SQL schema scripts (migrations, release scripts, DDL dumps) into the code graph. Each CREATE of a table, view, function/procedure, trigger or sequence becomes one node; foreign keys, the relations a view or routine reads and writes, and a trigger's table and function become references edges, so the graph can answer "what depends on this table".

Scripts are NOT Tree-sitter parsed. There is no grammar for SQL in the set this binary vendors, dialects diverge exactly where schema scripts live (PL/pgSQL $$ bodies, PARTITION OF, Oracle packages), and one statement a strict parser rejects would cost the whole file. Instead the source is split into statements — respecting quotes, comments and dollar quotes — and each statement's head is matched against the DDL shapes that name an object. It is pure Go, so the static build indexes SQL too.

What is deliberately NOT a node:

  • PARTITION OF tables. A partitioned fact table's release script created 7,611 monthly partitions in one repo; as nodes they would outnumber every real table and each would be embedded for nothing.
  • Indexes and ALTERs. They describe an existing table, so they fold into it (index and added columns into its text when it is in the same file) and contribute foreign-key edges. As nodes, one repo's 37k ALTERs would have drowned its 8k tables.

Index

Constants

View Source
const (
	KindTable    = "Table"
	KindView     = "View"
	KindRoutine  = "Routine" // FUNCTION and PROCEDURE
	KindTrigger  = "Trigger"
	KindSequence = "Sequence"
)

Node kinds for SQL objects.

View Source
const (
	ExtraRef     = "sqlRef"
	ExtraRefKind = "sqlRefKind"
	ExtraFrom    = "sqlFrom"
	RefRelation  = "relation"
	RefRoutine   = "routine"
)

Edge hint keys. A SQL reference names an object, not a qualified node, and that object is often declared in another script, so resolution happens at link time (graph.Build) against every SQL node in the repo:

ExtraRef      the referenced object's normalized name
ExtraRefKind  RefRelation (a table or view) or RefRoutine
ExtraFrom     the referencing object's name, set only when it is not
              declared in this file (ALTER TABLE x ADD FOREIGN KEY) and so
              the edge Source is empty and must be resolved the same way

Variables

Kinds lists every node kind this package emits.

Functions

func BareName

func BareName(n string) string

BareName is the last dotted segment of a normalized name: "s1.store" → "store". The linker falls back to it because one script qualifies a table by schema and the next relies on search_path.

func Parse

func Parse(path string, source []byte) parser.Result

Parse turns one SQL script into schema-object nodes + reference edges.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL