Asynchronous handle for rusqlite library.

Overview

License Crates.io Docs - Stable

tokio-rusqlite

Asynchronous handle for rusqlite library.

Usage

use rusqlite::{params, Result};
use tokio_rusqlite::Connection;

#[derive(Debug)]
struct Person {
    id: i32,
    name: String,
    data: Option<Vec<u8>>,
}

#[tokio::main]
async fn main() -> Result<()> {
    let conn = Connection::open_in_memory().await?;

    let people = conn
        .call(|conn| {
            conn.execute(
                "CREATE TABLE person (
                    id    INTEGER PRIMARY KEY,
                    name  TEXT NOT NULL,
                    data  BLOB
                )",
                [],
            )?;

            let steven = Person {
                id: 1,
                name: "Steven".to_string(),
                data: None,
            };

            conn.execute(
                "INSERT INTO person (name, data) VALUES (?1, ?2)",
                params![steven.name, steven.data],
            )?;

            let mut stmt = conn.prepare("SELECT id, name, data FROM person")?;
            let people = stmt
                .query_map([], |row| {
                    Ok(Person {
                        id: row.get(0)?,
                        name: row.get(1)?,
                        data: row.get(2)?,
                    })
                })?
                .collect::<Result<Vec<Person>, rusqlite::Error>>()?;

            Ok::<_, rusqlite::Error>(people)
        })
        .await?;

    for person in people {
        println!("Found person {:?}", person);
    }

    Ok(())
}

Safety

This crate uses #![forbid(unsafe_code)] to ensure everything is implemented in 100% safe Rust.

License

This project is licensed under the MIT license.

You might also like...
Mysql client library implemented in rust.

mysql This crate offers: MySql database driver in pure rust; connection pool. Features: macOS, Windows and Linux support; TLS support via nativetls cr

LevelDB is a fast key-value storage library written at Google that provides an ordered mapping from string keys to string values.

LevelDB is a fast key-value storage library written at Google that provides an ordered mapping from string keys to string values. Authors: Sanjay Ghem

Hypergraph is data structure library to create a directed hypergraph in which a hyperedge can join any number of vertices.

Hypergraph is data structure library to create a directed hypergraph in which a hyperedge can join any number of vertices.

RedisLess is a fast, lightweight, embedded and scalable in-memory Key/Value store library compatible with the Redis API.

RedisLess is a fast, lightweight, embedded and scalable in-memory Key/Value store library compatible with the Redis API.

GlueSQL is a SQL database library written in Rust

GlueSQL is a SQL database library written in Rust. It provides a parser (sqlparser-rs), execution layer, and optional storage (sled) packaged into a single library.

Skytable rust client support library for the bb8 connection pool

bb8-skytable Skytable rust client support library for the bb8 connection pool. Heavily based on bb8-redis Basic usage example use bb8_skytable::{

CouchDB client library for the Rust programming language

CouchDB This project is reborn! As of its v0.6.0 release, the couchdb crate has new life as a toolkit instead of providing a full-blown client. In a n

Canary - Distributed systems library for making communications through the network easier, while keeping minimalism and flexibility.
Canary - Distributed systems library for making communications through the network easier, while keeping minimalism and flexibility.

Canary Canary is a distributed systems and communications framework, focusing on minimalism, ease of use and performance. Development of Canary utiliz

LDAP client library

LDAP client library A pure-Rust LDAP client library using the Tokio stack. Compatibility with Tokio versions Tokio 1.0 is the long-term stable version

Comments
  • Cut a new version and push to crates.io

    Cut a new version and push to crates.io

    Crates.io is still using the original v0.2.0 release (#2 ea696510ad6e5930590f8dcf65cd244eb1a83974) which will conflict with the latest rusqlite version. The latest commit from August (#4 33914f835453bf28cedfd6d94cebfde21a1407b5) which updates Cargo.toml dependencies versions fixes it. This however was never pushed up to crates.io.

    opened by stranger-danger-zamu 3
  • failed to select a version for `libsqlite3-sys`

    failed to select a version for `libsqlite3-sys`

    Encountered this issue when trying to use tokio-rusqlite: https://paste.buymymojo.net/pivepilorecusami.log

    Rustc version: rustc 1.62.0 (a8314ef7d 2022-06-27) Cargo version: cargo 1.62.0 (a748cf5a3 2022-06-08)

    opened by BuyMyMojo 1
  • Version 0.2.0

    Version 0.2.0

    • changed: Now using unbounded crossbeam-channel instead of bounded std::sync::mpsc channel internally.
    • changed: Channel send errors in background database thread are now ignored instead of panicking.
    opened by programatik29 0
  • Explicitly closing a connection

    Explicitly closing a connection

    It seems that the only way to close a connection is to drop the the async handle. This will indeed close it but it may take time as that process happens on a different thread and we can never know when the file handle on the database is released. This is a problem on Windows.

    call provides a &mut Connection so calling close on that doesn't work since Rusqlite's close must consume the connection.

    It would be great if there was an explicit close method on the async handle that consumes the handle along with the connection and returns only when the closing process is over.

    opened by negative-ttl 0
Releases(v0.3.0)
Owner
Eray Karatay
Eray Karatay
A boilerplate eliminator for rusqlite.

Exemplar A boilerplate eliminator for rusqlite. Getting Started A taste of what you can do: #[derive(Debug, PartialEq, Model)] #[table("users")] #[che

null 4 Oct 20, 2023
The rust client for CeresDB. CeresDB is a high-performance, distributed, schema-less, cloud native time-series database that can handle both time-series and analytics workloads.

The rust client for CeresDB. CeresDB is a high-performance, distributed, schema-less, cloud native time-series database that can handle both time-series and analytics workloads.

null 12 Nov 18, 2022
influxdb provides an asynchronous Rust interface to an InfluxDB database.

influxdb influxdb provides an asynchronous Rust interface to an InfluxDB database. This crate supports insertion of strings already in the InfluxDB Li

null 9 Feb 16, 2021
asynchronous and synchronous interfaces and persistence implementations for your OOD architecture

OOD Persistence Asynchronous and synchronous interfaces and persistence implementations for your OOD architecture Installation Add ood_persistence = {

Dmitriy Pleshevskiy 1 Feb 15, 2022
Ratchet is a fast, robust, lightweight and fully asynchronous implementation of RFC6455 (The WebSocket protocol).

Ratchet ?? Ratchet is a fast, robust, lightweight and fully asynchronous implementation of RFC6455 (The WebSocket protocol). Complete with an optional

SwimOS 7 Dec 16, 2022
Awesome books, tutorials, courses, and resources for the Tokio asynchronous runtime ecosystem. ⚡

Awesome Tokio Tokio is an asynchronous runtime for the Rust programming language. It provides the building blocks needed for writing network applicati

Marcus Cvjeticanin 59 Oct 27, 2023
CouchDB client-side library for the Rust programming language

Chill Chill is a client-side CouchDB library for the Rust programming language, available on crates.io. It targets Rust Stable. Chill's three chief de

null 35 Jun 26, 2022
An etcd client library for Rust.

etcd An etcd client library for Rust. etcd on crates.io Documentation for the latest crates.io release Running the tests Install Docker and Docker Com

Jimmy Cuadra 138 Dec 27, 2022
Redis library for rust

redis-rs Redis-rs is a high level redis library for Rust. It provides convenient access to all Redis functionality through a very flexible but low-lev

Armin Ronacher 2.8k Jan 8, 2023
Pure Rust library for Apache ZooKeeper built on MIO

rust-zookeeper Zookeeper client written 100% in Rust This library is intended to be equivalent with the official (low-level) ZooKeeper client which sh

Nándor István Krácser 168 Dec 25, 2022