tiny.smg.storage.rows
Defined in storage.
API (38)
Actions
Public operations.
GraphEdits.isEmptydecodeEdgeRowdecodeNodeRowedgeRelViewedgeSourceViewedgeTargetViewfreeConceptDocumentRowSlicefreeEdgeRowSlicefreeNodeRowSlicenodeDocstringViewnodeNameViewnodeTypeViewputConceptDocumentRowputEdgeRowputNodeRowscanConceptDocumentRowsscanEdgeRowsscanEdgeRowsIntoscanNodeRowsscanNodeRowsInto
Types and contracts
Public types and contracts.
Values and defaults
Public values and defaults.
concept_document_columnsconcept_documents_relationconcept_name_indexedge_columnsedge_source_indexedge_target_indexedges_relationnode_columnsnode_name_indexnodes_relation
Source
Source: tools/smg/src/storage/rows/types.zig:44
pub const ConceptDocumentPut = struct { rowid: i64, name: []const u8, document: []const u8,};Source: tools/smg/src/storage/rows/types.zig:28
pub const ConceptDocumentRow = struct { rowid: i64, name: []const u8, document: []const u8,};Source: tools/smg/src/storage/rows/types.zig:39
Source: tools/smg/src/storage/rows/types.zig:23
Source: tools/smg/src/storage/rows/types.zig:50
pub const GraphEdits = struct { node_puts: []const NodePut = &.{}, node_deletes: []const i64 = &.{}, edge_puts: []const EdgePut = &.{}, edge_deletes: []const i64 = &.{}, concept_document_puts: []const ConceptDocumentPut = &.{}, concept_document_deletes: []const i64 = &.{}, pub fn isEmpty(self: GraphEdits) bool { return self.node_puts.len == 0 and self.node_deletes.len == 0 and self.edge_puts.len == 0 and self.edge_deletes.len == 0 and self.concept_document_puts.len == 0 and self.concept_document_deletes.len == 0; }};Source: tools/smg/src/storage/rows/types.zig:34
Source: tools/smg/src/storage/rows/read.zig:205
pub fn decodeEdgeRow(allocator: std.mem.Allocator, rowid: i64, bytes: []const u8) Error!types.EdgeRow { const view = try sql.RowView.init(bytes); var edge = model.Edge{ .source = try columnText(allocator, view, 0), .target = &.{}, .rel = &.{}, }; errdefer model.deinitEdge(&edge, allocator); edge.rel = try columnText(allocator, view, 1); edge.target = try columnText(allocator, view, 2); edge.metadata = try decodeMetadata(allocator, view, 3); return .{ .rowid = rowid, .edge = edge };}Source: tools/smg/src/storage/rows/read.zig:174
pub fn decodeNodeRow(allocator: std.mem.Allocator, rowid: i64, bytes: []const u8) Error!types.NodeRow { const view = try sql.RowView.init(bytes); var node = model.Node{ .name = try columnText(allocator, view, 0), .type = &.{}, }; errdefer model.deinitNode(&node, allocator); node.type = try columnText(allocator, view, 1); node.file = try columnOptionalText(allocator, view, 2); node.line = try columnOptionalInteger(view, 3); node.end_line = try columnOptionalInteger(view, 4); node.docstring = try columnOptionalText(allocator, view, 5); node.metadata = try decodeMetadata(allocator, view, 6); return .{ .rowid = rowid, .node = node };}Source: tools/smg/src/storage/rows/read.zig:224
pub fn edgeRelView(bytes: []const u8) Error![]const u8 { const view = try sql.RowView.init(bytes); return try columnTextView(view, 1);}Source: tools/smg/src/storage/rows/read.zig:219
pub fn edgeSourceView(bytes: []const u8) Error![]const u8 { const view = try sql.RowView.init(bytes); return try columnTextView(view, 0);}Source: tools/smg/src/storage/rows/read.zig:229
pub fn edgeTargetView(bytes: []const u8) Error![]const u8 { const view = try sql.RowView.init(bytes); return try columnTextView(view, 2);}Source: tools/smg/src/storage/rows/read.zig:166
pub fn freeConceptDocumentRowSlice(row_allocator: std.mem.Allocator, value_allocator: std.mem.Allocator, row_slice: []types.ConceptDocumentRow) void { for (row_slice) |row| { value_allocator.free(row.name); value_allocator.free(row.document); } if (row_slice.len != 0) row_allocator.free(row_slice);}Source: tools/smg/src/storage/rows/read.zig:161
pub fn freeEdgeRowSlice(row_allocator: std.mem.Allocator, value_allocator: std.mem.Allocator, row_slice: []types.EdgeRow) void { for (row_slice) |*loaded| model.deinitEdge(&loaded.edge, value_allocator); if (row_slice.len != 0) row_allocator.free(row_slice);}Source: tools/smg/src/storage/rows/read.zig:156
pub fn freeNodeRowSlice(row_allocator: std.mem.Allocator, value_allocator: std.mem.Allocator, row_slice: []types.NodeRow) void { for (row_slice) |*loaded| model.deinitNode(&loaded.node, value_allocator); if (row_slice.len != 0) row_allocator.free(row_slice);}Source: tools/smg/src/storage/rows/read.zig:200
pub fn nodeDocstringView(bytes: []const u8) Error!?[]const u8 { const view = try sql.RowView.init(bytes); return try columnOptionalTextView(view, 5);}Source: tools/smg/src/storage/rows/read.zig:190
pub fn nodeNameView(bytes: []const u8) Error![]const u8 { const view = try sql.RowView.init(bytes); return try columnTextView(view, 0);}Source: tools/smg/src/storage/rows/read.zig:195
pub fn nodeTypeView(bytes: []const u8) Error![]const u8 { const view = try sql.RowView.init(bytes); return try columnTextView(view, 1);}Source: tools/smg/src/storage/rows/read.zig:71
pub fn scanConceptDocumentRows( opened_catalog: anytype, scratch_allocator: std.mem.Allocator, row_allocator: std.mem.Allocator, value_allocator: std.mem.Allocator,) Error![]types.ConceptDocumentRow { var handle = opened_catalog.openRelation(scratch_allocator, types.concept_documents_relation) catch |err| switch (err) { error.RelationNotFound => return &.{}, else => return err, }; defer handle.deinit(); var scan: sql.TableScan = undefined; try handle.relation.scan(&scan, scratch_allocator, null, null); defer scan.deinit(); const count = try handle.relation.table.count(); var loaded: std.ArrayList(types.ConceptDocumentRow) = .empty; errdefer freeConceptDocumentRows(row_allocator, value_allocator, &loaded); try loaded.ensureTotalCapacityPrecise(row_allocator, count); while (try scan.next()) |entry| { const view = try sql.RowView.init(entry.bytes); const name = try columnText(value_allocator, view, 0); errdefer value_allocator.free(name); const document = try columnText(value_allocator, view, 1); if (loaded.items.len == count) { value_allocator.free(document); return error.MalformedRow; } loaded.appendAssumeCapacity(.{ .rowid = entry.rowid, .name = name, .document = document, }); } if (loaded.items.len != count) return error.MalformedRow; return try loaded.toOwnedSlice(row_allocator);}Source: tools/smg/src/storage/rows/read.zig:40
pub fn scanEdgeRows( opened_catalog: anytype, scratch_allocator: std.mem.Allocator, row_allocator: std.mem.Allocator, value_allocator: std.mem.Allocator,) Error![]types.EdgeRow { var handle = opened_catalog.openRelation(scratch_allocator, types.edges_relation) catch |err| switch (err) { error.RelationNotFound => return &.{}, else => return err, }; defer handle.deinit(); var scan: sql.TableScan = undefined; try handle.relation.scan(&scan, scratch_allocator, null, null); defer scan.deinit(); const count = try handle.relation.table.count(); var loaded: std.ArrayList(types.EdgeRow) = .empty; errdefer freeEdgeRows(row_allocator, value_allocator, &loaded); try loaded.ensureTotalCapacityPrecise(row_allocator, count); while (try scan.next()) |entry| { const decoded = try decodeEdgeRow(value_allocator, entry.rowid, entry.bytes); if (loaded.items.len == count) { var rejected = decoded; model.deinitEdge(&rejected.edge, value_allocator); return error.MalformedRow; } loaded.appendAssumeCapacity(decoded); } if (loaded.items.len != count) return error.MalformedRow; return try loaded.toOwnedSlice(row_allocator);}Source: tools/smg/src/storage/rows/read.zig:132
pub fn scanEdgeRowsInto( opened_catalog: anytype, scratch_allocator: std.mem.Allocator, value_allocator: std.mem.Allocator, out: []types.EdgeRow,) Error!void { var handle = opened_catalog.openRelation(scratch_allocator, types.edges_relation) catch |err| switch (err) { error.RelationNotFound => if (out.len == 0) return else return error.MalformedRow, else => return err, }; defer handle.deinit(); var scan: sql.TableScan = undefined; try handle.relation.scan(&scan, scratch_allocator, null, null); defer scan.deinit(); var filled: usize = 0; errdefer for (out[0..filled]) |*loaded| model.deinitEdge(&loaded.edge, value_allocator); while (try scan.next()) |entry| { if (filled == out.len) return error.MalformedRow; out[filled] = try decodeEdgeRow(value_allocator, entry.rowid, entry.bytes); filled += 1; } if (filled != out.len) return error.MalformedRow;}Source: tools/smg/src/storage/rows/read.zig:9
pub fn scanNodeRows( opened_catalog: anytype, scratch_allocator: std.mem.Allocator, row_allocator: std.mem.Allocator, value_allocator: std.mem.Allocator,) Error![]types.NodeRow { var handle = opened_catalog.openRelation(scratch_allocator, types.nodes_relation) catch |err| switch (err) { error.RelationNotFound => return &.{}, else => return err, }; defer handle.deinit(); var scan: sql.TableScan = undefined; try handle.relation.scan(&scan, scratch_allocator, null, null); defer scan.deinit(); const count = try handle.relation.table.count(); var loaded: std.ArrayList(types.NodeRow) = .empty; errdefer freeNodeRows(row_allocator, value_allocator, &loaded); try loaded.ensureTotalCapacityPrecise(row_allocator, count); while (try scan.next()) |entry| { const decoded = try decodeNodeRow(value_allocator, entry.rowid, entry.bytes); if (loaded.items.len == count) { var rejected = decoded; model.deinitNode(&rejected.node, value_allocator); return error.MalformedRow; } loaded.appendAssumeCapacity(decoded); } if (loaded.items.len != count) return error.MalformedRow; return try loaded.toOwnedSlice(row_allocator);}Source: tools/smg/src/storage/rows/read.zig:108
pub fn scanNodeRowsInto( opened_catalog: anytype, scratch_allocator: std.mem.Allocator, value_allocator: std.mem.Allocator, out: []types.NodeRow,) Error!void { var handle = opened_catalog.openRelation(scratch_allocator, types.nodes_relation) catch |err| switch (err) { error.RelationNotFound => if (out.len == 0) return else return error.MalformedRow, else => return err, }; defer handle.deinit(); var scan: sql.TableScan = undefined; try handle.relation.scan(&scan, scratch_allocator, null, null); defer scan.deinit(); var filled: usize = 0; errdefer for (out[0..filled]) |*loaded| model.deinitNode(&loaded.node, value_allocator); while (try scan.next()) |entry| { if (filled == out.len) return error.MalformedRow; out[filled] = try decodeNodeRow(value_allocator, entry.rowid, entry.bytes); filled += 1; } if (filled != out.len) return error.MalformedRow;}Source: tools/smg/src/storage/rows/types.zig:5
pub const Error = error{ MalformedRow, InvalidMetadata, OutOfMemory } || sql.statement.Error || sql.catalog.Error;Source: tools/smg/src/storage/rows/types.zig:16
pub const concept_document_columns = "name, document, INDEX " ++ concept_name_index ++ " (name)";Source: tools/smg/src/storage/rows/types.zig:9
pub const concept_documents_relation = "concepts";Source: tools/smg/src/storage/rows/types.zig:13
pub const concept_name_index = "concepts_name";Source: tools/smg/src/storage/rows/types.zig:15
pub const edge_columns = "source, rel, target, metadata, INDEX " ++ edge_source_index ++ " (source), INDEX " ++ edge_target_index ++ " (target)";Source: tools/smg/src/storage/rows/types.zig:11
pub const edge_source_index = "edges_source";Source: tools/smg/src/storage/rows/types.zig:12
pub const edge_target_index = "edges_target";Source: tools/smg/src/storage/rows/types.zig:8
pub const edges_relation = "edges";Source: tools/smg/src/storage/rows/types.zig:14
pub const node_columns = "name, type, file, line, end_line, docstring, metadata, INDEX " ++ node_name_index ++ " (name)";Source: tools/smg/src/storage/rows/types.zig:10
pub const node_name_index = "nodes_name";Source: tools/smg/src/storage/rows/types.zig:7
pub const nodes_relation = "nodes";Source: tools/smg/src/storage/rows/write.zig:36
pub fn putConceptDocumentRow(session: *sql.RelationSession, put: types.ConceptDocumentPut) Error!void { try session.put(put.rowid, &.{ .{ .text = put.name }, .{ .text = put.document }, });}Source: tools/smg/src/storage/rows/write.zig:24
pub fn putEdgeRow(allocator: std.mem.Allocator, session: *sql.RelationSession, rowid: i64, edge: model.Edge) Error!void { const metadata = try renderMetadata(allocator, edge.metadata); defer if (metadata) |rendered| allocator.free(rendered); const values = [_]sql.row.Value{ .{ .text = edge.source }, .{ .text = edge.rel }, .{ .text = edge.target }, optionalText(metadata), }; try session.put(rowid, &values);}Source: tools/smg/src/storage/rows/write.zig:9
pub fn putNodeRow(allocator: std.mem.Allocator, session: *sql.RelationSession, rowid: i64, node: model.Node) Error!void { const metadata = try renderMetadata(allocator, node.metadata); defer if (metadata) |rendered| allocator.free(rendered); const values = [_]sql.row.Value{ .{ .text = node.name }, .{ .text = node.type }, optionalText(node.file), optionalInteger(node.line), optionalInteger(node.end_line), optionalText(node.docstring), optionalText(metadata), }; try session.put(rowid, &values);}Source: tools/smg/src/storage/root.zig:9
pub const rows = @import("rows/root.zig");Source: tools/smg/src/storage/rows/root.zig
const read = @import("read.zig");const types = @import("types.zig");const write = @import("write.zig");pub const Error = types.Error;pub const node_columns = types.node_columns;pub const edge_columns = types.edge_columns;pub const concept_document_columns = types.concept_document_columns;pub const nodes_relation = types.nodes_relation;pub const edges_relation = types.edges_relation;pub const concept_documents_relation = types.concept_documents_relation;pub const node_name_index = types.node_name_index;pub const edge_source_index = types.edge_source_index;pub const edge_target_index = types.edge_target_index;pub const concept_name_index = types.concept_name_index;pub const NodeRow = types.NodeRow;pub const EdgeRow = types.EdgeRow;pub const ConceptDocumentRow = types.ConceptDocumentRow;pub const NodePut = types.NodePut;pub const EdgePut = types.EdgePut;pub const ConceptDocumentPut = types.ConceptDocumentPut;pub const GraphEdits = types.GraphEdits;pub const freeNodeRowSlice = read.freeNodeRowSlice;pub const freeEdgeRowSlice = read.freeEdgeRowSlice;pub const freeConceptDocumentRowSlice = read.freeConceptDocumentRowSlice;pub const scanNodeRows = read.scanNodeRows;pub const scanEdgeRows = read.scanEdgeRows;pub const scanConceptDocumentRows = read.scanConceptDocumentRows;pub const scanNodeRowsInto = read.scanNodeRowsInto;pub const scanEdgeRowsInto = read.scanEdgeRowsInto;pub const decodeNodeRow = read.decodeNodeRow;pub const decodeEdgeRow = read.decodeEdgeRow;pub const nodeNameView = read.nodeNameView;pub const nodeTypeView = read.nodeTypeView;pub const nodeDocstringView = read.nodeDocstringView;pub const edgeSourceView = read.edgeSourceView;pub const edgeRelView = read.edgeRelView;pub const edgeTargetView = read.edgeTargetView;pub const putNodeRow = write.putNodeRow;pub const putEdgeRow = write.putEdgeRow;pub const putConceptDocumentRow = write.putConceptDocumentRow;Audit
| Definitions | 38 |
|---|---|
| Public names | 38 |
| Members | 18 |
| Version | 26.7.0 |
| Revision | daab053ee433 |