Crates.io | r2d2-aykroyd |
lib.rs | r2d2-aykroyd |
version | 0.2.1 |
source | src |
created_at | 2023-12-15 18:46:37.876096 |
updated_at | 2024-02-20 17:46:10.144013 |
description | Aykroyd micro-ORM for the r2d2 connection pool. |
homepage | |
repository | https://git.sr.ht/~couch/aykroyd |
max_upload_size | |
id | 1071188 |
size | 15,170 |
aykroyd support library for the r2d2 connection pool.
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);
});
}
}