command_vault::db::store

Struct Database

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

The main database interface for command-vault.

Handles all database operations including:

  • Command storage and retrieval
  • Tag management
  • Search functionality

§Example

use anyhow::Result;
use command_vault::db::Database;
 
fn main() -> Result<()> {
    let db = Database::new("commands.db")?;
    db.init()?;
    Ok(())
}

Implementations§

Source§

impl Database

Source

pub fn new(path: &str) -> Result<Self>

Creates a new database connection.

§Arguments
  • path - Path to the SQLite database file
§Returns
  • Result<Database> - A new database instance
Source

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

Initializes the database schema.

Creates the following tables if they don’t exist:

  • commands: Stores command information
  • tags: Stores tag information
  • command_tags: Links commands to tags
Source

pub fn add_command(&mut self, command: &Command) -> Result<i64>

Adds a new command to the database.

§Arguments
  • command - The command to add
§Returns
  • Result<i64> - The ID of the newly added command
Source

pub fn add_tags_to_command( &mut self, command_id: i64, tags: &[String], ) -> Result<()>

Adds tags to an existing command.

§Arguments
  • command_id - The ID of the command to add tags to
  • tags - The tags to add
§Returns
  • Result<()> - Success or failure
Source

pub fn remove_tag_from_command( &mut self, command_id: i64, tag_name: &str, ) -> Result<()>

Removes a tag from a command.

§Arguments
  • command_id - The ID of the command to remove the tag from
  • tag_name - The name of the tag to remove
§Returns
  • Result<()> - Success or failure
Source

pub fn search_commands(&self, query: &str, limit: usize) -> Result<Vec<Command>>

Searches for commands containing a given query string.

§Arguments
  • query - The query string to search for
  • limit - The maximum number of results to return
§Returns
  • Result<Vec<Command>> - A list of matching commands
Source

pub fn search_by_tag(&self, tag: &str, limit: usize) -> Result<Vec<Command>>

Searches for commands with a given tag.

§Arguments
  • tag - The tag to search for
  • limit - The maximum number of results to return
§Returns
  • Result<Vec<Command>> - A list of matching commands
Source

pub fn list_tags(&self) -> Result<Vec<(String, i64)>>

Lists all tags in the database.

§Returns
  • Result<Vec<(String, i64)>> - A list of tags with their respective counts
Source

pub fn list_commands( &self, limit: usize, ascending: bool, ) -> Result<Vec<Command>>

Lists all commands in the database.

§Arguments
  • limit - The maximum number of results to return
  • ascending - Whether to return results in ascending order
§Returns
  • Result<Vec<Command>> - A list of commands
Source

pub fn get_command(&self, id: i64) -> Result<Option<Command>>

Gets a command by its ID.

§Arguments
  • id - The ID of the command to retrieve
§Returns
  • Result<Option<Command>> - The command if found
Source

pub fn update_command(&mut self, command: &Command) -> Result<()>

Updates an existing command.

§Arguments
  • command - The updated command
§Returns
  • Result<()> - Success or failure
Source

pub fn delete_command(&mut self, command_id: i64) -> Result<()>

Deletes a command by its ID.

§Arguments
  • command_id - The ID of the command to delete
§Returns
  • Result<()> - Success or failure

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