tiny.sql.RelationSession
Defined in tiny.sql.
API (17)
Actions
Public operations.
Fields and members
Public fields and members.
Source
Source: lib/sql/src/session/relation.zig:47
zig
pub const RelationSession = struct { allocator: Allocator, catalog: catalog_mod.Catalog, name: []u8, schema: catalog_mod.Schema, handle: catalog_mod.RelationHandle, stats: ?catalog_mod.RelationStats, root: version.RelationRoot, edits: std.ArrayList(relation_mod.Edit), pub fn open(allocator: Allocator, catalog: *const catalog_mod.Catalog, name: []const u8) Error!RelationSession { const owned_name = try allocator.dupe(u8, name); errdefer allocator.free(owned_name); var state = try catalog.readRelation(allocator, name); errdefer state.deinit(); var root = try version.relationRootMaintained( allocator, name, state.schema, &state.handle, state.relationStats(), ); errdefer root.deinit(); return .{ .allocator = allocator, .catalog = catalog.*, .name = owned_name, .schema = state.schema, .handle = state.handle, .stats = state.stats, .root = root, .edits = .empty, }; } pub fn deinit(self: *RelationSession) void { self.clearEdits(); self.edits.deinit(self.allocator); self.root.deinit(); if (self.stats) |*stats| stats.deinit(); self.handle.deinit(); self.allocator.free(self.name); self.* = undefined; } pub fn put(self: *RelationSession, rowid: i64, values: []const row.Value) Error!void { const phase = trace.scope("session.relation.put"); defer phase.end(); try appendPutEdit(self.allocator, &self.edits, rowid, values); } pub fn putEncoded(self: *RelationSession, rowid: i64, bytes: []const u8) Error!void { const phase = trace.scope("session.relation.put_encoded"); defer phase.end(); _ = try row.View.init(bytes); const owned = try self.allocator.dupe(u8, bytes); errdefer self.allocator.free(owned); try self.edits.append(self.allocator, .{ .put = .{ .rowid = rowid, .bytes = owned, } }); } pub fn update(self: *RelationSession, rowid: i64, assignments: []const relation_mod.Edit.Assignment) Error!void { const phase = trace.scope("session.relation.update"); defer phase.end(); try appendUpdateEdit(self.allocator, &self.edits, rowid, assignments); } pub fn delete(self: *RelationSession, rowid: i64) Error!void { const phase = trace.scope("session.relation.delete"); defer phase.end(); try appendDeleteEdit(self.allocator, &self.edits, rowid); } pub fn pendingEdits(self: *const RelationSession) usize { return self.edits.items.len; } pub fn stagingLimits(self: *const RelationSession) Error!staging.Limits { const demand = try staging.Storage.demandForEdits(self.edits.items); return .{ .relations = 1, .edits = demand.edits, .payload_bytes = demand.payload_bytes, .assignments = demand.assignments, }; } pub fn refresh(self: *RelationSession) Error!void { const phase = trace.scope("session.relation.refresh"); defer phase.end(); var state = try self.catalog.readRelation(self.allocator, self.name); errdefer state.deinit(); try state.handle.relation.validateIndexes(self.allocator); var root = try version.relationRootMaintained( self.allocator, self.name, state.schema, &state.handle, state.relationStats(), ); errdefer root.deinit(); self.root.deinit(); if (self.stats) |*old_stats| old_stats.deinit(); self.handle.deinit(); self.schema = state.schema; self.handle = state.handle; self.stats = state.stats; self.root = root; } fn clearEdits(self: *RelationSession) void { self.discardEditsFrom(0); self.edits.clearRetainingCapacity(); } fn discardEditsFrom(self: *RelationSession, start: usize) void { for (self.edits.items[start..]) |edit| switch (edit) { .put => |put_edit| self.allocator.free(put_edit.bytes), .update => |update_edit| relation_mod.freeAssignments(self.allocator, update_edit.assignments), .delete => {}, }; self.edits.items.len = start; }};Source: lib/sql/src/root.zig:171
zig
pub const RelationSession = session.RelationSession;Also reachable as
Complete caller list for RelationSession.open
11 direct callers.
lib.sql.src.session.test.test_database_session_applies_catalog_roots_before_history_commits[function] — test source atlib/sql/src/session/test.zig:806in nearest public ownerlib.sql.src.session.testlib.sql.src.session.test.test_database_session_assembles_staged_flushes_from_working_database_value[function] — test source atlib/sql/src/session/test.zig:657in nearest public ownerlib.sql.src.session.testlib.sql.src.session.test.test_database_session_clears_analyzed_stats_after_relation_edits[function] — test source atlib/sql/src/session/test.zig:905in nearest public ownerlib.sql.src.session.testlib.sql.src.session.test.test_database_session_deinit_discards_queued_relation_edits[function] — test source atlib/sql/src/session/test.zig:750in nearest public ownerlib.sql.src.session.testlib.sql.src.session.test.test_database_session_flushes_queued_relation_edits_into_one_working_root[function] — test source atlib/sql/src/session/test.zig:564in nearest public ownerlib.sql.src.session.testlib.sql.src.session.test.test_database_session_rejects_staged_relations_that_drift_from_working_values[function] — test source atlib/sql/src/session/test.zig:418in nearest public ownerlib.sql.src.session.testlib.sql.src.session.test.test_database_session_stages_flushed_database_roots_before_history_commits[function] — test source atlib/sql/src/session/test.zig:478in nearest public ownerlib.sql.src.session.testlib.sql.src.session.test.test_database_write_appends_staged_edits_to_staged_relations[function] — test source atlib/sql/src/session/test.zig:110in nearest public ownerlib.sql.src.session.testlib.sql.src.session.test.test_database_write_can_trust_staged_relation_indexes[function] — test source atlib/sql/src/session/test.zig:331in nearest public ownerlib.sql.src.session.testlib.sql.src.session.test.test_database_write_limits_bound_staged_edit_storage[function] — test source atlib/sql/src/session/test.zig:185in nearest public ownerlib.sql.src.session.testlib.sql.src.session.test.test_relation_sessions_stage_edits_through_database_flush[function] — test source atlib/sql/src/session/test.zig:39in nearest public ownerlib.sql.src.session.test
Audit
| Definitions | 10 |
|---|---|
| Public names | 20 |
| Members | 8 |
| Version | 26.7.0 |
| Revision | daab053ee433 |