r2d2-aykroyd

Crates.ior2d2-aykroyd
lib.rsr2d2-aykroyd
version0.2.1
sourcesrc
created_at2023-12-15 18:46:37.876096
updated_at2024-02-20 17:46:10.144013
descriptionAykroyd micro-ORM for the r2d2 connection pool.
homepage
repositoryhttps://git.sr.ht/~couch/aykroyd
max_upload_size
id1071188
size15,170
Andrew Dona-Couch -- GitHub drop ICE (couchand)

documentation

https://docs.rs/r2d2-aykroyd/latest/r2d2_aykroyd/

README

r2d2-aykroyd

Documentation

aykroyd support library for the r2d2 connection pool.

Examples

An example of the postgres client.

use std::thread;
use postgres::NoTls;
use r2d2_aykroyd::postgres::AykroydConnectionManager;

#[derive(aykroyd::QueryOne)]
#[query(row(Row), text = "SELECT 1 + $1")]
struct AddOneTo(i32);

#[derive(aykroyd::FromRow)]
struct Row(i32);

fn main() {
    let manager = AykroydConnectionManager::new(
        "host=localhost user=postgres".parse().unwrap(),
        NoTls,
    );
    let pool = r2d2::Pool::new(manager).unwrap();

    for i in 0..10i32 {
        let pool = pool.clone();
        thread::spawn(move || {
            let mut client = pool.get().unwrap();
            let row = client.query_one(&AddOneTo(i)).unwrap();
            let value = row.0;
            assert_eq!(value, i + 1);
        });
    }
}

An example of the mysql client.

use std::thread;
use r2d2_aykroyd::mysql::AykroydConnectionManager;

#[derive(aykroyd::QueryOne)]
#[query(row(Row), text = "SELECT 1 + ?")]
struct AddOneTo(i32);

#[derive(aykroyd::FromRow)]
struct Row(i32);

fn main() {
    let opts = mysqsl::Opts::from_url(
        "mysql://user:password@locahost:3307/db_name",
    );
    let builder = mysql::OptsBuilder::from_opts(opts);
    let manager = AykroydConnectionManager::new(builder);
    let pool = r2d2::Pool::new(manager).unwrap();

    for i in 0..10i32 {
        let pool = pool.clone();
        thread::spawn(move || {
            let mut client = pool.get().unwrap();
            let row = client.query_one(&AddOneTo(i)).unwrap();
            let value = row.0;
            assert_eq!(value, i + 1);
        });
    }
}
Commit count: 0

cargo fmt