gwenn / r2d2-sqlite Goto Github PK
View Code? Open in Web Editor NEWsqlite support library for the r2d2 connection pool.
License: MIT License
sqlite support library for the r2d2 connection pool.
License: MIT License
Hi, I'm happily using Pool::new(SqliteConnectionManager::file(foo))
in my production code and everything is working fine.
However now I'm writing unit tests which I want to run on an in-memory instance of sqlite.
I create my connection pool like:
pub struct DbConnection(Pool<SqliteConnectionManager>);
impl DbConnection {
pub fn test() -> Self {
let manager = SqliteConnectionManager::memory();
let pool = Pool::new(manager).unwrap();
let db_conn = DbConnection(pool);
db_conn.initialise().unwrap();
db_conn
}
fn initialise(&self) -> Result<(), Error> {
let conn = &*self.0.clone().get()?;
conn.execute_batch("create table if not exists foo (...)")?;
Ok(())
}
}
and my unit tests (which just insert into that table) fail with "table foo does not exist".
If I instead change it to
let manager = SqliteConnectionManager::memory();
let pool = Pool::builder().max_size(1).build(manager).unwrap();
then my test passes. If I make that max_size(2)
then it fails again.
The only conclusion I can come to is that when the initialisation and the test use the same connection then everything is fine, but if they use different ones then the test does not see the result of the initialisation call.
Is this intended? It seems like very surprising behaviour if so.
The full code can be found here: https://github.com/djmcgill/dominions-5-status/blob/master/src/db/mod.rs
P. S. I'm fairly new to Rust so if I'm using something unidiomatically please do let me know.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.