Skip to content

Conversation

@Hoverbear
Copy link
Contributor

@Hoverbear Hoverbear commented May 27, 2022

Based off #56 , is a draft until it merges.

Requires the experimental develop-v0.5.0 PGX branch locally! Test with:

PLRUST_EXPERIMENTAL_CRATES=/home/ana/git/zombodb/pgx/pgx cargo pgx run

Then:

DROP EXTENSION IF EXISTS plrust CASCADE; CREATE EXTENSION plrust;

CREATE TABLE dogs (
    name TEXT,
    scritches INT NOT NULL DEFAULT 0
);
 
CREATE FUNCTION pet_trigger() RETURNS trigger AS $$
    let current = trigger.current().unwrap();
    let mut current = current.into_owned();

    let field = "scritches";

    match current.get_by_name::<i32>(field).unwrap() {
        Some(val) => current.set_by_name(field, val + 1).unwrap(),
        None => (),
    }

    Ok(current)
$$ LANGUAGE plrust;

CREATE TRIGGER pet_trigger BEFORE INSERT OR UPDATE ON dogs
    FOR EACH ROW EXECUTE FUNCTION pet_trigger();

INSERT INTO dogs (name) VALUES ('Nami');

Hoverbear added 30 commits May 13, 2022 12:58
Signed-off-by: Ana Hobden <operator@hoverbear.org>
Signed-off-by: Ana Hobden <operator@hoverbear.org>
Signed-off-by: Ana Hobden <operator@hoverbear.org>
Signed-off-by: Ana Hobden <operator@hoverbear.org>
Signed-off-by: Ana Hobden <operator@hoverbear.org>
Signed-off-by: Ana Hobden <operator@hoverbear.org>
Signed-off-by: Ana Hobden <operator@hoverbear.org>
Signed-off-by: Ana Hobden <operator@hoverbear.org>
Signed-off-by: Ana Hobden <operator@hoverbear.org>
Signed-off-by: Ana Hobden <operator@hoverbear.org>
Signed-off-by: Ana Hobden <operator@hoverbear.org>
Signed-off-by: Ana Hobden <operator@hoverbear.org>
Signed-off-by: Ana Hobden <operator@hoverbear.org>
Signed-off-by: Ana Hobden <operator@hoverbear.org>
Signed-off-by: Ana Hobden <operator@hoverbear.org>
Signed-off-by: Ana Hobden <operator@hoverbear.org>
Signed-off-by: Ana Hobden <operator@hoverbear.org>
Signed-off-by: Ana Hobden <operator@hoverbear.org>
Signed-off-by: Ana Hobden <operator@hoverbear.org>
Signed-off-by: Ana Hobden <operator@hoverbear.org>
Signed-off-by: Ana Hobden <operator@hoverbear.org>
Signed-off-by: Ana Hobden <operator@hoverbear.org>
Signed-off-by: Ana Hobden <operator@hoverbear.org>
Signed-off-by: Ana Hobden <operator@hoverbear.org>
Signed-off-by: Ana Hobden <operator@hoverbear.org>
Signed-off-by: Ana Hobden <operator@hoverbear.org>
Signed-off-by: Ana Hobden <operator@hoverbear.org>
@Hoverbear
Copy link
Contributor Author

This is based off #56 :)

This was referenced Jul 4, 2022
@Hoverbear Hoverbear marked this pull request as ready for review July 5, 2022 18:12
Copy link
Contributor

@workingjubilee workingjubilee left a comment

Choose a reason for hiding this comment

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

I think this looks good! My commentary is mostly so extensive like this, including some remarks that aren't actually about your code, because I realized that everything that bothered or confused me about the code here is something that

  • this PR is not directly responsible for
  • I can also probably fix this week
  • expressing inclinations may elicit concurrence, disagreement, or other discussion for future direction, so I should do it now.

So I figured I should immediately leave as many notes as possible even if they make this less of a review and more of a running stream. Thus if you have any inclination for commentary on my commentary you are welcome to it, but this is good to merge this as-is and we can address improvements in followups.

fn #symbol_ident(
trigger: &::pgx::PgTrigger,
) -> core::result::Result<
::pgx::heap_tuple::PgHeapTuple<'_, impl ::pgx::WhoAllocated<::pgx::pg_sys::HeapTupleData>>,
Copy link
Contributor

@workingjubilee workingjubilee Jul 5, 2022

Choose a reason for hiding this comment

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

I need to get back to refactoring the allocation code in PGX, now that it's creeping more into this codebase again.

Comment on lines +75 to +78
#[tracing::instrument(level = "debug", skip_all)]
pub(crate) fn trigger() -> Self {
Self::Trigger
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm guessing this constructor is mostly for tracing purposes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think also to avoid future me going "Why is there no ctor for this?" as I am known to do.

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.

4 participants