mirror of
https://github.com/launchbadge/sqlx.git
synced 2025-10-02 15:25:32 +00:00
fix some remaining usage of PoolOptions
This commit is contained in:
parent
05cf469945
commit
54c857b448
@ -161,9 +161,9 @@ use sqlx::postgres::PgPool;
|
||||
#[async_std::main] // or #[tokio::main]
|
||||
async fn main() -> Result<(), sqlx::Error> {
|
||||
// Create a connection pool
|
||||
let pool = PgPoolOptions::new(&env::var("DATABASE_URL")?)?
|
||||
let pool = PgPoolOptions::new()
|
||||
.max_connections(5)
|
||||
.connect().await?;
|
||||
.connect(&env::var("DATABASE_URL")?).await?;
|
||||
|
||||
// Make a simple query to return the given parameter
|
||||
let row: (i64,) = sqlx::query_as("SELECT $1")
|
||||
|
@ -24,9 +24,7 @@ fn bench_pgpool_acquire(c: &mut Criterion) {
|
||||
|
||||
fn do_bench_acquire(b: &mut Bencher, concurrent: u32, fair: bool) {
|
||||
let pool = sqlx_rt::block_on(
|
||||
PgPoolOptions::new(
|
||||
&dotenv::var("DATABASE_URL").expect("DATABASE_URL must be set to run benchmarks"),
|
||||
)
|
||||
PgPoolOptions::new()
|
||||
// we don't want timeouts because we want to see how the pool degrades
|
||||
.connect_timeout(Duration::from_secs(3600))
|
||||
// force the pool to start full
|
||||
@ -35,7 +33,9 @@ fn do_bench_acquire(b: &mut Bencher, concurrent: u32, fair: bool) {
|
||||
// we're not benchmarking `ping()`
|
||||
.test_before_acquire(false)
|
||||
.__fair(fair)
|
||||
.connect(),
|
||||
.connect(
|
||||
&dotenv::var("DATABASE_URL").expect("DATABASE_URL must be set to run benchmarks"),
|
||||
),
|
||||
)
|
||||
.expect("failed to open PgPool");
|
||||
|
||||
|
@ -76,11 +76,11 @@ CREATE TEMPORARY TABLE users (id INTEGER PRIMARY KEY);
|
||||
|
||||
#[sqlx_macros::test]
|
||||
async fn it_executes_with_pool() -> anyhow::Result<()> {
|
||||
let pool: MySqlPool = MySqlPoolOptions::new(&dotenv::var("DATABASE_URL")?)?
|
||||
let pool: MySqlPool = MySqlPoolOptions::new()
|
||||
.min_connections(2)
|
||||
.max_connections(2)
|
||||
.test_before_acquire(false)
|
||||
.connect()
|
||||
.connect(&dotenv::var("DATABASE_URL")?)
|
||||
.await?;
|
||||
|
||||
let rows = pool.fetch_all("SELECT 1; SELECT 2").await?;
|
||||
|
@ -370,11 +370,11 @@ async fn pool_smoke_test() -> anyhow::Result<()> {
|
||||
|
||||
eprintln!("starting pool");
|
||||
|
||||
let pool = PgPoolOptions::new(&dotenv::var("DATABASE_URL")?)?
|
||||
let pool = PgPoolOptions::new()
|
||||
.connect_timeout(Duration::from_secs(30))
|
||||
.min_connections(5)
|
||||
.max_connections(10)
|
||||
.connect()
|
||||
.connect(&dotenv::var("DATABASE_URL")?)
|
||||
.await?;
|
||||
|
||||
// spin up more tasks than connections available, and ensure we don't deadlock
|
||||
|
@ -127,11 +127,11 @@ async fn it_fetches_in_loop() -> anyhow::Result<()> {
|
||||
|
||||
#[sqlx_macros::test]
|
||||
async fn it_executes_with_pool() -> anyhow::Result<()> {
|
||||
let pool: SqlitePool = SqlitePoolOptions::new(&dotenv::var("DATABASE_URL")?)?
|
||||
let pool: SqlitePool = SqlitePoolOptions::new()?
|
||||
.min_connections(2)
|
||||
.max_connections(2)
|
||||
.test_before_acquire(false)
|
||||
.connect()
|
||||
.connect(&dotenv::var("DATABASE_URL")?)
|
||||
.await?;
|
||||
|
||||
let rows = pool.fetch_all("SELECT 1; SElECT 2").await?;
|
||||
|
Loading…
x
Reference in New Issue
Block a user