Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Database.PostgreSQL.Query.Types
Contents
Synopsis
- class MonadBase IO m => HasPostgres m where
- withPGConnection :: (Connection -> m a) -> m a
- type MonadPostgres m = (HasPostgres m, MonadLogger m)
- class TransactionSafe (m :: Type -> Type)
- newtype PgMonadT m a = PgMonadT {
- unPgMonadT :: ReaderT Connection m a
- runPgMonadT :: HasCallStack => Connection -> (HasCallStack => PgMonadT m a) -> m a
- launchPG :: (HasPostgres m, HasCallStack) => (HasCallStack => PgMonadT m a) -> m a
- data Qp = forall row.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
- toMarkedRow :: a -> MarkedRow
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 #
Instances
type MonadPostgres m = (HasPostgres m, MonadLogger m) Source #
class TransactionSafe (m :: Type -> Type) 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
.
Constructors
PgMonadT | |
Fields
|
Instances
runPgMonadT :: HasCallStack => Connection -> (HasCallStack => PgMonadT m a) -> m a Source #
launchPG :: (HasPostgres m, HasCallStack) => (HasCallStack => 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 Methods 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.
Constructors
InetText | |
Fields
|
Instances
IsString InetText Source # | |
Defined in Database.PostgreSQL.Query.Types Methods fromString :: String -> InetText # | |
Monoid InetText Source # | |
Semigroup InetText Source # | |
Read InetText Source # | |
Show InetText Source # | |
Eq InetText Source # | |
Ord InetText Source # | |
Defined in Database.PostgreSQL.Query.Types | |
FromField InetText Source # | |
Defined in Database.PostgreSQL.Query.Types Methods | |
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
>>>
run $ toSqlBuilder n
"\"u\".\"name\""
>>>
("user" <> "name") :: FN
FN ["user","name"]
>>>
let a = "name" :: FN
>>>
let b = "email" :: FN
>>>
run [sqlExp|^{"u" <> a} = 'name', ^{"e" <> b} = 'email'|]
"\"u\".\"name\" = 'name', \"e\".\"email\" = 'email'"
Instances
IsString FN Source # | |
Defined in Database.PostgreSQL.Query.Types Methods fromString :: String -> FN # | |
Monoid FN Source # | |
Semigroup FN Source # | |
Generic FN Source # | |
Show FN Source # | |
Eq FN Source # | |
Ord FN Source # | |
ToSqlBuilder FN Source # | |
Defined in Database.PostgreSQL.Query.Types Methods toSqlBuilder :: FN -> SqlBuilder Source # | |
Lift FN 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
Constructors
MR | |
Fields
|
Instances
Monoid MarkedRow Source # | |
Semigroup MarkedRow Source # | |
Generic MarkedRow Source # | |
ToMarkedRow MarkedRow Source # | |
Defined in Database.PostgreSQL.Query.Types Methods 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.10.0-HqZ8vBAT9kAL74IiVyVZTe" 'True) (C1 ('MetaCons "MR" 'PrefixI 'True) (S1 ('MetaSel ('Just "unMR") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [(FN, SqlBuilder)]))) |
Arguments
:: SqlBuilder | Builder to intercalate with |
-> MarkedRow | |
-> SqlBuilder |
Turns marked row to query intercalating it with other builder
>>>
run $ mrToBuilder "AND" $ MR [("name", mkValue "petr"), ("email", mkValue "[email protected]")]
" \"name\" = 'petr' AND \"email\" = '[email protected]' "
class ToMarkedRow a where Source #
Instances
ToMarkedRow MarkedRow Source # | |
Defined in Database.PostgreSQL.Query.Types Methods toMarkedRow :: MarkedRow -> MarkedRow Source # |