stdenttypeid

package
v0.0.240 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package stdenttypeid is the Go-side companion to a Postgres `typeid` type. It carries a typeid value as its canonical *printable* form (e.g. `upld_01j8...`) on the Go side while letting ent / pgx round-trip it transparently against a `public.typeid` column.

The Postgres `typeid` is a scalar `text` domain that stores the printable form directly, so the Go-side string and the column value are the same bytes — no conversion is needed in either direction. (Historically `typeid` was a composite `(prefix text, uuid uuid)`; this package still normalises that legacy composite-literal shape on ID.Scan for robustness, but new schemas use the text domain.)

ID adapts the value at the ent column-type layer:

  • ID.Scan returns the already-printable text verbatim, and (for legacy/robustness) also normalises a composite literal `(prefix,uuid)` into the printable form. The Go-side value of a typeid column is therefore always the same shape a wire API consumes.

  • ID.FormatParam returns the placeholder verbatim. Because the column is a scalar text domain, a bare `id = $N` is a LEAKPROOF `text` comparison that pushes as an index scan-key under FORCE ROW LEVEL SECURITY — wrapping it in a function call would defeat that.

  • ID.Value passes the printable string through unchanged.

The base32 alphabet mirrors the Crockford-style alphabet (`0123456789abcdefghjkmnpqrstvwxyz`) that the companion SQL `typeid_print()` / `base32_encode()` functions use EXACTLY so the Go-side normalisation produces the same string `typeid_print()` does — round-trip tests against a known vector pin this end-to-end.

The matching Postgres-side schema (the `typeid` domain, the `typeid_parse()` / `typeid_print()` / `typeid_generate()` functions, and the Crockford `base32_encode()` helper) is the caller's responsibility; this package is the Go-side adapter only.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ID

type ID string //nolint:recvcheck // sql.Scanner needs pointer; ent calls Value/FormatParam on value.

ID is the Go-side companion to a Postgres `typeid` composite. The zero value is the empty string; non-empty values are always in printable form (`prefix_base32suffix`).

Use ID via ent's `field.String("...").GoType(stdenttypeid.ID(""))` declaration; ent will hand out and accept ID values everywhere the column appears (predicates, builders, mutations, edges that reuse the column via `.Field("...")`).

Receiver mix is deliberate: ID.Value, ID.String and ID.FormatParam are value receivers because ent passes the ID by value into its SQL builder (where the interface assertions live), and ID.Scan is a pointer receiver because the database/sql.Scanner contract requires it. This is the same pattern github.com/google/uuid uses; the recvcheck linter is silenced at the type declaration only.

func (ID) FormatParam

func (id ID) FormatParam(placeholder string, _ *entsql.StmtInfo) string

FormatParam implements ent's entsql.ParamFormatter interface, which ent's SQL builder calls for every parameter that is bound from this Go type. The Postgres `typeid` type is a scalar `text` domain, so the bound printable string needs no conversion and the placeholder is returned verbatim. This is deliberate: `text` `=`/`<`/`>` are LEAKPROOF, so a bare `id = $N` predicate pushes as an index scan-key under FORCE ROW LEVEL SECURITY. Wrapping the placeholder in a function call (as the historical composite-typeid form did with `public.typeid_parse(...)`) would defeat that pushdown.

func (*ID) Scan

func (id *ID) Scan(src any) error

Scan implements database/sql.Scanner. Accepts both the raw composite literal Postgres emits for a `typeid` column (`(prefix,uuid)`) and the already-printable form (`prefix_base32`) — the latter so callers that select `typeid_print(id)` directly continue to work unchanged.

func (ID) String

func (id ID) String() string

String returns the printable form of the id.

func (ID) Value

func (id ID) Value() (driver.Value, error)

Value implements database/sql/driver.Valuer. The driver sees the printable string, which is exactly what a scalar `typeid` text domain column stores.

Jump to

Keyboard shortcuts

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