From d6aee960fac6e4ba4b45b9b0fc23ebeb83f37383 Mon Sep 17 00:00:00 2001 From: EliasSchriefer Date: Mon, 28 Jun 2021 13:50:28 +0000 Subject: [PATCH] Wrap sqlite connection in an Arc and tokios RwLock --- src/main.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 0ae6f36..d92ace0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,6 +5,7 @@ use std::{ io::prelude::*, boxed::Box, error::Error, + sync::Arc, }; use serde::Deserialize; use sqlx::{ @@ -14,6 +15,9 @@ use sqlx::{ SqliteConnectOptions, }, }; +use tokio::{ + sync::RwLock, +}; const DEFAULT_DATABASE_PATH: &'static str = "/var/lib/noise-server/noise-server.sqlite"; @@ -55,7 +59,11 @@ async fn main() -> Result<(), Box> { println!("{:?}", options); #[cfg(feature = "sqlite")] - let sqlite_connection = connect_sqlite(&config.database_path).await?; + let sqlite_connection = Arc::new( + RwLock::new( + connect_sqlite(&config.database_path).await? + ) + ); Ok(()) }