graphql-engine/server/src-lib/Hasura/Backends/MySQL/Connection.hs
Aniket Deshpande 921bdf709b MySQL: Initial connection and corresponding types
https://github.com/hasura/graphql-engine-mono/pull/1517

Co-authored-by: Sibi Prabakaran <737477+psibi@users.noreply.github.com>
Co-authored-by: Chris Done <11019+chrisdone@users.noreply.github.com>
Co-authored-by: Abby Sassel <3883855+sassela@users.noreply.github.com>
GitOrigin-RevId: e0f61664b33d8ca50f223ec7fb76c66940eabc89
2021-07-13 13:33:21 +00:00

27 lines
935 B
Haskell

module Hasura.Backends.MySQL.Connection where
import Data.Pool (createPool)
import qualified Data.Text as T
import Database.MySQL.Base
import Hasura.Backends.MySQL.Types
import Hasura.Base.Error
import Hasura.Prelude
import Hasura.RQL.Types.Common
resolveSourceConfig :: (MonadIO m) =>
SourceName -> ConnSourceConfig -> m (Either QErr SourceConfig)
resolveSourceConfig _name csc@ConnSourceConfig{..} =
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 (60 {-seconds-} * 60 {-minutes-}) 1)