tsweb-0.1.0.0: An API binding Web.Spock to Database.Beam

Safe HaskellNone
LanguageHaskell2010

TsWeb.Types.Db

Description

TsWeb has a strong notion that postgres should be configured in a warm-standby mode, with read-only queries being shipped to synchronous standbys whenever possible. This module defines types for descriminating between read-only and read-write connections, and also functions for making postgres connections, pools, etc. The connect function is working well enough for me, but will undoubtedly need to be improved to support the full depth of postgresql connection options.

Synopsis

Documentation

type SomeConn t = Tagged t Connection Source #

Wrapper for some sort of Postgres connection; a raw `SomeConn t` represents either a read-only or a read-write connection, but the concrete ReadOnlyConn and ReadWriteConn are probably more useful in general.

type ReadOnlyConn = SomeConn ReadOnly Source #

Concrete read-only connection. Instantiate with connect

type ReadWriteConn = SomeConn ReadWrite Source #

Concrete read-write connection. Instantiate with connect

type ReadOnlyPool = Pool ReadOnlyConn Source #

Pool of read-only connections. Instantiate with pool

type ReadWritePool = Pool ReadWriteConn Source #

Pool of read-write connections. Instantiate with pool

data ReadOnly Source #

Empty type to mark read-only db connections

data ReadWrite Source #

Empty type to mark read-write db connections

type HostName = String Source #

String alias for the postgres host to connect to

type DbName = String Source #

String alias for the postgres database to connect to

type SubPools = Int Source #

Int alias for the createPool function numStripes argument

type KeepOpen = Int Source #

Int alias for the createPool function maxResources argument

count :: ProjectibleWithPredicate AnyType Postgres (WithExprContext (BeamSqlBackendExpressionSyntax' Postgres)) t => Q Postgres db (QNested s0) t -> Q Postgres db s0 (QGenExpr QValueContext Postgres s0 Int) Source #

An example of how Database.Beam does counts; this really doesn't belong here, and was just written for preliminary testing.

pool Source #

Arguments

:: HostName

Postgres hostname/address

-> DbName

Postgres database name

-> String

User to connect as

-> SubPools

Number of sub-pools to maintain (1 is fine)

-> NominalDiffTime

How long to let an idle db connection linger

-> KeepOpen

Max number of connections per stripe

-> IO (Pool (SomeConn t)) 

Create a resource pool of either read-only or read-write postgres connections. The docs for createPool give the best description for how this works.

withConnection :: Pool (SomeConn a) -> (SomeConn a -> IO b) -> IO b Source #

Run an action in a Pool connection

connect :: HostName -> DbName -> String -> IO (SomeConn t) Source #

Create a ReadOnly or ReadWrite postgres connection. This doesn't actually check whether the connection is read-only or read-write, so it's really just to help with type juggling.

withSavepoint :: SomeConn t -> IO a -> IO a Source #

Run an action within a postgresql savepoint

withTransaction :: SomeConn t -> IO a -> IO a Source #

Run an action within a postgresql transaction

readOnly :: SomeConn t -> Pg a -> IO a Source #

Run a read-only query; this will actually run any query at all, so higher-level logic should ensure that only read-only queries hit this function.

readOnlyDebug :: SomeConn t -> Pg a -> IO a Source #

Same as readOnly, but prints any SQL that it runs.

readWrite :: ReadWriteConn -> Pg a -> IO a Source #

Run a query against a ReadWriteConn

readWriteDebug :: ReadWriteConn -> Pg a -> IO a Source #

Same as readWrite, but printing all the SQL that gets executed.