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

Safe HaskellNone
LanguageHaskell2010

Database.PostgreSQL.Query.SqlBuilder

Contents

Synopsis

Types

newtype SqlBuilder Source

Builder wich can be effectively concatenated. Requires Connection inside for string quoting implemented in libpq

Constructors

SqlBuilder 

data Qp Source

Special constructor to perform old-style query interpolation

Constructors

forall row . ToRow row => Qp Query row 

Instances

SqlBuilder helpers

emptyB :: SqlBuilder Source

Typed synonym of mempty

runSqlBuilder :: Connection -> SqlBuilder -> IO Query Source

Performs parameters interpolation and return ready to execute query

>>> let val = 10
>>> let name = "field"
>>> runSqlBuilder c $ "SELECT * FROM tbl WHERE " <> mkIdent name <> " = " <> mkValue val
"SELECT * FROM tbl WHERE \"field\" = 10"

mkIdent :: Text -> SqlBuilder Source

Shorthand function to convert identifier name to builder

>>> runSqlBuilder c $ mkIdent "simple\"ident"
"\"simple\"\"ident\""

Note correct string quoting made by libpq

mkValue :: ToField a => a -> SqlBuilder Source

Shorthand function to convert single value to builder

>>> runSqlBuilder c $ mkValue "some ' value"
"'some '' value'"

Note correct string quoting

sqlBuilderPure :: Builder -> SqlBuilder Source

Lift pure bytestring builder to SqlBuilder