Skip to content

Catalog API

The catalog module manages schema definitions, table metadata, and type affinity.

Table Definitions

zig
const catalog = @import("catalog");

// Table definition
const table_def = catalog.TableDef{
    .name = "users",
    .columns = &.{
        .{ .name = "id", .type = .integer, .primary_key = true },
        .{ .name = "name", .type = .text },
    },
};

Schema Management

zig
const schema = @import("schema");

// Get current schema
const current_schema = try schema.Schema.init(allocator, &connection);

// Clone for backup
const backup = try current_schema.clone();

Type Affinity

SQLite uses type affinity to determine how values are stored:

AffinityStorageDescription
INTEGER1-8 bytesWhole numbers
REAL8 bytesFloating-point
TEXTVariableText strings
BLOBVariableBinary data
NULL0 bytesNull values

Column Definitions

zig
const column = catalog.ColumnDef{
    .name = "email",
    .type = .text,
    .nullable = false,
    .unique = true,
};

Index Definitions

zig
const index_def = catalog.IndexDef{
    .name = "idx_users_email",
    .table_name = "users",
    .columns = &.{"email"},
    .unique = true,
};

Key Definitions

zig
// Primary key
const pk = User.key("id");

// Composite primary key
const cpk = &.{ User.key("a"), User.key("b") };

Released under the MIT License.