This is an rqlite database client library with optional extra convenience.
rqlite is an easy-to-use, lightweight, distributed relational database, which uses SQLite as its storage engine. It is super-simple to deploy, operating it is very straightforward, and its clustering capabilities provide you with fault-tolerance and high-availability.
See the documentation of rqlite database for a Quick start!
rqlite_client provides a type safe Rust library API to use some rqlite database backend from your code.
There is the possibility to create type safe queries and retrieve type safe results.
It has an optional implementation for database scheme migration and rollback.
Per default the HTTP(S) requests are handled by a provided
RequestBuilder
implementation based on crate ureq.
But you can provide any implementation yourself for supporting your preferred HTTP client.
The crate supports log or tracing.
See Usage and Examples for further information!
-
default = ["monitor", "ureq", "url"]
-
logUses
logfor some logging. Logger need to be configured vialogcrate in your application code. -
migrationEnables support for schema migration of rqlite database. See
Migration. -
migration_embedEnables schema migration support with embedding SQL from files in the application code. See
Migration. -
monitorEnables monitor endpoints. See Monitor.
-
percent_encodingIf you disable feature
url, you have to add featurepercent_encodingto get working GET SELECT queries. -
tracingUses
tracingfor some logging. Tracing need to be configured viatracingcrate in your application code. -
ureqThe default HTTP client used for communication with the rqlite database. If you disable the feature, you have to provide an own
RequestBuilderimplementation to handle your replacement ofRequest. -
ureq_charsetEnables Non-UTF8 charset handling in
ureqrequests. -
ureq_socks_proxyEnables support of Socks Proxy Urls in
ureq. -
ureq_tlsEnables TLS support for
ureq-requests with loading certs from system store. -
ureq_webpkiEnables TLS support for
ureq-requests with only embedded Mozilla cert store. -
urlUses per default
url::Urlinstead of string manipulation andpercent_encoding.
rqlite_client is an Open Source project and everybody should be encouraged to contribute
with the individual possibilities to improve the project and its results.
If you need help with your development based on this library, you may ask questions and for assistance in the Github discussions.
For any assistance with rqlite database, you are requested to get in contact with the rqlite project at https://rqlite.io/community/.
You are free to create meaningful and reproducable issue reports in Github issues. Please be kind, tolerant and forbear with developers providing you a beneficial product, although it isn't everybodys flavour and can't be perfect 😉
You can provide Pull-Requests to the Github main branch.
It is preferred that there are no warnings with warn(clippy::pedantic) and the build needs to
be successful with forbid(unsafe_code).
The stable-toolchain is used for development, but the crate should compile back to specified MSRV in Cargo.toml.
For running tests you'll need a working rqlited installation in subdirectory rqlite.
There is an rqlite/install.sh script which could do the installation for your environment, if the environment
is already supported in the script.
The test routines are looking up rqlited in a directory structure like rqlite/<arch>/rqlite/rqlited.
For testing make use of cargo.
$ cargo test --all-featuresThere is also a shell script ./test-features.sh to test all meaningful feature combinations.
$ ./test-features.shBefore crate release the tests need to be successful in all combinations with the cargo addon test-all-features:
$ cargo test-all-featuresBy default the enabled feature url handles url encoding. If you don't want to use url dependency, there is the possibility
to enable feature percent_encoding for handling url encoding.
One or the other needs to be enabled or the generated urls won't be correct!
If you want to use database scheme migration and rollback, you have to enable migration or migration_embed feature.
See Migration
for further documentation.
rqlite_client does some logging if there is enabled the feature log or tracing and the crates has been initialised
for logging.
A simple query of your local database might look like...
use std::time::Duration;
use rqlite_client::{
request_type::Get, response, Connection, Mapping, Query, Request,
RequestBuilder, response::Result,
};
let url = "http://localhost:4001";
##[cfg(feature = "url")]
let con = Connection::new(url).expect("url failed");
##[cfg(not(feature = "url"))]
let con = Connection::new(url);
let query = con
.query()
.set_sql_str_slice(&["SELECT COUNT(*) FROM tbl WHERE col = ?", "test"]);
let response_result = response::query::Query::from(query.request_run().unwrap());
if let Some(Mapping::Standard(success)) = response_result.results().next() {
let row = 0;
let col = 0;
if let Some(rows_found) = &success.value(row, col) {
println!("tbl has {rows_found} row(s)");
}
}See Query for further documentation.
To insert data you have to use
Connection::execute()
and request_type::Post.
use std::time::Duration;
use rqlite_client::{
request_type::Post, response, Connection, Mapping, Query, Request,
RequestBuilder, response::Result,
};
let url = "http://localhost:4001";
##[cfg(feature = "url")]
let con = Connection::new(url).expect("url failed");
##[cfg(not(feature = "url"))]
let con = Connection::new(url);
let query = con
.execute()
.push_sql_str_slice(&["INSERT INTO tbl (col) VALUES (?)", "test"]);
let response_result = response::query::Query::from(query.request_run().unwrap());
if let Some(Mapping::Execute(success)) = response_result.results().next() {
println!("last inserted primary key {}", success.last_insert_id);
}See Query for further documentation.
Source https://github.com/kolbma/rs_rqlite_client/tree/v0.1.0
Download https://github.com/kolbma/rs_rqlite_client/releases/tag/v0.1.0
LGPL-2.1-only LICENSE.md
rqlite_client - rqlite database client
Copyright (C) 2025 Markus Kolb
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA