Questions tagged [r2d2]
12 questions
5
votes
1 answer
How to use SQLite via rusqlite from multiple threads?
There are a number of articles explaining the problem of multi-threaded access with SQLite but I couldn't find any easy solutions. How does one access SQLite from e.g. a web server where multiple threads work concurrently?
Sources (that still don't…

VasiliNovikov
- 9,681
- 4
- 44
- 62
4
votes
2 answers
Imlementing connection pooling in a rust/diesel app with r2d2
I am trying to implement connection pooling in a rust/diesel/rocket application. I am not sure how to ensure the content of the establish_pooled_connection() method is invoked only once, so as to prepare the connection pool.
Here is my code.
from…

balteo
- 23,602
- 63
- 219
- 412
1
vote
0 answers
Why are closed connections in an actor not returned to the connection pool?
I am quite new to Rust and Database handling in general and so i have clearly bitten off more than I can chew with my current async project.
I am using actix actors, actix_web, diesel and r2d2 for my connection pool.
In essence, the user sends a…

Rairot
- 11
- 1
- 3
1
vote
1 answer
The latest chrono 0.4 crate uses time 0.1 which has a potential segfault - how to fix?
I'm writing an app in Rust that uses a PostgreSQL client connection pool with Chrono (0.4.22) features for date time calculations. So my Cargo.toml has these lines:
[dependencies]
postgres = {version = "0.19", features = ["with-chrono-0_4"]}
chrono…

Code4R7
- 2,600
- 1
- 19
- 42
1
vote
1 answer
How to use DB connections in Actix several times per function?
At https://actix.rs/docs/databases/ there is an example:
async fn index(pool: web::Data, name: web::Path<(String)>) -> impl Responder {
let name = name.into_inner();
let conn = pool.get().expect("couldn't get db connection from…

porton
- 5,214
- 11
- 47
- 95
1
vote
1 answer
Why is the Connection pool cloned here?
In this code example, from the Github page of r2d2:
fn main() {
let manager = r2d2_foodb::FooConnectionManager::new("localhost:1234");
let pool = r2d2::Pool::builder()
.max_size(15)
.build(manager)
.unwrap();
for…

Jonah Allerton
- 35
- 1
- 3
1
vote
0 answers
Rust serde_json::value::RawValue gives errors "the trait bound ... `r2d2_postgres::postgres::types::FromSql<'_>` is not satisfied"
I am using r2d2_postgres to run raw SQL and return the result directly in Actix response.
I need to run raw sql with dynamic data, types and unknown at compile time columns/data types etc. To do this, I came across serde_json::value::RawValue:
It…

sudoExclaimationExclaimation
- 7,992
- 10
- 47
- 105
1
vote
1 answer
How to save a document in MongoDB by r2d2 and actix?
I am new to Rust and was trying to create a webserver with Actix-web to perform CRUD operations via MongoDB. The first API I am creating is to save a simple document in MongoDB by something received from a POST request. The code for the post request…

Alonzo
- 25
- 5
0
votes
1 answer
How to optimize querying multiple unrelated tables in SQLite?
I have scenario when I have to iterate through multiple tables in quite big sqlite database. In tables I store informations about planet position on sky through years. So e.g. for Mars I have tables Mars_2000, Mars_2001 and so on. Table structure is…

Mateusz Pydych
- 117
- 8
0
votes
1 answer
Implement default trait API in database module by diesel r2d2?
I'm quite new to rust/diesel. Trying to implement a database module with default trait API (avoid duplicate code work), by crate diesel and r2d2.
Here's the model.rs:
use chrono::NaiveDate;
use diesel;
use…

linrongbin
- 2,967
- 6
- 31
- 59
0
votes
0 answers
Rust diesel with r2d2 load expected struct `Mysql`, found struct `Sqlite`?
I'm writing a database module for my rust application, use diesel.
Here's the compile error:
error[E0271]: type mismatch resolving `::Backend == Sqlite`
--> src/quant/common/persistence/database.rs:155:18
|
155…

linrongbin
- 2,967
- 6
- 31
- 59
0
votes
1 answer
Rust - Cannot Access r2d2 pool connection from Rocket State
I am currently learning Rust and Rocket
Using Rust 1.54.0+Rocket 0.5.0_rc1+ Diesel 1.4.7 + r2d2 0.8.9
I created a DB Postgres connection pool with r2d2. I want to share the connection pool between requests/Routes, to do that I am trying to use…

Gonzalo
- 45
- 8