Safe Haskell | None |
---|---|
Language | Haskell2010 |
- newtype SqlBuilder = SqlBuilder {
- sqlBuild :: Connection -> IO Builder
- class ToSqlBuilder a where
- toSqlBuilder :: a -> SqlBuilder
- data Qp = forall row . ToRow row => Qp Query row
- emptyB :: SqlBuilder
- runSqlBuilder :: Connection -> SqlBuilder -> IO Query
- mkIdent :: Text -> SqlBuilder
- mkValue :: ToField a => a -> SqlBuilder
- sqlBuilderPure :: Builder -> SqlBuilder
- sqlBuilderFromField :: ToField a => Query -> a -> SqlBuilder
Types
newtype SqlBuilder Source
Builder wich can be effectively concatenated. Requires Connection
inside for string quoting implemented in libpq
SqlBuilder | |
|
class ToSqlBuilder a where Source
Things which always can be transformed to SqlBuilder
toSqlBuilder :: a -> SqlBuilder Source
Special constructor to perform old-style query interpolation
SqlBuilder helpers
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
sqlBuilderFromField :: ToField a => Query -> a -> SqlBuilder Source