Safe Haskell | None |
---|---|
Language | Haskell2010 |
Connect to a single server or a replica set of servers
- type Secs = Double
- type Pipe = Pipeline Response Message
- close :: Pipeline i o -> IO ()
- isClosed :: Pipeline i o -> IO Bool
- data Host = Host HostName PortID
- data PortID :: *
- defaultPort :: PortID
- host :: HostName -> Host
- showHostPort :: Host -> String
- readHostPort :: String -> Host
- readHostPortM :: Monad m => String -> m Host
- globalConnectTimeout :: IORef Secs
- connect :: Host -> IO Pipe
- connect' :: Secs -> Host -> IO Pipe
- type ReplicaSetName = Text
- openReplicaSet :: (ReplicaSetName, [Host]) -> IO ReplicaSet
- openReplicaSet' :: Secs -> (ReplicaSetName, [Host]) -> IO ReplicaSet
- data ReplicaSet
- primary :: ReplicaSet -> IO Pipe
- secondaryOk :: ReplicaSet -> IO Pipe
- routedHost :: ((Host, Bool) -> (Host, Bool) -> IO Ordering) -> ReplicaSet -> IO Pipe
- closeReplicaSet :: ReplicaSet -> IO ()
- replSetName :: ReplicaSet -> Text
Util
Connection
Server
Default MongoDB port = 27017
host :: HostName -> Host Source
Host on defaultPort
showHostPort :: Host -> String Source
Display host as "host:port" TODO: Distinguish Service and UnixSocket port
readHostPort :: String -> Host Source
Read string "hostname:port" as Host hostname (PortNumber port)
or "hostname" as host hostname
(default port). Error if string does not match either syntax.
readHostPortM :: Monad m => String -> m Host Source
Read string "hostname:port" as Host hosthame (PortNumber port)
or "hostname" as host hostname
(default port). Fail if string does not match either syntax.
TODO: handle Service and UnixSocket port
globalConnectTimeout :: IORef Secs Source
connect
(and openReplicaSet
) fails if it can't connect within this many seconds (default is 6 seconds). Use 'connect\'' (and 'openReplicaSet\'') if you want to ignore this global and specify your own timeout. Note, this timeout only applies to initial connection establishment, not when reading/writing to the connection.
connect :: Host -> IO Pipe Source
Connect to Host returning pipelined TCP connection. Throw IOError if connection refused or no response within globalConnectTimeout
.
connect' :: Secs -> Host -> IO Pipe Source
Connect to Host returning pipelined TCP connection. Throw IOError if connection refused or no response within given number of seconds.
Replica Set
type ReplicaSetName = Text Source
openReplicaSet :: (ReplicaSetName, [Host]) -> IO ReplicaSet Source
Open connections (on demand) to servers in replica set. Supplied hosts is seed list. At least one of them must be a live member of the named replica set, otherwise fail. The value of globalConnectTimeout
at the time of this call is the timeout used for future member connect attempts. To use your own value call 'openReplicaSet\'' instead.
openReplicaSet' :: Secs -> (ReplicaSetName, [Host]) -> IO ReplicaSet Source
Open connections (on demand) to servers in replica set. Supplied hosts is seed list. At least one of them must be a live member of the named replica set, otherwise fail. Supplied seconds timeout is used for connect attempts to members.
data ReplicaSet Source
Maintains a connection (created on demand) to each server in the named replica set
primary :: ReplicaSet -> IO Pipe Source
Return connection to current primary of replica set. Fail if no primary available.
secondaryOk :: ReplicaSet -> IO Pipe Source
Return connection to a random secondary, or primary if no secondaries available.
routedHost :: ((Host, Bool) -> (Host, Bool) -> IO Ordering) -> ReplicaSet -> IO Pipe Source
Return a connection to a host using a user-supplied sorting function, which sorts based on a tuple containing the host and a boolean indicating whether the host is primary.
closeReplicaSet :: ReplicaSet -> IO () Source
Close all connections to replica set
replSetName :: ReplicaSet -> Text Source
name of connected replica set