2021-02-23 20:37:27 +03:00
|
|
|
module Hasura.Backends.MSSQL.DDL.Source
|
|
|
|
( resolveSourceConfig
|
|
|
|
, resolveDatabaseMetadata
|
|
|
|
, postDropSourceHook
|
|
|
|
)
|
|
|
|
where
|
|
|
|
|
|
|
|
import Hasura.Prelude
|
|
|
|
|
|
|
|
import Hasura.Backends.MSSQL.Connection
|
|
|
|
import Hasura.Backends.MSSQL.Meta
|
|
|
|
import Hasura.RQL.Types.Common
|
|
|
|
import Hasura.RQL.Types.Error
|
|
|
|
import Hasura.RQL.Types.Source
|
|
|
|
import Hasura.SQL.Backend
|
|
|
|
|
|
|
|
resolveSourceConfig
|
|
|
|
:: (MonadIO m)
|
|
|
|
=> SourceName
|
|
|
|
-> MSSQLConnConfiguration
|
|
|
|
-> m (Either QErr MSSQLSourceConfig)
|
2021-02-25 21:15:55 +03:00
|
|
|
resolveSourceConfig _name (MSSQLConnConfiguration connInfo) = do
|
|
|
|
mssqlPool <- liftIO $ createMSSQLPool connInfo
|
|
|
|
pure $ Right $ MSSQLSourceConfig connString mssqlPool
|
2021-02-23 20:37:27 +03:00
|
|
|
where
|
|
|
|
connString = _mciConnectionString connInfo
|
|
|
|
|
|
|
|
resolveDatabaseMetadata
|
|
|
|
:: (MonadIO m)
|
|
|
|
=> MSSQLSourceConfig
|
|
|
|
-> m (Either QErr (ResolvedSource 'MSSQL))
|
|
|
|
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
|
|
|
|
|
|
|
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
|