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
|
2021-05-11 18:18:31 +03:00
|
|
|
import Hasura.Base.Error
|
2021-02-23 20:37:27 +03:00
|
|
|
import Hasura.RQL.Types.Common
|
|
|
|
import Hasura.RQL.Types.Source
|
|
|
|
import Hasura.SQL.Backend
|
|
|
|
|
|
|
|
resolveSourceConfig
|
|
|
|
:: (MonadIO m)
|
|
|
|
=> SourceName
|
|
|
|
-> MSSQLConnConfiguration
|
|
|
|
-> m (Either QErr MSSQLSourceConfig)
|
2021-03-18 21:32:47 +03:00
|
|
|
resolveSourceConfig _name (MSSQLConnConfiguration connInfo) = runExceptT do
|
|
|
|
(connString, mssqlPool) <- createMSSQLPool connInfo
|
|
|
|
pure $ MSSQLSourceConfig connString mssqlPool
|
2021-02-23 20:37:27 +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
|
|
|
|
|
|
|
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
|