Crates.io | unreql |
lib.rs | unreql |
version | 0.1.8 |
source | src |
created_at | 2024-01-21 09:18:58.43829 |
updated_at | 2024-04-27 18:31:45.79242 |
description | Well documented and easy to use RethinkDB Rust Driver |
homepage | |
repository | https://github.com/vettich/un-rethinkdb-rs.git |
max_upload_size | |
id | 1107462 |
size | 382,205 |
Well documented and easy to use
The official driver is difficult to support, awkward to use, and has little to no documentation or examples. Therefore, an attempt was made by me to remedy these shortcomings
$ cargo add unreql
or
[dependencies]
unreql = "0.1.8"
use unreql::r;
let conn = r.connect(()).await?;
Get by ID
let user: User = r.table("users").get(1).exec(&conn).await?;
Get all data
let users: Vec<User> = r.table("users").exec_to_vec(&conn).await?;
or
let mut cur = r.table("users").run(&conn);
let mut users: Vec<User> = vec![];
while let Ok(Some(user)) = cur.try_next().await? {
users.push(user);
}
Use a nested reql query
r.table("users")
.get(1)
.update(rjson!({
"name": "John",
"upd_count": r.row().g("upd_count").add(1),
}))
.run(&conn);
Implemented session manager for async deadpool
use unreql::{r, cmd::connect};
use unreql_deadpool::{IntoPoolWrapper, SessionManager};
use deadpool::managed::Pool;
// config to connect to rethinkdb
let config = connect::Options::default();
// new session manager
let manager = SessionManager::new(config);
// create a pool that is wrapped for ease of use (to be able to be passed to `.run(&pool)`)
let pool = Pool::builder(manager).max_size(20).build().unwrap().wrapper();
// now you can to pass `pool` to `.run()` and `.exec()`
let user: User = r.table("users").get(1).exec(&pool).await?;