graphql-engine-1.0.0: GraphQL API over Postgres
Safe HaskellSafe-Inferred
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 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

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