Documentation
¶
Overview ¶
Package sqlref extracts the tables, columns and equi-joins a statement reads and writes from the sqlglot AST (#538, #625). Extraction runs the fork's qualify pass so a reference is resolved to its physical source: a CTE, subquery or derived table is followed to the table it reads, and an unqualified table is stamped with the target's default schema.
It is best-effort: no engine round-trip is needed, and a parse or qualify failure yields an empty Reference, never an error the caller must treat as fatal.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Persist ¶
func Persist(ctx context.Context, q Store, statementID, workspaceID, catalogID db.UUID, namespace, sql string) error
Persist replaces the stored references, columns and joins of one statement with the extractor's result (#538, #625). It is idempotent: the old rows are deleted first. The caller owns the transaction.
func PersistWithDialect ¶
func PersistWithDialect(ctx context.Context, q Store, statementID, workspaceID, catalogID db.UUID, d dialect.Dialect, namespace, sql string) error
PersistWithDialect is Persist with the connection's dialect: table names are resolved against the target's default schema (namespace) and through CTEs, subqueries and derived tables by the fork's qualify pass.
Types ¶
type Column ¶
Column is one column reference, resolved to its physical table. Namespace and Table are both empty when the reference is unqualified and ambiguous or unresolved.
type Reference ¶
Reference is what one statement reads and writes.
func Extract ¶
Extract returns references using Baleia's generic SQL dialect. Callers that know the connection dialect and its default schema should use ExtractResolved.
func ExtractResolved ¶
ExtractResolved returns the tables, columns and equi-joins of one statement, parsed with d and resolved against defaultSchema (the target's default schema, stamped on unqualified table references). An unparsable statement yields an empty Reference.
type Store ¶
type Store interface {
DeleteStatementReferences(ctx context.Context, statementID db.UUID) error
DeleteStatementJoins(ctx context.Context, statementID db.UUID) error
DeleteStatementColumns(ctx context.Context, statementID db.UUID) error
InsertStatementReference(ctx context.Context, arg db.InsertStatementReferenceParams) error
InsertStatementJoin(ctx context.Context, arg db.InsertStatementJoinParams) error
InsertStatementColumn(ctx context.Context, arg db.InsertStatementColumnParams) error
}
Store is the persistence of a statement's references, columns and joins; *repo.Repo implements it.
type Table ¶
type Table struct {
// Path is the resolved name, 1 to 3 parts (table, schema.table,
// catalog.schema.table). The default schema is stamped on unqualified
// names when ExtractResolved is given one.
Path []string
Alias string
// Kind is "read" for FROM/JOIN and "write" for UPDATE/INTO.
Kind string
}
Table is one physical table named in FROM/JOIN/UPDATE/INTO.