pub trait History: Send {
fn save(&mut self, h: HistoryItem) -> Result<HistoryItem, ReedlineError>;
fn load(&self, id: HistoryItemId) -> Result<HistoryItem, ReedlineError>;
fn count(&self, query: SearchQuery) -> Result<i64, ReedlineError>;
fn search(
&self,
query: SearchQuery
) -> Result<Vec<HistoryItem>, ReedlineError>;
fn update(
&mut self,
id: HistoryItemId,
updater: &dyn Fn(HistoryItem) -> HistoryItem
) -> Result<(), ReedlineError>;
fn delete(&mut self, h: HistoryItemId) -> Result<(), ReedlineError>;
fn sync(&mut self) -> Result<()>;
fn count_all(&self) -> Result<i64, ReedlineError> { ... }
}
Expand description
Represents a history file or database
Data could be stored e.g. in a plain text file, in a JSONL
file, in a SQLite
database
Required Methods
sourcefn save(&mut self, h: HistoryItem) -> Result<HistoryItem, ReedlineError>
fn save(&mut self, h: HistoryItem) -> Result<HistoryItem, ReedlineError>
save a history item to the database if given id is None, a new id is created and set in the return value if given id is Some, the existing entry is updated
sourcefn load(&self, id: HistoryItemId) -> Result<HistoryItem, ReedlineError>
fn load(&self, id: HistoryItemId) -> Result<HistoryItem, ReedlineError>
load a history item by its id
sourcefn count(&self, query: SearchQuery) -> Result<i64, ReedlineError>
fn count(&self, query: SearchQuery) -> Result<i64, ReedlineError>
retrieves the next unused session id count the results of a query
sourcefn search(&self, query: SearchQuery) -> Result<Vec<HistoryItem>, ReedlineError>
fn search(&self, query: SearchQuery) -> Result<Vec<HistoryItem>, ReedlineError>
return the results of a query
sourcefn update(
&mut self,
id: HistoryItemId,
updater: &dyn Fn(HistoryItem) -> HistoryItem
) -> Result<(), ReedlineError>
fn update(
&mut self,
id: HistoryItemId,
updater: &dyn Fn(HistoryItem) -> HistoryItem
) -> Result<(), ReedlineError>
update an item atomically
sourcefn delete(&mut self, h: HistoryItemId) -> Result<(), ReedlineError>
fn delete(&mut self, h: HistoryItemId) -> Result<(), ReedlineError>
remove an item from this history