From 99918f1bb920e8a72075409aedbf8239fb6969c2 Mon Sep 17 00:00:00 2001 From: EliasSchriefer Date: Tue, 15 Jun 2021 14:49:21 +0000 Subject: [PATCH] Add method for preparing sqlite connection This is not being used yet Co-authored-by: Erik Foris --- src/main.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/main.rs b/src/main.rs index 2e0f4cb..a6c33bc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,6 +7,13 @@ use std::{ error::Error, }; use serde::Deserialize; +use sqlx::{ + prelude::*, + sqlite::{ + SqliteConnection, + SqliteConnectOptions, + }, +}; const DEFAULT_DATABASE_PATH: &'static str = "/var/lib/noise-server/noise-server.sqlite"; @@ -48,6 +55,15 @@ fn main() -> Result<(), Box> { Ok(()) } +/// Prepare sqlite database connection +#[cfg(feature = "sqlite")] +async fn connect_sqlite(path: &PathBuf) -> sqlx::Result { + 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 { let mut config_file = File::open(&options.config)?;