Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Postgres Execute Prepare
Deals with translating (session) variables to SQL expressions. Uses a state monad to keep track of things like variables and generating fresh variable names.
See Execute
.
Synopsis
- type PlanVariables = HashMap PlanVariable Int
- type PrepArgMap = IntMap (PrepArg, PGScalarValue)
- data PlanningSt = PlanningSt {}
- initPlanningSt :: PlanningSt
- prepareWithPlan :: (MonadState PlanningSt m, MonadError QErr m) => UserInfo -> UnpreparedValue ('Postgres pgKind) -> m SQLExp
- prepareWithoutPlan :: MonadError QErr m => UserInfo -> UnpreparedValue ('Postgres pgKind) -> m SQLExp
- withUserVars :: SessionVariables -> PrepArgMap -> PrepArgMap
Documentation
type PlanVariables = HashMap PlanVariable Int Source #
type PrepArgMap = IntMap (PrepArg, PGScalarValue) Source #
The value is (PG.PrepArg, PGScalarValue) because we want to log the human-readable value of the prepared argument and not the binary encoding in PG format
data PlanningSt Source #
Instances
Show PlanningSt Source # | |
Defined in Hasura.Backends.Postgres.Execute.Prepare showsPrec :: Int -> PlanningSt -> ShowS # show :: PlanningSt -> String # showList :: [PlanningSt] -> ShowS # | |
Eq PlanningSt Source # | |
Defined in Hasura.Backends.Postgres.Execute.Prepare (==) :: PlanningSt -> PlanningSt -> Bool # (/=) :: PlanningSt -> PlanningSt -> Bool # |
prepareWithPlan :: (MonadState PlanningSt m, MonadError QErr m) => UserInfo -> UnpreparedValue ('Postgres pgKind) -> m SQLExp Source #
If we're preparing a value with planning state, we favour referring to
values by their prepared argument index. If the value refers to a session
value, we look for it in prepared value (1) and access the particular keys
using the JSONB ->>
accessor.
prepareWithoutPlan :: MonadError QErr m => UserInfo -> UnpreparedValue ('Postgres pgKind) -> m SQLExp Source #
If we're not using a prepared statement, substitution is pretty naïve:
we resolve session variable names, ignore parameter names, and substitute
into the SQLExp
.
withUserVars :: SessionVariables -> PrepArgMap -> PrepArgMap Source #
The map of user session variables is always given the number (1) as its
variable argument number (see getVarArgNum
). If we want to refer to a
particular variable in this map, we use JSONB functions to interrogate
variable (1).