Xqlite.TypeExtension.UUID (Xqlite v0.8.0)
View SourceType extension for canonical UUID text ↔ compact 16-byte storage.
Encodes a canonical hyphenated UUID string (36 chars, 8-4-4-4-12 hex,
case-insensitive) to the raw 16-byte binary it represents — half the size of
the textual form. SQLite stores that binary with BLOB affinity in the common
case (real UUIDs are not valid UTF-8); the rare value whose bytes do form
valid UTF-8 (e.g. the nil UUID) is stored as TEXT instead. Both are 16 bytes
and decode identically.
Only the canonical hyphenated form is encoded. A raw 16-byte binary passed to
encode/1 returns :skip — encoding it would be indistinguishable from an
ordinary blob a caller wanted stored verbatim.
Decode is a 16-byte heuristic, not a type
SQLite has no UUID type, and rows arrive as plain Elixir binaries with no
storage-class tag attached. decode/1 therefore cannot tell a 16-byte
BLOB from a 16-character TEXT value — it converts any 16-byte binary to
a UUID string. A column holding the 16-character string "abcdefghijklmnop"
will decode to "61626364-6566-6768-696a-6b6c6d6e6f70".
Enable this extension only when every 16-byte value your query returns is a UUID, and order it in the chain accordingly (place extensions that match other 16-byte shapes first — they win via first-match).
Decoded strings are always lowercase and hyphenated.