4 releases
0.2.1 | Feb 20, 2024 |
---|---|
0.2.0 | Jan 29, 2024 |
0.1.1 | Dec 15, 2023 |
0.1.0 | Dec 15, 2023 |
#2316 in Database interfaces
49 downloads per month
190KB
3.5K
SLoC
r2d2-aykroyd
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);
});
}
}
Dependencies
~0.5–16MB
~236K SLoC