Skip to main content

Module rewrite

Module rewrite 

Source
Expand description

Imposition of this tool’s own row ceiling on a caller’s query.

§Why the query is not wrapped in a sub-query

The Rust reference implementation paginates by wrapping the caller’s query as a sub-query and selecting from it. That breaks two legitimate queries:

  • SELECT a + 1 FROM t has an unnamed column, and a derived table demands that every column be named.
  • SELECT t.a, u.a FROM t JOIN u has a repeated column name, and a derived table demands that every name be distinct.

Labelling those columns would work, but it changes the names the caller asked for, and the caller reads results by name. So this module does not wrap and does not relabel. It reads the syntax tree to prove the query has no row clause of its own, then appends the ceiling to the original text.

§Why the text is appended rather than re-rendered

Rendering the tree back to text would drop a conditional comment, whose body is executable on this server, and would normalise spacing the caller wrote. Appending leaves every byte the caller sent untouched except the suffix.

A query that already carries a clause this module cannot append after is refused with a named reason rather than silently rewritten.

Functions§

with_limit
Imposes a row ceiling and a starting offset on a caller’s query.