Skip to main content

Crate sqlite_containers

Crate sqlite_containers 

Source
Expand description

§SQLite-based containers for Rust

sqlite-containers provides map and set implementations that are backed by SQLite in-memory databases.

Intended as drop-in replacements for HashMap and HashSet.

Leveraging the power of the SQLite engine, sqlite-containers efficiently store billions of elements 😎

§Quick Start

This example demonstrates how to use SQLiteSet:

use sqlite_containers::SQLiteSet;

let mut sqlite_set = SQLiteSet::<String>::new().expect("Failed to create SQLiteSet!");
let mut tx = sqlite_set.transaction().expect("Failed to start transaction!");

println!("Inserting elements, please wait...");

for n in 0..1_000_000u64 {
    tx.insert(&format!("{:016X}", n)).expect("Insertion failed!");
}

tx.commit();
println!("{} element(s) successfully inserted.", sqlite_set.len().unwrap());

👉 For more details, please refer to the SQLiteMap and SQLiteSet documentation!

§Usage instructions

In order to use sqlite-containers in your Rust project, simply add it to your Cargo.toml file:

[dependencies]
sqlite-containers = "2.0.0"
§Features
  • The bundled feature, which is enabled by default, automatically compiles and links in an up to date version of SQLite for you. This avoids many common build issues, and avoids depending on the version of SQLite on the users system.

    Use default-features = false, if you want to disable this default behavior and instead use the “system” SQLite library.

  • The with_rowid feature, which is disabled by default, prevents sqlite-containers from using the WITHOUT ROWID optimization, allowing SQLite to implicitly create the special “rowid” column. By default, i.e., if the with_rowid feature is not explicitly enabled, WITHOUT ROWID will be used and thus the creation of a “rowid” column is suppressed.

    Please note that, in most cases, using the WITHOUT ROWID optimization (the default) should improve the performance. This means that enabling the with_rowid feature is not normally recommended! Nonetheless, there are situations where with_rowid can actually be beneficial, so it is definitely worth trying for fine-tuning the performance of your application.

§Acknowledgement

This project is based on the SQLite library and the Rusqlite wrapper for Rust 😻

§License

The “SQLite-based Containers for Rust” project is released under the Unlicense.

Re-exports§

pub use rusqlite;

Structs§

Error
Indicates that the operation failed due to an SQLite error.
SQLiteMap
A map that stores key-value pairs with keys of type K and values of type V, backed by an SQLite in-memory database.
SQLiteMapTransaction
Represents an active SQLite transaction for a SQLiteMap.
SQLiteSet
A set that stores keys of type T, backed by an SQLite in-memory database.
SQLiteSetTransaction
Represents an active SQLite transaction for a SQLiteSet.

Traits§

CharType
Represents a character-based type, e.g., String.
SizeExt
Provides useful helper functions for the Size type.
Type
The type of the keys or values that are stored in an SQLiteMap or an SQLiteSet.

Type Aliases§

Blob
Binary Large Object (BLOB), represented as a Vec<u8>.
Size
The “size” type used by len(), equal to usize on this platform.