Add sqlite template insertion for users.sql

This commit is contained in:
Elias Schriefer 2021-06-28 15:54:52 +00:00
parent 59d26277db
commit c42fbebe09

View File

@ -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<dyn Error>> {
}
#[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<SqliteConnection> {
}
#[cfg(feature = "sqlite")]
async fn load_sqlite_template(){
async fn load_sqlite_template(sqlite_handle: &mut SqliteConnection) -> sqlx::Result<SqliteQueryResult> {
sqlx::query(include_str!("sqlite/users.sql")).execute(sqlite_handle).await
}
fn get_config(options: &Options) -> std::io::Result<Config> {