You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Building upon @yrashk's work in #902, this does a few small things, which caused a bunch of files (mostly tests and examples) to be updated.
First off, the various Spi functions like `Spi::get_one()` go back to returning `-> Result<Option<T>, Error>`. This might seem counter to my comment at #902 (review), but there's an important thing Spi **must** support: Any Datum **can be NULL**, which means we must return `Option<T>`.
So, the thing that makes this better is we also now have `impl<T, E> IntoDatum for Result<T, E> where T: IntoDatum, E: std::error::Error`. This means any `#[pg_extern]` function can now return a `Result`, and if that Result represents an error, it is raised as a Postgres ERROR.
This is a big win for `#[pg_extern]`-style functions in general, and makes working with an Spi interface that returns `Result<Option<T>, Error>` pretty fluent as now you can just directly return the result from `Spi::get_XXX()` or you can use the `?` operator to nicely unwrap the error and then deal with the returned, possibly NULL, Datum.
Doing this, and updating the Spi API caused all sorts of code to be touched in the tests and examples. As a result, there's (hacky) support for `#[pg_test]` functions being able to return `-> Result<(), pgx::spi::Error>`, which makes using Spi in the tests nearly the same, but now with a `?` operator and a `return Ok(())` at the end of such functions.
The examples that use SPI needed to be touched as well. This is a pretty big breaking API change, afterall.
0 commit comments