sqlite-wasm-uuid-rs
Rust SQLite-WASM extension for UUIDv4 (Random) & UUIDv7 (Time-ordered) generation.
Powered by the uuid crate and built for sqlite-wasm-rs.
The crate is no_std and compiles to wasm32-unknown-unknown.
SQL Functions
uuid(): Returns a new random Version 4 UUID as a 36-character string.uuid_str(X): Parses X (blob or text) and returns a canonical 36-char string.uuid_blob(X): Converts X to a 16-byte blob, or generates a new one if no X.uuid7(): Returns a new Version 7 UUID as a 36-character string.uuid7_blob(): Returns a new Version 7 UUID as a 16-byte BLOB. If called with 1 argument, converts the input UUID (TEXT or BLOB format) to a 16-byte BLOB.
For instance, you can now set the DEFAULT value of a TEXT column to uuid() and of a BLOB column to uuid_blob() to have UUIDs automatically generated upon insertion.
(
id_text TEXT PRIMARY KEY DEFAULT (uuid),
id_blob BLOB PRIMARY KEY DEFAULT (uuid_blob),
idv7_text TEXT DEFAULT (uuid7),
idv7_blob BLOB DEFAULT (uuid7_blob)
);
Usage
First, add the dependency to your Cargo.toml:
[]
= "0.1"
Then, register the extension with your SQLite database connection:
unsafe
Rusqlite
See test-rusqlite for a complete example of using this extension with rusqlite.
Diesel
See test-diesel for a complete example of using this extension with diesel.
Testing
To run the tests (including the usage examples which are mirrored in the test suite), use wasm-pack:
# Run tests in Headless Firefox
# Or in Headless Chrome
Note: Standard
cargo testdoes not work for this crate as it targetswasm32-unknown-unknownand requires a browser environment provided bywasm-pack.