postgresql-query-1.4.0: Sql interpolating quasiquote plus some kind of primitive ORM using it

Safe HaskellNone
LanguageHaskell2010

Database.PostgreSQL.Query.Types

Contents

Synopsis

Query execution

class MonadBase IO m => HasPostgres m where Source

Instances of this typeclass can acquire connection and pass it to computation. It can be reader of pool of connections or just reader of connection

Methods

withPGConnection :: (Connection -> m a) -> m a Source

class TransactionSafe m Source

Empty typeclass signing monad in which transaction is safe. i.e. PgMonadT have this instance, but some other monad giving connection from e.g. connection pool is not.

newtype PgMonadT m a Source

Reader of connection. Has instance of HasPostgres. So if you have a connection you can run queries in this monad using runPgMonadT. Or you can use this transformer to run sequence of queries using same connection with launchPG.

Constructors

PgMonadT 

launchPG :: HasPostgres m => PgMonadT m a -> m a Source

If your monad have instance of HasPostgres you maybe dont need this function, unless your instance use withPGPool which acquires connection from pool for each query. If you want to run sequence of queries using same connection you need this function

Auxiliary types

newtype InetText Source

type to put and get from db inet and cidr typed postgresql fields. This should be in postgresql-simple in fact.

Constructors

InetText 

Fields

unInetText :: Text
 

newtype FN Source

Dot-separated field name. Each element in nested list will be properly quoted and separated by dot. It also have instance of ToSqlBuilder and IsString so you can:

>>> let a = "hello" :: FN
>>> a
FN ["hello"]
>>> let b = "user.name" :: FN
>>> b
FN ["user","name"]
>>> let n = "u.name" :: FN
>>> runSqlBuilder c $ toSqlBuilder n
"\"u\".\"name\""
>>> ("user" <> "name") :: FN
FN ["user","name"]
>>> let a = "name" :: FN
>>> let b = "email" :: FN
>>> runSqlBuilder c [sqlExp|^{"u" <> a} = 'name', ^{"e" <> b} = 'email'|]
"\"u\".\"name\" = 'name', \"e\".\"email\" = 'email'"

Constructors

FN [Text] 

textFN :: Text -> FN Source

Single field to FN

>>> textFN "hello"
FN ["hello"]
>>> textFN "user.name"
FN ["user.name"]

Note that it does not split string to parts by point like instance of IsString does

newtype MarkedRow Source

Marked row is list of pairs of field name and some sql expression. Used to generate queries like:

name = name AND size = 10 AND length = 20

or

UPDATE tbl SET name = name, size = 10, lenght = 20

Constructors

MR 

Fields

unMR :: [(FN, SqlBuilder)]
 

mrToBuilder Source

Arguments

:: SqlBuilder

Builder to intercalate with

-> MarkedRow 
-> SqlBuilder 

Turns marked row to query intercalating it with other builder

>>> runSqlBuilder c $ mrToBuilder "AND" $ MR [("name", mkValue "petr"), ("email", mkValue "foo@bar.com")]
" \"name\" = 'petr' AND \"email\" = 'foo@bar.com' "

class ToMarkedRow a where Source

Methods

toMarkedRow :: a -> MarkedRow Source

generate list of pairs (field name, field value)