add cli util, bump version to publish to crates
This commit is contained in:
parent
50a59e1898
commit
f4ac603ac8
4 changed files with 64 additions and 9 deletions
11
Cargo.toml
11
Cargo.toml
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "julid-rs"
|
name = "julid-rs"
|
||||||
version = "1.6.180"
|
version = "1.6.1803"
|
||||||
authors = ["Joe Ardent <code@ardent.nebcorp.com>"]
|
authors = ["Joe Ardent <code@ardent.nebcorp.com>"]
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
keywords = ["ulid", "library", "sqlite", "extension", "julid"]
|
keywords = ["ulid", "library", "sqlite", "extension", "julid"]
|
||||||
|
@ -26,14 +26,19 @@ crate-type = ["cdylib", "rlib"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
rand = "0.8"
|
rand = "0.8"
|
||||||
|
|
||||||
|
# for the CLI
|
||||||
|
clap = { version = "4.3", default-features = false, features = ["help", "usage", "std", "derive"] }
|
||||||
|
|
||||||
# all other deps are optional
|
# all other deps are optional
|
||||||
chrono = { version = "0.4", optional = true, default-features = false, features = ["std", "time"] }
|
chrono = { version = "0.4", optional = true, default-features = false, features = ["std", "time"] }
|
||||||
serde = { version = "1.0", features = ["derive"], optional = true }
|
serde = { version = "1.0", features = ["derive"], optional = true }
|
||||||
sqlx = { version = "0.7", features = ["sqlite"], default-features = false, optional = true }
|
sqlx = { version = "0.7", features = ["sqlite"], default-features = false, optional = true }
|
||||||
sqlite-loadable = { version = "0.0.5", optional = true }
|
sqlite-loadable = { version = "0.0.5", optional = true }
|
||||||
|
|
||||||
[dev-dependencies]
|
[[bin]]
|
||||||
clap = { version = "4.3", default-features = false, features = ["help", "usage", "std", "derive"] }
|
name = "julid-gen"
|
||||||
|
path = "src/bin/gen.rs"
|
||||||
|
|
||||||
[package.metadata.docs.rs]
|
[package.metadata.docs.rs]
|
||||||
all-features = true
|
all-features = true
|
||||||
|
|
42
README.md
42
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
|
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.
|
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
|
## Inside a Rust program
|
||||||
|
|
||||||
Of course, you can also use it outside of a database; the `Julid` type is publicly exported. There's
|
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
|
your application. You'll get a long and confusing runtime panic due to there being multiple
|
||||||
entrypoints defined with the same name.
|
entrypoints defined with the same name.
|
||||||
|
|
||||||
### Safety
|
## On the command line
|
||||||
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
|
An even simpler program than the benchmark called `julid-gen` is available to install via cargo:
|
||||||
the C interface, which is inherently unsafe. If you are not building the plugin, there is no
|
|
||||||
`unsafe` code.
|
`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
|
# Thanks
|
||||||
|
|
||||||
|
|
2
VERSION
2
VERSION
|
@ -1 +1 @@
|
||||||
1.6180
|
1.61803
|
||||||
|
|
18
src/bin/gen.rs
Normal file
18
src/bin/gen.rs
Normal file
|
@ -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());
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue