use sqlx_core::error::Error;
use sqlx_core::pool::{Pool, PoolOptions};
use crate::database::Spg;
use crate::options::SpgConnectOptions;
pub type SpgPool = Pool<Spg>;
pub type SpgPoolOptions = PoolOptions<Spg>;
pub trait SpgPoolExt: Sized {
fn connect_in_memory() -> futures_core::future::BoxFuture<'static, Result<SpgPool, Error>>;
fn connect_path(
path: std::path::PathBuf,
) -> futures_core::future::BoxFuture<'static, Result<SpgPool, Error>>;
}
impl SpgPoolExt for SpgPool {
fn connect_in_memory() -> futures_core::future::BoxFuture<'static, Result<SpgPool, Error>> {
Box::pin(async {
SpgPoolOptions::new()
.connect_with(SpgConnectOptions::in_memory())
.await
})
}
fn connect_path(
path: std::path::PathBuf,
) -> futures_core::future::BoxFuture<'static, Result<SpgPool, Error>> {
Box::pin(async move {
SpgPoolOptions::new()
.connect_with(SpgConnectOptions::file(path))
.await
})
}
}