···2233Documenting changes between versions beginning from v0.3.0
4455+## v0.10.0
66+77+* SQLite DB support
88+ * Safir now supports using either a JSON file as storage or an SQLite database
99+ * Activate this by running `safir mode database` or `safir mode file`
1010+1111+* Environments
1212+ * Safir now supports storing Key-Value pairs in specific environments
1313+ * Calling `safir use [environment-name]` will activate the specific environment
1414+ * New environments are created empty and stored KV pairs will remain in this environment
1515+ * A default environment called `default` is used initially
1616+ * Old stores from previous versions will be ported to this new format automatically
1717+518## v0.9.0
619720**THIS IS A BREAKING CHANGE**
···11[package]
22name = "safir"
33-version = "0.9.0"
33+version = "0.10.0"
44edition = "2021"
55-authors = ["Graham Keenan graham.keenan@outlook.com"]
55+authors = ["Graham Keenan <graham.keenan@outlook.com>"]
66license = "MIT OR Apache-2.0"
77description = "Key/Value store to share values between different shell sessions"
88readme = "README.md"
···1616anyhow = "1.0.75"
1717dirs = "5.0.1"
1818serde_json = "1.0.108"
1919+serde = { version = "1.0.203", features = ["derive"] }
2020+tokio = { version = "1.38.0", features = ["full"] }
2121+sqlx = { version = "0.7.4", features = ["runtime-tokio", "sqlite"] }
2222+async-trait = "0.1.80"
19232024# The profile that 'cargo dist' will build with
2125[profile.dist]
+34
README.md
···3333 rm Remove values from the store
3434 alias Output the alias command for key / value pairs
3535 export Output the export command for a key / value pairs
3636+ mode Sets the mode for Safir (active on the next run of Safir)
3637 list List all values in the store
3738 clear Clear all keys/values from the store
3839 purge Purges the .safirstore directory, removing it and its contents
4040+ use Use / create an environment to store key / value pairs
3941 help Print this message or the help of the given subcommand(s)
40424143Options:
4244 -h, --help Print help
4345 -V, --version Print version
4446```
4747+4848+## File Mode vs Database Mode
4949+5050+File mode is just like the old version of `safir` - all KV pairs are stored in a JSON value like before.
5151+5252+Database mode uses an SQLite database as storage instead which is _technically_ more secure.
5353+5454+Switching between modes does not carry over any changes from the previous mode (i.e. KV pairs added in File mode are not present in Database mode unless you add them yourself).
5555+5656+This could change in a future release
5757+5858+## Environments
5959+6060+Safir now supports storing KV pairs in specific environments which will declutter the `list` command and also keep all related KV pairs in one single place.
6161+6262+When Safir is loaded initially, it creates a new `default` environment (or loads an existing one) and uses that unlesss you switch environment.
6363+6464+Stores from older versions of Safir will automatically be ported over to this new format so there is no worry of lost data!
45654666## Examples
4767···103123```bash
104124safir purge # Will remove the .safirstore directory
105125```
126126+127127+Setting an environment:
128128+129129+```bash
130130+safir use [environment-name] # This will create an empty environment or load an existing one
131131+```
132132+133133+Switching between `file` and `database` mode:
134134+135135+```bash
136136+safir mode file # Switch to using a JSON file for storage
137137+138138+safir mode database # Switch to using an SQLite database for storage
139139+```
+8
migrations/20240620173629_create_db.sql
···11+-- Add migration script here
22+create table if not exists safir (
33+ key text not null primary key,
44+ value text not null,
55+ environment text not null
66+);
77+88+create index if not exists idx_key on safir(key);
+39-42
src/cli.rs
···11//! CLI for using the Safir binary
22-pub use clap::{Args, Parser, Subcommand};
22+use crate::store::config::SafirMode;
33+pub use clap::{Parser, Subcommand};
3445/// CLI arguments for running the program
56#[derive(Parser, Debug)]
···1617#[derive(Subcommand, Debug)]
1718pub enum Commands {
1819 /// Add a value to the store with the given key
1919- Add(AddArgs),
2020+ Add {
2121+ /// Key for the value
2222+ key: String,
2323+2424+ /// Value to add
2525+ value: String,
2626+ },
20272128 /// Get values from the store
2222- Get(GetArgs),
2929+ Get {
3030+ /// Keys for values to retrieve from the store
3131+ keys: Vec<String>,
3232+ },
23332434 /// Remove values from the store
2525- Rm(RemoveArgs),
3535+ Rm {
3636+ /// Keys for values to remove from the store
3737+ keys: Vec<String>,
3838+ },
3939+4040+ /// Output the alias command for key / value pairs
4141+ Alias {
4242+ /// Keys to alias the values
4343+ keys: Vec<String>,
4444+ },
26452727- /// Output the alias command for key / value pairs
2828- Alias(SetArgs),
4646+ /// Output the export command for a key / value pairs
4747+ Export {
4848+ /// Keys to export the values
4949+ keys: Vec<String>,
5050+ },
29513030- /// Output the export command for a key / value pairs
3131- Export(SetArgs),
5252+ /// Sets the mode for Safir (active on the next run of Safir)
5353+ Mode {
5454+ /// Mode to set (KV-file store or SQLite DB store)
5555+ mode: SafirMode,
5656+ },
32573358 /// List all values in the store
3459 List,
···38633964 /// Purges the .safirstore directory, removing it and its contents
4065 Purge,
4141-}
4242-4343-/// Arguments for adding a value to the store with a given key
4444-#[derive(Args, Debug)]
4545-pub struct AddArgs {
4646- /// Name of the item to store
4747- pub key: String,
4848-4949- /// Value to store
5050- pub value: String,
5151-}
5252-5353-/// Arguments for retrieving values from the store with the given keys
5454-#[derive(Args, Debug)]
5555-pub struct GetArgs {
5656- /// Keys to retrieve the values for
5757- ///
5858- /// Returns nothing if the key does not exist
5959- pub keys: Vec<String>,
6060-}
61666262-/// Arguments for removing values from the store with given keys
6363-#[derive(Args, Debug)]
6464-pub struct RemoveArgs {
6565- /// Name of the keys to remove from the store
6666- ///
6767- /// Does nothing if the keys do not exist
6868- pub keys: Vec<String>,
6969-}
7070-7171-/// Arguments for outputting commands with a given prefix
7272-#[derive(Args, Debug)]
7373-pub struct SetArgs {
7474- /// Name of the keys to display (e.g. alias / export)
7575- pub keys: Vec<String>,
6767+ /// Use / create an environment to store key / value pairs
6868+ Use {
6969+ /// Name of the environment to use / create
7070+ #[arg(default_value_t = String::from("default"))]
7171+ environment: String,
7272+ },
7673}