examples/

directory
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 11, 2026 License: Apache-2.0

README

examples

Code that exists to be read, and to prove claims that prose cannot.

Nothing here is a toy. Every statement in this tree is built by a test whose expected SQL is written into the test, so a change in rendering fails the build rather than quietly changing what the documentation says. When a page in docs/ shows a snippet, this is usually where it came from.

The tree

Directory What it is Size
cookbook/ Twelve recipes, and the four packages that tell the cross-package story the library exists for 12 examples
packages/ One file per layer — render, expr, stmt, exec, results, schema — the source of the per-package documentation snippets 43 examples
typecheck/ The one file in the repository that must not compile 8 statements
pgsurface/ The Postgres surface, area by area 89 examples
pgsurface/advancedsql/ An external catalogue of advanced PostgreSQL queries, translated section by section 53 examples
pgsurface/snippets/ A 21-section catalogue of advanced Postgres snippets, in the original order 159 examples
pgsurface/periodcompare/ One worked report: a multi-source period comparison, the hardest shape a reporting API has 5 examples

The pgvector README is translated query by query in pg/vector/example_test.go, which lives beside the package it documents rather than here.

Running them

task cookbook   # the recipes with their rendered SQL
task surface    # the Postgres catalogue with its rendered SQL
task typecheck  # compiles the negative build and fails if it succeeds

go test ./examples/...                                    # all of it
go test ./examples/cookbook -run Example_loadComposite -v  # one recipe

A PASS means the SQL in that example's // Output: block is byte-for-byte what the builder produced. There is no mode in which a passing example prints something other than what is written down.

Why an example rather than a test

A test answers "does this work". An example answers "what does this look like", and prints the SQL so the answer can be read without running anything. Both are checked by go test, so the second costs nothing in trust: the documentation and the assertion are the same three lines.

The limit is worth stating plainly. An example proves the text; only execution proves the SQL. Nothing in this tree opens a database — the core module has no driver and cannot. Execution lives in contrib/driver-sqlite and contrib/driver-pgx, where the same constructs run against real servers, and where eleven pg constructs were once found whose rendering tests passed and whose SQL Postgres rejects.

Directories

Path Synopsis
cookbook
app
Package app is the application side of the cross-package story: the code that owns no library, imports three of them, and consolidates what they each own into one statement.
Package app is the application side of the cross-package story: the code that owns no library, imports three of them, and consolidates what they each own into one statement.
authlite
Package authlite is a deliberately small stand-in for a ubgo library that owns tables, for the cookbook.
Package authlite is a deliberately small stand-in for a ubgo library that owns tables, for the cookbook.
phone
Package phone is the plugin shape: it borrows a core table under its own alias and contributes a join plus bindings to a composite user.
Package phone is the plugin shape: it borrows a core table under its own alias and contributes a join plus bindings to a composite user.
workspace
Package workspace is the second-library shape: it owns tables that refer to a user by id, and it does not import the auth library.
Package workspace is the second-library shape: it owns tables that refer to a user by id, and it does not import the auth library.
pgsurface
advancedsql
Package advancedsql translates an external catalogue of advanced PostgreSQL queries into sqlb and checks the rendered SQL.
Package advancedsql translates an external catalogue of advanced PostgreSQL queries into sqlb and checks the rendered SQL.
periodcompare
Package periodcompare builds a period-comparison report over several fact tables in Postgres: sales for the current, previous and third-year periods, current stock, stock at a past snapshot date, open purchase orders and advertising spend, all keyed by one chosen dimension.
Package periodcompare builds a period-comparison report over several fact tables in Postgres: sales for the current, previous and third-year periods, current stock, stock at a past snapshot date, open purchase orders and advertising spend, all keyed by one chosen dimension.
snippets
Package snippets translates a catalogue of advanced PostgreSQL snippets into sqlb, section by section and in the catalogue's own order and numbering.
Package snippets translates a catalogue of advanced PostgreSQL snippets into sqlb, section by section and in the catalogue's own order and numbering.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL