Struct SqliteStorage

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

SQLite-based storage

Implementations§

Source§

impl SqliteStorage

Source

pub fn new() -> Result<Self>

Builds a new SQLite storage on the default path

Source

pub fn new_in_memory() -> Result<Self>

Builds a new in-memory SQLite storage for testing purposes

Source

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

Inserts a command and updates its id with the inserted value.

If the command already exist on the database, its description will be updated.

Returns wether the command was inserted or not (updated)

Source

pub fn insert_commands(&self, commands: &mut [Command]) -> Result<u64>

Inserts a bunch of commands and updates its id with the inserted value.

If any command already exist on the database, its description will be updated.

Returns the number of commands inserted (the rest are updated)

Source

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

Updates an existing command

Returns wether the command exists and was updated or not.

Source

pub fn increment_command_usage(&self, command_id: i64) -> Result<bool>

Updates an existing command by incrementing its usage by one

Returns wether the command exists and was updated or not.

Source

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

Deletes an existing command

Returns wether the command exists and was deleted or not.

Source

pub fn get_commands(&self, category: impl AsRef<str>) -> Result<Vec<Command>>

Get commands matching a category

Source

pub fn find_commands(&self, search: impl AsRef<str>) -> Result<Vec<Command>>

Finds commands matching the given search criteria

Source

pub fn export( &self, category: impl AsRef<str>, file_path: impl Into<String>, ) -> Result<usize>

Exports the commands from a given category into the given file path

§Returns

The number of exported commands

Source

pub fn import( &self, category: impl AsRef<str>, file_path: String, ) -> Result<u64>

Imports commands from the given file into a category.

§Returns

The number of newly inserted commands

Source

pub fn is_empty(&self) -> Result<bool>

Determines if the store is empty (no commands stored)

Source

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

Returns the number of stored commands

Source

pub fn insert_label_suggestion( &self, suggestion: &LabelSuggestion, ) -> Result<bool>

Inserts a label suggestion if it doesn’t exists.

Returns wether the suggestion was inserted or not (already existed)

Source

pub fn update_label_suggestion( &self, suggestion: &mut LabelSuggestion, new_suggestion: impl Into<String>, ) -> Result<bool>

Updates an existing label suggestion

Returns wether the suggestion exists and was updated or not.

Source

pub fn update_label_suggestion_usage( &self, suggestion: &LabelSuggestion, ) -> Result<bool>

Updates the usage of an existing label suggestion

Returns wether the suggestion exists and was updated or not.

Source

pub fn delete_label_suggestion( &self, suggestion: &LabelSuggestion, ) -> Result<bool>

Deletes an existing label suggestion

Returns wether the suggestion exists and was deleted or not.

Source

pub fn find_suggestions_for( &self, root_cmd: impl AsRef<str>, label: impl AsRef<str>, ) -> Result<Vec<LabelSuggestion>>

Finds label suggestions for the given root command and label

Trait Implementations§

Source§

impl Drop for SqliteStorage

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

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.
Source§

impl<T> ErasedDestructor for T
where T: 'static,