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

add new catalog and cache APIs #1545

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
Next Next commit
add ::new API for catalog wrappers
Signed-off-by: usamoi <[email protected]>
usamoi committed Aug 17, 2024
commit f70b053fe2b1d4be1a766defe86196b0b56a0daf
40 changes: 32 additions & 8 deletions pgrx/src/pg_catalog.rs
Original file line number Diff line number Diff line change
@@ -213,9 +213,14 @@ macro_rules! define_column {
paste::paste! {
impl [<$table:camel>]<'_> {
$(#[$column_meta])*
/// # Panics
///
/// This function panics if the catalog wrapper is created by `Self::new` but there is no `cache_id` provided.
pub fn $column(&self) -> Option<$column_type> {
unsafe {
get_attr::<$column_type>(self.inner, self.cache_id, pg_sys::[<Anum_ $table _ $column>])
if let Some(cache_id) = self.cache_id {
unsafe { get_attr::<$column_type>(self.inner, cache_id, pg_sys::[<Anum_ $table _ $column>]) }
} else {
panic!("`cache_id` is not provided")
}
}
}
@@ -227,10 +232,15 @@ macro_rules! define_column {
paste::paste! {
impl [<$table:camel>]<'_> {
$(#[$column_meta])*
/// # Panics
///
/// This function panics if the catalog wrapper is created by `Self::new` but there is no `cache_id` provided.
pub fn $column(&self) -> $column_type {
unsafe {
get_attr::<$column_type>(self.inner, self.cache_id, pg_sys::[<Anum_ $table _ $column>])
}.unwrap()
if let Some(cache_id) = self.cache_id {
unsafe { get_attr::<$column_type>(self.inner, cache_id, pg_sys::[<Anum_ $table _ $column>]).unwrap() }
} else {
panic!("`cache_id` is not provided")
}
}
}
}
@@ -247,7 +257,21 @@ macro_rules! define_catalog {
pub struct [<$table:camel>]<'a> {
inner: &'a pg_sys::HeapTupleData,
#[allow(dead_code)]
cache_id: i32,
cache_id: Option<i32>,
}

impl<'a> [<$table:camel>]<'a> {
/// Create a catalog wrapper by a heap tuple.
///
/// # Safety
///
/// If `cache_id` is provided, `cache_id` must be an ID for a `syscache` for this catalog.
pub unsafe fn new(inner: &'a pg_sys::HeapTupleData, cache_id: Option<i32>) -> Self {
Self {
inner,
cache_id,
}
}
}

#[doc = concat!("The search result for pg_catalog.", stringify!($table), ".")]
@@ -266,7 +290,7 @@ macro_rules! define_catalog {
unsafe {
Some([<$table:camel>] {
inner: self.inner?.as_ref(),
cache_id: self.cache_id,
cache_id: Some(self.cache_id),
})
}
}
@@ -304,7 +328,7 @@ macro_rules! define_catalog {
unsafe {
Some([<$table:camel>] {
inner: syscache_get(self.inner, i)?,
cache_id: self.cache_id
cache_id: Some(self.cache_id)
})
}
}