From c42fbebe09cd33ceda5d1abab21ecba2d5b38adf Mon Sep 17 00:00:00 2001 From: EliasSchriefer Date: Mon, 28 Jun 2021 15:54:52 +0000 Subject: [PATCH] Add sqlite template insertion for users.sql --- src/main.rs | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/main.rs b/src/main.rs index d92ace0..711d8b4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,7 +5,6 @@ use std::{ io::prelude::*, boxed::Box, error::Error, - sync::Arc, }; use serde::Deserialize; use sqlx::{ @@ -13,6 +12,7 @@ use sqlx::{ sqlite::{ SqliteConnection, SqliteConnectOptions, + SqliteQueryResult, }, }; use tokio::{ @@ -56,14 +56,13 @@ async fn main() -> Result<(), Box> { } #[cfg(debug_assertions)] - println!("{:?}", options); + println!("{:?}", config); #[cfg(feature = "sqlite")] - let sqlite_connection = Arc::new( - RwLock::new( - connect_sqlite(&config.database_path).await? - ) - ); + let mut sqlite_connection = RwLock::new(connect_sqlite(&config.database_path).await?); + + #[cfg(feature = "sqlite")] + load_sqlite_template(sqlite_connection.get_mut()).await?; Ok(()) } @@ -78,8 +77,8 @@ async fn connect_sqlite(path: &PathBuf) -> sqlx::Result { } #[cfg(feature = "sqlite")] -async fn load_sqlite_template(){ - +async fn load_sqlite_template(sqlite_handle: &mut SqliteConnection) -> sqlx::Result { + sqlx::query(include_str!("sqlite/users.sql")).execute(sqlite_handle).await } fn get_config(options: &Options) -> std::io::Result {