TugQT: a query tree you can diff
Store a TugQL read query as structured YAML, review a changed field in Git, and validate the serialized document.
The YAML document
This Go TugQL serialization selects invoice IDs above 10. Each query part is a YAML node rather than an opaque SQL string.
from:
name: Invoice
where:
op: '>'
left:
field: InvoiceId
right:
value: 10
orderBy:
- field: InvoiceId
columns:
- field: InvoiceId
The from node names a source, where contains a comparison tree, and columns is the output projection. The Go library's Deserialize and Serialize APIs accept and emit this document; this exact sample was round-tripped against the current Go source.
Review a change in Git
Save the document in a file such as queries/invoices.tugql.yaml. Changing the threshold produces a focused diff:
right:
- value: 10
+ value: 20
Reviewers can see which predicate changed without comparing an encoded query string. Keep connection credentials outside the query document.
Validate the serialized form
The published JSON Schema describes the Go library's YAML serialization of the core relational read-only structured query subset. It uses JSON Schema draft 2020-12. YAML can be parsed to JSON-compatible values and validated against that schema before a caller resolves or executes the query.
The SQL-like text parsers also use versioned authoring trees. Those are separate representations; the linked serialization schema does not claim to validate them. See the Go implementation and language references for their current contracts.