graphql-engine/server/src-lib/Hasura/Backends/MSSQL/DDL/Source.hs

44 lines
1.2 KiB
Haskell
Raw Normal View History

module Hasura.Backends.MSSQL.DDL.Source
( resolveSourceConfig,
resolveDatabaseMetadata,
postDropSourceHook,
)
where
import Data.Environment qualified as Env
import Hasura.Backends.MSSQL.Connection
import Hasura.Backends.MSSQL.Meta
import Hasura.Base.Error
import Hasura.Prelude
import Hasura.RQL.Types.Common
import Hasura.RQL.Types.Source
import Hasura.SQL.Backend
resolveSourceConfig ::
(MonadIO m) =>
SourceName ->
MSSQLConnConfiguration ->
Env.Environment ->
m (Either QErr MSSQLSourceConfig)
resolveSourceConfig _name (MSSQLConnConfiguration connInfo) env = runExceptT do
(connString, mssqlPool) <- createMSSQLPool connInfo env
pure $ MSSQLSourceConfig connString mssqlPool
resolveDatabaseMetadata ::
(MonadIO m) =>
MSSQLSourceConfig ->
m (Either QErr (ResolvedSource 'MSSQL))
resolveDatabaseMetadata config = runExceptT do
dbTablesMetadata <- loadDBMetadata pool
pure $ ResolvedSource config dbTablesMetadata mempty mempty
where
MSSQLSourceConfig _connString pool = config
postDropSourceHook ::
(MonadIO m) =>
MSSQLSourceConfig ->
m ()
postDropSourceHook (MSSQLSourceConfig _ pool) =
-- Close the connection
liftIO $ drainMSSQLPool pool