Skip to content

Commit

Permalink
Minor ver, Requre rusqlite-v0.33, MSRV, dep update (#52)
Browse files Browse the repository at this point in the history
* Require v0.33 of the rusqlite dependency
* Update all other dependencies
* Bump minor version due to MSRV change

---------

Co-authored-by: Yuri Astrakhan <[email protected]>
  • Loading branch information
jessekrubin and nyurik authored Feb 11, 2025
1 parent dd62cf0 commit c1a6c4e
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 54 deletions.
58 changes: 16 additions & 42 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
[package]
name = "sqlite-hashes"
version = "0.7.9" # This value is also used in the README.md
version = "0.8.0" # This value is also used in the README.md
description = "Hashing functions for SQLite with aggregation support: MD5, SHA1, SHA256, SHA512, FNV-1a, xxHash"
authors = ["Yuri Astrakhan <[email protected]>"]
repository = "https://github.com/nyurik/sqlite-hashes"
edition = "2021"
license = "MIT OR Apache-2.0"
keywords = ["sqlite", "rusqlite", "hash", "md5", "sha256"]
categories = ["database", "cryptography"]
rust-version = "1.77.2"
rust-version = "1.82"

[lib]
name = "sqlite_hashes"
Expand Down Expand Up @@ -61,8 +61,7 @@ hex = { version = "0.4", optional = true }
log = { version = "0.4.25", optional = true }

# There are multiple versions that could work, but sqlx requires a specific one, so don't limit it here
# Note that cdylib requires >= 0.32 (controlled by the lock file)
rusqlite = { version = ">=0.30, <0.33", features = ["functions"] }
rusqlite = { version = ">=0.33", features = ["functions"] }

# Digest and all hashing algorithms are using the same crates internally, so should be kept in sync
digest = "0.10.7"
Expand Down
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,18 @@ register_hash_functions(&db).unwrap();

// Hash 'password' using SHA-256, and dump resulting BLOB as a HEX string
let sql = "SELECT hex(sha256('password'));";
let hash: String = db.query_row_and_then( & sql, [], | r| r.get(0)).unwrap();
let hash: String = db.query_row_and_then(&sql, [], |r| r.get(0)).unwrap();
assert_eq!(hash, "5E884898DA28047151D0E56F8DC6292773603D0D6AABBDD62A11EF721D1542D8");

// Same as above, but use sha256_hex() function to dump the result as a HEX string directly
let sql = "SELECT sha256_hex('password');";
let hash: String = db.query_row_and_then( & sql, [], | r| r.get(0)).unwrap();
let hash: String = db.query_row_and_then(&sql, [], |r| r.get(0)).unwrap();
assert_eq!(hash, "5E884898DA28047151D0E56F8DC6292773603D0D6AABBDD62A11EF721D1542D8");

// Hash 'pass' (as text) and 'word' (as blob) using SHA-256, and dump it as a HEX string
// The result is the same as the above 'password' example.
let sql = "SELECT sha256_hex(cast('pass' as text), cast('word' as blob));";
let hash: String = db.query_row_and_then( & sql, [], | r| r.get(0)).unwrap();
let hash: String = db.query_row_and_then(&sql, [], |r| r.get(0)).unwrap();
assert_eq!(hash, "5E884898DA28047151D0E56F8DC6292773603D0D6AABBDD62A11EF721D1542D8");
```

Expand Down Expand Up @@ -126,7 +126,7 @@ least for now.
use sqlite_hashes::{register_hash_functions, rusqlite::Connection};

let db = Connection::open_in_memory().unwrap();
register_hash_functions( & db).unwrap();
register_hash_functions(&db).unwrap();

// Pre-populate the DB with some data. Note that the b values are not alphabetical.
db.execute_batch("
Expand All @@ -137,12 +137,12 @@ db.execute_batch("
let sql = "SELECT sha256_concat_hex(v) OVER (
ORDER BY v ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING)
FROM tbl LIMIT 1;";
let hash: String = db.query_row_and_then( & sql, [], | r| r.get(0)).unwrap();
let hash: String = db.query_row_and_then(&sql, [], |r| r.get(0)).unwrap();
assert_eq!(hash, "FB84A45F6DF7D1D17036F939F1CFEB87339FF5DBDF411222F3762DD76779A287");

// The above window aggregation example is equivalent to this scalar hash:
let sql = "SELECT sha256_hex('aaabbbccc');";
let hash: String = db.query_row_and_then( & sql, [], | r| r.get(0)).unwrap();
let hash: String = db.query_row_and_then(&sql, [], |r| r.get(0)).unwrap();
assert_eq!(hash, "FB84A45F6DF7D1D17036F939F1CFEB87339FF5DBDF411222F3762DD76779A287");
```

Expand Down Expand Up @@ -178,7 +178,7 @@ binary size.

```toml
[dependencies]
sqlite-hashes = { version = "0.7", default-features = false, features = ["hex", "window", "sha256"] }
sqlite-hashes = { version = "0.8", default-features = false, features = ["hex", "window", "sha256"] }
```

* **trace** - enable tracing support, logging all function calls and their arguments
Expand Down
2 changes: 1 addition & 1 deletion src/scalar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ pub(crate) fn create_hash_fn<T: NamedDigest + Clone + UnwindSafe + RefUnwindSafe

pub fn create_scalar_function<F, T>(conn: &Connection, fn_name: &str, function: F) -> Result<()>
where
F: FnMut(&Context<'_>) -> Result<T> + Send + UnwindSafe + 'static,
F: Fn(&Context<'_>) -> Result<T> + Send + UnwindSafe + 'static,
T: ToSql,
{
trace!("Registering function {fn_name}");
Expand Down

0 comments on commit c1a6c4e

Please sign in to comment.