Skip to main content

sqlite_containers/
lib.rs

1// SQLite Containers
2// This file is part of the 'SQLite-based containers for Rust' project (sqlite-containers)
3// SPDX-License-Identifier: Unlicense
4
5//! SQLite-based containers for Rust
6//! ================================
7//!
8//! **`sqlite-containers`** provides [*map*](https://en.wikipedia.org/wiki/Associative_array) and [*set*](https://en.wikipedia.org/wiki/Set_(abstract_data_type)) implementations that are backed by **SQLite** [in-memory](https://www.sqlite.org/inmemorydb.html) databases.
9//!
10//! Intended as drop-in replacements for [`HashMap`](std::collections::HashMap) and [`HashSet`](std::collections::HashSet).
11//!
12//! Leveraging the power of the SQLite engine, `sqlite-containers` efficiently store billions of elements 😎
13//!
14//! Quick Start
15//! -----------
16//!
17//! This example demonstrates how to use **`SQLiteSet`**:
18//!
19//! ```rust
20//! use sqlite_containers::SQLiteSet;
21//!
22//! let mut sqlite_set = SQLiteSet::<String>::new().expect("Failed to create SQLiteSet!");
23//! let mut tx = sqlite_set.transaction().expect("Failed to start transaction!");
24//!
25//! println!("Inserting elements, please wait...");
26//!
27//! for n in 0..1_000_000u64 {
28//!     tx.insert(&format!("{:016X}", n)).expect("Insertion failed!");
29//! }
30//!
31//! tx.commit();
32//! println!("{} element(s) successfully inserted.", sqlite_set.len().unwrap());
33//! ```
34//!
35//! &#128073; For more details, please refer to the [`SQLiteMap`] and [`SQLiteSet`] documentation!
36//!
37//! Usage instructions
38//! ------------------
39//!
40//! In order to use **`sqlite-containers`** in your Rust project, simply add it to your `Cargo.toml` file:
41//!
42//! ```toml
43//! [dependencies]
44//! sqlite-containers = "2.0.0"
45//! ```
46//!
47//! #### Features
48//!
49//! * 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.
50//!
51//!   Use `default-features = false`, if you want to disable this default behavior and instead use the "system" SQLite library.
52//!
53//! * The **`with_rowid`** feature, which is *disabled* by default, prevents `sqlite-containers` from using the [`WITHOUT ROWID`](https://www.sqlite.org/withoutrowid.html) 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.
54//!
55//!   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.
56//!
57//! Acknowledgement
58//! ---------------
59//!
60//! This project is based on the [**SQLite**](https://www.sqlite.org/) library and the [**Rusqlite**](https://crates.io/crates/rusqlite) wrapper for Rust &#128571;
61//!
62//! License
63//! -------
64//!
65//! The “SQLite-based Containers for Rust” project is released under the [Unlicense](https://unlicense.org/).
66
67mod common;
68mod sqlite_map;
69mod sqlite_set;
70
71pub use crate::common::{Blob, CharType, Error, Size, SizeExt, Type};
72pub use crate::sqlite_map::{SQLiteMap, SQLiteMapTransaction};
73pub use crate::sqlite_set::{SQLiteSet, SQLiteSetTransaction};
74
75pub use rusqlite;