graphql-engine/server/src-lib/Hasura/Backends/MySQL/Connection.hs
Sibi Prabakaran 385d27449e mysql: Metadata awareness
https://github.com/hasura/graphql-engine-mono/pull/1599

Co-authored-by: Chris Done <11019+chrisdone@users.noreply.github.com>
Co-authored-by: Aniket Deshpande <922486+aniketd@users.noreply.github.com>
Co-authored-by: Abby Sassel <3883855+sassela@users.noreply.github.com>
GitOrigin-RevId: 4df4a8ff00fa8ef311a85199d66abe4cc10adc8c
2021-07-15 12:45:51 +00:00

45 lines
1.5 KiB
Haskell

module Hasura.Backends.MySQL.Connection where
import Data.Pool (createPool, withResource)
import qualified Data.Text as T
import Database.MySQL.Base
import Hasura.Backends.MySQL.Meta (getMetadata)
import Hasura.Backends.MySQL.Types
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 -> ConnSourceConfig -> m (Either QErr SourceConfig)
resolveSourceConfig _name csc@ConnSourceConfig{_cscPoolSettings = ConnPoolSettings{..}, ..} =
let connectInfo =
defaultConnectInfo
{ connectHost = T.unpack _cscHost
, connectPort = _cscPort
, connectUser = T.unpack _cscUser
, connectPassword = T.unpack _cscPassword
, connectDatabase = T.unpack _cscDatabase
}
in runExceptT $
SourceConfig csc <$>
liftIO
(createPool
(connect connectInfo)
close
1
(fromIntegral _cscIdleTimeout)
(fromIntegral _cscMaxConnections))
resolveDatabaseMetadata :: (MonadIO m) =>
SourceConfig ->
m (Either QErr (ResolvedSource 'MySQL))
resolveDatabaseMetadata sc@SourceConfig{..} =
runExceptT $ do
metadata <- liftIO $ withResource scConnectionPool (getMetadata scConfig)
pure $ ResolvedSource sc metadata mempty mempty