pub struct Storage { /* private fields */ }Expand description
Per-repo Cozo DB handle.
Implementations§
Source§impl Storage
impl Storage
Sourcepub fn put_symbols(&self, symbols: &[Symbol]) -> Result<()>
pub fn put_symbols(&self, symbols: &[Symbol]) -> Result<()>
Bulk insert symbols using :put with a $rows parameter so user data
is bound, not pasted into the script (avoids quote-escape pitfalls).
Sourcepub fn gc_symbols_not_in(&self, live_files: &HashSet<String>) -> Result<usize>
pub fn gc_symbols_not_in(&self, live_files: &HashSet<String>) -> Result<usize>
Index GC: delete every symbol whose file is NOT in live_files.
Also reaps every inbound/outbound edge from those symbols.
Use case: during ckg index, the indexer walks the working tree and
produces a fresh symbol set for the files it sees. Files that were
indexed previously but have since been renamed or deleted leave
phantom Symbol rows that pollute dead-code, orphan-calls, and
blast-radius results. Without this sweep, removing a source file
silently leaves its symbols behind forever.
live_files is the set of file paths the current index pass
produced symbols for. Anything in the Symbol relation with a
file not in this set is treated as phantom and dropped.
Returns the count of deleted Symbol rows (edges are deleted as a side-effect via Cozo’s referential rules — see comment below).
Sourcepub fn put_edges(&self, edges: &[Edge]) -> Result<()>
pub fn put_edges(&self, edges: &[Edge]) -> Result<()>
Bulk insert edges. Routes by EdgeKind to the right relation.
by_rel groups edges by their Cozo relation name (&'static str from
EdgeKind::as_relation()). An enum-keyed array would be marginally
faster but EdgeKind variants are few and the BTreeMap overhead is
negligible — see L5 tracking comment. Deferring until EdgeKind gains
a stable #[repr(u8)] discriminant.
Source§impl Storage
impl Storage
Sourcepub fn open_unverified(repo_id: RepoId, base: &Path) -> Result<Self>
pub fn open_unverified(repo_id: RepoId, base: &Path) -> Result<Self>
Escape hatch — open without recording / verifying a canonical
root_path. Use ONLY when the caller has no canonical root available
(tests, ad-hoc CLI exploration of a known repo_id, benchmarks).
Sourcepub fn open_at(repo_id: RepoId, root_path: &Path, base: &Path) -> Result<Self>
pub fn open_at(repo_id: RepoId, root_path: &Path, base: &Path) -> Result<Self>
Open or create with canonical root-path verification (I2).
On first init, the canonical path is stamped into Meta. Subsequent opens read it back; if the recorded path doesn’t match we refuse rather than silently merge two repos that happen to hash to the same 96-bit RepoId.
On schema-version mismatch, performs a destructive auto-rebuild. This is
intentional for the indexer path, which holds the repo lock. Readers
(query/resolve/MCP) should use open_at_readonly instead so they never
trigger a destructive rebuild concurrently with an ongoing ckg index.
Sourcepub fn open_at_readonly(
repo_id: RepoId,
root_path: &Path,
base: &Path,
) -> Result<Self>
pub fn open_at_readonly( repo_id: RepoId, root_path: &Path, base: &Path, ) -> Result<Self>
Read-only open: like open_at but never triggers a destructive
schema-mismatch rebuild. On version mismatch, returns a clear error
directing the user to re-index rather than wiping the DB.
Use this from all reader paths (query, resolve, MCP) so a reader
running concurrently with ckg index cannot destroy the indexer’s
in-progress write.
Source§impl Storage
impl Storage
Sourcepub fn resolve_cross_file_calls(&self) -> Result<usize>
pub fn resolve_cross_file_calls(&self) -> Result<usize>
Cross-file resolution pass: for every Calls edge whose dst is a
bare name (not an existing symbol id) AND the name matches exactly
one Symbol.name in the same repo, rewrite dst to that id.
Returns the number of edges rewritten. Confidence on rewritten edges stays at 0.5 (still ambiguous compared to in-file resolution which gets 1.0 at extract time).
Sourcepub fn detect_test_edges(&self) -> Result<usize>
pub fn detect_test_edges(&self) -> Result<usize>
Detect test functions and emit Tests edges to their candidate target.
Rule: any Symbol of kind=function/method whose name starts with
test_ is a test. Strip the prefix to get the bare target name.
If exactly one other symbol shares that bare name, emit a Tests edge.
Returns the number of Tests edges written.
Source§impl Storage
impl Storage
pub fn repo_id(&self) -> &RepoId
pub fn db_path(&self) -> &Path
Sourcepub fn recorded_root_path(&self) -> Result<Option<String>>
pub fn recorded_root_path(&self) -> Result<Option<String>>
CR-storage-M-7: returns the currently-recorded Meta.root_path,
which may differ from the caller’s input shape if open_at auto-
migrated a symlink-equivalent path (canonicalize-equal). Callers
that also stamp the path elsewhere (e.g. registry’s Repo.root_path
via RegistryStorage::put_repo) should use this accessor so the
two authoritative shapes stay consistent.
CR-storage-H3: returns Result<Option<String>> so callers can
distinguish “no row recorded” (Ok(None) — fresh DB) from “Meta
read failed” (Err — disk error / corruption). Pre-fix the
.ok()? collapse made both cases indistinguishable, mirroring
the same bug pattern that RootPathProbe::ReadFailed was
introduced to fix in lifecycle.rs.
pub fn db(&self) -> &DbInstance
Sourcepub fn run_mutable_unchecked(&self, script: &str) -> Result<NamedRows>
pub fn run_mutable_unchecked(&self, script: &str) -> Result<NamedRows>
Run a Cozo script with mutable access (:put, :rm, :create
etc. are allowed). Safety relies on Cozo’s ScriptMutability::Mutable
runtime gate — there is no string-level prefilter.
STORAGE-H2 / danger: The name is intentionally verbose. Callers
must hold an explicit intent to mutate; prefer Self::run_immutable
or Self::run_with_immutable for all read paths and any
caller-supplied Datalog (e.g. MCP query tool). This keeps the
footprint of mutable execution small and auditable.
Sourcepub fn run_immutable(&self, script: &str) -> Result<NamedRows>
pub fn run_immutable(&self, script: &str) -> Result<NamedRows>
Read-only run — passes ScriptMutability::Immutable to Cozo which
rejects scripts containing :put, :rm, :create, :replace,
:ensure_not, etc. at execution time (not string-prefiltered).
Use this for any caller-supplied Datalog (MCP query tool) so a
malicious client can’t drop or mutate relations.
Sourcepub fn run_with(
&self,
script: &str,
params: BTreeMap<String, DataValue>,
) -> Result<NamedRows>
pub fn run_with( &self, script: &str, params: BTreeMap<String, DataValue>, ) -> Result<NamedRows>
Mutable run with parameters. Same safety model as Self::run — relies
on ScriptMutability::Mutable runtime gate, no string prefilter.
Sourcepub fn run_with_immutable(
&self,
script: &str,
params: BTreeMap<String, DataValue>,
) -> Result<NamedRows>
pub fn run_with_immutable( &self, script: &str, params: BTreeMap<String, DataValue>, ) -> Result<NamedRows>
Read-only variant of run_with — caller-supplied params, but the
script is rejected if it contains :put / :rm / :create /
:replace. Use for any caller-controlled Datalog so a malicious /
typo’d script can’t mutate.
Sourcepub fn needs_reindex(&self) -> bool
pub fn needs_reindex(&self) -> bool
True if this repo was schema-rebuilt and hasn’t been re-indexed since.
Set when Storage::open_* triggers rebuild_at_path, cleared via
mark_indexed() after a successful ckg index run.
Returns false on any read failure — the sentinel is best-effort UX
guidance, not a correctness gate.
Sourcepub fn mark_index_in_progress(&self) -> Result<()>
pub fn mark_index_in_progress(&self) -> Result<()>
CR-I-2: Atomicity sentinel. Stamp index_in_progress=true BEFORE the
first put_symbols / put_edges of a fresh index run. On next
Storage::open, if this flag is still set, needs_reindex is promoted.
Cleared by mark_indexed.
Sourcepub fn is_index_in_progress(&self) -> bool
pub fn is_index_in_progress(&self) -> bool
CR-I-2: True if a previous index run started but didn’t reach
mark_indexed. Mostly internal — Storage::open_at checks this on
every open.
Sourcepub fn mark_indexed(&self) -> Result<()>
pub fn mark_indexed(&self) -> Result<()>
Clear the needs_reindex AND index_in_progress sentinels after a
successful ckg index run. Safe to call when the sentinels are already
absent.
Auto Trait Implementations§
impl Freeze for Storage
impl RefUnwindSafe for Storage
impl Send for Storage
impl Sync for Storage
impl Unpin for Storage
impl UnsafeUnpin for Storage
impl UnwindSafe for Storage
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<D> OwoColorize for D
impl<D> OwoColorize for D
Source§fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
Source§fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
Source§fn black<'a>(&'a self) -> FgColorDisplay<'a, Black, Self>
fn black<'a>(&'a self) -> FgColorDisplay<'a, Black, Self>
Source§fn on_black<'a>(&'a self) -> BgColorDisplay<'a, Black, Self>
fn on_black<'a>(&'a self) -> BgColorDisplay<'a, Black, Self>
Source§fn red<'a>(&'a self) -> FgColorDisplay<'a, Red, Self>
fn red<'a>(&'a self) -> FgColorDisplay<'a, Red, Self>
Source§fn on_red<'a>(&'a self) -> BgColorDisplay<'a, Red, Self>
fn on_red<'a>(&'a self) -> BgColorDisplay<'a, Red, Self>
Source§fn green<'a>(&'a self) -> FgColorDisplay<'a, Green, Self>
fn green<'a>(&'a self) -> FgColorDisplay<'a, Green, Self>
Source§fn on_green<'a>(&'a self) -> BgColorDisplay<'a, Green, Self>
fn on_green<'a>(&'a self) -> BgColorDisplay<'a, Green, Self>
Source§fn yellow<'a>(&'a self) -> FgColorDisplay<'a, Yellow, Self>
fn yellow<'a>(&'a self) -> FgColorDisplay<'a, Yellow, Self>
Source§fn on_yellow<'a>(&'a self) -> BgColorDisplay<'a, Yellow, Self>
fn on_yellow<'a>(&'a self) -> BgColorDisplay<'a, Yellow, Self>
Source§fn blue<'a>(&'a self) -> FgColorDisplay<'a, Blue, Self>
fn blue<'a>(&'a self) -> FgColorDisplay<'a, Blue, Self>
Source§fn on_blue<'a>(&'a self) -> BgColorDisplay<'a, Blue, Self>
fn on_blue<'a>(&'a self) -> BgColorDisplay<'a, Blue, Self>
Source§fn magenta<'a>(&'a self) -> FgColorDisplay<'a, Magenta, Self>
fn magenta<'a>(&'a self) -> FgColorDisplay<'a, Magenta, Self>
Source§fn on_magenta<'a>(&'a self) -> BgColorDisplay<'a, Magenta, Self>
fn on_magenta<'a>(&'a self) -> BgColorDisplay<'a, Magenta, Self>
Source§fn purple<'a>(&'a self) -> FgColorDisplay<'a, Magenta, Self>
fn purple<'a>(&'a self) -> FgColorDisplay<'a, Magenta, Self>
Source§fn on_purple<'a>(&'a self) -> BgColorDisplay<'a, Magenta, Self>
fn on_purple<'a>(&'a self) -> BgColorDisplay<'a, Magenta, Self>
Source§fn cyan<'a>(&'a self) -> FgColorDisplay<'a, Cyan, Self>
fn cyan<'a>(&'a self) -> FgColorDisplay<'a, Cyan, Self>
Source§fn on_cyan<'a>(&'a self) -> BgColorDisplay<'a, Cyan, Self>
fn on_cyan<'a>(&'a self) -> BgColorDisplay<'a, Cyan, Self>
Source§fn white<'a>(&'a self) -> FgColorDisplay<'a, White, Self>
fn white<'a>(&'a self) -> FgColorDisplay<'a, White, Self>
Source§fn on_white<'a>(&'a self) -> BgColorDisplay<'a, White, Self>
fn on_white<'a>(&'a self) -> BgColorDisplay<'a, White, Self>
Source§fn default_color<'a>(&'a self) -> FgColorDisplay<'a, Default, Self>
fn default_color<'a>(&'a self) -> FgColorDisplay<'a, Default, Self>
Source§fn on_default_color<'a>(&'a self) -> BgColorDisplay<'a, Default, Self>
fn on_default_color<'a>(&'a self) -> BgColorDisplay<'a, Default, Self>
Source§fn bright_black<'a>(&'a self) -> FgColorDisplay<'a, BrightBlack, Self>
fn bright_black<'a>(&'a self) -> FgColorDisplay<'a, BrightBlack, Self>
Source§fn on_bright_black<'a>(&'a self) -> BgColorDisplay<'a, BrightBlack, Self>
fn on_bright_black<'a>(&'a self) -> BgColorDisplay<'a, BrightBlack, Self>
Source§fn bright_red<'a>(&'a self) -> FgColorDisplay<'a, BrightRed, Self>
fn bright_red<'a>(&'a self) -> FgColorDisplay<'a, BrightRed, Self>
Source§fn on_bright_red<'a>(&'a self) -> BgColorDisplay<'a, BrightRed, Self>
fn on_bright_red<'a>(&'a self) -> BgColorDisplay<'a, BrightRed, Self>
Source§fn bright_green<'a>(&'a self) -> FgColorDisplay<'a, BrightGreen, Self>
fn bright_green<'a>(&'a self) -> FgColorDisplay<'a, BrightGreen, Self>
Source§fn on_bright_green<'a>(&'a self) -> BgColorDisplay<'a, BrightGreen, Self>
fn on_bright_green<'a>(&'a self) -> BgColorDisplay<'a, BrightGreen, Self>
Source§fn bright_yellow<'a>(&'a self) -> FgColorDisplay<'a, BrightYellow, Self>
fn bright_yellow<'a>(&'a self) -> FgColorDisplay<'a, BrightYellow, Self>
Source§fn on_bright_yellow<'a>(&'a self) -> BgColorDisplay<'a, BrightYellow, Self>
fn on_bright_yellow<'a>(&'a self) -> BgColorDisplay<'a, BrightYellow, Self>
Source§fn bright_blue<'a>(&'a self) -> FgColorDisplay<'a, BrightBlue, Self>
fn bright_blue<'a>(&'a self) -> FgColorDisplay<'a, BrightBlue, Self>
Source§fn on_bright_blue<'a>(&'a self) -> BgColorDisplay<'a, BrightBlue, Self>
fn on_bright_blue<'a>(&'a self) -> BgColorDisplay<'a, BrightBlue, Self>
Source§fn bright_magenta<'a>(&'a self) -> FgColorDisplay<'a, BrightMagenta, Self>
fn bright_magenta<'a>(&'a self) -> FgColorDisplay<'a, BrightMagenta, Self>
Source§fn on_bright_magenta<'a>(&'a self) -> BgColorDisplay<'a, BrightMagenta, Self>
fn on_bright_magenta<'a>(&'a self) -> BgColorDisplay<'a, BrightMagenta, Self>
Source§fn bright_purple<'a>(&'a self) -> FgColorDisplay<'a, BrightMagenta, Self>
fn bright_purple<'a>(&'a self) -> FgColorDisplay<'a, BrightMagenta, Self>
Source§fn on_bright_purple<'a>(&'a self) -> BgColorDisplay<'a, BrightMagenta, Self>
fn on_bright_purple<'a>(&'a self) -> BgColorDisplay<'a, BrightMagenta, Self>
Source§fn bright_cyan<'a>(&'a self) -> FgColorDisplay<'a, BrightCyan, Self>
fn bright_cyan<'a>(&'a self) -> FgColorDisplay<'a, BrightCyan, Self>
Source§fn on_bright_cyan<'a>(&'a self) -> BgColorDisplay<'a, BrightCyan, Self>
fn on_bright_cyan<'a>(&'a self) -> BgColorDisplay<'a, BrightCyan, Self>
Source§fn bright_white<'a>(&'a self) -> FgColorDisplay<'a, BrightWhite, Self>
fn bright_white<'a>(&'a self) -> FgColorDisplay<'a, BrightWhite, Self>
Source§fn on_bright_white<'a>(&'a self) -> BgColorDisplay<'a, BrightWhite, Self>
fn on_bright_white<'a>(&'a self) -> BgColorDisplay<'a, BrightWhite, Self>
Source§fn bold<'a>(&'a self) -> BoldDisplay<'a, Self>
fn bold<'a>(&'a self) -> BoldDisplay<'a, Self>
Source§fn dimmed<'a>(&'a self) -> DimDisplay<'a, Self>
fn dimmed<'a>(&'a self) -> DimDisplay<'a, Self>
Source§fn italic<'a>(&'a self) -> ItalicDisplay<'a, Self>
fn italic<'a>(&'a self) -> ItalicDisplay<'a, Self>
Source§fn underline<'a>(&'a self) -> UnderlineDisplay<'a, Self>
fn underline<'a>(&'a self) -> UnderlineDisplay<'a, Self>
Source§fn blink<'a>(&'a self) -> BlinkDisplay<'a, Self>
fn blink<'a>(&'a self) -> BlinkDisplay<'a, Self>
Source§fn blink_fast<'a>(&'a self) -> BlinkFastDisplay<'a, Self>
fn blink_fast<'a>(&'a self) -> BlinkFastDisplay<'a, Self>
Source§fn reversed<'a>(&'a self) -> ReversedDisplay<'a, Self>
fn reversed<'a>(&'a self) -> ReversedDisplay<'a, Self>
Source§fn strikethrough<'a>(&'a self) -> StrikeThroughDisplay<'a, Self>
fn strikethrough<'a>(&'a self) -> StrikeThroughDisplay<'a, Self>
Source§fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::fg or
a color-specific method, such as OwoColorize::green, Read moreSource§fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::bg or
a color-specific method, such as OwoColorize::on_yellow, Read more