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

Hasura.Backends.Postgres.DDL.RunSQL

Description

Postgres DDL RunSQL

Escape hatch for running raw SQL against a postgres database.

runRunSQL executes the provided raw SQL.

isSchemaCacheBuildRequiredRunSQL checks for known schema-mutating keywords in the raw SQL text.

See V2Query and Query.

Synopsis

Documentation

data RunSQL Source #

Constructors

RunSQL 

Instances

Instances details
Eq RunSQL Source # 
Instance details

Defined in Hasura.Backends.Postgres.DDL.RunSQL

Methods

(==) :: RunSQL -> RunSQL -> Bool #

(/=) :: RunSQL -> RunSQL -> Bool #

Show RunSQL Source # 
Instance details

Defined in Hasura.Backends.Postgres.DDL.RunSQL

FromJSON RunSQL Source # 
Instance details

Defined in Hasura.Backends.Postgres.DDL.RunSQL

Methods

parseJSON :: Value -> Parser RunSQL

parseJSONList :: Value -> Parser [RunSQL]

ToJSON RunSQL Source # 
Instance details

Defined in Hasura.Backends.Postgres.DDL.RunSQL

Methods

toJSON :: RunSQL -> Value

toEncoding :: RunSQL -> Encoding

toJSONList :: [RunSQL] -> Value

toEncodingList :: [RunSQL] -> Encoding

isSchemaCacheBuildRequiredRunSQL :: RunSQL -> Bool Source #

Check for known schema-mutating keywords in the raw SQL text.

See Note [Checking metadata consistency in run_sql].

fetchTablesFunctionsMetadata :: forall pgKind m. (ToMetadataFetchQuery pgKind, FetchTableMetadata pgKind, FetchFunctionMetadata pgKind, BackendMetadata ('Postgres pgKind), MonadTx m) => TableCache ('Postgres pgKind) -> [TableName ('Postgres pgKind)] -> [FunctionName ('Postgres pgKind)] -> m ([TableMeta ('Postgres pgKind)], [FunctionMeta ('Postgres pgKind)]) Source #

Fetch metadata of tracked tablesfunctions and build @TableMetaFunctionMeta to calculate diff later in withMetadataCheck.

runRunSQL :: forall (pgKind :: PostgresKind) m. (BackendMetadata ('Postgres pgKind), ToMetadataFetchQuery pgKind, FetchTableMetadata pgKind, FetchFunctionMetadata pgKind, CacheRWM m, HasServerConfigCtx m, MetadataM m, MonadBaseControl IO m, MonadError QErr m, MonadIO m, MonadTrace m, UserInfoM m) => RunSQL -> m EncJSON Source #

Used as an escape hatch to run raw SQL against a database.

withMetadataCheck :: forall (pgKind :: PostgresKind) a m. (BackendMetadata ('Postgres pgKind), ToMetadataFetchQuery pgKind, FetchTableMetadata pgKind, FetchFunctionMetadata pgKind, CacheRWM m, HasServerConfigCtx m, MetadataM m, MonadBaseControl IO m, MonadError QErr m, MonadIO m) => SourceName -> Bool -> TxAccess -> TxET QErr m a -> m a Source #

withMetadataCheck source cascade txAccess runSQLQuery executes runSQLQuery and checks if the schema changed as a result. If it did, it checks to ensure the changes do not violate any integrity constraints, and if not, incorporates them into the schema cache. TODO(antoine): shouldn't this be generalized?

runTxWithMetadataCheck :: forall m a (pgKind :: PostgresKind). (BackendMetadata ('Postgres pgKind), ToMetadataFetchQuery pgKind, FetchTableMetadata pgKind, FetchFunctionMetadata pgKind, CacheRWM m, MonadIO m, MonadBaseControl IO m, MonadError QErr m) => SourceName -> SourceConfig ('Postgres pgKind) -> TxAccess -> TableCache ('Postgres pgKind) -> FunctionCache ('Postgres pgKind) -> Bool -> TxET QErr m a -> m (a, MetadataModifier) Source #

'runTxWithMetadataCheck source sourceConfig txAccess tableCache functionCache cascadeDependencies tx' checks for changes in GraphQL Engine metadata when a tx is executed on the database alters Postgres schema of tables and functions. If any indirect dependencies (Eg. remote table dependence of a relationship) are found and @cascadeDependencies is False, then an exception is raised.

fetchTablesFunctionsFromOids :: MonadIO m => [OID] -> [OID] -> TxET QErr m ([TableName ('Postgres pgKind)], [FunctionName ('Postgres pgKind)]) Source #

Fetch list of tables and functions with provided oids