Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 5 additions & 5 deletions pgrx-examples/bgworker/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,15 @@ pub extern "C" fn background_worker_main(arg: pg_sys::Datum) {
// within a transaction, execute an SQL statement, and log its results
let result: Result<(), pgrx::spi::Error> = BackgroundWorker::transaction(|| {
Spi::connect(|client| {
let tuple_table = client.select(
let mut tuple_table = client.select(
"SELECT 'Hi', id, ''||a FROM (SELECT id, 42 from generate_series(1,10) id) a ",
None,
None,
)?;
for tuple in tuple_table {
let a = tuple.get_datum_by_ordinal(1)?.value::<String>()?;
let b = tuple.get_datum_by_ordinal(2)?.value::<i32>()?;
let c = tuple.get_datum_by_ordinal(3)?.value::<String>()?;
while let Some(tuple) = tuple_table.next() {
let a = tuple[1].value::<String>()?;
let b = tuple[2].value::<i32>()?;
let c = tuple[3].value::<String>()?;
log!("from bgworker: ({:?}, {:?}, {:?})", a, b, c);
}
Ok(())
Expand Down
14 changes: 4 additions & 10 deletions pgrx-examples/custom_sql/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,10 @@ mod tests {
#[pg_test]
fn test_ordering() -> Result<(), spi::Error> {
let buf = Spi::connect(|client| {
Ok::<_, spi::Error>(
client
.select("SELECT * FROM extension_sql", None, None)?
.flat_map(|tup| {
tup.get_datum_by_ordinal(1)
.ok()
.and_then(|ord| ord.value::<String>().ok().unwrap())
})
.collect::<Vec<String>>(),
)
client
.select("SELECT * FROM extension_sql", None, None)?
.map(|tup| Ok(tup.get::<String>(1)?.unwrap()))
.collect::<spi::Result<Vec<_>>>()
})?;

assert_eq!(
Expand Down
2 changes: 1 addition & 1 deletion pgrx-examples/schemas/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ mod tests {

#[pg_test]
fn test_my_some_schema_type() -> Result<(), spi::Error> {
Spi::connect(|mut c| {
Spi::connect(|c| {
// "MySomeSchemaType" is in 'some_schema', so it needs to be discoverable
c.update("SET search_path TO some_schema,public", None, None)?;
assert_eq!(
Expand Down
2 changes: 1 addition & 1 deletion pgrx-examples/spi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ fn issue1209_fixed() -> Result<Option<String>, Box<dyn std::error::Error>> {
let res = Spi::connect(|c| {
let mut cursor = c.open_cursor("SELECT 'hello' FROM generate_series(1, 10000)", None);
let table = cursor.fetch(10000)?;
table.into_iter().map(|row| row.get::<&str>(1)).collect::<Result<Vec<_>, _>>()
table.map(|row| row.get::<&str>(1)).collect::<Result<Vec<_>, _>>()
})?;

Ok(res.first().cloned().flatten().map(|s| s.to_string()))
Expand Down
6 changes: 2 additions & 4 deletions pgrx-tests/src/tests/spi_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ mod tests {

fn sum_all(table: pgrx::spi::SpiTupleTable) -> i32 {
table
.map(|r| r.get_datum_by_ordinal(1)?.value::<i32>())
.map(|r| r.get_one::<i32>())
.map(|r| r.expect("failed to get ordinal #1").expect("ordinal #1 was null"))
.sum()
}
Expand Down Expand Up @@ -356,7 +356,6 @@ mod tests {
let _b = client.select("SELECT 1 WHERE 'f'", None, None)?;
assert!(!a.is_empty());
assert_eq!(1, a.len());
assert!(a.get_heap_tuple().is_ok());
assert_eq!(Ok(Some(1)), a.get::<i32>(1));
Ok(())
})
Expand All @@ -372,7 +371,6 @@ mod tests {
let _b = client.select("SELECT 1", None, None)?;
assert!(a.is_empty());
assert_eq!(0, a.len());
assert!(a.get_heap_tuple().is_ok());
assert_eq!(Err(pgrx::spi::Error::InvalidPosition), a.get::<i32>(1));
Ok(())
})
Expand Down Expand Up @@ -540,7 +538,7 @@ mod tests {
let res = Spi::connect(|c| {
let mut cursor = c.open_cursor("SELECT 'hello' FROM generate_series(1, 10000)", None);
let table = cursor.fetch(10000)?;
table.into_iter().map(|row| row.get::<&str>(1)).collect::<Result<Vec<_>, _>>()
table.map(|row| row.get::<&str>(1)).collect::<Result<Vec<_>, _>>()
})?;

let value = res.first().cloned().flatten().map(|s| s.to_string());
Expand Down
2 changes: 1 addition & 1 deletion pgrx/src/spi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ mod tuple;
pub use client::SpiClient;
pub use cursor::SpiCursor;
pub use query::{OwnedPreparedStatement, PreparedStatement, Query};
pub use tuple::{SpiHeapTupleData, SpiHeapTupleDataEntry, SpiTupleTable};
pub use tuple::SpiTupleTable;

pub type SpiResult<T> = std::result::Result<T, SpiError>;
pub use SpiResult as Result;
Expand Down
Loading