Skip to content

Commit

Permalink
added ability to create connection pool for single-use database with …
Browse files Browse the repository at this point in the history
…unrestricted privileges; bumped to v0.2.0
  • Loading branch information
yasamoka committed Apr 13, 2024
1 parent e0a3f71 commit 2ca9cfd
Show file tree
Hide file tree
Showing 53 changed files with 1,790 additions and 451 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "db-pool"
version = "0.1.4"
version = "0.2.0"
edition = "2021"
description = "A thread-safe database pool for running database-tied integration tests in parallel"
license = "MIT"
Expand Down
4 changes: 2 additions & 2 deletions book/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion book/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "book"
version = "0.1.0"
version = "0.2.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
10 changes: 4 additions & 6 deletions book/src/tutorials/async/05.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@ mod tests {
use bb8::Pool;
use db_pool::{
r#async::{
// import connection pool
ConnectionPool,
DatabasePool,
DatabasePoolBuilderTrait,
DieselAsyncPostgresBackend,
DieselBb8,
// import reusable object wrapper
Reusable,
// import reusable connection pool
ReusableConnectionPool,
},
PrivilegedPostgresConfig,
};
Expand All @@ -25,7 +23,7 @@ mod tests {

// change return type
async fn get_connection_pool(
) -> Reusable<'static, ConnectionPool<DieselAsyncPostgresBackend<DieselBb8>>> {
) -> ReusableConnectionPool<'static, DieselAsyncPostgresBackend<DieselBb8>> {
static POOL: OnceCell<DatabasePool<DieselAsyncPostgresBackend<DieselBb8>>> =
OnceCell::const_new();

Expand Down Expand Up @@ -60,6 +58,6 @@ mod tests {
.await;

// pull connection pool
db_pool.pull().await
db_pool.pull_immutable().await
}
}
8 changes: 4 additions & 4 deletions book/src/tutorials/async/06.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ mod tests {

use db_pool::{
r#async::{
ConnectionPool, DatabasePool, DatabasePoolBuilderTrait, DieselAsyncPostgresBackend,
DieselBb8, Reusable,
DatabasePool, DatabasePoolBuilderTrait, DieselAsyncPostgresBackend, DieselBb8,
ReusableConnectionPool,
},
PrivilegedPostgresConfig,
};
Expand All @@ -19,7 +19,7 @@ mod tests {
use tokio::sync::OnceCell;

async fn get_connection_pool(
) -> Reusable<'static, ConnectionPool<DieselAsyncPostgresBackend<DieselBb8>>> {
) -> ReusableConnectionPool<'static, DieselAsyncPostgresBackend<DieselBb8>> {
static POOL: OnceCell<DatabasePool<DieselAsyncPostgresBackend<DieselBb8>>> =
OnceCell::const_new();

Expand Down Expand Up @@ -53,7 +53,7 @@ mod tests {
})
.await;

db_pool.pull().await
db_pool.pull_immutable().await
}

// add test case
Expand Down
8 changes: 4 additions & 4 deletions book/src/tutorials/async/07.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ mod tests {
use bb8::Pool;
use db_pool::{
r#async::{
ConnectionPool, DatabasePool, DatabasePoolBuilderTrait, DieselAsyncPostgresBackend,
DieselBb8, Reusable,
DatabasePool, DatabasePoolBuilderTrait, DieselAsyncPostgresBackend, DieselBb8,
ReusableConnectionPool,
},
PrivilegedPostgresConfig,
};
Expand All @@ -21,7 +21,7 @@ mod tests {
use tokio_shared_rt::test;

async fn get_connection_pool(
) -> Reusable<'static, ConnectionPool<DieselAsyncPostgresBackend<DieselBb8>>> {
) -> ReusableConnectionPool<'static, DieselAsyncPostgresBackend<DieselBb8>> {
static POOL: OnceCell<DatabasePool<DieselAsyncPostgresBackend<DieselBb8>>> =
OnceCell::const_new();

Expand Down Expand Up @@ -55,7 +55,7 @@ mod tests {
})
.await;

db_pool.pull().await
db_pool.pull_immutable().await
}

async fn test() {
Expand Down
10 changes: 4 additions & 6 deletions book/src/tutorials/sync/05.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@ mod tests {

use db_pool::{
sync::{
// import connection pool
ConnectionPool,
DatabasePool,
DatabasePoolBuilderTrait,
DieselPostgresBackend,
// import reusable object wrapper
Reusable,
// import reusable connection pool
ReusableConnectionPool,
},
PrivilegedPostgresConfig,
};
Expand All @@ -23,7 +21,7 @@ mod tests {
use r2d2::Pool;

// change return type
fn get_connection_pool() -> Reusable<'static, ConnectionPool<DieselPostgresBackend>> {
fn get_connection_pool() -> ReusableConnectionPool<'static, DieselPostgresBackend> {
static POOL: OnceLock<DatabasePool<DieselPostgresBackend>> = OnceLock::new();

let db_pool = POOL.get_or_init(|| {
Expand All @@ -47,6 +45,6 @@ mod tests {
});

// pull connection pool
db_pool.pull()
db_pool.pull_immutable()
}
}
6 changes: 3 additions & 3 deletions book/src/tutorials/sync/06.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ mod tests {

use db_pool::{
sync::{
ConnectionPool, DatabasePool, DatabasePoolBuilderTrait, DieselPostgresBackend, Reusable,
DatabasePool, DatabasePoolBuilderTrait, DieselPostgresBackend, ReusableConnectionPool,
},
PrivilegedPostgresConfig,
};
Expand All @@ -17,7 +17,7 @@ mod tests {
use dotenvy::dotenv;
use r2d2::Pool;

fn get_connection_pool() -> Reusable<'static, ConnectionPool<DieselPostgresBackend>> {
fn get_connection_pool() -> ReusableConnectionPool<'static, DieselPostgresBackend> {
static POOL: OnceLock<DatabasePool<DieselPostgresBackend>> = OnceLock::new();

let db_pool = POOL.get_or_init(|| {
Expand All @@ -40,7 +40,7 @@ mod tests {
backend.create_database_pool().unwrap()
});

db_pool.pull()
db_pool.pull_immutable()
}

// add test case
Expand Down
6 changes: 3 additions & 3 deletions book/src/tutorials/sync/07.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ mod tests {

use db_pool::{
sync::{
ConnectionPool, DatabasePool, DatabasePoolBuilderTrait, DieselPostgresBackend, Reusable,
DatabasePool, DatabasePoolBuilderTrait, DieselPostgresBackend, ReusableConnectionPool,
},
PrivilegedPostgresConfig,
};
use diesel::{insert_into, sql_query, table, Insertable, QueryDsl, RunQueryDsl};
use dotenvy::dotenv;
use r2d2::Pool;

fn get_connection_pool() -> Reusable<'static, ConnectionPool<DieselPostgresBackend>> {
fn get_connection_pool() -> ReusableConnectionPool<'static, DieselPostgresBackend> {
static POOL: OnceLock<DatabasePool<DieselPostgresBackend>> = OnceLock::new();

let db_pool = POOL.get_or_init(|| {
Expand All @@ -37,7 +37,7 @@ mod tests {
backend.create_database_pool().unwrap()
});

db_pool.pull()
db_pool.pull_immutable()
}

fn test() {
Expand Down
2 changes: 1 addition & 1 deletion examples/async-graphql/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ mod tests {
})
.await;

let conn_pool = db_pool.pull().await;
let conn_pool = db_pool.pull_immutable().await;
PoolWrapper::ReusablePool(conn_pool)
}

Expand Down
8 changes: 4 additions & 4 deletions examples/diesel_async_mysql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ mod tests {
use bb8::Pool;
use db_pool::{
r#async::{
ConnectionPool, DatabasePool, DatabasePoolBuilderTrait, DieselAsyncMySQLBackend,
DieselBb8, Reusable,
DatabasePool, DatabasePoolBuilderTrait, DieselAsyncMySQLBackend, DieselBb8,
ReusableConnectionPool,
},
PrivilegedMySQLConfig,
};
Expand All @@ -19,7 +19,7 @@ mod tests {
use tokio_shared_rt::test;

async fn get_connection_pool(
) -> Reusable<'static, ConnectionPool<DieselAsyncMySQLBackend<DieselBb8>>> {
) -> ReusableConnectionPool<'static, DieselAsyncMySQLBackend<DieselBb8>> {
static POOL: OnceCell<DatabasePool<DieselAsyncMySQLBackend<DieselBb8>>> =
OnceCell::const_new();

Expand Down Expand Up @@ -51,7 +51,7 @@ mod tests {
})
.await;

db_pool.pull().await
db_pool.pull_immutable().await
}

async fn test() {
Expand Down
8 changes: 4 additions & 4 deletions examples/diesel_async_postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ mod tests {
use bb8::Pool;
use db_pool::{
r#async::{
ConnectionPool, DatabasePool, DatabasePoolBuilderTrait, DieselAsyncPostgresBackend,
DieselBb8, Reusable,
DatabasePool, DatabasePoolBuilderTrait, DieselAsyncPostgresBackend, DieselBb8,
ReusableConnectionPool,
},
PrivilegedPostgresConfig,
};
Expand All @@ -19,7 +19,7 @@ mod tests {
use tokio_shared_rt::test;

async fn get_connection_pool(
) -> Reusable<'static, ConnectionPool<DieselAsyncPostgresBackend<DieselBb8>>> {
) -> ReusableConnectionPool<'static, DieselAsyncPostgresBackend<DieselBb8>> {
static POOL: OnceCell<DatabasePool<DieselAsyncPostgresBackend<DieselBb8>>> =
OnceCell::const_new();

Expand Down Expand Up @@ -53,7 +53,7 @@ mod tests {
})
.await;

db_pool.pull().await
db_pool.pull_immutable().await
}

async fn test() {
Expand Down
6 changes: 3 additions & 3 deletions examples/diesel_mysql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ mod tests {

use db_pool::{
sync::{
ConnectionPool, DatabasePool, DatabasePoolBuilderTrait, DieselMySQLBackend, Reusable,
DatabasePool, DatabasePoolBuilderTrait, DieselMySQLBackend, ReusableConnectionPool,
},
PrivilegedMySQLConfig,
};
use diesel::{insert_into, sql_query, table, Insertable, QueryDsl, RunQueryDsl};
use dotenvy::dotenv;
use r2d2::Pool;

fn get_connection_pool() -> Reusable<'static, ConnectionPool<DieselMySQLBackend>> {
fn get_connection_pool() -> ReusableConnectionPool<'static, DieselMySQLBackend> {
static POOL: OnceLock<DatabasePool<DieselMySQLBackend>> = OnceLock::new();

let db_pool = POOL.get_or_init(|| {
Expand All @@ -37,7 +37,7 @@ mod tests {
backend.create_database_pool().unwrap()
});

db_pool.pull()
db_pool.pull_immutable()
}

fn test() {
Expand Down
6 changes: 3 additions & 3 deletions examples/diesel_postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ mod tests {

use db_pool::{
sync::{
ConnectionPool, DatabasePool, DatabasePoolBuilderTrait, DieselPostgresBackend, Reusable,
DatabasePool, DatabasePoolBuilderTrait, DieselPostgresBackend, ReusableConnectionPool,
},
PrivilegedPostgresConfig,
};
use diesel::{insert_into, sql_query, table, Insertable, QueryDsl, RunQueryDsl};
use dotenvy::dotenv;
use r2d2::Pool;

fn get_connection_pool() -> Reusable<'static, ConnectionPool<DieselPostgresBackend>> {
fn get_connection_pool() -> ReusableConnectionPool<'static, DieselPostgresBackend> {
static POOL: OnceLock<DatabasePool<DieselPostgresBackend>> = OnceLock::new();

let db_pool = POOL.get_or_init(|| {
Expand All @@ -37,7 +37,7 @@ mod tests {
backend.create_database_pool().unwrap()
});

db_pool.pull()
db_pool.pull_immutable()
}

fn test() {
Expand Down
6 changes: 3 additions & 3 deletions examples/mysql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ mod tests {
use std::sync::OnceLock;

use db_pool::{
sync::{ConnectionPool, DatabasePool, DatabasePoolBuilderTrait, MySQLBackend, Reusable},
sync::{DatabasePool, DatabasePoolBuilderTrait, MySQLBackend, ReusableConnectionPool},
PrivilegedMySQLConfig,
};
use dotenvy::dotenv;
use mysql::{params, prelude::Queryable};
use r2d2::Pool;

fn get_connection_pool() -> Reusable<'static, ConnectionPool<MySQLBackend>> {
fn get_connection_pool() -> ReusableConnectionPool<'static, MySQLBackend> {
static POOL: OnceLock<DatabasePool<MySQLBackend>> = OnceLock::new();

let db_pool = POOL.get_or_init(|| {
Expand All @@ -36,7 +36,7 @@ mod tests {
backend.create_database_pool().unwrap()
});

db_pool.pull()
db_pool.pull_immutable()
}

fn test() {
Expand Down
6 changes: 3 additions & 3 deletions examples/postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ mod tests {
use std::sync::OnceLock;

use db_pool::{
sync::{ConnectionPool, DatabasePool, DatabasePoolBuilderTrait, PostgresBackend, Reusable},
sync::{DatabasePool, DatabasePoolBuilderTrait, PostgresBackend, ReusableConnectionPool},
PrivilegedPostgresConfig,
};
use dotenvy::dotenv;
use r2d2::Pool;

fn get_connection_pool() -> Reusable<'static, ConnectionPool<PostgresBackend>> {
fn get_connection_pool() -> ReusableConnectionPool<'static, PostgresBackend> {
static POOL: OnceLock<DatabasePool<PostgresBackend>> = OnceLock::new();

let db_pool = POOL.get_or_init(|| {
Expand All @@ -36,7 +36,7 @@ mod tests {
backend.create_database_pool().unwrap()
});

db_pool.pull()
db_pool.pull_immutable()
}

fn test() {
Expand Down
Loading

0 comments on commit 2ca9cfd

Please sign in to comment.