Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adjust new_with_pool to return PGMQueue directly #217

Merged
merged 4 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pgmq-rs/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pgmq"
version = "0.26.1"
version = "0.27.0"
edition = "2021"
authors = ["Tembo.io"]
description = "A distributed message queue for Rust applications, on Postgres."
Expand Down
10 changes: 5 additions & 5 deletions pgmq-rs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,21 +170,21 @@ pub struct PGMQueue {
}

impl PGMQueue {
pub async fn new(url: String) -> Result<PGMQueue, PgmqError> {
pub async fn new(url: String) -> Result<Self, PgmqError> {
let con = util::connect(&url, 5).await?;
Ok(PGMQueue {
Ok(Self {
url,
connection: con,
})
}

/// BYOP - bring your own pool
/// initialize a PGMQ connection with your own SQLx Postgres connection pool
pub async fn new_with_pool(pool: Pool<Postgres>) -> Result<PGMQueue, PgmqError> {
Ok(PGMQueue {
pub async fn new_with_pool(pool: Pool<Postgres>) -> Self {
Self {
url: "".to_owned(),
connection: pool,
})
}
}

/// Create a queue. This sets up the queue's tables, indexes, and metadata.
Expand Down
10 changes: 5 additions & 5 deletions pgmq-rs/src/pg_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,20 @@ pub struct PGMQueueMeta {
}
impl PGMQueueExt {
/// Initialize a connection to PGMQ/Postgres
pub async fn new(url: String, max_connections: u32) -> Result<PGMQueueExt, PgmqError> {
Ok(PGMQueueExt {
pub async fn new(url: String, max_connections: u32) -> Result<Self, PgmqError> {
Ok(Self {
connection: connect(&url, max_connections).await?,
url,
})
}

/// BYOP - bring your own pool
/// initialize a PGMQ connection with your own SQLx Postgres connection pool
pub async fn new_with_pool(pool: Pool<Postgres>) -> Result<PGMQueueExt, PgmqError> {
Ok(PGMQueueExt {
pub async fn new_with_pool(pool: Pool<Postgres>) -> Self {
Self {
url: "".to_owned(),
connection: pool,
})
}
}

pub async fn init(&self) -> Result<bool, PgmqError> {
Expand Down
4 changes: 1 addition & 3 deletions pgmq-rs/tests/pg_ext_integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,9 +356,7 @@ async fn test_byop() {
let _queue = init_queue_ext(&test_queue).await;
let pool = _queue.connection;

let queue = pgmq::PGMQueueExt::new_with_pool(pool)
.await
.expect("failed to connect to postgres");
let queue = pgmq::PGMQueueExt::new_with_pool(pool).await;

let init = queue.init().await.expect("failed to create extension");
assert!(init, "failed to create extension");
Expand Down
Loading