Skip to content

Commit

Permalink
generate unique in-memory sqlite database per request and share data …
Browse files Browse the repository at this point in the history
…between connections
  • Loading branch information
eugene-babichenko authored and dkijania committed Jan 22, 2021
1 parent 1c065e1 commit cf48e12
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions vit-servicing-station-lib/Cargo.toml
Expand Up @@ -36,3 +36,4 @@ libsqlite3-sys = { version = "0.9.3", features = ["bundled"] }

[dev-dependencies]
tempfile = "3"
rand = "0.8"
10 changes: 9 additions & 1 deletion vit-servicing-station-lib/src/v0/context.rs
Expand Up @@ -36,11 +36,19 @@ pub fn new_shared_context(

#[cfg(test)]
pub mod test {
use rand::{distributions::Alphanumeric, thread_rng, Rng};

use super::*;
use crate::db;

pub fn new_in_memmory_db_test_shared_context() -> SharedContext {
let pool = db::load_db_connection_pool("").unwrap();
let name: String = thread_rng()
.sample_iter(Alphanumeric)
.take(5)
.map(char::from)
.collect();
let db_url = format!("file:{}?mode=memory&cache=shared", name);
let pool = db::load_db_connection_pool(&db_url).unwrap();
let block0: Vec<u8> = vec![1, 2, 3, 4, 5];
Arc::new(RwLock::new(Context::new(pool, "", block0)))
}
Expand Down

0 comments on commit cf48e12

Please sign in to comment.