use pgboss::Client; use sqlx::Connection; lazy_static::lazy_static! { pub(crate) static ref POSRGRES_URL: String = { let var_name = std::env::var("POSTGRES_PROVIDER") .unwrap_or_else(|_| "POSTGRES_URL".to_string()); std::env::var(var_name) .unwrap_or_else(|_| "postgres://localhost:5432".to_string()) }; } pub(crate) async fn ad_hoc_sql(stmt: I) -> Result<(), sqlx::Error> where I: IntoIterator, { let mut conn = sqlx::PgConnection::connect(&*POSRGRES_URL).await?; let r = sqlx::raw_sql(&stmt.into_iter().collect::>().join("\n")) .execute(&mut conn) .await; conn.close().await?; Ok(r.map(|_| ())?) } pub(crate) async fn drop_schema(schema: &str) -> Result<(), sqlx::Error> { let stmt = format!("DROP SCHEMA IF EXISTS {} CASCADE", schema); ad_hoc_sql([stmt]).await } pub(crate) async fn prepare(schema: &str, qname: &str) -> Client { drop_schema(schema).await.unwrap(); let c = Client::builder().schema(schema).connect().await.unwrap(); c.create_standard_queue(qname).await.unwrap(); c }