Module types
June 1, 2026 · View on GitHub
Module types
PostgreSQL data type OIDs and the extensible type codec registry.
Built-in OID constants (DataTypeOIDs)
Every PostgreSQL built-in type has a stable numeric OID. The DataTypeOIDs
dict provides named constants so user code never needs to hard-code raw
numbers:
import postgres { DataTypeOIDs }
echo DataTypeOIDs.Int4 # 23
echo DataTypeOIDs.Uuid # 2950
Type codec registry (TypeRegistry)
The TypeRegistry maps OIDs to encoder / decoder function pairs. The
singleton DefaultRegistry is pre-loaded with codecs for every type listed
in the type-mapping table. Custom types can be registered with
TypeRegistry.register().
import postgres { TypeRegistry }
# Register a custom "money" OID → Zuri number codec
TypeRegistry.register(790, @(buf) { # decode binary → number
return buf_to_int64(buf) / 100.0
}, @(value) { # encode number → binary
return int64_to_buf(value * 100)
})
Variables
DataTypeOIDs
Named constants for every PostgreSQL built-in type OID that the library
supports. Use these instead of raw integers in prepare() calls.
Array-type OIDs follow the PostgreSQL convention of being the scalar OID
minus a well-known offset; they are listed as <Type>Array.
DefaultRegistry
The shared default type registry used by all connections unless overridden. Mutate this to add global custom type support across the entire process.
Classes
class TypeRegistry
Registry that maps PostgreSQL type OIDs to binary encode / decode function
pairs. A singleton instance (DefaultRegistry) is pre-populated with
every built-in type listed in the type-mapping table.
Call register() to add support for custom types, or to override the
default behaviour of a built-in type.
Example — custom money type
import postgres { TypeRegistry }
TypeRegistry.register(
790,
)
Methods
-
TypeRegistry()(Constructor) -
register(oid, decoder, encoder)Registers a custom codec for the given OID.
Parameters
-
number oid The PostgreSQL OID to handle.
-
function decoder
@(buf_list) → value— binary → Zuri value. -
function encoder
@(value) → list— Zuri value → byte list.
-
-
decode(buf, oid)Decodes a binary buffer
buf(list of bytes) using the codec foroid. Returnsnilif no decoder is registered for the OID (text fallback).Parameters
-
list buf Raw bytes from the PostgreSQL binary wire format.
-
number oid The PostgreSQL OID of the value.
-
-
encode(value, oid)Encodes
valueto a byte list using the codec foroid.Parameters
-
any value The Zuri value to encode.
-
number oid The PostgreSQL OID for the target column / param.
-