{-# LANGUAGE UndecidableInstances #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}

-- | MSSQL Instances Metadata
--
-- Defines a 'Hasura.RQL.Types.Metadata.Backend.BackendMetadata' type class instance for MSSQL.
module Hasura.Backends.MSSQL.Instances.Metadata () where

import Hasura.Backends.MSSQL.DDL qualified as MSSQL
import Hasura.Base.Error (throw500)
import Hasura.RQL.Types.Metadata.Backend
import Hasura.SQL.Backend

instance BackendMetadata 'MSSQL where
  prepareCatalog :: SourceConfig 'MSSQL -> ExceptT QErr m RecreateEventTriggers
prepareCatalog = SourceConfig 'MSSQL -> ExceptT QErr m RecreateEventTriggers
forall (m :: * -> *).
(MonadIO m, MonadBaseControl IO m) =>
MSSQLSourceConfig -> ExceptT QErr m RecreateEventTriggers
MSSQL.prepareCatalog
  buildComputedFieldInfo :: HashSet (TableName 'MSSQL)
-> TableName 'MSSQL
-> HashSet (Column 'MSSQL)
-> ComputedFieldName
-> ComputedFieldDefinition 'MSSQL
-> RawFunctionInfo 'MSSQL
-> Comment
-> m (ComputedFieldInfo 'MSSQL)
buildComputedFieldInfo = HashSet (TableName 'MSSQL)
-> TableName 'MSSQL
-> HashSet (Column 'MSSQL)
-> ComputedFieldName
-> ComputedFieldDefinition 'MSSQL
-> RawFunctionInfo 'MSSQL
-> Comment
-> m (ComputedFieldInfo 'MSSQL)
forall (m :: * -> *).
MonadError QErr m =>
HashSet (TableName 'MSSQL)
-> TableName 'MSSQL
-> HashSet (Column 'MSSQL)
-> ComputedFieldName
-> ComputedFieldDefinition 'MSSQL
-> RawFunctionInfo 'MSSQL
-> Comment
-> m (ComputedFieldInfo 'MSSQL)
MSSQL.buildComputedFieldInfo
  fetchAndValidateEnumValues :: SourceConfig 'MSSQL
-> TableName 'MSSQL
-> Maybe (PrimaryKey 'MSSQL (RawColumnInfo 'MSSQL))
-> [RawColumnInfo 'MSSQL]
-> m (Either QErr EnumValues)
fetchAndValidateEnumValues = SourceConfig 'MSSQL
-> TableName 'MSSQL
-> Maybe (PrimaryKey 'MSSQL (RawColumnInfo 'MSSQL))
-> [RawColumnInfo 'MSSQL]
-> m (Either QErr EnumValues)
forall (m :: * -> *).
Monad m =>
SourceConfig 'MSSQL
-> TableName 'MSSQL
-> Maybe (PrimaryKey 'MSSQL (RawColumnInfo 'MSSQL))
-> [RawColumnInfo 'MSSQL]
-> m (Either QErr EnumValues)
MSSQL.fetchAndValidateEnumValues
  resolveSourceConfig :: Logger Hasura
-> SourceName
-> SourceConnConfiguration 'MSSQL
-> BackendSourceKind 'MSSQL
-> BackendConfig 'MSSQL
-> Environment
-> Manager
-> m (Either QErr (SourceConfig 'MSSQL))
resolveSourceConfig = Logger Hasura
-> SourceName
-> SourceConnConfiguration 'MSSQL
-> BackendSourceKind 'MSSQL
-> BackendConfig 'MSSQL
-> Environment
-> Manager
-> m (Either QErr (SourceConfig 'MSSQL))
forall (m :: * -> *) manager.
(MonadIO m, MonadResolveSource m) =>
Logger Hasura
-> SourceName
-> MSSQLConnConfiguration
-> BackendSourceKind 'MSSQL
-> BackendConfig 'MSSQL
-> Environment
-> manager
-> m (Either QErr MSSQLSourceConfig)
MSSQL.resolveSourceConfig
  resolveDatabaseMetadata :: SourceMetadata 'MSSQL
-> SourceConfig 'MSSQL
-> SourceTypeCustomization
-> m (Either QErr (ResolvedSource 'MSSQL))
resolveDatabaseMetadata SourceMetadata 'MSSQL
_ = SourceConfig 'MSSQL
-> SourceTypeCustomization
-> m (Either QErr (ResolvedSource 'MSSQL))
forall (m :: * -> *).
(MonadIO m, MonadBaseControl IO m) =>
MSSQLSourceConfig
-> SourceTypeCustomization
-> m (Either QErr (ResolvedSource 'MSSQL))
MSSQL.resolveDatabaseMetadata
  parseBoolExpOperations :: ValueParser 'MSSQL m v
-> TableName 'MSSQL
-> FieldInfoMap (FieldInfo 'MSSQL)
-> ColumnReference 'MSSQL
-> Value
-> m [OpExpG 'MSSQL v]
parseBoolExpOperations = ValueParser 'MSSQL m v
-> TableName 'MSSQL
-> FieldInfoMap (FieldInfo 'MSSQL)
-> ColumnReference 'MSSQL
-> Value
-> m [OpExpG 'MSSQL v]
forall (m :: * -> *) v.
MonadError QErr m =>
ValueParser 'MSSQL m v
-> TableName
-> FieldInfoMap (FieldInfo 'MSSQL)
-> ColumnReference 'MSSQL
-> Value
-> m [OpExpG 'MSSQL v]
MSSQL.parseBoolExpOperations
  buildFunctionInfo :: SourceName
-> FunctionName 'MSSQL
-> SystemDefined
-> FunctionConfig
-> FunctionPermissionsMap
-> RawFunctionInfo 'MSSQL
-> Maybe Text
-> NamingCase
-> m (FunctionInfo 'MSSQL, SchemaDependency)
buildFunctionInfo = SourceName
-> FunctionName 'MSSQL
-> SystemDefined
-> FunctionConfig
-> FunctionPermissionsMap
-> RawFunctionInfo 'MSSQL
-> Maybe Text
-> NamingCase
-> m (FunctionInfo 'MSSQL, SchemaDependency)
forall (m :: * -> *).
MonadError QErr m =>
SourceName
-> FunctionName 'MSSQL
-> SystemDefined
-> FunctionConfig
-> FunctionPermissionsMap
-> RawFunctionInfo 'MSSQL
-> Maybe Text
-> NamingCase
-> m (FunctionInfo 'MSSQL, SchemaDependency)
MSSQL.buildFunctionInfo
  updateColumnInEventTrigger :: TableName 'MSSQL
-> Column 'MSSQL
-> Column 'MSSQL
-> TableName 'MSSQL
-> EventTriggerConf 'MSSQL
-> EventTriggerConf 'MSSQL
updateColumnInEventTrigger = TableName 'MSSQL
-> Column 'MSSQL
-> Column 'MSSQL
-> TableName 'MSSQL
-> EventTriggerConf 'MSSQL
-> EventTriggerConf 'MSSQL
MSSQL.updateColumnInEventTrigger
  parseCollectableType :: CollectableType (ColumnType 'MSSQL)
-> Value -> m (PartialSQLExp 'MSSQL)
parseCollectableType = CollectableType (ColumnType 'MSSQL)
-> Value -> m (PartialSQLExp 'MSSQL)
forall (m :: * -> *).
MonadError QErr m =>
CollectableType (ColumnType 'MSSQL)
-> Value -> m (PartialSQLExp 'MSSQL)
MSSQL.parseCollectableType
  postDropSourceHook :: SourceConfig 'MSSQL -> TableEventTriggers 'MSSQL -> m ()
postDropSourceHook = SourceConfig 'MSSQL -> TableEventTriggers 'MSSQL -> m ()
forall (m :: * -> *).
(MonadIO m, MonadBaseControl IO m) =>
MSSQLSourceConfig -> TableEventTriggers 'MSSQL -> m ()
MSSQL.postDropSourceHook
  buildComputedFieldBooleanExp :: BoolExpResolver 'MSSQL m v
-> BoolExpRHSParser 'MSSQL m v
-> TableName 'MSSQL
-> FieldInfoMap (FieldInfo 'MSSQL)
-> ComputedFieldInfo 'MSSQL
-> Value
-> m (AnnComputedFieldBoolExp 'MSSQL v)
buildComputedFieldBooleanExp BoolExpResolver 'MSSQL m v
_ BoolExpRHSParser 'MSSQL m v
_ TableName 'MSSQL
_ FieldInfoMap (FieldInfo 'MSSQL)
_ ComputedFieldInfo 'MSSQL
_ Value
_ =
    Text -> m (AnnComputedFieldBoolExp 'MSSQL v)
forall (m :: * -> *) a. QErrM m => Text -> m a
throw500 Text
"Computed fields are not yet defined for MSSQL backends"