1use sqlx_core::error::Error;
4use sqlx_core::pool::{Pool, PoolOptions};
5
6use crate::database::Spg;
7use crate::options::SpgConnectOptions;
8
9pub type SpgPool = Pool<Spg>;
13
14pub type SpgPoolOptions = PoolOptions<Spg>;
17
18pub trait SpgPoolExt: Sized {
23 fn connect_in_memory() -> futures_core::future::BoxFuture<'static, Result<SpgPool, Error>>;
25 fn connect_path(
27 path: std::path::PathBuf,
28 ) -> futures_core::future::BoxFuture<'static, Result<SpgPool, Error>>;
29}
30
31impl SpgPoolExt for SpgPool {
32 fn connect_in_memory() -> futures_core::future::BoxFuture<'static, Result<SpgPool, Error>> {
33 Box::pin(async {
34 SpgPoolOptions::new()
35 .max_connections(1)
36 .connect_with(SpgConnectOptions::in_memory())
37 .await
38 })
39 }
40
41 fn connect_path(
42 path: std::path::PathBuf,
43 ) -> futures_core::future::BoxFuture<'static, Result<SpgPool, Error>> {
44 Box::pin(async move {
45 SpgPoolOptions::new()
46 .max_connections(1)
47 .connect_with(SpgConnectOptions::file(path))
48 .await
49 })
50 }
51}