Makefile.toml

TestContainers and diesel test database
This commit is contained in:
Martin Berg Alstad
2024-08-31 12:21:59 +02:00
parent ce770e9c6f
commit 8fb89e0459
19 changed files with 901 additions and 39 deletions

1
src/diesel/mod.rs Normal file
View File

@ -0,0 +1 @@
pub mod pool;

24
src/diesel/pool.rs Normal file
View File

@ -0,0 +1,24 @@
use deadpool_diesel::postgres::BuildError;
use diesel_async::pooled_connection::deadpool::Pool;
use diesel_async::pooled_connection::AsyncDieselConnectionManager;
use diesel_async::AsyncPgConnection;
/// A type alias for the asynchronous PostgreSQL connection pool.
pub type PgPool = Pool<AsyncPgConnection>;
/// Create a deadpool connection pool from the given URL.
/// Using the default pool size and other settings.
pub fn create_pool_from_url(url: impl Into<String>) -> Result<PgPool, BuildError> {
let config = AsyncDieselConnectionManager::<AsyncPgConnection>::new(url);
Pool::builder(config).build()
}
/// Create a deadpool connection pool from the given URL.
/// Using the given pool size and other default settings.
pub fn create_pool_from_url_with_size(
url: impl Into<String>,
size: usize,
) -> Result<PgPool, BuildError> {
let config = AsyncDieselConnectionManager::<AsyncPgConnection>::new(url);
Pool::builder(config).max_size(size).build()
}

View File

@ -1,6 +1,4 @@
#![allow(dead_code)]
extern crate self as lib;
#[cfg(all(feature = "derive", feature = "diesel"))]
pub extern crate diesel_crud_derive;
#[cfg(feature = "diesel")]
@ -9,9 +7,12 @@ pub extern crate diesel_crud_trait;
pub extern crate into_response_derive;
#[cfg(feature = "read-files")]
pub extern crate read_files;
extern crate self as lib;
#[cfg(feature = "axum")]
pub mod axum;
#[cfg(feature = "diesel")]
pub mod diesel;
#[cfg(feature = "io")]
pub mod io;
#[cfg(feature = "nom")]