29 releases

new 0.6.0 Jan 12, 2025
0.5.0 Dec 28, 2024
0.4.1 Dec 17, 2024
0.4.0 Nov 25, 2024
0.3.6 Mar 22, 2024

#728 in Database interfaces

Download history 33/week @ 2024-09-25 14/week @ 2024-10-02 1/week @ 2024-10-09 203/week @ 2024-10-16 52/week @ 2024-10-23 1/week @ 2024-11-06 27/week @ 2024-11-13 109/week @ 2024-11-20 74/week @ 2024-11-27 39/week @ 2024-12-04 91/week @ 2024-12-11 62/week @ 2024-12-18 149/week @ 2024-12-25 64/week @ 2025-01-01 181/week @ 2025-01-08

520 downloads per month
Used in testcontainers-modules

MIT/Apache

110KB
2.5K SLoC

rqlite-rs

build status Test Coverage Crates.io Documentation License Crates.io Rust

rqlite-rs is a Rust client for rqlite, the distributed relational database built on SQLite, providing an async interface for seamless integration with Rust's async ecosystems. Utilizing reqwest for efficient connection management, it offers a Rustic, high-level API for easy and efficient interaction with rqlite clusters.

Features

  • Asynchronous Interface: Fully async, compatible with Tokio, async-std, and smol.
  • Connection Pooling: Efficient management of connections to the rqlite cluster.
  • High-Level API: Simplifies interactions with the rqlite API.
  • Resilience: Automatic failover to a secondary node on connectivity issues.
  • Cluster Management: Full control over the cluster with node query and management features.

Installation

Add to your Cargo.toml:

[dependencies]
...
+ rqlite-rs = "0.6.0"

Quick Start

Ensure you have a running rqlite cluster. Replace localhost:4001 and localhost:4002 with your node addresses:

use rqlite_rs::prelude::*;

#[derive(FromRow)]
pub struct Table {
    name: String,
}

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    let client = RqliteClientBuilder::new()
        .known_host("localhost:4001")
        .build()?;

    let query = rqlite_rs::query!(
        "SELECT name FROM sqlite_master WHERE type='table' AND name NOT LIKE 'sqlite_%'"
    )?;

    let rows = client.fetch(query).await?;

    let tables = rows.into_typed::<Table>()?;

    for table in tables {
        println!("Table: {}", table.name);
    }

    Ok(())
}

Resilience

rqlite-rs supports automatic failover to a different node in the cluster. This can be done using one of the provided fallback strategies (e.g., Random, RoundRobin, Priority). Furthermore you can also implement your own fallback strategy by implementing the FallbackStrategy trait. An example of this can be found in the custom_fallback example.

Documentation

For detailed API documentation and advanced usage, visit rqlite-rs documentation.

Contributing

Contributions are welcome!

License

rqlite-rs is licensed under either of

at your option.

Dependencies

~4–16MB
~200K SLoC