Skip to content

Commit

Permalink
feat(ext): add is_partitioned and is_unlogged to list_queues (#128)
Browse files Browse the repository at this point in the history
* feat(ext): add is_partitioned and is_unlogged to list_queues

* format
  • Loading branch information
v0idpwn authored Sep 30, 2023
1 parent 811cc21 commit bbab928
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pgmq"
version = "0.28.0"
version = "0.29.0"
edition = "2021"
authors = ["Tembo.io"]
description = "Postgres extension for PGMQ"
Expand Down
13 changes: 13 additions & 0 deletions sql/pgmq--0.28.0--0.29.0.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
DROP FUNCTION pgmq.list_queues();

-- Copy-pasted from schema
-- pgmq::api::list_queues
CREATE FUNCTION pgmq."list_queues"() RETURNS TABLE (
"queue_name" TEXT, /* alloc::string::String */
"created_at" timestamp with time zone, /* pgrx::datum::time_stamp_with_timezone::TimestampWithTimeZone */
"is_partitioned" bool, /* bool */
"is_unlogged" bool /* bool */
)
STRICT
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'pgmq_list_queues_wrapper';
12 changes: 9 additions & 3 deletions src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ fn pgmq_list_queues() -> Result<
(
name!(queue_name, String),
name!(created_at, TimestampWithTimeZone),
name!(is_partitioned, bool),
name!(is_unlogged, bool),
),
>,
spi::Error,
Expand All @@ -57,8 +59,8 @@ fn pgmq_list_queues() -> Result<
Ok(TableIterator::new(results))
}

pub fn listit() -> Result<Vec<(String, TimestampWithTimeZone)>, spi::Error> {
let mut results: Vec<(String, TimestampWithTimeZone)> = Vec::new();
pub fn listit() -> Result<Vec<(String, TimestampWithTimeZone, bool, bool)>, spi::Error> {
let mut results: Vec<(String, TimestampWithTimeZone, bool, bool)> = Vec::new();
let query = format!("SELECT * FROM {PGMQ_SCHEMA}.meta");
let _: Result<(), spi::Error> = Spi::connect(|client| {
let tup_table: SpiTupleTable = client.select(&query, None, None)?;
Expand All @@ -67,7 +69,11 @@ pub fn listit() -> Result<Vec<(String, TimestampWithTimeZone)>, spi::Error> {
let created_at = row["created_at"]
.value::<TimestampWithTimeZone>()?
.expect("no created_at");
results.push((queue_name, created_at));
let is_partitioned = row["is_partitioned"]
.value::<bool>()?
.expect("no is_partitioned");
let is_unlogged = row["is_unlogged"].value::<bool>()?.expect("no is_unlogged");
results.push((queue_name, created_at, is_partitioned, is_unlogged));
}
Ok(())
});
Expand Down

0 comments on commit bbab928

Please sign in to comment.