Skip to main content

Module sqlx

Module sqlx 

Source
Expand description

Dataform SQLX handling shared by every reader and rewrite.

Mirrors kumo_sql_prover.sqlx and sqlx_fragments. A SQLX file splits into config, js, pre_operations, post_operations and input "name" blocks (kept byte for byte) and SQL sections. ${...} interpolations in SQL are masked with SQL-safe sentinels for parsing and restored afterwards; a restore that finds a sentinel lost or duplicated fails rather than producing different SQL.

Dataform leaves a ${...} inside a -- or /* */ comment as text, so those are never masked or read as references. A # comment is not one of them: @dataform/cli 3.0.71 evaluates ${ref(...)} after #.

Structs§

MaskedSqlx
SQL with its interpolations replaced by sentinels.
RefCall
One ref(...), resolve(...), self() or when(...) call in a masked interpolation.
RefTarget
A literal ref/resolve target.
SqlxAssertions
The assertions: {...} block.
SqlxBigQuery
The bigquery: {...} block (and its top-level spellings).
SqlxColumn
Documentation of one column (columns: {a: "text"} or {a: {description, columns, bigqueryPolicyTags}}).
SqlxConfig
What a config block says, read without running it.
SqlxRestoration
How to put one interpolation back.
SqlxSection
One section with its exact text and where it sits in the file.

Enums§

RefFunction
A Dataform function called in an interpolation.
SqlxDependency
A dependency named in dependencies: [...].
SqlxSectionKind
What a section of a SQLX file is.

Constants§

LOADER_TOKEN_REASON
Refused: the text holds a positional sentinel, which means different things in different models.
STRING_REASON
Refused: a string literal holds a masked expression, so its value is unknown.

Functions§

content_sentinel
The content-derived sentinel for an interpolation: __sqlx_<16 hex of sha256>__.
decode_sqlx_bytes
File text from bytes: UTF-8 with any byte-order mark dropped (it would hide a leading config block), else Windows-1252.
defuse_comment_templates
sql with each ${ inside a -- or /* */ comment written $ {, so it is never read as an interpolation (Dataform does not evaluate it).
dynamic_sentinels
Content sentinels of every interpolation in sql that is not a relation reference.
is_relation_reference
Whether a ${...} always expands to exactly one table or view name: self(), or one ref(...)/resolve(...) call whose closing parenthesis ends the expression, with no template literal, comment, / or backslash in its arguments.
is_table_reference
${ref("t")}, ${ref("dataset", "t")}, ${resolve("t")} or ${self()}: one table name once compiled.
looks_like_sqlx
Whether text looks like Dataform SQLX: it has a block (config {, js {, …) at the start of a line, or a ${ anywhere.
mask_sqlx
Replace every ${...} outside --//* */ comments with a SQL-safe sentinel and record how to restore it. An interpolation that opens or continues a condition (${when(incremental(), "WHERE x > 1")}) is masked with the clause keyword beside it so the masked text still parses.
mask_sqlx_by_content
Mask with sentinels derived from each interpolation’s text, so the same interpolation has the same sentinel wherever a rewrite moves it.
masked_template_problem
Why a prover must not read these masked texts as they are, or None.
outside_sql_comments
The matches of pattern in sql that do not start inside a -- or /* */ comment.
parse_sqlx_config
Read a config { ... } block (or just its { ... }) without running it. An empty block, tags: [], trailing commas, unquoted keys, single-quoted strings and // comments are fine; computed values are listed in SqlxConfig::computed.
restore_sqlx
Put the interpolations back into rewritten (a rewrite of masked.masked). Fails when a sentinel was lost or duplicated, or separated from the connective it stands with.
restore_sqlx_interpolations
restore_sqlx from the restorations alone.
split_sqlx_sections
Split SQLX into SQL sections and blocks, in order. The result always ends with a SQL section (possibly empty), and joining the texts gives back the input.
sql_comment_spans
(start, end) of every -- and /* */ comment in SQL.
with_preserved_whitespace
transformed with original’s leading and trailing whitespace.