refactor db complete

This commit is contained in:
2023-08-29 21:34:01 +02:00
parent 04a559f4fd
commit ffb1b42f42
5 changed files with 282 additions and 168 deletions

View File

@@ -7,14 +7,26 @@ use tracing::Instrument;
use sqlx::sqlite::{SqliteConnectOptions, SqlitePoolOptions};
use sqlx::ConnectOptions;
pub use sqlx::{Pool, Sqlite};
pub use sqlx::{Pool as SqlitePool, Sqlite};
use std::str::FromStr as _;
pub use sqlx::Type;
use crate::StartError;
pub type Pool = sqlx::Pool<sqlx::Sqlite>;
pub fn int_to_bool(value: i32) -> bool {
match value {
0 => false,
1 => true,
_ => panic!("got invalid boolean from sqlite"),
}
}
#[tracing::instrument]
pub async fn init_database_pool(url: &str) -> Result<Pool<Sqlite>, StartError> {
pub async fn init_database_pool(url: &str) -> Result<Pool, StartError> {
async {
SqlitePoolOptions::new()
.max_connections(5)