Add method for preparing sqlite connection

This is not being used yet

Co-authored-by: Erik Foris
This commit is contained in:
Elias Schriefer 2021-06-15 14:49:21 +00:00
parent e62f3ee2dc
commit 99918f1bb9

View File

@ -7,6 +7,13 @@ use std::{
error::Error, error::Error,
}; };
use serde::Deserialize; use serde::Deserialize;
use sqlx::{
prelude::*,
sqlite::{
SqliteConnection,
SqliteConnectOptions,
},
};
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";
@ -48,6 +55,15 @@ fn main() -> Result<(), Box<dyn Error>> {
Ok(()) Ok(())
} }
/// Prepare sqlite database connection
#[cfg(feature = "sqlite")]
async fn connect_sqlite(path: &PathBuf) -> sqlx::Result<SqliteConnection> {
let connect_options = SqliteConnectOptions::new()
.filename(&path)
.create_if_missing(true);
SqliteConnection::connect_with(&connect_options).await
}
/// ///
fn get_config(options: &Options) -> std::io::Result<Config> { fn get_config(options: &Options) -> std::io::Result<Config> {
let mut config_file = File::open(&options.config)?; let mut config_file = File::open(&options.config)?;