sqlite_hashes/fnv.rs
1use noncrypto_digests::Fnv;
2
3use crate::rusqlite::{Connection, Result};
4
5/// Register the `fnv1a` SQL function with the given `SQLite` connection.
6/// The `fnv1a` function uses [Fowler–Noll–Vo hash function](https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function#FNV-1a_hash) to compute the hash of the argument(s).
7///
8/// # Example
9///
10/// ```
11/// # use sqlite_hashes::rusqlite::{Connection, Result};
12/// # use sqlite_hashes::register_fnv_functions;
13/// # fn main() -> Result<()> {
14/// let db = Connection::open_in_memory()?;
15/// register_fnv_functions(&db)?;
16/// let hash: Vec<u8> = db.query_row("SELECT fnv1a('hello')", [], |r| r.get(0))?;
17/// let expected = b"\xA4\x30\xD8\x46\x80\xAA\xBD\x0B";
18/// assert_eq!(hash, expected);
19/// # Ok(())
20/// # }
21/// ```
22pub fn register_fnv_functions(conn: &Connection) -> Result<()> {
23 crate::scalar::create_hash_fn::<Fnv>(conn, "fnv1a")
24}