From 80fc6548d0a1062f15e6e78834c3628981db6ddf Mon Sep 17 00:00:00 2001 From: EliasSchriefer Date: Mon, 19 Jul 2021 15:28:33 +0000 Subject: [PATCH] Use `SqlitePool` instead of `SqliteConnection` --- src/main.rs | 5 ++--- src/sqlite/mod.rs | 21 ++++++++++----------- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/src/main.rs b/src/main.rs index c4ee5d8..06cab5b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,7 +3,6 @@ use std::{ boxed::Box, error::Error, }; -use tokio::sync::RwLock; use crate::{ cli::Options, config::Config, @@ -36,10 +35,10 @@ async fn main() -> Result<(), Box> { dbg!(&config); #[cfg(feature = "sqlite")] - let mut sqlite_connection = RwLock::new(sqlite::connect(&config.database_path).await?); + let sqlite_connection = sqlite::connect(&config.database_path).await?; #[cfg(feature = "sqlite")] - sqlite::load_template(sqlite_connection.get_mut()).await?; + sqlite::load_template(&sqlite_connection).await?; Ok(()) } \ No newline at end of file diff --git a/src/sqlite/mod.rs b/src/sqlite/mod.rs index 06e2738..edbbc00 100644 --- a/src/sqlite/mod.rs +++ b/src/sqlite/mod.rs @@ -1,23 +1,22 @@ use std::path::PathBuf; -use sqlx::{ - prelude::*, - sqlite::{ - SqliteConnection, - SqliteConnectOptions, - SqliteQueryResult, - }, +use sqlx::sqlite::{ + SqlitePool, + SqliteConnectOptions, + SqliteQueryResult, + SqliteSynchronous, }; /// Prepare sqlite database connection -pub async fn connect(path: &PathBuf) -> sqlx::Result { +pub async fn connect(path: &PathBuf) -> sqlx::Result { let connect_options = SqliteConnectOptions::new() .filename(&path) - .create_if_missing(true); - SqliteConnection::connect_with(&connect_options).await + .create_if_missing(true) + .synchronous(SqliteSynchronous::Normal); + SqlitePool::connect_with(connect_options).await } /// Create tables from template -pub async fn load_template(sqlite_handle: &mut SqliteConnection) -> sqlx::Result { +pub async fn load_template(sqlite_handle: &SqlitePool) -> sqlx::Result { sqlx::query(concat!( include_str!("users.sql"), include_str!("security_preferences.sql"),