Documentation
¶
Overview ¶
Package joinmeta reads the relations a DTQL query reads and the foreign keys of a database, from the query's own tree and from DALgo's engine-neutral schema calls (dbschema.ListCollections and DescribeCollection), never from engine-specific SQL. The terminal chat and `query run --result-id` share it.
Index ¶
Constants ¶
const MaxCollections = 500
MaxCollections bounds how many collections one snapshot describes.
Variables ¶
var ErrTooManyCollections = errors.New("the database holds more collections than are described")
ErrTooManyCollections is returned when a database holds more collections than MaxCollections.
Functions ¶
func RelationKey ¶
RelationKey is the key of schema.relation in a snapshot; an empty schema is the source's default one.
Types ¶
type ForeignKey ¶
type ForeignKey struct {
ConstraintID string
Schema string
FromRelation string
FromFields []string
ToSchema string
ToRelation string
ToFields []string
}
ForeignKey is source-scoped schema evidence. Fields are paired by index and are intentionally not flattened: a composite FK remains one relationship.
type ForeignKeySnapshot ¶
type ForeignKeySnapshot struct {
Source string
Keys []ForeignKey
// Columns contains the source's ordered physical columns, keyed by
// lowercase schema.relation. It is used to expand wildcards before a JOIN.
Columns map[string][]string
// Definitions is each described collection, keyed like Columns.
Definitions map[string]*dbschema.CollectionDef
// Views is the collections the source reports as views, keyed like Columns.
Views map[string]bool
}
ForeignKeySnapshot is the foreign keys of one source.
func LoadForeignKeySnapshot ¶
func LoadForeignKeySnapshot(ctx context.Context, db dal.DB, source string) (ForeignKeySnapshot, error)
LoadForeignKeySnapshot describes every collection of db through dalgo's schema reader: each collection's fields and primary key, and each declared foreign key. A foreign key whose referenced fields are not reported points at the target's primary key. Describing every collection yields every incoming key too. A provider without a schema reader answers a *dbschema.NotSupportedError.
func (ForeignKeySnapshot) Kind ¶
func (s ForeignKeySnapshot) Kind(schema, relation string) string
Kind is "view", "table" or "unknown" for schema.relation of the snapshot.
type RelationInstance ¶
type RelationInstance struct {
ID RelationInstanceID
Schema string
Relation string
Alias string
// Database is the named database of a federated query's source, else "".
Database string
}
RelationInstance is one source occurrence of a query.
func RelationInstances ¶
func RelationInstances(from dal.FromSource) []RelationInstance
RelationInstances walks a DTQL FROM/JOIN tree into its source occurrences, root first, each join's subtree in order.
type RelationInstanceID ¶
type RelationInstanceID string
RelationInstanceID identifies a node in the DTQL source tree. It is stable for a given document: root is "root" and child joins append their index.