Copyright | (c) 2020-2021 Tim Emiola |
---|---|
License | BSD3 |
Maintainer | Tim Emiola <[email protected] > |
Safe Haskell | None |
Language | Haskell2010 |
System.TmpProc.Docker.Postgres
Description
Provides an instance of Proc
that launches postgres
as a tmp proc
.
The instance this module provides can be used in integration tests as is.
It's also possible to write other instances that launch postgres
in different
ways; for those, this instance can be used as a reference example.
Synopsis
- newtype TmpPostgres = TmpPostgres [Text]
- aProc :: HList '[TmpPostgres]
- aHandle :: IO (HandlesOf '[TmpPostgres])
- only :: x -> HList '[x]
- class (KnownSymbol (Image a), KnownSymbol (Name a)) => Proc a where
- type family Name a = (labelName :: Symbol) | labelName -> a
- class Proc a => Connectable a where
- type family Conn a = (conn :: Type) | conn -> a
- data HList (a :: [Type]) where
- type HandlesOf (procs :: [Type]) = HList (Proc2Handle procs)
- type SvcURI = ByteString
- type HostIpAddress = Text
- data Pinged
- = OK
- | NotOK
- | PingFailed Text
- type family Image a :: Symbol
- data ProcHandle a where
- pattern ProcHandle :: a -> String -> SvcURI -> HostIpAddress -> ProcHandle a
- startupAll :: forall (procs :: [Type]). AreProcs procs => HList procs -> IO (HandlesOf procs)
- withTmpConn :: Connectable a => ProcHandle a -> (Conn a -> IO b) -> IO b
Proc
instance
newtype TmpPostgres Source #
Provides the capability to launch a Postgres database as a tmp proc
.
The constructor receives the names of the tables to be dropped on reset
.
Constructors
TmpPostgres [Text] |
Instances
Connectable TmpPostgres Source # | Specifies how to connect to a tmp | ||||||||
Defined in System.TmpProc.Docker.Postgres Associated Types
Methods openConn :: ProcHandle TmpPostgres -> IO (Conn TmpPostgres) # closeConn :: Conn TmpPostgres -> IO () # | |||||||||
Proc TmpPostgres Source # | Specifies how to run | ||||||||
Defined in System.TmpProc.Docker.Postgres Associated Types
Methods uriOf :: HostIpAddress -> SvcURI # reset :: ProcHandle TmpPostgres -> IO () # ping :: ProcHandle TmpPostgres -> IO Pinged # | |||||||||
type Conn TmpPostgres Source # | |||||||||
Defined in System.TmpProc.Docker.Postgres | |||||||||
type Image TmpPostgres Source # | |||||||||
Defined in System.TmpProc.Docker.Postgres | |||||||||
type Name TmpPostgres Source # | |||||||||
Defined in System.TmpProc.Docker.Postgres |
Useful definitions
aProc :: HList '[TmpPostgres] Source #
A singleton HList
containing a TmpPostgres
.
Re-exports
class (KnownSymbol (Image a), KnownSymbol (Name a)) => Proc a where #
Specifies how to launch a temporary process using Docker.
Associated Types
The image name of the docker image, e.g, postgres:10.6
type Name a = (labelName :: Symbol) | labelName -> a #
A label used to refer to the running tmp proc created from this image, e.g, a-postgres-db
Methods
Additional arguments to the docker command that launches the tmp proc.
uriOf :: HostIpAddress -> SvcURI #
Determines the service URI of the tmp proc, when applicable.
reset :: ProcHandle a -> IO () #
Resets some state in a tmp proc service.
ping :: ProcHandle a -> IO Pinged #
Checks if the tmp proc started correctly.
Maximum number of pings to perform during startup.
Number of milliseconds between pings.
Instances
Proc TmpPostgres Source # | Specifies how to run | ||||||||
Defined in System.TmpProc.Docker.Postgres Associated Types
Methods uriOf :: HostIpAddress -> SvcURI # reset :: ProcHandle TmpPostgres -> IO () # ping :: ProcHandle TmpPostgres -> IO Pinged # |
type family Name a = (labelName :: Symbol) | labelName -> a #
A label used to refer to the running tmp proc created from this image, e.g, a-postgres-db
Instances
type Name TmpPostgres Source # | |
Defined in System.TmpProc.Docker.Postgres |
class Proc a => Connectable a where #
Specifies how to construct a connection datatype for accessing the launched
service specified by a Proc
.
Minimal complete definition
Methods
openConn :: ProcHandle a -> IO (Conn a) #
Get a connection to the Proc via its ProcHandle
.
closeConn :: Conn a -> IO () #
Close a connection to a Proc
.
Instances
Connectable TmpPostgres Source # | Specifies how to connect to a tmp | ||||
Defined in System.TmpProc.Docker.Postgres Associated Types
Methods openConn :: ProcHandle TmpPostgres -> IO (Conn TmpPostgres) # closeConn :: Conn TmpPostgres -> IO () # |
type family Conn a = (conn :: Type) | conn -> a #
The connection type.
Instances
type Conn TmpPostgres Source # | |
Defined in System.TmpProc.Docker.Postgres |
data HList (a :: [Type]) where #
Defines a Heterogenous list.
Constructors
HNil :: HList ('[] :: [Type]) | |
HCons :: forall anyTy (manyTys :: [Type]). anyTy -> HList manyTys -> HList (anyTy ': manyTys) infixr 5 |
type HandlesOf (procs :: [Type]) = HList (Proc2Handle procs) #
A list of
values.ProcHandle
type SvcURI = ByteString #
A connection string used to access the service once its running.
type HostIpAddress = Text #
The IP address of the docker host.
Indicates the result of pinging a Proc
.
If the ping succeeds, ping
should return OK
.
ping
should catch any exceptions that are expected when the
service
is not available and return Proc
sNotOK
.
startupAll
uses PingFailed
to report any unexpected exceptions that escape
ping
.
Constructors
OK | The service is running OK. |
NotOK | The service is not running. |
PingFailed Text | Contact to the service failed unexpectedly. |
type family Image a :: Symbol #
The image name of the docker image, e.g, postgres:10.6
Instances
type Image TmpPostgres Source # | |
Defined in System.TmpProc.Docker.Postgres |
data ProcHandle a where #
Provides access to a Proc
that has been started.
Bundled Patterns
pattern ProcHandle | A The selectors are readonly, i.e they only match in a pattern context since
|
Fields
|
startupAll :: forall (procs :: [Type]). AreProcs procs => HList procs -> IO (HandlesOf procs) #
Start up processes for each Proc
type
the processes' are able to communicate via a docker network with a unique generated name
withTmpConn :: Connectable a => ProcHandle a -> (Conn a -> IO b) -> IO b #
Run an action on a Connectable
handle as a callback on its Conn