Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- class MonadBase IO m => HasPostgres m where
- type MonadPostgres m = (HasPostgres m, MonadLogger m)
- class TransactionSafe (m :: * -> *)
- newtype PgMonadT m a = PgMonadT {
- unPgMonadT :: ReaderT Connection m a
- runPgMonadT :: Connection -> PgMonadT m a -> m a
- launchPG :: HasPostgres m => PgMonadT m a -> m a
- data Qp = ToRow row => Qp Query row
- newtype InetText = InetText {
- unInetText :: Text
- newtype FN = FN [Text]
- textFN :: Text -> FN
- newtype MarkedRow = MR {
- unMR :: [(FN, SqlBuilder)]
- mrToBuilder :: SqlBuilder -> MarkedRow -> SqlBuilder
- class ToMarkedRow a where
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
withPGConnection :: (Connection -> m a) -> m a Source #
Instances
type MonadPostgres m = (HasPostgres m, MonadLogger m) 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.
Instances
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
.
PgMonadT | |
|
Instances
runPgMonadT :: Connection -> PgMonadT m a -> m a Source #
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
Special constructor to perform old-style query interpolation
Instances
ToSqlBuilder Qp Source # | |
Defined in Database.PostgreSQL.Query.Types toSqlBuilder :: Qp -> SqlBuilder Source # |
type to put and get from db inet
and cidr
typed postgresql
fields. This should be in postgresql-simple in fact.
Instances
Eq InetText Source # | |
Ord InetText Source # | |
Defined in Database.PostgreSQL.Query.Types | |
Read InetText Source # | |
Show InetText Source # | |
IsString InetText Source # | |
Defined in Database.PostgreSQL.Query.Types fromString :: String -> InetText # | |
Semigroup InetText Source # | |
Monoid InetText Source # | |
FromField InetText Source # | |
Defined in Database.PostgreSQL.Query.Types | |
ToField InetText Source # | |
Defined in Database.PostgreSQL.Query.Types |
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'"
Instances
Eq FN Source # | |
Ord FN Source # | |
Show FN Source # | |
IsString FN Source # | |
Defined in Database.PostgreSQL.Query.Types fromString :: String -> FN # | |
Generic FN Source # | |
Semigroup FN Source # | |
Monoid FN Source # | |
Lift FN Source # | |
ToSqlBuilder FN Source # | |
Defined in Database.PostgreSQL.Query.Types toSqlBuilder :: FN -> SqlBuilder Source # | |
type Rep FN Source # | |
Defined in Database.PostgreSQL.Query.Types |
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
MR | |
|
Instances
Generic MarkedRow Source # | |
Semigroup MarkedRow Source # | |
Monoid MarkedRow Source # | |
ToMarkedRow MarkedRow Source # | |
Defined in Database.PostgreSQL.Query.Types toMarkedRow :: MarkedRow -> MarkedRow Source # | |
type Rep MarkedRow Source # | |
Defined in Database.PostgreSQL.Query.Types type Rep MarkedRow = D1 (MetaData "MarkedRow" "Database.PostgreSQL.Query.Types" "postgresql-query-3.5.0-1AbagAFOSyg4vQytTFD1c" True) (C1 (MetaCons "MR" PrefixI True) (S1 (MetaSel (Just "unMR") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 [(FN, SqlBuilder)]))) |
:: 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 #
toMarkedRow :: a -> MarkedRow Source #
generate list of pairs (field name, field value)
Instances
ToMarkedRow MarkedRow Source # | |
Defined in Database.PostgreSQL.Query.Types toMarkedRow :: MarkedRow -> MarkedRow Source # |