-
Notifications
You must be signed in to change notification settings - Fork 195
SQLite History (third version) #401
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
4f71b89
basic sqlite history
phiresky dd93aba
fix test compilation
phiresky 4c03e68
final touches for MVP
phiresky a669fb3
better documentation
phiresky 187f867
fix for empty history
phiresky 01b62e7
partial change to non-generic history
phiresky 3e76ae7
mostly working
phiresky 317a69f
fix tests and ci
phiresky 7d4b7ca
fixes, format
phiresky 5fc904e
move history item to new file
phiresky f756189
fix some comments, fix test compile errors
phiresky 4d60705
ci features matrix
phiresky 13b32b9
fix index creation
phiresky 56a210c
fix file-based tests
phiresky 7c6b09a
move logic for not saving empty entries to engine
phiresky 9cab40f
fix update last command on empty, set up application_id and check ver…
phiresky 37afda0
Merge remote-tracking branch 'origin/main' into sqlite-history-2
phiresky 556115b
add specific error variants
phiresky 285ea4b
format
phiresky c772fad
fix compile errors
phiresky 74c8f71
fix fmt
fdncred d84fd86
sqlite with bashisms
elferherrera a9c9d3a
Merge branch 'main' of https://github.com/nushell/reedline into sqlit…
elferherrera 428544d
hide with features
elferherrera 014bd48
cargo fmt
elferherrera a8d8703
improve performance of bashisms selectors
phiresky 33b7610
Merge remote-tracking branch 'origin/main' into sqlite-history-2
phiresky 6d803bb
Style: Remove commented out code
sholderbach File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
move history item to new file
- Loading branch information
commit 5fc904e0750f54a065720c1b74acecc6d208f890
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| use std::time::Duration; | ||
|
|
||
| use chrono::Utc; | ||
| use serde::{de::DeserializeOwned, Deserialize, Serialize}; | ||
|
|
||
| #[derive(Debug, Copy, Clone, PartialEq, Eq)] | ||
| pub struct HistoryItemId(pub(crate) i64); | ||
| impl HistoryItemId { | ||
| pub(crate) fn new(i: i64) -> HistoryItemId { | ||
| HistoryItemId(i) | ||
| } | ||
| } | ||
| #[derive(Debug, Copy, Clone, PartialEq, Eq)] | ||
| pub struct HistorySessionId(pub(crate) i64); | ||
| impl HistorySessionId { | ||
| pub(crate) fn new(i: i64) -> HistorySessionId { | ||
sholderbach marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| HistorySessionId(i) | ||
| } | ||
| } | ||
| /// This trait represents additional arbitrary context to be added to a history (optional, see [HistoryItem]) | ||
| pub trait HistoryItemExtraInfo: Serialize + DeserializeOwned + Default + Send {} | ||
| #[derive(Default, Debug, PartialEq, Eq)] | ||
| /// something that is serialized as null and deserialized by ignoring everything | ||
| pub struct Anything; | ||
sholderbach marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| impl Serialize for Anything { | ||
| fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error> | ||
| where | ||
| S: serde::Serializer, | ||
| { | ||
| Option::<Anything>::None.serialize(serializer) | ||
| } | ||
| } | ||
| impl<'de> Deserialize<'de> for Anything { | ||
| fn deserialize<D>(d: D) -> std::result::Result<Self, D::Error> | ||
| where | ||
| D: serde::Deserializer<'de>, | ||
| { | ||
| serde::de::IgnoredAny::deserialize(d).map(|_| Anything) | ||
| } | ||
| } | ||
| impl HistoryItemExtraInfo for Anything {} | ||
| /// Represents one run command with some optional additional context | ||
| #[derive(Clone, Debug, PartialEq)] | ||
| pub struct HistoryItem<ExtraInfo: HistoryItemExtraInfo = Anything> { | ||
| /// primary key, unique across one history | ||
| pub id: Option<HistoryItemId>, | ||
| /// date-time when this command was started | ||
| pub start_timestamp: Option<chrono::DateTime<Utc>>, | ||
| /// the full command line as text | ||
| pub command_line: String, | ||
| /// a unique id for one shell session. | ||
| /// used so the history can be filtered to a single session | ||
| pub session_id: Option<HistorySessionId>, | ||
| /// the hostname the commands were run in | ||
| pub hostname: Option<String>, | ||
| /// the current working directory | ||
| pub cwd: Option<String>, | ||
| /// the duration the command took to complete | ||
| pub duration: Option<Duration>, | ||
| /// the exit status of the command | ||
| pub exit_status: Option<i64>, | ||
| /// arbitrary additional information that might be interesting | ||
| pub more_info: Option<ExtraInfo>, | ||
| } | ||
|
|
||
| impl HistoryItem { | ||
| /// create a history item purely from the command line with everything else set to None | ||
| pub fn from_command_line(cmd: impl Into<String>) -> HistoryItem { | ||
| HistoryItem { | ||
| id: None, | ||
| start_timestamp: None, | ||
| command_line: cmd.into(), | ||
| session_id: None, | ||
| hostname: None, | ||
| cwd: None, | ||
| duration: None, | ||
| exit_status: None, | ||
| more_info: None, | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,15 +1,14 @@ | ||
| mod base; | ||
| mod cursor; | ||
| mod file_backed; | ||
| mod item; | ||
| #[cfg(feature = "sqlite")] | ||
| mod sqlite_backed; | ||
| #[cfg(feature = "sqlite")] | ||
| pub use sqlite_backed::SqliteBackedHistory; | ||
|
|
||
| pub use base::{ | ||
| History, HistoryItem, HistoryItemId, HistoryNavigationQuery, Result, SearchDirection, | ||
| SearchQuery, | ||
| }; | ||
| pub use base::{History, HistoryNavigationQuery, Result, SearchDirection, SearchQuery}; | ||
| pub use cursor::HistoryCursor; | ||
| pub use item::{HistoryItem, HistoryItemId, HistorySessionId}; | ||
|
|
||
| pub use file_backed::{FileBackedHistory, HISTORY_SIZE}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.