#sqlx #rqlite #driver #sql #direct #details

sqlx-rqlite

rqlite driver implementation for SQLx. Not for direct use; see the sqlx crate for details.

4 releases

0.1.3 Mar 13, 2024
0.1.2 Mar 13, 2024
0.1.1 Mar 13, 2024
0.1.0 Mar 13, 2024

#1207 in Database interfaces

Download history 242/week @ 2024-03-13 10/week @ 2024-03-20 8/week @ 2024-03-27 13/week @ 2024-04-03

273 downloads per month

Apache-2.0

61KB
1.5K SLoC

SQLx rqlite

The Rust SQL Toolkit rqlite driver

Sqlx driver for rqlite

Install

You need to have rqlite installed on your system.

Usage

A simple Cargo dependency would look like this :

[dependencies]
sqlx-rqlite = { version = "0.1" }
sqlx = {  version = "0.7" , default-features = false, features = ["macros", "runtime-tokio", "tls-none"] }
tokio = { version = "1", features = [ "full" ] }

Assuming an rqlite node listens at "127.0.0.1:4001", a simple app would proceed as follows:

use futures_util::StreamExt;
use sqlx::prelude::*;
use sqlx_rqlite::RqlitePoolOptions;

//#[async_std::main] // Requires the `attributes` feature of `async-std`
#[tokio::main]
// or #[actix_web::main]
async fn main() -> Result<(), sqlx::Error> {
  let pool = RqlitePoolOptions::new()
        //.max_connections(5)
        .connect("rqlite://localhost:4001")
        .await?;
  sqlx::query(
        "CREATE TABLE IF NOT EXISTS _sqlx_rqlite_test_user_ (
        id INTEGER PRIMARY KEY,
        name TEXT NOT NULL UNIQUE
    )",
    )
    .execute(&pool)
    .await?;
    
  
    
  let mut row = sqlx::query("SELECT * FROM _sqlx_rqlite_test_user_  WHERE name = ?")
        .bind("JohnDoe")
        .fetch_optional(&pool)
        .await?;

    if row.is_none() {
        sqlx::query("INSERT INTO _sqlx_rqlite_test_user_  (name) VALUES (?);")
            .bind("JohnDoe")
            .execute(&pool)
            .await?;
        row = sqlx::query("SELECT * FROM _sqlx_rqlite_test_user_  WHERE name = 'JohnDoe'")
            .fetch_optional(&pool)
            .await?;
    }
    assert!(row.is_some());
    sqlx::query(
        "DROP TABLE _sqlx_rqlite_test_user_",
    )
    .execute(&pool)
    .await?;
    Ok(())
}

To get "datetime" support, you need to enable the feature "chrono".


Security

For a secured connection, use:

let pool = RqlitePoolOptions::new()
        //.max_connections(5)
        .connect("rqlite://localhost:4001&ssl=yes")
        .await?;

⚠️ DANGER In case you opt in for an insecure ssl connection (which accepts invalid certificates), use:

let pool = RqlitePoolOptions::new()
        //.max_connections(5)
        .connect("rqlite://localhost:4001&ssl-insecure=yes")
        .await?;

License

Licensed under

Contribution

Unless you explicitly state otherwise, any Contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be licensed as above, without any additional terms or conditions.

Dependencies

~19–32MB
~574K SLoC