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 ¶
const ( KindTable = "Table" KindView = "View" KindRoutine = "Routine" // FUNCTION and PROCEDURE KindTrigger = "Trigger" KindSequence = "Sequence" )
Node kinds for SQL objects.
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 ¶
var Kinds = []string{KindTable, KindView, KindRoutine, KindTrigger, KindSequence}
Kinds lists every node kind this package emits.
Functions ¶
Types ¶
This section is empty.