diff --git a/examples/demo.rs b/examples/demo.rs index 2e7a402e..347fe3d1 100644 --- a/examples/demo.rs +++ b/examples/demo.rs @@ -34,12 +34,8 @@ fn main() -> std::io::Result<()> { #[cfg(any(feature = "sqlite", feature = "sqlite-dynlib"))] let history = Box::new( - reedline::SqliteBackedHistory::with_file( - "history.sqlite3".into(), - history_session_id, - Some(chrono::Utc::now()), - ) - .map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e))?, + reedline::SqliteBackedHistory::with_file("history.sqlite3".into(), history_session_id) + .map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e))?, ); #[cfg(not(any(feature = "sqlite", feature = "sqlite-dynlib")))] let history = Box::new(FileBackedHistory::with_file(50, "history.txt".into())?); diff --git a/src/edit_mode/vi/command.rs b/src/edit_mode/vi/command.rs index e86f9f31..598867ba 100644 --- a/src/edit_mode/vi/command.rs +++ b/src/edit_mode/vi/command.rs @@ -122,7 +122,7 @@ impl Command { matches!(self, Command::Delete | Command::Change) } - pub fn to_reedline(&self, vi_state: &mut Vi) -> Vec { + pub fn to_reedline(&self, vi_state: &Vi) -> Vec { match self { Self::EnterViInsert => vec![ReedlineOption::Event(ReedlineEvent::Repaint)], Self::EnterViAppend => vec![ReedlineOption::Edit(EditCommand::MoveRight)], diff --git a/src/history/base.rs b/src/history/base.rs index 26d4da05..0f1b9a41 100644 --- a/src/history/base.rs +++ b/src/history/base.rs @@ -395,7 +395,7 @@ mod test { #[cfg(any(feature = "sqlite", feature = "sqlite-dynlib"))] fn open_history() -> Box { Box::new( - crate::SqliteBackedHistory::with_file("target/test-history.db".into(), None, None) + crate::SqliteBackedHistory::with_file("target/test-history.db".into(), None) .unwrap(), ) } diff --git a/src/history/item.rs b/src/history/item.rs index ec477bbc..a0537e43 100644 --- a/src/history/item.rs +++ b/src/history/item.rs @@ -21,7 +21,7 @@ impl Display for HistoryItemId { /// Unique ID for the session in which reedline was run to disambiguate different sessions #[derive(Debug, Copy, Clone, PartialEq, Eq)] -pub struct HistorySessionId(pub(crate) i64); +pub struct HistorySessionId(pub i64); impl HistorySessionId { pub(crate) const fn new(i: i64) -> HistorySessionId { HistorySessionId(i) diff --git a/src/history/sqlite_backed.rs b/src/history/sqlite_backed.rs index 7ab56e96..1ecf6a71 100644 --- a/src/history/sqlite_backed.rs +++ b/src/history/sqlite_backed.rs @@ -192,18 +192,18 @@ impl SqliteBackedHistory { /// /// **Side effects:** creates all nested directories to the file /// - pub fn with_file( - file: PathBuf, - session: Option, - session_timestamp: Option>, - ) -> Result { + pub fn with_file(file: PathBuf, session: Option) -> Result { if let Some(base_dir) = file.parent() { std::fs::create_dir_all(base_dir).map_err(|e| { ReedlineError(ReedlineErrorVariants::HistoryDatabaseError(format!("{e}"))) })?; } let db = Connection::open(&file).map_err(map_sqlite_err)?; - Self::from_connection(db, session, session_timestamp) + Self::from_connection( + db, + session, + session.map(|s| chrono::Utc.timestamp_nanos(s.0)), + ) } /// Creates a new history in memory pub fn in_memory() -> Result { @@ -357,6 +357,7 @@ impl SqliteBackedHistory { wheres.push("exit_status != 0"); } } + if let (Some(session_id), Some(session_timestamp)) = (query.filter.session, self.session_timestamp) { @@ -374,6 +375,7 @@ impl SqliteBackedHistory { if wheres.is_empty() { wheres = "true".to_string(); } + let query = format!( "SELECT {select_expression} \ FROM history \