Use SqlitePool
instead of SqliteConnection
This commit is contained in:
parent
998b6f93bc
commit
80fc6548d0
@ -3,7 +3,6 @@ use std::{
|
|||||||
boxed::Box,
|
boxed::Box,
|
||||||
error::Error,
|
error::Error,
|
||||||
};
|
};
|
||||||
use tokio::sync::RwLock;
|
|
||||||
use crate::{
|
use crate::{
|
||||||
cli::Options,
|
cli::Options,
|
||||||
config::Config,
|
config::Config,
|
||||||
@ -36,10 +35,10 @@ async fn main() -> Result<(), Box<dyn Error>> {
|
|||||||
dbg!(&config);
|
dbg!(&config);
|
||||||
|
|
||||||
#[cfg(feature = "sqlite")]
|
#[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")]
|
#[cfg(feature = "sqlite")]
|
||||||
sqlite::load_template(sqlite_connection.get_mut()).await?;
|
sqlite::load_template(&sqlite_connection).await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
@ -1,23 +1,22 @@
|
|||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use sqlx::{
|
use sqlx::sqlite::{
|
||||||
prelude::*,
|
SqlitePool,
|
||||||
sqlite::{
|
|
||||||
SqliteConnection,
|
|
||||||
SqliteConnectOptions,
|
SqliteConnectOptions,
|
||||||
SqliteQueryResult,
|
SqliteQueryResult,
|
||||||
},
|
SqliteSynchronous,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Prepare sqlite database connection
|
/// Prepare sqlite database connection
|
||||||
pub async fn connect(path: &PathBuf) -> sqlx::Result<SqliteConnection> {
|
pub async fn connect(path: &PathBuf) -> sqlx::Result<SqlitePool> {
|
||||||
let connect_options = SqliteConnectOptions::new()
|
let connect_options = SqliteConnectOptions::new()
|
||||||
.filename(&path)
|
.filename(&path)
|
||||||
.create_if_missing(true);
|
.create_if_missing(true)
|
||||||
SqliteConnection::connect_with(&connect_options).await
|
.synchronous(SqliteSynchronous::Normal);
|
||||||
|
SqlitePool::connect_with(connect_options).await
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create tables from template
|
/// Create tables from template
|
||||||
pub async fn load_template(sqlite_handle: &mut SqliteConnection) -> sqlx::Result<SqliteQueryResult> {
|
pub async fn load_template(sqlite_handle: &SqlitePool) -> sqlx::Result<SqliteQueryResult> {
|
||||||
sqlx::query(concat!(
|
sqlx::query(concat!(
|
||||||
include_str!("users.sql"),
|
include_str!("users.sql"),
|
||||||
include_str!("security_preferences.sql"),
|
include_str!("security_preferences.sql"),
|
||||||
|
Loading…
Reference in New Issue
Block a user