Skip to main content

ExternalStore

Struct ExternalStore 

pub struct ExternalStore { /* private fields */ }
Expand description

Sidecar DuckDB store owning its own !Send + !Sync Connection.

Implementations§

§

impl ExternalStore

pub fn open_existing( cache_root: &Path, repo_path: &Path, ) -> Result<Option<Self>>

Open the sidecar store read-only if it already exists on disk.

Returns None when the sidecar file is absent — no directory is created and no file is written. Use this in read paths (e.g. gate evaluation) where creating the sidecar as a side-effect would be wrong. The connection is opened with AccessMode::ReadOnly, so it takes a shared lock and coexists with other readers; it never runs DDL, so a sidecar missing its table is returned as-is (queries against it will fail — prefer ExternalStore::open_nonempty, which maps that case to None).

§Errors

Returns CodeLoreError::Analysis only if the file exists but cannot be opened read-only.

pub fn open_nonempty( cache_root: &Path, repo_path: &Path, ) -> Result<Option<Self>>

Open the sidecar store read-only only when it exists, is readable, and holds at least one finding.

Returns None when the sidecar is absent, present-but-empty, or present but unusable (truncated/corrupt — missing the external_findings table). For a reader these are one “nothing to read” state: an empty sidecar carries no more information than a missing one, and a tableless sidecar cannot be healed under a read-only lock (only ExternalStore::open_or_create heals). The “absent, empty, and unreadable are equivalent” policy lives here; call sites keep their own presentation (skip notice, precondition error).

§Errors

Returns CodeLoreError::Analysis if the file exists but cannot be opened read-only, or if the table-presence probe itself fails for a reason other than the table being absent.

pub fn open_or_create(cache_root: &Path, repo_path: &Path) -> Result<Self>

Open or create the sidecar store for repo_path under cache_root.

Creates the parent directory and the table schema on first call.

§Errors

Returns CodeLoreError::Analysis if the directory cannot be created or the DuckDB connection/schema step fails.

pub fn replace_engine( &self, engine: &str, findings: &[ExternalFinding], ) -> Result<usize>

Replace all findings for engine with findings.

Wraps the DELETE + INSERT loop in a single transaction so a mid-loop process kill never leaves the engine’s rows deleted without replacement. The operation is idempotent: re-ingesting the same file produces an identical row count.

Returns the count of inserted rows.

§Errors

Returns CodeLoreError::Analysis on any DuckDB error. On error the transaction is rolled back automatically when it is dropped.

pub fn count(&self) -> Result<u64>

Count all findings currently stored across all engines.

§Errors

Returns CodeLoreError::Analysis on DuckDB error.

pub fn findings_by_path(&self) -> Result<HashMap<String, PathFindings>>

Read all findings grouped by file path.

Returns a map from path(engines, finding_count, worst_level) where:

  • engines is the sorted, deduplicated list of engine names that flagged the path
  • finding_count is the total number of findings across all engines
  • worst_level is the most severe level present ("error" > "warning" > "note")

The caller uses this map for a Rust-side join against the behavioral analyses (hotspots, code-health): the sidecar and fact-store each own a !Send + !Sync DuckDB connection, so the two are never joined across a single connection — the join happens in Rust instead.

§Errors

Returns CodeLoreError::Analysis on DuckDB error.

pub fn path(&self) -> &Path

Path to the sidecar store file (for printing in diagnostics).

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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<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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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