Skip to main content

Database

Struct Database 

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

MorphArch database wrapper.

Holds the SQLite connection and provides all database operations. Migration runs automatically on creation.

Implementations§

Source§

impl Database

Source

pub fn open(path: &Path) -> Result<Self>

Opens (or creates) the database at the specified file path.

After opening the connection:

  • WAL mode is enabled (for concurrent reads)
  • Required tables are created (CREATE IF NOT EXISTS)
  • migration (drift_json column) is applied
Source

pub fn begin_transaction(&self) -> Result<()>

Begins an explicit transaction. Call commit_transaction() when done. All inserts between begin/commit are batched into a single fsync.

Source

pub fn commit_transaction(&self) -> Result<()>

Commits the current transaction (flushes all batched writes).

Source

pub fn clear_all_graph_snapshots(&self) -> Result<()>

Clears all graph data before a scan operation.

Source

pub fn insert_commit(&self, commit: &CommitInfo) -> Result<()>

Inserts a single commit into the database (INSERT OR REPLACE — idempotent).

Source

pub fn list_commits(&self) -> Result<Vec<CommitInfo>>

Lists all commits in descending timestamp order.

Source

pub fn commit_count(&self) -> Result<usize>

Returns the total number of commits in the database.

Source

pub fn insert_graph_snapshot(&self, snapshot: &GraphSnapshot) -> Result<()>

Saves a graph snapshot as JSON to the database.

The GraphSnapshot struct is serialized with serde_json and written to the snapshot_json column. node_count and edge_count are also stored as denormalized columns for fast queries.

Source

pub fn list_recent_graphs( &self, limit: usize, ) -> Result<Vec<(String, String, i64, usize, usize)>>

Lists the last N graph snapshots with commit information.

JOINs with the commits table to include commit message and timestamp. Results are in descending timestamp order.

§Returns

Vec<(commit_hash, message_first_line, timestamp, node_count, edge_count)>

Source

pub fn graph_snapshot_count(&self) -> Result<usize>

Returns the total number of graph snapshots in the database.

Source

pub fn get_graph_snapshot( &self, commit_hash: &str, ) -> Result<Option<GraphSnapshot>>

Retrieves a graph snapshot for a specific commit hash.

Deserializes from JSON and returns the full GraphSnapshot. If drift info exists, the drift field will be populated.

§Returns
  • Ok(Some(snapshot)): Snapshot found
  • Ok(None): No snapshot for this commit
Source

pub fn list_drift_trend( &self, limit: usize, ) -> Result<Vec<(String, String, usize, usize, Option<u8>, i64)>>

Lists drift trend data for the last N commits.

Returns snapshots with drift scores in timestamp order. Each row: commit_hash, message, node count, edge count, drift score, delta from previous commit.

§Returns

Vec<(commit_hash, message, nodes, edges, drift_total, timestamp)>

Source

pub fn update_drift_score( &self, commit_hash: &str, drift: &DriftScore, ) -> Result<()>

Updates the drift score for a specific commit.

Updates the drift_json column of an existing graph snapshot. Only drift info is added if the snapshot already exists.

Source

pub fn get_latest_scanned_commit(&self) -> Result<Option<String>>

Returns the commit hash of the most recently scanned commit.

Used for incremental scanning — only scan commits newer than this. Returns None if no snapshots exist in the database.

Source

pub fn get_recent_snapshots(&self, limit: usize) -> Result<Vec<GraphSnapshot>>

Loads the last N graph snapshots with full JSON deserialization.

Returns snapshots in newest → oldest order for use in the TUI timeline. Each snapshot contains the full GraphSnapshot struct (nodes, edges, drift).

Source

pub fn get_sampled_snapshots( &self, target_count: usize, ) -> Result<Vec<GraphSnapshot>>

Loads graph snapshots sampled evenly across the full history.

When the DB contains more snapshots than target_count, this method picks snapshots at evenly spaced intervals so the TUI timeline covers the entire commit history instead of just the most recent N.

The first (newest) and last (oldest) snapshots are always included.

Returns snapshots in newest-first order (consistent with get_recent_snapshots).

Source

pub fn get_commit_messages_for_snapshots( &self, snapshots: &[GraphSnapshot], ) -> Result<Vec<(String, String, i64)>>

Retrieves commit message info for the given snapshot list.

Returns (hash, first_line_of_message, timestamp) tuples for display in the timeline widget. Preserves snapshot order.

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