graphql-engine-1.0.0: GraphQL API over Postgres
Safe HaskellNone
LanguageHaskell2010

Hasura.Backends.Postgres.Execute.Prepare

Description

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

Documentation

type PlanVariables = HashMap Name Int Source #

type PrepArgMap = IntMap (PrepArg, PGScalarValue) Source #

The value is (Q.PrepArg, PGScalarValue) because we want to log the human-readable value of the prepared argument and not the binary encoding in PG format

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).

getVarArgNum :: MonadState PlanningSt m => Name -> m Int Source #

In prepared statements, we refer to variables by a number, not their name. If the statement already refers to a variable, then we'll already have a number for it, and so we just return that. Otherwise, we produce a new number, and that will refer to the variable from now on.

addPrepArg :: MonadState PlanningSt m => Int -> (PrepArg, PGScalarValue) -> m () Source #

Add a prepared argument to the prepared argument map. These are keyed by the variable argument numbers, which can be computed using getVarArgNum.

getNextArgNum :: MonadState PlanningSt m => m Int Source #

Get _psArgNumber from inside the PlanningSt and increment it for the next operation. Think of this as a pure analogue to newUnique.