realworld-hs-0.1.0.0: Scotty impl of https://github.com/gothinkster/realworld
Safe HaskellSafe-Inferred
LanguageGHC2021

Conduit.DB.Core

Synopsis

Documentation

newtype DBPool Source #

The ConnectionPool managing the DB connections.

Constructors

DBPool 

Instances

Instances details
Has' DBPool Env Source # 
Instance details

Defined in Conduit.App.Env

Methods

obtain :: Env -> DBPool Source #

class Monad m => MonadDB m where Source #

Some monad which can run an Esqueleto SQL query/stmt.

Methods

runDB :: SqlPersistT m a -> m (Either DBError a) Source #

Instances

Instances details
(Monad m, MonadUnliftIO m, Has DBPool c m) => MonadDB m Source # 
Instance details

Defined in Conduit.DB.Core

Methods

runDB :: SqlPersistT m a -> m (Either DBError a) Source #

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)

Methods

sqlKey2ID :: Key t -> id Source #

id2sqlKey :: id -> Key t Source #

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

data DBError Source #

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

See authorizationSqlError

NotFoundError

See resourceNotFoundSqlError

Instances

Instances details
Read DBError Source # 
Instance details

Defined in Conduit.DB.Core

Show DBError Source # 
Instance details

Defined in Conduit.DB.Core

Eq DBError Source # 
Instance details

Defined in Conduit.DB.Core

Methods

(==) :: DBError -> DBError -> Bool #

(/=) :: DBError -> DBError -> Bool #

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.name

mapMaybeDBResult :: 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

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

getConName :: Name -> Q Name Source #

(Internal) Gets the constructor name of some newtype