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

Trigger support improvements #558

Merged
merged 19 commits into from
May 25, 2022
Merged

Trigger support improvements #558

merged 19 commits into from
May 25, 2022

Conversation

Hoverbear
Copy link
Contributor

@Hoverbear Hoverbear commented May 9, 2022

Improves Trigger support roughly in line with #503 :

use pgx::{pg_trigger, pg_sys, PgHeapTuple, WhoAllocated, PgHeapTupleError, PgTrigger};

#[derive(thiserror::Error, Debug)]
enum CustomTriggerError {
    #[error("No current HeapTuple")]
    NoCurrentHeapTuple,
    #[error("pgx::PgHeapTupleError: {0}")]
    PgHeapTuple(PgHeapTupleError),
}

#[pg_trigger]
fn example_custom_error(trigger: &PgTrigger) -> Result<
    PgHeapTuple<'_, impl WhoAllocated<pg_sys::HeapTupleData>>,
    CustomTriggerError,
> {
    unsafe { trigger.current() }.ok_or(CustomTriggerError::NoCurrentHeapTuple)
}

@Hoverbear Hoverbear self-assigned this May 9, 2022
Hoverbear added 9 commits May 9, 2022 13:43
Signed-off-by: Ana Hobden <[email protected]>
Signed-off-by: Ana Hobden <[email protected]>
Signed-off-by: Ana Hobden <[email protected]>
Signed-off-by: Ana Hobden <[email protected]>
Signed-off-by: Ana Hobden <[email protected]>
Signed-off-by: Ana Hobden <[email protected]>
Signed-off-by: Ana Hobden <[email protected]>
Signed-off-by: Ana Hobden <[email protected]>
Signed-off-by: Ana Hobden <[email protected]>
@Hoverbear Hoverbear marked this pull request as ready for review May 11, 2022 17:56
@Hoverbear Hoverbear changed the base branch from develop-v0.5.0 to develop May 11, 2022 17:56
@Hoverbear Hoverbear changed the base branch from develop to develop-v0.5.0 May 11, 2022 17:56
@Hoverbear
Copy link
Contributor Author

I'd like to add some more tests...

@eeeebbbbrrrr
Copy link
Contributor

fn trigger_example<'a>(trigger: &'a pgx::PgTrigger<'a>) -> Result<Option<PgHeapTuple<'a, impl WhoAllocated<pgx::pg_sys::HeapTupleData>>>, TriggerError> {

That's special. Wonder if we could make a type alias like:

type TriggerResult = PgHeapTuple<'a, impl WhoAllocated<pgx::pg_sys::HeapTupleData>

Hoverbear added 2 commits May 11, 2022 12:47
Signed-off-by: Ana Hobden <[email protected]>
Signed-off-by: Ana Hobden <[email protected]>
@Hoverbear
Copy link
Contributor Author

You can't use impl Trait in type aliases sadly.

@Hoverbear
Copy link
Contributor Author

(I removed the extra lifetimes from the siganture when I was testing now)

@Hoverbear Hoverbear requested a review from eeeebbbbrrrr May 12, 2022 17:14
Hoverbear added 5 commits May 12, 2022 10:35
Signed-off-by: Ana Hobden <[email protected]>
Signed-off-by: Ana Hobden <[email protected]>
Signed-off-by: Ana Hobden <[email protected]>
Signed-off-by: Ana Hobden <[email protected]>
Signed-off-by: Ana Hobden <[email protected]>
@Hoverbear Hoverbear requested a review from eeeebbbbrrrr May 13, 2022 17:21
/// The caller should already have at least AccessShareLock on the relation ID, else there are nasty race conditions.
///
/// As such, this function is unsafe as we cannot guarantee that this requirement is true.
pub unsafe fn relation(&self) -> Result<crate::PgRelation, PgTriggerError> {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's your take on the safety of this one, @eeeebbbbrrrr ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants