diff --git a/Cargo.toml b/Cargo.toml index b6d9c5f..f0f2e26 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "julid-rs" -version = "1.6.180" +version = "1.6.1803" authors = ["Joe Ardent "] edition = "2021" keywords = ["ulid", "library", "sqlite", "extension", "julid"] @@ -26,14 +26,19 @@ crate-type = ["cdylib", "rlib"] [dependencies] rand = "0.8" + +# for the CLI +clap = { version = "4.3", default-features = false, features = ["help", "usage", "std", "derive"] } + # all other deps are optional chrono = { version = "0.4", optional = true, default-features = false, features = ["std", "time"] } serde = { version = "1.0", features = ["derive"], optional = true } sqlx = { version = "0.7", features = ["sqlite"], default-features = false, optional = true } sqlite-loadable = { version = "0.0.5", optional = true } -[dev-dependencies] -clap = { version = "4.3", default-features = false, features = ["help", "usage", "std", "derive"] } +[[bin]] +name = "julid-gen" +path = "src/bin/gen.rs" [package.metadata.docs.rs] all-features = true diff --git a/README.md b/README.md index c0c535b..efa7e3e 100644 --- a/README.md +++ b/README.md @@ -140,6 +140,12 @@ where the wildcards get bound in a loop with unique values and the Julid `id` fi generated by the extension for each row, I get over 100,000 insertions/second when using a file-backed DB in WAL mode and `NORMAL` durability settings. +### Safety +There is one `unsafe fn` in this project, `sqlite_julid_init()`, and it is only built for the +`plugin` feature. The reason for it is that it's interacting with foreign code (SQLite itself) via +the C interface, which is inherently unsafe. If you are not building the plugin, there is no +`unsafe` code. + ## Inside a Rust program Of course, you can also use it outside of a database; the `Julid` type is publicly exported. There's @@ -191,11 +197,37 @@ inside your Rust application, especially if you're *also* loading it as an exten your application. You'll get a long and confusing runtime panic due to there being multiple entrypoints defined with the same name. -### Safety -There is one `unsafe fn` in this project, `sqlite_julid_init()`, and it is only built for the -`plugin` feature. The reason for it is that it's interacting with foreign code (SQLite itself) via -the C interface, which is inherently unsafe. If you are not building the plugin, there is no -`unsafe` code. +## On the command line + +An even simpler program than the benchmark called `julid-gen` is available to install via cargo: + +`cargo install julid-rs --no-default-features` + +And then using it is as simple as, + +``` text +$ julid-gen -h +Generate and print Julids + +Usage: julid-gen [NUM] + +Arguments: + [NUM] Number of Julids to generate [default: 1] + +Options: + -h, --help Print help + -V, --version Print version + +$ julid-gen +01H9DYRVDX0001X0RE5Y7XFGBC + +$ julid-gen 5 +01H9DYT48E000EK2EH7P67N8GG +01H9DYT48E000ZBKXVZ91HEZX4 +01H9DYT48E0012VX89PYX4HDKP +01H9DYT48E001GE29AWCH1RDCM +01H9DYT48E0028CDHNVC59KKHQ +``` # Thanks diff --git a/VERSION b/VERSION index d0873b8..9a0be07 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.6180 +1.61803 diff --git a/src/bin/gen.rs b/src/bin/gen.rs new file mode 100644 index 0000000..616ba8f --- /dev/null +++ b/src/bin/gen.rs @@ -0,0 +1,18 @@ +use clap::Parser; +use julid::Julid; + +#[derive(Debug, Parser)] +#[command(author, version = "1.61803", about = "Generate and print Julids")] +struct Cli { + #[clap(help = "Number of Julids to generate", default_value_t = 1)] + pub num: usize, +} + +fn main() { + let cli = Cli::parse(); + let num = cli.num; + + for _ in 0..num { + println!("{}", Julid::new()); + } +}