Skip to content

Docs: the declared form first where an application writes the call, then the ad hoc one-liner - #292

Merged
electricessence merged 3 commits into
masterfrom
docs/definition-first
Dec 2, 2026
Merged

electricessence merged 3 commits into
masterfrom
docs/definition-first

Conversation

@electricessence

Copy link
Copy Markdown
Collaborator

The docs now show the declared form first where a reader is writing application code, and then the same call written ad hoc ("Or, simply expressive"), so both are on the page and a reader sees how little a one-off needs. A query is declared once, as a static readonly definition with no connection (DbQuery.Text(...).Map<T>()), and the source and the values are bound where it runs (Using(source).AddParam(...) and a terminal). Pages that demonstrate one feature in one line, or compare line counts, stay ad hoc.

Where the declared form leads

Place Change
README, Core, Channel and Dataflow package pages the declared query first (as a field of a data-access class), then the one-liner
Getting started "Your first query": declared, then from a connection you own, then the one-liners side by side
Foundation, Transactions a declared query or write on the transaction with Using(transaction), then the ad hoc transaction.Command(...)
Coming from Dapper the consumer of the registered factory: the declared query first, the one-liner second
Expressive commands "Defining a query once" moves ahead of the command form, which is retitled "Building a command where you need it"; a sentence on why AddParamIf is a command-form call (a declared query has fixed text); the scalar forms, declared first
Mapping, Terminals first and single, a new id, a dictionary, a page and a stream that stops early, each declared first, then ad hoc
Async buffers a page of a buffer, and the data layer of the controller story
Channels and Dataflow the producer is a declared query
Async reads the opt-in is part of the declaration
Shaping rows a RowMap declared with its query
What's new in 11 the DbQuery section moves to the top
Index the declared form follows the headline one-liner

Stays ad hoc: How little code (one call against one call; one sentence says what declaring adds), the rule demonstrations of Mapping, and the other feature demonstrations.

What the samples show, and what was checked

All new samples are in docsite/samples/Defined.cs, compile in the samples project, and are run and checked by the sample program (14 checks of what each returns).

The scalar forms were checked against the definition path (10 checks, all pass): Scalar<T>() converts as ExecuteScalarAsync<T>() does (a SQLite bigint as int; a value that does not fit throws ValueMappingException; no rows and NULL are null for a type that takes null and throw for one that does not; strings), and DbNonQuery returns what ExecuteNonQueryAsync returns.

Left ad hoc, on purpose, and why

  • AddParamIf: the docs' only use varies the SQL text with the same condition; a declared query has fixed text. The page says so.
  • The custom scalar conversion (ExecuteScalarAsync(value => ...)): Scalar<T>() has no overload for it.
  • The large value read as a stream with SequentialAccess(): a declared raw query has no SequentialAccess() and no public ExecuteReaderAsync (only the explicit IExecuteReader one, reached by a cast of a struct). That is an API question for the owner, not something this change papers over.

Checks

  • Samples build and all 255 sample checks pass; the docs build has 0 warnings and 0 errors; Release and Debug builds and the Core tests pass (Release 15,759; Debug 15,738 with 16 skipped); dotnet format style and analyzers at --severity info report nothing on all 14 projects, including the samples project; the pre-push scan is clean.
  • Reviewed by two Haiku reviewers (docs flow and accuracy; sample correctness and rules), arbitrated. Fixed: a lead-in sentence that now sat before the wrong sample, an explanation separated from its sample, the README snippets showing a declared query as a bare static where it is a class field, and a few comments (the insert that returns a value, the transaction cast, what the stream timeout bounds, who disposes the buffer). Not taken: renaming Post and the sample database's other names (the established sample database of every page), and the PooledArray disposal point (the view is valid until its buffer is disposed, as in the existing sample).

🤖 Generated with Claude Code

electricessence and others added 3 commits December 2, 2026 05:57
… against the definition path

Adds `Defined.cs`: the queries the docs show as one-liners, written the way an application writes them, as `static readonly` definitions (`DbQuery.Text(...).Map<T>()`, `DbNonQuery.Text(...)`, `Scalar<T>()`) with the source and the values bound where they run: a list, a list on a connection you own, a write on a transaction, the first/single, new-id, page, dictionary and early-stop terminals, a pooled buffer and stream, an `AsyncReads` declaration, a declared `RowMap`, scalars and a write.

`Program.cs` runs every new sample and checks what it returns (13 checks), and checks that the definition path reads what the same call on a command reads: `Scalar<int>()` over a SQLite bigint, `Scalar<long>()`, a value that does not fit, no rows and NULL for a type that takes null and for one that does not, `Scalar<string>()`, and `DbNonQuery` against `ExecuteNonQueryAsync` (10 checks). All pass: `Scalar<T>()` converts as `ExecuteScalarAsync<T>()` does. The custom conversion form (`ExecuteScalarAsync(Func<object?, T>)`) has no counterpart on the definition path, so that sample stays ad hoc.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…hen the ad hoc one-liner

The query an application runs again and again is declared once, as a `static readonly` definition with no connection (`DbQuery.Text(...).Map<T>()`), and bound where it runs; the docs now show that form first in the places that are application code, and then the same call ad hoc ("Or, simply expressive"), with nothing to declare. The places that demonstrate one feature in one line, or compare line counts, stay ad hoc.

- Declared first: the README, the Core, Channel and Dataflow package pages, Getting started (the first query, and from a connection you own), the foundation's transactions (`Using(transaction)`), Coming from Dapper (the consumer of the registered factory), Expressive commands ("Defining a query once" moves ahead of the command form, which is retitled "Building a command where you need it"), the mapping terminals (first and single, a new id, a dictionary, a page, a stream that stops early), the async buffers (a page, the data layer), Channels and Dataflow (the producer), Async reads (the opt-in is part of the declaration), Shaping rows (a map declared with its query), and What's new (the `DbQuery` section moves to the top).
- Stays ad hoc: How little code (one call against one call; a sentence says what declaring adds), the rule demonstrations of Mapping, and the rest of the feature demonstrations.
- Said plainly: a declared query has fixed text, so `AddParamIf` is a command-form call; the scalar that converts in your own way (`ExecuteScalarAsync(value => ...)`) has no declared counterpart, while `Scalar<T>()` converts as `ExecuteScalarAsync<T>()` does (checked by the samples).

Every new sample compiles in the samples project and is run and checked there; the new regions are in `Defined.cs`.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The chain style of the new declared samples and README snippets: the first call stays on the receiver's line (`await ByAuthor.Using(connectionFactory)`), and the chain goes vertical from the second call, each call on its own line; no receiver is alone on a line. A text too long for the receiver's line breaks inside the first call's argument.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@electricessence
electricessence merged commit 41331b7 into master Dec 2, 2026
9 checks passed
@electricessence
electricessence deleted the docs/definition-first branch December 2, 2026 14:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant