Copyright | Flipstone Technology Partners 2023 |
---|---|
License | MIT |
Stability | Stable |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
Since: 1.0.0.0
Synopsis
- data Operation param result = Operation {
- executeOperationOne :: forall m. MonadOrville m => param -> m (Either AssertionFailed result)
- executeOperationMany :: forall m. MonadOrville m => NonEmpty param -> m (Either AssertionFailed (Many param result))
- explainOperationOne :: Explanation
- explainOperationMany :: Explanation
- data AssertionFailed
- mkAssertionFailed :: String -> AssertionFailed
- data WherePlanner param = WherePlanner {
- paramMarshaller :: forall entity. (entity -> param) -> SqlMarshaller entity param
- executeOneWhereCondition :: param -> BooleanExpr
- executeManyWhereCondition :: NonEmpty param -> BooleanExpr
- explainOneWhereCondition :: BooleanExpr
- explainManyWhereCondition :: BooleanExpr
- byField :: Ord fieldValue => FieldDefinition nullability fieldValue -> WherePlanner fieldValue
- byFieldTuple :: forall nullabilityA fieldValueA nullabilityB fieldValueB. (Ord fieldValueA, Ord fieldValueB) => FieldDefinition nullabilityA fieldValueA -> FieldDefinition nullabilityB fieldValueB -> WherePlanner (fieldValueA, fieldValueB)
- findOne :: Ord param => TableDefinition key writeEntity readEntity -> WherePlanner param -> Operation param (Maybe readEntity)
- findOneWhere :: Ord param => TableDefinition key writeEntity readEntity -> WherePlanner param -> BooleanExpr -> Operation param (Maybe readEntity)
- findAll :: Ord param => TableDefinition key writeEntity readEntity -> WherePlanner param -> Operation param [readEntity]
- findAllWhere :: Ord param => TableDefinition key writeEntity readEntity -> WherePlanner param -> BooleanExpr -> Operation param [readEntity]
- findSelect :: forall param row. Select row -> Operation param [row]
- askParam :: Operation param param
- assertRight :: Operation (Either String a) a
- data SelectOperation param row result = SelectOperation {
- selectOne :: param -> Select row
- selectMany :: NonEmpty param -> Select row
- explainSelectOne :: Select row
- explainSelectMany :: Select row
- categorizeRow :: row -> param
- produceResult :: [row] -> result
- selectOperation :: Ord param => SelectOperation param row result -> Operation param result
Documentation
data Operation param result Source #
Operation
provides a stucture for building primitive operations that can be
incorporated into a Plan
. An Operation
provides base case implementations of the various plan execution functions.
You only need to care about this type if you want to create new custom
operations to include in a Plan
beyond
those already provided in the Plan
API.
You can build your own custom Operation
values either directly, or using
the function and types in this module, such as WherePlanner
(via findAll
,
etc), or SelectOperation
(via selectOperation
).
Since: 1.0.0.0
Operation | |
|
data AssertionFailed Source #
AssertionFailed
may be returned from the execute functions of an
Operation
to indicate that some expected invariant has failed. For example,
following a foreign key that is enforced by the database only to find that no
record exists. When an Operation
returns an AssertionFailed
value during
plan execution, the error is thrown as an exception using the
MonadThrow
instance for whatever monad the plan is
executing in.
Since: 1.0.0.0
Instances
Exception AssertionFailed Source # | |
Defined in Orville.PostgreSQL.Plan.Operation | |
Show AssertionFailed Source # | |
Defined in Orville.PostgreSQL.Plan.Operation showsPrec :: Int -> AssertionFailed -> ShowS # show :: AssertionFailed -> String # showList :: [AssertionFailed] -> ShowS # |
mkAssertionFailed :: String -> AssertionFailed Source #
mkAssertionFailed
builds an AssertionFailed
error from an error message.
Since: 1.0.0.0
data WherePlanner param Source #
The functions below (findOne
, findAll
, etc) accept a WherePlanner
to determine how to build the where conditions for executing a Select
statement as part of a plan operation.
For simple queries, you can use the functions such as byField
that are
provided here to build a WherePlanner
, but you may also build your own
custom WherePlanner
for more advanced use cases.
If you need to execute a custom query that cannot be built by providing a
custom where clause via WherePlanner
, you may want to use more
direct selectOperation
functions.
Since: 1.0.0.0
WherePlanner | |
|
byField :: Ord fieldValue => FieldDefinition nullability fieldValue -> WherePlanner fieldValue Source #
Builds a WherePlanner
that will match on a single
FieldDefinition
. The resulting WherePlanner
can be used
with functions such as findOne
and findAll
to construct an Operation
.
Since: 1.0.0.0
byFieldTuple :: forall nullabilityA fieldValueA nullabilityB fieldValueB. (Ord fieldValueA, Ord fieldValueB) => FieldDefinition nullabilityA fieldValueA -> FieldDefinition nullabilityB fieldValueB -> WherePlanner (fieldValueA, fieldValueB) Source #
Builds a WherePlanner
that will match on a 2-tuple of
FieldDefinition
s. The resulting WherePlanner
can be used
with functions such as findOne
and findAll
to construct an Operation
.
Since: 1.0.0.0
findOne :: Ord param => TableDefinition key writeEntity readEntity -> WherePlanner param -> Operation param (Maybe readEntity) Source #
findOne
builds a planning primitive that finds (at most) one row from the
given table where the column value for the provided FieldDefinition
matches the plan's input parameter. When executed on multiple parameters, it
fetches all rows where the field matches the inputs and arbitrarily picks at
most one of those rows to use as the result for each input.
Since: 1.0.0.0
findOneWhere :: Ord param => TableDefinition key writeEntity readEntity -> WherePlanner param -> BooleanExpr -> Operation param (Maybe readEntity) Source #
findOneWhere
is similar to findOne
but allows a BooleanExpr
to be
specified that is added to the database query to restrict which rows are
returned.
Since: 1.0.0.0
findAll :: Ord param => TableDefinition key writeEntity readEntity -> WherePlanner param -> Operation param [readEntity] Source #
findAll
builds a planning primitive that finds all the rows from the given
table where the column value for the provided field matches the plan's input
parameter. When executed on multiple parameters, all rows are fetched in a
single query and then associated with their respective inputs after being
fetched.
Since: 1.0.0.0
findAllWhere :: Ord param => TableDefinition key writeEntity readEntity -> WherePlanner param -> BooleanExpr -> Operation param [readEntity] Source #
findAllWhere
is similar to findAll
but allows a BooleanExpr
to be
specified that is added to the database query to restrict which rows are
returned.
Since: 1.0.0.0
findSelect :: forall param row. Select row -> Operation param [row] Source #
findSelect
builds a plan Operation
where the select that is run does not
use the input parameters for the plan in any way. The executeOperationMany
function of the resulting Operation
will run the query once and use the
entire result set as the result each of the input parameters in turn.
Since: 1.0.0.0
askParam :: Operation param param Source #
askParam
simply returns the parameter given from the plan.
Since: 1.0.0.0
assertRight :: Operation (Either String a) a Source #
assertRight
returns the value on the Right
side of an Either
. If
the Either
is a Left
, it raises AssertionFailed
with the message
from the Left
side of the Either
.
Since: 1.0.0.0
data SelectOperation param row result Source #
SelectOperation
is a helper type for building Operation
primitives that
run cSelect
queries. Specifying the fields of SelectOperation
and then
using the selectOperation
function to build an Operation
is more
convenient than building functions to execute the queries that are required
by the Operation
type.
Note: If you only need to build a custom where clause based on the
Operation
parameter, you may want to use a custom WherePlanner
with one
of the existing findOne
or findAll
functions.
If you cannot respresent your custom operation using SelectOperation
then
you need to build the Operation
value directly yourself.
Since: 1.0.0.0
SelectOperation | |
|
selectOperation :: Ord param => SelectOperation param row result -> Operation param result Source #
selectOperation
builds a primitive planning Operation
using the functions
given by a SelectOperation
. If you are implementing a custom operation that
runs a select statement, it is probably easier to use this function rather
than building the Operation
functions directly.
Since: 1.0.0.0