TGL: Overview
TGL: Overview
What is TGL?
TGL (Tailglow Query Language) is the small scripting language used inside views to transform data one record at a time. A view can read records from a collection or from another view. For each input record, the TGL script reads fields from $row, builds an output object in $out, and either emits one record or drops the input.
You don’t have to write TGL by hand. When you create a view, Tailglow generates a script for you using the output schema (and any optional hint you provide). But once it’s generated, you can edit it, and a lot of useful patterns like filtering rows, computing totals, and deriving fields only need a few lines of TGL.
Hello world
$out.id = $row.id
$out.name = upperCase($row.name) That’s a complete, valid TGL script. For each input record, it copies the id field through and uppercases the name. The view this powers will have one record out for every valid input record.
How a TGL script runs
Every input record follows the same steps:
- Make the input available as
$row. - Run the TGL script and build
$out. - If the script sets
$out = null, drop the input record. - Otherwise, add
$outto the view.
A successful input produces at most one output record. Invalid rows and rows that exceed a safety limit are skipped; a structurally invalid output can fail the transform. See Recipes for error handling and limits.
What’s on each page
This guide is split into focused sections. Read in order if you’re new, or jump to whatever you need:
- Syntax: variables, statements, comments, what
$row,$meta, and$outmean. - Control flow: filtering rows, conditionals (
#if/#elseif/#else//if), loops (#each). - Operators: comparison, logical, nullish coalescing, plus type semantics and null propagation.
- Functions: every built-in function (math, string, array, type, date) with examples and null-handling notes.
- Recipes: common patterns, plus the limits, validation, and error model.
Where else TGL shows up
- Views for how transforms fit into the view pipeline.
- API reference:
- Create View Transform
- Update View Transform
- Generate TGL with AI