Skip to main content

Storage

Struct Storage 

Source
pub struct Storage { /* private fields */ }
Expand description

Per-repo Cozo DB handle.

Implementations§

Source§

impl Storage

Source

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).

Source

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).

Source

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

Source

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).

Source

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.

Source

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

Source

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).

Source

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

Source

pub fn repo_id(&self) -> &RepoId

Source

pub fn db_path(&self) -> &Path

Source

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.

Source

pub fn db(&self) -> &DbInstance

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 more
Source§

impl<D> OwoColorize for D

Source§

fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>
where C: Color,

Set the foreground color generically Read more
Source§

fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>
where C: Color,

Set the background color generically. Read more
Source§

fn black<'a>(&'a self) -> FgColorDisplay<'a, Black, Self>

Change the foreground color to black
Source§

fn on_black<'a>(&'a self) -> BgColorDisplay<'a, Black, Self>

Change the background color to black
Source§

fn red<'a>(&'a self) -> FgColorDisplay<'a, Red, Self>

Change the foreground color to red
Source§

fn on_red<'a>(&'a self) -> BgColorDisplay<'a, Red, Self>

Change the background color to red
Source§

fn green<'a>(&'a self) -> FgColorDisplay<'a, Green, Self>

Change the foreground color to green
Source§

fn on_green<'a>(&'a self) -> BgColorDisplay<'a, Green, Self>

Change the background color to green
Source§

fn yellow<'a>(&'a self) -> FgColorDisplay<'a, Yellow, Self>

Change the foreground color to yellow
Source§

fn on_yellow<'a>(&'a self) -> BgColorDisplay<'a, Yellow, Self>

Change the background color to yellow
Source§

fn blue<'a>(&'a self) -> FgColorDisplay<'a, Blue, Self>

Change the foreground color to blue
Source§

fn on_blue<'a>(&'a self) -> BgColorDisplay<'a, Blue, Self>

Change the background color to blue
Source§

fn magenta<'a>(&'a self) -> FgColorDisplay<'a, Magenta, Self>

Change the foreground color to magenta
Source§

fn on_magenta<'a>(&'a self) -> BgColorDisplay<'a, Magenta, Self>

Change the background color to magenta
Source§

fn purple<'a>(&'a self) -> FgColorDisplay<'a, Magenta, Self>

Change the foreground color to purple
Source§

fn on_purple<'a>(&'a self) -> BgColorDisplay<'a, Magenta, Self>

Change the background color to purple
Source§

fn cyan<'a>(&'a self) -> FgColorDisplay<'a, Cyan, Self>

Change the foreground color to cyan
Source§

fn on_cyan<'a>(&'a self) -> BgColorDisplay<'a, Cyan, Self>

Change the background color to cyan
Source§

fn white<'a>(&'a self) -> FgColorDisplay<'a, White, Self>

Change the foreground color to white
Source§

fn on_white<'a>(&'a self) -> BgColorDisplay<'a, White, Self>

Change the background color to white
Source§

fn default_color<'a>(&'a self) -> FgColorDisplay<'a, Default, Self>

Change the foreground color to the terminal default
Source§

fn on_default_color<'a>(&'a self) -> BgColorDisplay<'a, Default, Self>

Change the background color to the terminal default
Source§

fn bright_black<'a>(&'a self) -> FgColorDisplay<'a, BrightBlack, Self>

Change the foreground color to bright black
Source§

fn on_bright_black<'a>(&'a self) -> BgColorDisplay<'a, BrightBlack, Self>

Change the background color to bright black
Source§

fn bright_red<'a>(&'a self) -> FgColorDisplay<'a, BrightRed, Self>

Change the foreground color to bright red
Source§

fn on_bright_red<'a>(&'a self) -> BgColorDisplay<'a, BrightRed, Self>

Change the background color to bright red
Source§

fn bright_green<'a>(&'a self) -> FgColorDisplay<'a, BrightGreen, Self>

Change the foreground color to bright green
Source§

fn on_bright_green<'a>(&'a self) -> BgColorDisplay<'a, BrightGreen, Self>

Change the background color to bright green
Source§

fn bright_yellow<'a>(&'a self) -> FgColorDisplay<'a, BrightYellow, Self>

Change the foreground color to bright yellow
Source§

fn on_bright_yellow<'a>(&'a self) -> BgColorDisplay<'a, BrightYellow, Self>

Change the background color to bright yellow
Source§

fn bright_blue<'a>(&'a self) -> FgColorDisplay<'a, BrightBlue, Self>

Change the foreground color to bright blue
Source§

fn on_bright_blue<'a>(&'a self) -> BgColorDisplay<'a, BrightBlue, Self>

Change the background color to bright blue
Source§

fn bright_magenta<'a>(&'a self) -> FgColorDisplay<'a, BrightMagenta, Self>

Change the foreground color to bright magenta
Source§

fn on_bright_magenta<'a>(&'a self) -> BgColorDisplay<'a, BrightMagenta, Self>

Change the background color to bright magenta
Source§

fn bright_purple<'a>(&'a self) -> FgColorDisplay<'a, BrightMagenta, Self>

Change the foreground color to bright purple
Source§

fn on_bright_purple<'a>(&'a self) -> BgColorDisplay<'a, BrightMagenta, Self>

Change the background color to bright purple
Source§

fn bright_cyan<'a>(&'a self) -> FgColorDisplay<'a, BrightCyan, Self>

Change the foreground color to bright cyan
Source§

fn on_bright_cyan<'a>(&'a self) -> BgColorDisplay<'a, BrightCyan, Self>

Change the background color to bright cyan
Source§

fn bright_white<'a>(&'a self) -> FgColorDisplay<'a, BrightWhite, Self>

Change the foreground color to bright white
Source§

fn on_bright_white<'a>(&'a self) -> BgColorDisplay<'a, BrightWhite, Self>

Change the background color to bright white
Source§

fn bold<'a>(&'a self) -> BoldDisplay<'a, Self>

Make the text bold
Source§

fn dimmed<'a>(&'a self) -> DimDisplay<'a, Self>

Make the text dim
Source§

fn italic<'a>(&'a self) -> ItalicDisplay<'a, Self>

Make the text italicized
Source§

fn underline<'a>(&'a self) -> UnderlineDisplay<'a, Self>

Make the text italicized
Make the text blink
Make the text blink (but fast!)
Source§

fn reversed<'a>(&'a self) -> ReversedDisplay<'a, Self>

Swap the foreground and background colors
Source§

fn hidden<'a>(&'a self) -> HiddenDisplay<'a, Self>

Hide the text
Source§

fn strikethrough<'a>(&'a self) -> StrikeThroughDisplay<'a, Self>

Cross out the text
Source§

fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>
where Color: DynColor,

Set the foreground color at runtime. Only use if you do not know which color will be used at compile-time. If the color is constant, use either OwoColorize::fg or a color-specific method, such as OwoColorize::green, Read more
Source§

fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>
where Color: DynColor,

Set the background color at runtime. Only use if you do not know what color to use at compile-time. If the color is constant, use either OwoColorize::bg or a color-specific method, such as OwoColorize::on_yellow, Read more
Source§

fn fg_rgb<const R: u8, const G: u8, const B: u8>( &self, ) -> FgColorDisplay<'_, CustomColor<R, G, B>, Self>

Set the foreground color to a specific RGB value.
Source§

fn bg_rgb<const R: u8, const G: u8, const B: u8>( &self, ) -> BgColorDisplay<'_, CustomColor<R, G, B>, Self>

Set the background color to a specific RGB value.
Source§

fn truecolor(&self, r: u8, g: u8, b: u8) -> FgDynColorDisplay<'_, Rgb, Self>

Sets the foreground color to an RGB value.
Source§

fn on_truecolor(&self, r: u8, g: u8, b: u8) -> BgDynColorDisplay<'_, Rgb, Self>

Sets the background color to an RGB value.
Source§

fn style(&self, style: Style) -> Styled<&Self>

Apply a runtime-determined style
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more