Help us shape the future of Go! Take the 2026 Go Developer Survey

identity

package
v0.2.7 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package identity encodes a graph identity for storage.

A graph identity is text: graph.StableID produces a prefix, a colon, and the first 20 hex characters of a SHA-256. Stored as text that is 22 bytes for a one-letter prefix, and identity columns are the widest thing in the index -- an edge row carries three of them and each of its indexes carries two or three more. Half of those 22 bytes are hex digits spelling out 10 bytes of digest.

So an identity is stored as a BLOB holding the digest raw, which takes a 12,744-file index from 1909 MiB to 1584 MiB. Two bytes of that encoding are deliberate overhead and both buy correctness:

The separator is kept, because without it nothing marks where the prefix ends: a digest byte can be an ASCII letter -- 0x6e is 'n' -- so a decoder that scanned leading letters would mis-split real identities. Prefixes are also not one letter wide; the repository node is "repo:".

The leading tag is kept because the encoding has to be total. Not every identity is StableID output: test fixtures use identities like "a" and "a-b", and the encoding has to return them unchanged rather than corrupt them or fail. The tag says which of the two forms a value is in, so decoding needs no guess. Guessing was tried and is not possible: a literal whose tail happens to be ten bytes after a colon is indistinguishable from a compact one.

Ordering is preserved for every identity a real index holds. Compact values share a tag and then compare prefix-first and digest-second, and for equal-length lowercase hex, string order and raw-byte order agree -- so identity columns can still be ORDER BY tiebreaks and pagination cursors. The empty identity encodes to an empty BLOB, which keeps the "no target" sentinel distinct from every present identity and still sorts before all of them.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decode

func Decode(stored []byte) string

Decode returns the identity a stored value holds. It is the exact inverse of Encode: every identity of a real index, and every shape a fixture uses, comes back byte for byte.

func Encode

func Encode(id string) []byte

Encode returns the stored form of an identity.

Types

type Key

type Key string

Key is a graph identity as it crosses the storage boundary. It is the Go type sqlc generates for every identity column, so the encoding happens in Value and Scan rather than at each of the call sites that bind or read one.

func (*Key) Scan

func (k *Key) Scan(source any) error

Scan decodes a stored identity.

Text is accepted as well as BLOB, because an index may be read before its migration has run -- a migration's own statements see the old column -- and because SQLite is dynamically typed, so a value's storage class is a property of the value and not of the column it sits in.

func (Key) Value

func (k Key) Value() (driver.Value, error)

Value encodes the identity for storage.

Jump to

Keyboard shortcuts

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