| Safe Haskell | Safe-Inferred |
|---|---|
| Language | GHC2021 |
Conduit.DB.Core
Synopsis
- newtype DBPool = DBPool {}
- class Monad m => MonadDB m where
- runDB :: SqlPersistT m a -> m (Either DBError a)
- class SqlKey t id | t -> id, id -> t where
- deriveSqlKey :: Name -> Name -> Q [Dec]
- data DBError
- mapDBResult :: FeatureError e => (a -> b) -> Either DBError a -> Either e b
- mapMaybeDBResult :: FeatureError e => e -> (a -> b) -> Either DBError (Maybe a) -> Either e b
- mapDBError :: FeatureError e => Either DBError a -> Either e a
- expectDBNonZero :: (FeatureError e, Num cnt, Ord cnt) => e -> Either DBError cnt -> Either e ()
- authorizationSqlError :: Show e => e -> SqlError
- resourceNotFoundSqlError :: SqlError
- catchSqlError :: MonadUnliftIO m => m a -> m (Either DBError a)
- mapSqlError :: SqlError -> DBError
- extractUniquenessViolation :: SqlError -> Text
- extractKeyField :: String -> Maybe String
- defaultSqlErr :: SqlError
- getConName :: Name -> Q Name
Documentation
The ConnectionPool managing the DB connections.
Constructors
| DBPool | |
Fields | |
class Monad m => MonadDB m where Source #
Some monad which can run an Esqueleto SQL query/stmt.
Instances
| (Monad m, MonadUnliftIO m, Has DBPool c m) => MonadDB m Source # | |
Defined in Conduit.DB.Core | |
class SqlKey t id | t -> id, id -> t where Source #
An abstraction to allow for easy conversion between Esqueleto entity Keys and Conduit's own ID datatypes.
deriveSqlKey can automagically create instances for this class.
newtype TableID = TableID { unID :: Int64 }
<define some persist table Table>
$(deriveSqlKey ''Table ''TableID)deriveSqlKey :: Name -> Name -> Q [Dec] Source #
just tried this for fun, very quickly realized I am nowhere near smart enough to be doing something like this. this took me over an hour. help.
see SqlKey for usage
Attempts to map relevant SqlErrors to more processable types.
Constructors
| SomeDBError Text | Catch-all for irrelevant/unkown SqlErrors |
| UniquenessError Text | Unique constraint violation err, holds name of violated column |
| AuthorizationError Text | |
| NotFoundError |
mapDBResult :: FeatureError e => (a -> b) -> Either DBError a -> Either e b Source #
Maps both sides of a potentially errored SQL query.
newtype Name = Name Text
mkNames :: [Value Text] -> [Name]
mkNames = map (\(Value name) -> Name name)
result :: (Monad m, MonadDB m, MonadUnliftIO m) => m (Either ??? [Name])
result = mapDBResult mkNames <$> runDBError do
select $ do
u <- from table @User
pure u.namemapMaybeDBResult :: FeatureError e => e -> (a -> b) -> Either DBError (Maybe a) -> Either e b Source #
Maps both sides of a potentially errored, potentially not-found SQL query.
mapDBError :: FeatureError e => Either DBError a -> Either e a Source #
Maps the error of a potentially errored SQL query/stmt.
expectDBNonZero :: (FeatureError e, Num cnt, Ord cnt) => e -> Either DBError cnt -> Either e () Source #
Maps the error of a potentially errored SQL query/stmt & Assurances that the result is > 0.
Intended for use with something like Esqueleto's insertCount or deleteCount.
authorizationSqlError :: Show e => e -> SqlError Source #
A custom SqlError w/ code 45401
resourceNotFoundSqlError :: SqlError Source #
A custom SqlError w/ code 45404
catchSqlError :: MonadUnliftIO m => m a -> m (Either DBError a) Source #
(Internal) Catches & maps any SqlErrors to DBErrors
mapSqlError :: SqlError -> DBError Source #
extractUniquenessViolation :: SqlError -> Text Source #
(Internal) Extracts the name of the column whose uniqueness was violated
defaultSqlErr :: SqlError Source #
(Internal) SqlError with irrelevant/unused fields pre-filled out