Documentation
¶
Overview ¶
Package tugqlbind binds the databases a saved TugQL query reads to project sources (spec/features/cli/query, REQ:cross-database-sources). A text body's root `databases (` block declares aliases and an `alias::path` source reads the database bound to its alias; a structured body names a source's database with its `database` key. DALgo leaves binding to the caller: this package is that caller for every surface that runs a saved query — `query run`, `chat` and `datatug serve` — so each binds the same way.
A name without a target is the project source of that name in the run's environment. A `datatug://<project>/<db>[?env=]` target is that project source. A connection-string target is refused: a saved query is project knowledge, and names its sources by project reference.
Index ¶
- func Databases(query dal.StructuredQuery) map[string]bool
- func IsError(err error) bool
- func LabelGuard(bindings map[string]Binding, ...) secureread.FederatedColumnGuard
- func Saved(ctx context.Context, queryDef *datatug.QueryDef, r Resolver) (dal.StructuredQuery, map[string]Binding, error)
- func SavedUnqualifiedMessage(name string) string
- func Sources(query dal.StructuredQuery, visit func(dal.CollectionRef))
- func URLs(bindings map[string]Binding) map[string]string
- func Unqualified(query dal.StructuredQuery) string
- func UnqualifiedMessage(name string) string
- type Binding
- type Error
- type Resolver
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Databases ¶
func Databases(query dal.StructuredQuery) map[string]bool
Databases is the set of database names the sources of query carry.
func LabelGuard ¶
func LabelGuard(bindings map[string]Binding, guardFor func(projectDir string) secureread.FederatedColumnGuard) secureread.FederatedColumnGuard
LabelGuard checks every federated leaf against the labels of the project source its alias is bound to, named by that source's catalog id. guardFor builds the label guard of one project directory; it is called once per directory. A source of no project (ProjectDir "") is named by no label.
func Saved ¶
func Saved(ctx context.Context, queryDef *datatug.QueryDef, r Resolver) (dal.StructuredQuery, map[string]Binding, error)
Saved parses a saved TugQL query once and binds every database it reads: the aliases its text declares and the database names its sources carry, subqueries included. A query that reads no named database has no bindings.
func SavedUnqualifiedMessage ¶
SavedUnqualifiedMessage refuses a saved query's source that names no database while another does. It is worded for both forms of a saved query.
func Sources ¶
func Sources(query dal.StructuredQuery, visit func(dal.CollectionRef))
Sources calls visit with every collection a query reads: its root and joined sources and, as DALgo's own database collection does, the sources of every subquery — a FROM subquery, an EXISTS or NOT EXISTS, and a subquery in a column, a condition, a GROUP BY or an ORDER BY expression.
func Unqualified ¶
func Unqualified(query dal.StructuredQuery) string
Unqualified is the first source of query, in walk order, that names no database, or "". DALgo's federated execution needs every source qualified.
func UnqualifiedMessage ¶
UnqualifiedMessage refuses a source with no alias next to a databases block.
Types ¶
type Binding ¶
type Binding struct {
// URL is the source opened; it never leaves the process.
URL string
// Ref is the datatug:// reference of a project source, written in full, or
// nil for a source with no registered project. It is the only form of the
// source a result records.
Ref *dbcopy.DatatugRef
// ProjectDir, Env and Catalog name the project source whose labels apply;
// ProjectDir is "" for a source no label names.
ProjectDir string
Env string
Catalog string
}
Binding is the source one database alias reads.
type Error ¶
type Error string
Error is a database of a saved query that cannot be bound: a usage error.
type Resolver ¶
type Resolver struct {
// ProjectID is the registered id of the query's project, "" when it has none.
ProjectID string
// ProjectDir is the query's project directory.
ProjectDir string
// Environment is the run's environment. It is called only when the query
// binds a database.
Environment func(ctx context.Context) (string, error)
// Local resolves a name of a source of the query's own project in env to
// the source's URL and its catalog id: the one name its sensitivity labels
// use, whichever of the source's names the query wrote.
Local func(ctx context.Context, env, name string) (url, catalog string, err error)
// Foreign binds a datatug:// target that names another project. Nil
// refuses one.
Foreign func(ctx context.Context, target string) (Binding, error)
}
Resolver resolves the project sources of one saved-query run.