Skip to documentation
SLOP

tiny.sql.LifecycleWorkspace

Reference tiny.sql LifecycleWorkspace

Defined in lifecycle.

Owns one database and the storage that database runs on, created by a tool at startup to open its database through it.

API (15)

Actions

Public operations.

Types and contracts

Public types and contracts.

Fields and members

Public fields and members.

No direct callersNo direct callslifecycleWorkspace
Static calls · unresolved targets: unknown · external targets: unknown.

Source

Source: lib/sql/src/lifecycle.zig:27

zig
/// Owns one database and the storage that database runs on, created by a tool/// at startup to open its database through it. The workspace holds the file/// workspace and, once opened, the database itself, and hands callers a pointer/// to that database. Because callers hold that pointer, the workspace has to/// stay at one address from the open until the opened database is released, so/// callers place it on the heap. The workspace takes its storage either from/// the caller with `init` or from an allocator with `allocate`, and gives it/// back with the matching `deinit` or `deallocate`. The workspace opens one/// database at a time, reports `WorkspaceBusy` for a second open while the/// first is live, and refuses teardown by assertion while a database is still/// open.pub const Workspace = struct {    pub const Limits = file_mod.Database.Workspace.Limits;    pub const Capacity = file_mod.Database.Workspace.Capacity;    pub const Storage = file_mod.Database.Workspace.Storage;    pub const InitError = file_mod.Database.Workspace.InitError;    pub const AllocateError = file_mod.Database.Workspace.AllocateError;    pub const AcquireError = file_mod.Database.Workspace.AcquireError;    file_workspace: file_mod.Database.Workspace,    database: file_mod.Database = undefined,    database_live: bool = false,    pub fn init(        storage: Storage,        limits: Limits,    ) InitError!Workspace {        return .{            .file_workspace = try file_mod.Database.Workspace.init(storage, limits),        };    }    pub fn allocate(allocator: Allocator, limits: Limits) AllocateError!Workspace {        return .{            .file_workspace = try file_mod.Database.Workspace.allocate(allocator, limits),        };    }    pub fn activate(self: *Workspace) void {        std.debug.assert(!self.database_live);        self.file_workspace.activate();    }    pub fn deinit(self: *Workspace) Storage {        std.debug.assert(!self.database_live);        const storage = self.file_workspace.deinit();        self.* = undefined;        return storage;    }    pub fn deallocate(self: *Workspace, allocator: Allocator) void {        std.debug.assert(!self.database_live);        self.file_workspace.deallocate(allocator);        self.* = undefined;    }    pub fn retainedBytes(self: *const Workspace) usize {        return self.file_workspace.retainedBytes();    }    fn acquireWritable(        self: *Workspace,        allocator: Allocator,        dir: std.Io.Dir,        options: file_mod.OpenOptions,    ) file_mod.Error!*file_mod.Database {        if (self.database_live) return error.WorkspaceBusy;        const writable = try file_mod.Database.open(            allocator,            &self.file_workspace,            dir,            options,        );        self.database = writable;        self.database_live = true;        return &self.database;    }    fn acquireReadOnly(        self: *Workspace,        allocator: Allocator,        dir: std.Io.Dir,        options: file_mod.ReadOpenOptions,    ) file_mod.Error!*file_mod.Database {        if (self.database_live) return error.WorkspaceBusy;        self.database = try file_mod.Database.openReadOnly(            allocator,            &self.file_workspace,            dir,            options,        );        self.database_live = true;        return &self.database;    }    fn releaseDatabase(self: *Workspace, database: *file_mod.Database) void {        std.debug.assert(self.database_live);        std.debug.assert(database == &self.database);        database.deinit();        self.database_live = false;    }    fn ownerOf(writable: *file_mod.Database) *Workspace {        const owner: *Workspace = @alignCast(@fieldParentPtr(            "file_workspace",            writable.workspace,        ));        std.debug.assert(owner.database_live);        std.debug.assert(writable == &owner.database);        return owner;    }};

Source: lib/sql/src/root.zig:90

zig
pub const LifecycleWorkspace = lifecycle.Workspace;
Called byCallsNo direct callslifecycleopenForTestinglifecycleopenReadOnlyForTestingtest sourcelib.sql.src.lifecycletest: lifecycle late read refs cancel...test sourcelib.sql.src.lifecycletest: lifecycle moved history preserv...test sourcelib.sql.src.lifecycletest: lifecycle read connection deriv...test sourcelib.sql.src.lifecycletest: lifecycle workspace reuses one ...LifecycleWorkspaceallocate
Static calls · unresolved targets: 0 · external targets: 1.

Audit

Definitions13
Public names26
Members3
Version26.7.0
Revisiondaab053ee433