Safe Haskell | None |
---|---|
Language | Haskell2010 |
- type ThentosQuery e a = EitherT (ThentosError e) (ReaderT Connection IO) a
- data Defaultable a
- = DefaultVal
- | CustomVal a
- runThentosQuery :: Connection -> ThentosQuery e a -> IO (Either (ThentosError e) a)
- queryT :: (ToRow q, FromRow r) => Query -> q -> ThentosQuery e [r]
- execT :: ToRow q => Query -> q -> ThentosQuery e Int64
- createDB :: Connection -> IO ()
- schemaFile :: IO FilePath
- wipeFile :: IO FilePath
- catchViolation :: MonadBaseControl IO m => (SqlError -> ConstraintViolation -> m a) -> m a -> m a
- catcher :: MonadBaseControl IO m => SqlError -> ConstraintViolation -> m (Either (ThentosError e) a)
- orDefault :: ToField a => Maybe a -> Defaultable a
Documentation
type ThentosQuery e a = EitherT (ThentosError e) (ReaderT Connection IO) a
data Defaultable a
Eq a => Eq (Defaultable a) | |
Ord a => Ord (Defaultable a) | |
Read a => Read (Defaultable a) | |
Show a => Show (Defaultable a) | |
ToField a => ToField (Defaultable a) |
runThentosQuery :: Connection -> ThentosQuery e a -> IO (Either (ThentosError e) a)
Execute a ThentosQuery
. Every query is a DB transaction, so the DB state won't change
if there are any errors, nor will other queries encouter a possibly inconsistent interim state.
queryT :: (ToRow q, FromRow r) => Query -> q -> ThentosQuery e [r]
execT :: ToRow q => Query -> q -> ThentosQuery e Int64
createDB :: Connection -> IO ()
Creates the database schema if it does not already exist.
schemaFile :: IO FilePath
wipeFile :: IO FilePath
catchViolation :: MonadBaseControl IO m => (SqlError -> ConstraintViolation -> m a) -> m a -> m a
Like postgresql-simple
's catchViolation
, but generalized to
MonadBaseControl IO m
catcher :: MonadBaseControl IO m => SqlError -> ConstraintViolation -> m (Either (ThentosError e) a)
Convert known SQL constraint errors to ThentosError
, rethrowing unknown
ones.
orDefault :: ToField a => Maybe a -> Defaultable a