src/sydra/catalog.zig
Purpose
Bootstraps a minimal PostgreSQL-style catalog (schemas/relations/types/columns) into the global compatibility store (compat.catalog.global()).
This module is invoked during startup (src/sydra/server.zig calls catalog.bootstrap) so pgwire and compatibility queries have a baseline pg_catalog model available.
Public API
pub const NamespaceInfo
name: []const u8owner: u32 = 10
pub const RelationInfo
namespace: []const u8name: []const u8kind: compat.catalog.RelationKindpersistence: compat.catalog.Persistence = .permanenthas_primary_key: bool = falserow_estimate: f64 = 0is_partition: bool = falsetoast_relation_oid: ?u32 = null
pub const TypeInfo
Maps directly onto compat.catalog.TypeSpec fields:
name,namespace,oid,length,by_valuekind: compat.catalog.TypeKind = .basecategory: u8 = 'U',delimiter: u8 = ','- array/element/base type OIDs, collation, input/output regprocs
pub const ColumnInfo
Maps directly onto compat.catalog.ColumnSpec fields:
namespace,relation,name,type_oidposition: ?i16 = null- nullability/default/drop flags
- type length/modifier
- identity/generated kind
dimensions: i32 = 0
pub const Adapter
An adapter is just a set of slices describing the desired catalog contents:
namespaces: []const NamespaceInforelations: []const RelationInfotypes: []const TypeInfocolumns: []const ColumnInfo
pub fn defaultAdapter() Adapter
Returns an Adapter backed by file-scoped arrays that model:
- namespaces:
pg_catalog,public - relations:
pg_catalog.pg_type(table) - types: a small set of common scalar and array types (e.g.
int4,text,_int4,_text, …) - columns: a minimal
pg_type“shape” with fields likeoid,typname,typlen,typbyval, etc.
const default_namespaces = [_]NamespaceInfo{
.{ .name = "pg_catalog" },
.{ .name = "public" },
};
const default_relations = [_]RelationInfo{
.{ .namespace = "pg_catalog", .name = "pg_type", .kind = .table },
};
pub fn defaultAdapter() Adapter {
return Adapter{
.namespaces = &default_namespaces,
.relations = &default_relations,
.types = &default_types,
.columns = &default_columns,
};
}
pub fn loadIntoStore(store: *compat.catalog.Store, alloc: std.mem.Allocator, adapter: Adapter) !void
Loads the adapter into a compatibility catalog store:
- Allocates temporary
[]compat.catalog.*Specarrays and fills them from the*Infoslices. - Calls
store.load(alloc, ns_specs, rel_specs, type_specs, col_specs). - Frees the temporary spec arrays.
Note: store.load ultimately duplicates names into its own owned snapshot, so it is safe that the temporary spec arrays are freed immediately.
pub fn refreshGlobal(alloc: std.mem.Allocator, adapter: Adapter) !void
Convenience wrapper:
loadIntoStore(compat.catalog.global(), alloc, adapter)
pub fn bootstrap(alloc: std.mem.Allocator) !void
Bootstraps the default catalog into the global store:
refreshGlobal(alloc, defaultAdapter())
pub fn bootstrap(alloc: std.mem.Allocator) !void {
try refreshGlobal(alloc, defaultAdapter());
}
Key internal helpers
The module contains conversion helpers that allocate and fill spec arrays:
toNamespaceSpecstoRelationSpecstoTypeSpecstoColumnSpecs
Each returns an empty static slice (&[_]T{}) when the input slice is empty.