pub trait History: Send {
fn save(&mut self, h: HistoryItem) -> Result<HistoryItem, ReedlineError>;
fn load(&self, id: HistoryItemId) -> Result<HistoryItem, ReedlineError>;
fn next_session_id(&mut self) -> Result<HistorySessionId, 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
fn 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
fn load(&self, id: HistoryItemId) -> Result<HistoryItem, ReedlineError>
fn load(&self, id: HistoryItemId) -> Result<HistoryItem, ReedlineError>
load a history item by its id
fn next_session_id(&mut self) -> Result<HistorySessionId, ReedlineError>
fn next_session_id(&mut self) -> Result<HistorySessionId, ReedlineError>
retrieves the next unused session id
fn count(&self, query: SearchQuery) -> Result<i64, ReedlineError>
fn count(&self, query: SearchQuery) -> Result<i64, ReedlineError>
count the results of a query
fn search(&self, query: SearchQuery) -> Result<Vec<HistoryItem>, ReedlineError>
fn search(&self, query: SearchQuery) -> Result<Vec<HistoryItem>, ReedlineError>
return the results of a query
fn 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
fn delete(&mut self, h: HistoryItemId) -> Result<(), ReedlineError>
fn delete(&mut self, h: HistoryItemId) -> Result<(), ReedlineError>
remove an item from this history