PostgresSigil.Results (postgres_sigil v0.4.0)

Functions that operate on Postgrex results to make it easier to extract values from them

Link to this section Summary

Functions

Returns whether any rows have come back

Extract the number of rows affected by the SQL operation

Given a result set, ensure it either contains exactly one value. In all other cases a match error will be thrown

Given a result set, ensure it either contains exactly one value or no values at all, in which case nil will be returned. The second argument is an optional function to apply to the value if it isn't nil.

Zip the returned column names with the rows to produce a list of maps, where each key is the column name.

Turn the results into a list of maps, then turn them into a struct. If any required keys are missing an exception will be raised.

Link to this section Functions

Returns whether any rows have come back

Extract the number of rows affected by the SQL operation

Link to this function

single_value!(map)

Given a result set, ensure it either contains exactly one value. In all other cases a match error will be thrown

Link to this function

single_value_or_nil!(results, function \\ nil)

Given a result set, ensure it either contains exactly one value or no values at all, in which case nil will be returned. The second argument is an optional function to apply to the value if it isn't nil.

Link to this function

to_maps(map, list \\ [keys: :strings])

Zip the returned column names with the rows to produce a list of maps, where each key is the column name.

Link to this function

to_structs!(results, struct)

Turn the results into a list of maps, then turn them into a struct. If any required keys are missing an exception will be raised.