Wrap sqlite connection in an Arc and tokios RwLock
This commit is contained in:
parent
898e10f040
commit
d6aee960fa
10
src/main.rs
10
src/main.rs
@ -5,6 +5,7 @@ use std::{
|
|||||||
io::prelude::*,
|
io::prelude::*,
|
||||||
boxed::Box,
|
boxed::Box,
|
||||||
error::Error,
|
error::Error,
|
||||||
|
sync::Arc,
|
||||||
};
|
};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use sqlx::{
|
use sqlx::{
|
||||||
@ -14,6 +15,9 @@ use sqlx::{
|
|||||||
SqliteConnectOptions,
|
SqliteConnectOptions,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
use tokio::{
|
||||||
|
sync::RwLock,
|
||||||
|
};
|
||||||
|
|
||||||
const DEFAULT_DATABASE_PATH: &'static str = "/var/lib/noise-server/noise-server.sqlite";
|
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);
|
println!("{:?}", options);
|
||||||
|
|
||||||
#[cfg(feature = "sqlite")]
|
#[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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user