Wrap sqlite connection in an Arc and tokios RwLock

This commit is contained in:
Elias Schriefer 2021-06-28 13:50:28 +00:00
parent 898e10f040
commit d6aee960fa

View File

@ -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<dyn Error>> {
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(())
}