From ef2f89897821c9ef8c70a74e4b46329ad7112a7a Mon Sep 17 00:00:00 2001 From: Lindsay Holmwood Date: Fri, 27 Nov 2026 01:39:18 +1100 Subject: [PATCH 1/2] docs(golang): name the types that implement driver.Valuer The encrypt README and package doc said every stored type implements driver.Valuer and sql.Scanner. The struct that stashgen writes for a field with encrypt or index=, such as EncryptedUserEmail, implements neither: it has no Value or Scan method, and stashgen writes none. The docs now name the types that do: encrypt.Ciphertext, the term types, and every type in encrypt/eql. They say to bind and scan each field of the per-field struct as its own column. The query section said every query type implements driver.Valuer, but a Range does not; it now lists the query types that do. Refs #1861 Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01CtEQzxj55RUn35dkbhdwQk --- languages/golang/CHANGELOG.md | 9 +++++++++ languages/golang/cmd/stashgen/README.md | 1 + languages/golang/encrypt/README.md | 18 +++++++++++++----- languages/golang/encrypt/doc.go | 16 +++++++++++++--- 4 files changed, 36 insertions(+), 8 deletions(-) diff --git a/languages/golang/CHANGELOG.md b/languages/golang/CHANGELOG.md index bd7ebcd19..62f09e10d 100644 --- a/languages/golang/CHANGELOG.md +++ b/languages/golang/CHANGELOG.md @@ -13,6 +13,15 @@ and `languages/golang/encrypt/encrypttest/vX.Y.Z` on the same commit. ## [Unreleased] +### Fixed + +- **The docs name the types that implement `driver.Valuer`** (#1861). They + said every stored type does. The struct that stashgen writes for a field + with `encrypt` or `index=`, such as `EncryptedUserEmail`, does not. Bind + and scan each of its fields as its own column. The docs also said every + query type implements `driver.Valuer`. A `Range` does not: it binds as two + parameters. + ## [0.1.0-rc.7] - 2026-11-25 ### Upgrading from rc.6 diff --git a/languages/golang/cmd/stashgen/README.md b/languages/golang/cmd/stashgen/README.md index 5c4b1800a..f6810bbe3 100644 --- a/languages/golang/cmd/stashgen/README.md +++ b/languages/golang/cmd/stashgen/README.md @@ -377,6 +377,7 @@ For `-type User`, the file `user_stash.go` holds: A passthrough field keeps its Go type. A field with `encrypt_into` holds one EQL value. A field with `encrypt` or `index=` holds a struct with one field for each output, such as `Email.Ciphertext` and `Email.Equality`. + That struct is not a `driver.Valuer` or an `sql.Scanner`. Bind and scan each of its fields as its own column. The types of its fields, `encrypt.Ciphertext` and the term types, implement both. - `Encrypt` and `Decrypt`, which take a slice and return a slice, and send one ZeroKMS request for each 500 sealed values in it, plus one the first time a keyset is used. - `Fields`, with one entry for each sealed field. An opaque struct, or a struct with no sealed field outside an opaque one, gets no `Fields`: nothing in it is sealed on its own, so nothing can be queried. diff --git a/languages/golang/encrypt/README.md b/languages/golang/encrypt/README.md index 6e67a1e8a..29e4bae6c 100644 --- a/languages/golang/encrypt/README.md +++ b/languages/golang/encrypt/README.md @@ -361,8 +361,14 @@ A field with `encrypt` and `index=` is a struct with one field for each output: `Ciphertext` (`encrypt.Ciphertext`, the frozen stack-encrypt leaf), and `Equality`, `Match`, `Ore` or `Ope` (the term types). A field with `encrypt` alone has `Ciphertext` only. A passthrough field keeps its Go type. -An `opaque` struct is one `Sealed` field. Every stored type implements -`driver.Valuer` and `sql.Scanner`. +An `opaque` struct is one `Sealed` field. + +Each stored value is one column. `encrypt.Ciphertext`, the term types and +every type in `encrypt/eql` implement `driver.Valuer` and `sql.Scanner`, so a +database library binds and scans each one. The struct that contains a +field's outputs, such as `EncryptedUserEmail`, implements neither. Bind and scan each +of its fields as its own column: `Email.Ciphertext`, `Email.Equality`. A +passthrough field implements them only when its own Go type does. A sealed field outside an opaque struct is one value of one of these types, or a type defined over one (`type Email string`): @@ -471,9 +477,11 @@ bytes, so the term would be stored, where anyone who reads the column can compare it, and no query could use it. A match index on an index-only field (`index=match` with no `encrypt`) is refused, because `Verify` checks a match query's rows by decrypting them. -Every query type implements `driver.Valuer`, so it binds as a parameter in -any library built on `database/sql` or pgx. A `Range` binds as two -parameters, `Low` and `High`. On an EQL column a range is one value instead: +`encrypt.EqualityTerm`, `encrypt.OreTerm`, `encrypt.OpeTerm`, +`encrypt.MatchQuery`, `encrypt.EQLMatchQuery` and every query type in +`encrypt/eql` implement `driver.Valuer`. Each binds as one parameter in any +library built on `database/sql` or pgx. A `Range` does not: it binds as +two parameters, `Low` and `High`. On an EQL column a range is one value instead: package `encrypt/eql` has a range query type per ordered family and order index (`eql.IntegerRangeOreQuery`, `eql.TextRangeOpeQuery`, ...), the one operand of `eql_v4.between(column, $1::eql_v4.query_integer_range_ore)`. Keep diff --git a/languages/golang/encrypt/doc.go b/languages/golang/encrypt/doc.go index 3003f54b6..260577a12 100644 --- a/languages/golang/encrypt/doc.go +++ b/languages/golang/encrypt/doc.go @@ -146,7 +146,15 @@ // the Rust crate derives, so a term from a generated Fields entry compares // against a stored term from any language. The indexes are [Equality], // [Match], [Ore] and [Ope]; [JSON] is declared and refused until the engine -// derives it. Every stored type implements driver.Valuer and sql.Scanner. +// derives it. +// +// Each stored value is one column. [Ciphertext], the term types and every +// type in package eql implement driver.Valuer and sql.Scanner, so a +// database library binds and scans each one. The struct that generated code +// writes for a field's outputs (EncryptedUserEmail, with Ciphertext and +// Equality fields) implements neither. Bind and scan each of its fields as +// its own column. A passthrough field implements them only when its own Go +// type does. // // A match index stores text with no token (an empty string, separator-only // text, or text shorter than the n-gram length of 3 characters) as the empty @@ -178,8 +186,10 @@ // [MatchQuery.Verify] reports true, one call into the engine for the page. // On a field with encrypt_into=TextMatch, Matches returns an // [EQLMatchQuery], the type's query value with the same two methods. -// Every query type implements driver.Valuer, so it binds as a parameter -// through database/sql or pgx. With separate byte columns, as the example/ +// [EqualityTerm], [OreTerm], [OpeTerm], [MatchQuery], [EQLMatchQuery] and +// every query type in package eql implement driver.Valuer. Each binds as +// one parameter through database/sql or pgx. A [Range] does not: bind its +// Low and High as two parameters. With separate byte columns, as the example/ // program declares its fields (Email `stash:"email,encrypt,index=equality;match"`, // Age `stash:"age,encrypt,index=equality;ore"`), not the encrypt_into User // above: From 687be358447e5b50f393e17cb88ef9c1ff75f75e Mon Sep 17 00:00:00 2001 From: Lindsay Holmwood Date: Fri, 27 Nov 2026 02:47:15 +1100 Subject: [PATCH 2/2] docs(golang): say a pointer implements sql.Scanner, and exclude eql.Type Each Scan method in encrypt and encrypt/eql has a pointer receiver, so a pointer to the type implements sql.Scanner and the value does not. The docs now say so, and show scanning into a field's address. "Every type in encrypt/eql" included eql.Type, the catalog struct, which has no Value or Scan method. The README, doc.go and the eql package doc now say every value and query type. The README also says that an opaque struct's Sealed field is an encrypt.Ciphertext, and two edited lines are wrapped again. Refs #1861 Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01CtEQzxj55RUn35dkbhdwQk --- languages/golang/cmd/stashgen/README.md | 2 +- languages/golang/encrypt/README.md | 19 +++++++++++-------- languages/golang/encrypt/doc.go | 5 +++-- languages/golang/encrypt/eql/eql.go | 7 ++++--- 4 files changed, 19 insertions(+), 14 deletions(-) diff --git a/languages/golang/cmd/stashgen/README.md b/languages/golang/cmd/stashgen/README.md index f6810bbe3..2aa9fdc07 100644 --- a/languages/golang/cmd/stashgen/README.md +++ b/languages/golang/cmd/stashgen/README.md @@ -377,7 +377,7 @@ For `-type User`, the file `user_stash.go` holds: A passthrough field keeps its Go type. A field with `encrypt_into` holds one EQL value. A field with `encrypt` or `index=` holds a struct with one field for each output, such as `Email.Ciphertext` and `Email.Equality`. - That struct is not a `driver.Valuer` or an `sql.Scanner`. Bind and scan each of its fields as its own column. The types of its fields, `encrypt.Ciphertext` and the term types, implement both. + That struct is not a `driver.Valuer` or an `sql.Scanner`. Bind and scan each of its fields as its own column. The types of its fields, `encrypt.Ciphertext` and the term types, implement `driver.Valuer`, and a pointer to each implements `sql.Scanner`. - `Encrypt` and `Decrypt`, which take a slice and return a slice, and send one ZeroKMS request for each 500 sealed values in it, plus one the first time a keyset is used. - `Fields`, with one entry for each sealed field. An opaque struct, or a struct with no sealed field outside an opaque one, gets no `Fields`: nothing in it is sealed on its own, so nothing can be queried. diff --git a/languages/golang/encrypt/README.md b/languages/golang/encrypt/README.md index 29e4bae6c..5f8df8c2d 100644 --- a/languages/golang/encrypt/README.md +++ b/languages/golang/encrypt/README.md @@ -361,14 +361,17 @@ A field with `encrypt` and `index=` is a struct with one field for each output: `Ciphertext` (`encrypt.Ciphertext`, the frozen stack-encrypt leaf), and `Equality`, `Match`, `Ore` or `Ope` (the term types). A field with `encrypt` alone has `Ciphertext` only. A passthrough field keeps its Go type. -An `opaque` struct is one `Sealed` field. +An `opaque` struct is one `Sealed` field, an `encrypt.Ciphertext`. Each stored value is one column. `encrypt.Ciphertext`, the term types and -every type in `encrypt/eql` implement `driver.Valuer` and `sql.Scanner`, so a -database library binds and scans each one. The struct that contains a -field's outputs, such as `EncryptedUserEmail`, implements neither. Bind and scan each -of its fields as its own column: `Email.Ciphertext`, `Email.Equality`. A -passthrough field implements them only when its own Go type does. +every value and query type in `encrypt/eql` implement `driver.Valuer`, and +a pointer to each implements `sql.Scanner`. So a database library binds +each one, and scans into its address (`rows.Scan(&e.Email.Ciphertext)`). + +The struct that contains a field's outputs, such as `EncryptedUserEmail`, +implements neither interface. Bind and scan each of its fields as its own +column: `Email.Ciphertext`, `Email.Equality`. A passthrough field +implements them only when its own Go type does. A sealed field outside an opaque struct is one value of one of these types, or a type defined over one (`type Email string`): @@ -480,8 +483,8 @@ is refused, because `Verify` checks a match query's rows by decrypting them. `encrypt.EqualityTerm`, `encrypt.OreTerm`, `encrypt.OpeTerm`, `encrypt.MatchQuery`, `encrypt.EQLMatchQuery` and every query type in `encrypt/eql` implement `driver.Valuer`. Each binds as one parameter in any -library built on `database/sql` or pgx. A `Range` does not: it binds as -two parameters, `Low` and `High`. On an EQL column a range is one value instead: +library built on `database/sql` or pgx. A `Range` does not: it binds as two +parameters, `Low` and `High`. On an EQL column a range is one value instead: package `encrypt/eql` has a range query type per ordered family and order index (`eql.IntegerRangeOreQuery`, `eql.TextRangeOpeQuery`, ...), the one operand of `eql_v4.between(column, $1::eql_v4.query_integer_range_ore)`. Keep diff --git a/languages/golang/encrypt/doc.go b/languages/golang/encrypt/doc.go index 260577a12..3bfce858f 100644 --- a/languages/golang/encrypt/doc.go +++ b/languages/golang/encrypt/doc.go @@ -149,8 +149,9 @@ // derives it. // // Each stored value is one column. [Ciphertext], the term types and every -// type in package eql implement driver.Valuer and sql.Scanner, so a -// database library binds and scans each one. The struct that generated code +// value and query type in package eql implement driver.Valuer, and a +// pointer to each implements sql.Scanner. So a database library binds each +// one, and scans into its address. The struct that generated code // writes for a field's outputs (EncryptedUserEmail, with Ciphertext and // Equality fields) implements neither. Bind and scan each of its fields as // its own column. A passthrough field implements them only when its own Go diff --git a/languages/golang/encrypt/eql/eql.go b/languages/golang/encrypt/eql/eql.go index 76d49448e..8e6ba54b4 100644 --- a/languages/golang/encrypt/eql/eql.go +++ b/languages/golang/encrypt/eql/eql.go @@ -6,9 +6,10 @@ // generated encrypted type, and its Fields entry's Eq returns a // [TextEqQuery]. The guest builds every value: generated code stores what // the guest returns and never assembles an EQL value itself (ADR-0007, -// amended 2026-10-06). Each type implements driver.Valuer and sql.Scanner -// for one column, and json.Marshaler, which writes the value as the JSON -// it is. It prints (fmt.Stringer, fmt.Formatter, for every verb) and logs +// amended 2026-10-06). Each value and query type implements driver.Valuer +// for one column, and a pointer to it implements sql.Scanner. Each also +// implements json.Marshaler, which writes the value as the JSON it is. It +// prints (fmt.Stringer, fmt.Formatter, for every verb) and logs // (slog.LogValuer) as its type's name and never its bytes, so fmt.Sprint // and %s do not give its JSON: a stored value holds ciphertext and terms, // and a query value terms. To print or log the JSON on purpose, call