pub struct SQLiteDriver {
pub name: String,
pub options: SQLiteDriverOptions,
pub table: String,
pub database: Connection,
}
Expand description
SQLite database driver for storing and managing JSON data.
The SQLiteDriver
provides methods for interacting with an SQLite database,
including adding, retrieving, updating, and deleting JSON data in a specified table.
It abstracts the database operations and allows the user to interact with the database as if it were a key-value store, with the data being stored as serialised JSON.
§Fields
name
: The name of the SQLite database file.options
: Configuration options for the SQLite driver, including the database file name and table name.table
: The name of the table in the SQLite database to operate on.database
: The connection to the SQLite database.
Fields§
§name: String
The name of the SQLite database file.
options: SQLiteDriverOptions
Configuration options for the SQLite driver, including the database file and table name
table: String
The name of the table in the SQLite database to operate on.
database: Connection
The connection to the SQLite database.
Implementations§
Source§impl SQLiteDriver
impl SQLiteDriver
Sourcepub fn new(options: Option<SQLiteDriverOptions>) -> Result<Self>
pub fn new(options: Option<SQLiteDriverOptions>) -> Result<Self>
Creates a new instance of the SQLiteDriver
with the provided options.
If no options are provided, it defaults to using json.sqlite
as the
database file and json
as the table name.
§Parameters
options
: Optional configuration options for the SQLite database.
§Returns
A Result
containing either the SQLiteDriver
instance or an error.
Sourcepub fn add(&self, key: &str, value: f64) -> Result<f64>
pub fn add(&self, key: &str, value: f64) -> Result<f64>
Adds a value to an existing entry or creates a new entry if it doesn’t exist. The value is added to the current value of the entry (if it exists).
§Parameters
key
: The key for the entry to update.value
: The value to add to the current entry.
§Returns
The new value after adding value
to the existing entry, or an error if
the value is not finite (e.g., NaN or infinity).
Sourcepub fn all(&self) -> Result<Vec<(String, Value)>>
pub fn all(&self) -> Result<Vec<(String, Value)>>
Retrieves all data entries from the database as a vector of tuples.
§Returns
A Result
containing a vector of tuples where each tuple consists of
a key (String
) and a corresponding value (serde_json::Value
).
Sourcepub fn delete_all(&self) -> Result<bool>
pub fn delete_all(&self) -> Result<bool>
Deletes all entries in the database.
§Returns
A Result
indicating whether the deletion was successful.