2021-02-23 20:37:27 +03:00
|
|
|
module Hasura.Backends.MSSQL.DDL.Source
|
2021-09-24 01:56:37 +03:00
|
|
|
( resolveSourceConfig,
|
|
|
|
resolveDatabaseMetadata,
|
|
|
|
postDropSourceHook,
|
2021-02-23 20:37:27 +03:00
|
|
|
)
|
|
|
|
where
|
|
|
|
|
2021-09-24 01:56:37 +03:00
|
|
|
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
|
2021-02-23 20:37:27 +03:00
|
|
|
|
2021-09-24 01:56:37 +03:00
|
|
|
resolveSourceConfig ::
|
|
|
|
(MonadIO m) =>
|
|
|
|
SourceName ->
|
|
|
|
MSSQLConnConfiguration ->
|
|
|
|
Env.Environment ->
|
|
|
|
m (Either QErr MSSQLSourceConfig)
|
2021-07-23 15:25:16 +03:00
|
|
|
resolveSourceConfig _name (MSSQLConnConfiguration connInfo) env = runExceptT do
|
|
|
|
(connString, mssqlPool) <- createMSSQLPool connInfo env
|
2021-03-18 21:32:47 +03:00
|
|
|
pure $ MSSQLSourceConfig connString mssqlPool
|
2021-02-23 20:37:27 +03:00
|
|
|
|
2021-09-24 01:56:37 +03:00
|
|
|
resolveDatabaseMetadata ::
|
|
|
|
(MonadIO m) =>
|
|
|
|
MSSQLSourceConfig ->
|
|
|
|
m (Either QErr (ResolvedSource 'MSSQL))
|
2021-05-25 09:50:13 +03:00
|
|
|
resolveDatabaseMetadata config = runExceptT do
|
2021-02-25 21:15:55 +03:00
|
|
|
dbTablesMetadata <- loadDBMetadata pool
|
|
|
|
pure $ ResolvedSource config dbTablesMetadata mempty mempty
|
2021-02-23 20:37:27 +03:00
|
|
|
where
|
2021-02-25 21:15:55 +03:00
|
|
|
MSSQLSourceConfig _connString pool = config
|
2021-02-23 20:37:27 +03:00
|
|
|
|
2021-09-24 01:56:37 +03:00
|
|
|
postDropSourceHook ::
|
|
|
|
(MonadIO m) =>
|
|
|
|
MSSQLSourceConfig ->
|
|
|
|
m ()
|
2021-02-25 21:15:55 +03:00
|
|
|
postDropSourceHook (MSSQLSourceConfig _ pool) =
|
2021-02-23 20:37:27 +03:00
|
|
|
-- Close the connection
|
2021-02-25 21:15:55 +03:00
|
|
|
liftIO $ drainMSSQLPool pool
|