Safe Haskell | None |
---|---|
Language | Haskell2010 |
Database.Esqueleto
Description
The esqueleto
EDSL (embedded domain specific language).
This module replaces Database.Persist
, so instead of
importing that module you should just import this one:
-- For a module using just esqueleto. import Database.Esqueleto
If you need to use persistent
's default support for queries
as well, either import it qualified:
-- For a module that mostly uses esqueleto. import Database.Esqueleto import qualified Database.Persist as P
or import esqueleto
itself qualified:
-- For a module that uses esqueleto just on some queries. import Database.Persist import qualified Database.Esqueleto as E
Other than identifier name clashes, esqueleto
does not
conflict with persistent
in any way.
Synopsis
- where_ :: SqlExpr (Value Bool) -> SqlQuery ()
- on :: SqlExpr (Value Bool) -> SqlQuery ()
- groupBy :: ToSomeValues a => a -> SqlQuery ()
- orderBy :: [SqlExpr OrderBy] -> SqlQuery ()
- rand :: SqlExpr OrderBy
- asc :: PersistField a => SqlExpr (Value a) -> SqlExpr OrderBy
- desc :: PersistField a => SqlExpr (Value a) -> SqlExpr OrderBy
- limit :: Int64 -> SqlQuery ()
- offset :: Int64 -> SqlQuery ()
- distinct :: SqlQuery a -> SqlQuery a
- distinctOn :: [SqlExpr DistinctOn] -> SqlQuery a -> SqlQuery a
- don :: SqlExpr (Value a) -> SqlExpr DistinctOn
- distinctOnOrderBy :: [SqlExpr OrderBy] -> SqlQuery a -> SqlQuery a
- having :: SqlExpr (Value Bool) -> SqlQuery ()
- locking :: LockingKind -> SqlQuery ()
- sub_select :: PersistField a => SqlQuery (SqlExpr (Value a)) -> SqlExpr (Value a)
- (^.) :: forall typ val. (PersistEntity val, PersistField typ) => SqlExpr (Entity val) -> EntityField val typ -> SqlExpr (Value typ)
- (?.) :: (PersistEntity val, PersistField typ) => SqlExpr (Maybe (Entity val)) -> EntityField val typ -> SqlExpr (Value (Maybe typ))
- val :: PersistField typ => typ -> SqlExpr (Value typ)
- isNothing :: PersistField typ => SqlExpr (Value (Maybe typ)) -> SqlExpr (Value Bool)
- just :: SqlExpr (Value typ) -> SqlExpr (Value (Maybe typ))
- nothing :: SqlExpr (Value (Maybe typ))
- joinV :: SqlExpr (Value (Maybe (Maybe typ))) -> SqlExpr (Value (Maybe typ))
- withNonNull :: PersistField typ => SqlExpr (Value (Maybe typ)) -> (SqlExpr (Value typ) -> SqlQuery a) -> SqlQuery a
- countRows :: Num a => SqlExpr (Value a)
- count :: Num a => SqlExpr (Value typ) -> SqlExpr (Value a)
- countDistinct :: Num a => SqlExpr (Value typ) -> SqlExpr (Value a)
- not_ :: SqlExpr (Value Bool) -> SqlExpr (Value Bool)
- (==.) :: PersistField typ => SqlExpr (Value typ) -> SqlExpr (Value typ) -> SqlExpr (Value Bool)
- (>=.) :: PersistField typ => SqlExpr (Value typ) -> SqlExpr (Value typ) -> SqlExpr (Value Bool)
- (>.) :: PersistField typ => SqlExpr (Value typ) -> SqlExpr (Value typ) -> SqlExpr (Value Bool)
- (<=.) :: PersistField typ => SqlExpr (Value typ) -> SqlExpr (Value typ) -> SqlExpr (Value Bool)
- (<.) :: PersistField typ => SqlExpr (Value typ) -> SqlExpr (Value typ) -> SqlExpr (Value Bool)
- (!=.) :: PersistField typ => SqlExpr (Value typ) -> SqlExpr (Value typ) -> SqlExpr (Value Bool)
- (&&.) :: SqlExpr (Value Bool) -> SqlExpr (Value Bool) -> SqlExpr (Value Bool)
- (||.) :: SqlExpr (Value Bool) -> SqlExpr (Value Bool) -> SqlExpr (Value Bool)
- between :: PersistField a => SqlExpr (Value a) -> (SqlExpr (Value a), SqlExpr (Value a)) -> SqlExpr (Value Bool)
- (+.) :: PersistField a => SqlExpr (Value a) -> SqlExpr (Value a) -> SqlExpr (Value a)
- (-.) :: PersistField a => SqlExpr (Value a) -> SqlExpr (Value a) -> SqlExpr (Value a)
- (/.) :: PersistField a => SqlExpr (Value a) -> SqlExpr (Value a) -> SqlExpr (Value a)
- (*.) :: PersistField a => SqlExpr (Value a) -> SqlExpr (Value a) -> SqlExpr (Value a)
- random_ :: (PersistField a, Num a) => SqlExpr (Value a)
- round_ :: (PersistField a, Num a, PersistField b, Num b) => SqlExpr (Value a) -> SqlExpr (Value b)
- ceiling_ :: (PersistField a, Num a, PersistField b, Num b) => SqlExpr (Value a) -> SqlExpr (Value b)
- floor_ :: (PersistField a, Num a, PersistField b, Num b) => SqlExpr (Value a) -> SqlExpr (Value b)
- min_ :: PersistField a => SqlExpr (Value a) -> SqlExpr (Value (Maybe a))
- max_ :: PersistField a => SqlExpr (Value a) -> SqlExpr (Value (Maybe a))
- sum_ :: (PersistField a, PersistField b) => SqlExpr (Value a) -> SqlExpr (Value (Maybe b))
- avg_ :: (PersistField a, PersistField b) => SqlExpr (Value a) -> SqlExpr (Value (Maybe b))
- castNum :: (Num a, Num b) => SqlExpr (Value a) -> SqlExpr (Value b)
- castNumM :: (Num a, Num b) => SqlExpr (Value (Maybe a)) -> SqlExpr (Value (Maybe b))
- coalesce :: PersistField a => [SqlExpr (Value (Maybe a))] -> SqlExpr (Value (Maybe a))
- coalesceDefault :: PersistField a => [SqlExpr (Value (Maybe a))] -> SqlExpr (Value a) -> SqlExpr (Value a)
- lower_ :: SqlString s => SqlExpr (Value s) -> SqlExpr (Value s)
- upper_ :: SqlString s => SqlExpr (Value s) -> SqlExpr (Value s)
- trim_ :: SqlString s => SqlExpr (Value s) -> SqlExpr (Value s)
- ltrim_ :: SqlString s => SqlExpr (Value s) -> SqlExpr (Value s)
- rtrim_ :: SqlString s => SqlExpr (Value s) -> SqlExpr (Value s)
- length_ :: (SqlString s, Num a) => SqlExpr (Value s) -> SqlExpr (Value a)
- left_ :: (SqlString s, Num a) => (SqlExpr (Value s), SqlExpr (Value a)) -> SqlExpr (Value s)
- right_ :: (SqlString s, Num a) => (SqlExpr (Value s), SqlExpr (Value a)) -> SqlExpr (Value s)
- like :: SqlString s => SqlExpr (Value s) -> SqlExpr (Value s) -> SqlExpr (Value Bool)
- ilike :: SqlString s => SqlExpr (Value s) -> SqlExpr (Value s) -> SqlExpr (Value Bool)
- (%) :: SqlString s => SqlExpr (Value s)
- concat_ :: SqlString s => [SqlExpr (Value s)] -> SqlExpr (Value s)
- (++.) :: SqlString s => SqlExpr (Value s) -> SqlExpr (Value s) -> SqlExpr (Value s)
- castString :: (SqlString s, SqlString r) => SqlExpr (Value s) -> SqlExpr (Value r)
- subList_select :: PersistField a => SqlQuery (SqlExpr (Value a)) -> SqlExpr (ValueList a)
- valList :: PersistField typ => [typ] -> SqlExpr (ValueList typ)
- justList :: SqlExpr (ValueList typ) -> SqlExpr (ValueList (Maybe typ))
- in_ :: PersistField typ => SqlExpr (Value typ) -> SqlExpr (ValueList typ) -> SqlExpr (Value Bool)
- notIn :: PersistField typ => SqlExpr (Value typ) -> SqlExpr (ValueList typ) -> SqlExpr (Value Bool)
- exists :: SqlQuery () -> SqlExpr (Value Bool)
- notExists :: SqlQuery () -> SqlExpr (Value Bool)
- set :: PersistEntity val => SqlExpr (Entity val) -> [SqlExpr (Update val)] -> SqlQuery ()
- (=.) :: (PersistEntity val, PersistField typ) => EntityField val typ -> SqlExpr (Value typ) -> SqlExpr (Update val)
- (+=.) :: (PersistEntity val, PersistField a) => EntityField val a -> SqlExpr (Value a) -> SqlExpr (Update val)
- (-=.) :: (PersistEntity val, PersistField a) => EntityField val a -> SqlExpr (Value a) -> SqlExpr (Update val)
- (*=.) :: (PersistEntity val, PersistField a) => EntityField val a -> SqlExpr (Value a) -> SqlExpr (Update val)
- (/=.) :: (PersistEntity val, PersistField a) => EntityField val a -> SqlExpr (Value a) -> SqlExpr (Update val)
- case_ :: PersistField a => [(SqlExpr (Value Bool), SqlExpr (Value a))] -> SqlExpr (Value a) -> SqlExpr (Value a)
- toBaseId :: ToBaseId ent => SqlExpr (Value (Key ent)) -> SqlExpr (Value (Key (BaseEnt ent)))
- subSelect :: PersistField a => SqlQuery (SqlExpr (Value a)) -> SqlExpr (Value (Maybe a))
- subSelectMaybe :: PersistField a => SqlQuery (SqlExpr (Value (Maybe a))) -> SqlExpr (Value (Maybe a))
- subSelectCount :: (Num a, PersistField a) => SqlQuery ignored -> SqlExpr (Value a)
- subSelectForeign :: (BackendCompatible SqlBackend (PersistEntityBackend val1), PersistEntity val1, PersistEntity val2, PersistField a) => SqlExpr (Entity val2) -> EntityField val2 (Key val1) -> (SqlExpr (Entity val1) -> SqlExpr (Value a)) -> SqlExpr (Value a)
- subSelectList :: PersistField a => SqlQuery (SqlExpr (Value a)) -> SqlExpr (ValueList a)
- subSelectUnsafe :: PersistField a => SqlQuery (SqlExpr (Value a)) -> SqlExpr (Value a)
- class ToBaseId ent where
- type BaseEnt ent :: *
- toBaseIdWitness :: Key (BaseEnt ent) -> Key ent
- when_ :: expr (Value Bool) -> () -> expr a -> (expr (Value Bool), expr a)
- then_ :: ()
- else_ :: expr a -> expr a
- from :: From a => (a -> SqlQuery b) -> SqlQuery b
- newtype Value a = Value {
- unValue :: a
- newtype ValueList a = ValueList a
- data OrderBy
- data DistinctOn
- data LockingKind
- class PersistField a => SqlString a
- data InnerJoin a b = a `InnerJoin` b
- data CrossJoin a b = a `CrossJoin` b
- data LeftOuterJoin a b = a `LeftOuterJoin` b
- data RightOuterJoin a b = a `RightOuterJoin` b
- data FullOuterJoin a b = a `FullOuterJoin` b
- data JoinKind
- data OnClauseWithoutMatchingJoinException = OnClauseWithoutMatchingJoinException String
- data SqlQuery a
- data SqlExpr a
- type SqlEntity ent = (PersistEntity ent, PersistEntityBackend ent ~ SqlBackend)
- select :: (SqlSelect a r, MonadIO m) => SqlQuery a -> SqlReadT m [r]
- selectSource :: (SqlSelect a r, BackendCompatible SqlBackend backend, IsPersistBackend backend, PersistQueryRead backend, PersistStoreRead backend, PersistUniqueRead backend, MonadResource m) => SqlQuery a -> ConduitT () r (ReaderT backend m) ()
- delete :: MonadIO m => SqlQuery () -> SqlWriteT m ()
- deleteCount :: MonadIO m => SqlQuery () -> SqlWriteT m Int64
- update :: (MonadIO m, PersistEntity val, BackendCompatible SqlBackend (PersistEntityBackend val)) => (SqlExpr (Entity val) -> SqlQuery ()) -> SqlWriteT m ()
- updateCount :: (MonadIO m, PersistEntity val, BackendCompatible SqlBackend (PersistEntityBackend val)) => (SqlExpr (Entity val) -> SqlQuery ()) -> SqlWriteT m Int64
- insertSelect :: (MonadIO m, PersistEntity a) => SqlQuery (SqlExpr (Insertion a)) -> SqlWriteT m ()
- insertSelectCount :: (MonadIO m, PersistEntity a) => SqlQuery (SqlExpr (Insertion a)) -> SqlWriteT m Int64
- (<#) :: (a -> b) -> SqlExpr (Value a) -> SqlExpr (Insertion b)
- (<&>) :: SqlExpr (Insertion (a -> b)) -> SqlExpr (Value a) -> SqlExpr (Insertion b)
- renderQueryToText :: (SqlSelect a r, BackendCompatible SqlBackend backend, Monad m) => Mode -> SqlQuery a -> ReaderT backend m (Text, [PersistValue])
- renderQuerySelect :: (SqlSelect a r, BackendCompatible SqlBackend backend, Monad m) => SqlQuery a -> ReaderT backend m (Text, [PersistValue])
- renderQueryUpdate :: (SqlSelect a r, BackendCompatible SqlBackend backend, Monad m) => SqlQuery a -> ReaderT backend m (Text, [PersistValue])
- renderQueryDelete :: (SqlSelect a r, BackendCompatible SqlBackend backend, Monad m) => SqlQuery a -> ReaderT backend m (Text, [PersistValue])
- renderQueryInsertInto :: (SqlSelect a r, BackendCompatible SqlBackend backend, Monad m) => SqlQuery a -> ReaderT backend m (Text, [PersistValue])
- class From a
- valkey :: (ToBackendKey SqlBackend entity, PersistField (Key entity)) => Int64 -> SqlExpr (Value (Key entity))
- valJ :: PersistField (Key entity) => Value (Key entity) -> SqlExpr (Value (Key entity))
- associateJoin :: forall e1 e0. Ord (Key e0) => [(Entity e0, e1)] -> Map (Key e0) (e0, [e1])
- deleteKey :: (PersistStore backend, BaseBackend backend ~ PersistEntityBackend val, MonadIO m, PersistEntity val) => Key val -> ReaderT backend m ()
- toJsonText :: ToJSON j => j -> Text
- entityIdFromJSON :: (PersistEntity record, FromJSON record) => Value -> Parser (Entity record)
- entityIdToJSON :: (PersistEntity record, ToJSON record) => Entity record -> Value
- entityValues :: PersistEntity record => Entity record -> [PersistValue]
- fromPersistValueJSON :: FromJSON a => PersistValue -> Either Text a
- keyValueEntityFromJSON :: (PersistEntity record, FromJSON record) => Value -> Parser (Entity record)
- keyValueEntityToJSON :: (PersistEntity record, ToJSON record) => Entity record -> Value
- toPersistValueJSON :: ToJSON a => a -> PersistValue
- selectKeys :: forall backend (m :: Type -> Type) record. (PersistQueryRead backend, MonadResource m, PersistRecordBackend record backend, MonadReader backend m) => [Filter record] -> [SelectOpt record] -> ConduitM () (Key record) m ()
- belongsTo :: forall backend ent1 ent2 (m :: Type -> Type). (PersistStoreRead backend, PersistEntity ent1, PersistRecordBackend ent2 backend, MonadIO m) => (ent1 -> Maybe (Key ent2)) -> ent1 -> ReaderT backend m (Maybe ent2)
- belongsToJust :: forall backend ent1 ent2 (m :: Type -> Type). (PersistStoreRead backend, PersistEntity ent1, PersistRecordBackend ent2 backend, MonadIO m) => (ent1 -> Key ent2) -> ent1 -> ReaderT backend m ent2
- getEntity :: forall backend e (m :: Type -> Type). (PersistStoreRead backend, PersistRecordBackend e backend, MonadIO m) => Key e -> ReaderT backend m (Maybe (Entity e))
- getJust :: forall backend record (m :: Type -> Type). (PersistStoreRead backend, PersistRecordBackend record backend, MonadIO m) => Key record -> ReaderT backend m record
- getJustEntity :: forall record backend (m :: Type -> Type). (PersistEntityBackend record ~ BaseBackend backend, MonadIO m, PersistEntity record, PersistStoreRead backend) => Key record -> ReaderT backend m (Entity record)
- insertEntity :: forall backend e (m :: Type -> Type). (PersistStoreWrite backend, PersistRecordBackend e backend, MonadIO m) => e -> ReaderT backend m (Entity e)
- insertRecord :: forall record backend (m :: Type -> Type). (PersistEntityBackend record ~ BaseBackend backend, PersistEntity record, MonadIO m, PersistStoreWrite backend) => record -> ReaderT backend m record
- liftPersist :: (MonadIO m, MonadReader backend m) => ReaderT backend IO b -> m b
- checkUnique :: forall (m :: Type -> Type) record backend. (MonadIO m, PersistRecordBackend record backend, PersistUniqueRead backend) => record -> ReaderT backend m (Maybe (Unique record))
- getByValue :: forall record (m :: Type -> Type) backend. (MonadIO m, PersistUniqueRead backend, PersistRecordBackend record backend, AtLeastOneUniqueKey record) => record -> ReaderT backend m (Maybe (Entity record))
- insertBy :: forall (m :: Type -> Type) backend record. (MonadIO m, PersistUniqueWrite backend, PersistRecordBackend record backend, AtLeastOneUniqueKey record) => record -> ReaderT backend m (Either (Entity record) (Key record))
- insertUniqueEntity :: forall (m :: Type -> Type) record backend. (MonadIO m, PersistRecordBackend record backend, PersistUniqueWrite backend) => record -> ReaderT backend m (Maybe (Entity record))
- onlyUnique :: forall (m :: Type -> Type) backend record. (MonadIO m, PersistUniqueWrite backend, PersistRecordBackend record backend, OnlyOneUniqueKey record) => record -> ReaderT backend m (Unique record)
- replaceUnique :: forall (m :: Type -> Type) record backend. (MonadIO m, Eq (Unique record), PersistRecordBackend record backend, PersistUniqueWrite backend) => Key record -> record -> ReaderT backend m (Maybe (Unique record))
- transactionSave :: forall (m :: Type -> Type). MonadIO m => ReaderT SqlBackend m ()
- transactionUndo :: forall (m :: Type -> Type). MonadIO m => ReaderT SqlBackend m ()
- defaultAttribute :: [Attr] -> Maybe Text
- mkColumns :: [EntityDef] -> EntityDef -> ([Column], [UniqueDef], [ForeignDef])
- getMigration :: forall (m :: Type -> Type). MonadIO m => Migration -> ReaderT SqlBackend m [Sql]
- migrate :: [EntityDef] -> EntityDef -> Migration
- parseMigration :: forall (m :: Type -> Type). MonadIO m => Migration -> ReaderT SqlBackend m (Either [Text] CautiousMigration)
- parseMigration' :: forall (m :: Type -> Type). MonadIO m => Migration -> ReaderT SqlBackend m CautiousMigration
- printMigration :: forall (m :: Type -> Type). MonadIO m => Migration -> ReaderT SqlBackend m ()
- runMigration :: forall (m :: Type -> Type). MonadIO m => Migration -> ReaderT SqlBackend m ()
- runMigrationSilent :: forall (m :: Type -> Type). MonadUnliftIO m => Migration -> ReaderT SqlBackend m [Text]
- runMigrationUnsafe :: forall (m :: Type -> Type). MonadIO m => Migration -> ReaderT SqlBackend m ()
- showMigration :: forall (m :: Type -> Type). MonadIO m => Migration -> ReaderT SqlBackend m [Text]
- decorateSQLWithLimitOffset :: Text -> (Int, Int) -> Bool -> Text -> Text
- fieldDBName :: PersistEntity record => EntityField record typ -> DBName
- fromSqlKey :: ToBackendKey SqlBackend record => Key record -> Int64
- getFieldName :: forall record typ (m :: Type -> Type) backend. (PersistEntity record, PersistEntityBackend record ~ SqlBackend, BackendCompatible SqlBackend backend, Monad m) => EntityField record typ -> ReaderT backend m Text
- getTableName :: forall record (m :: Type -> Type) backend. (PersistEntity record, BackendCompatible SqlBackend backend, Monad m) => record -> ReaderT backend m Text
- tableDBName :: PersistEntity record => record -> DBName
- toSqlKey :: ToBackendKey SqlBackend record => Int64 -> Key record
- withRawQuery :: forall (m :: Type -> Type) a. MonadIO m => Text -> [PersistValue] -> ConduitM [PersistValue] Void IO a -> ReaderT SqlBackend m a
- getStmtConn :: SqlBackend -> Text -> IO Statement
- rawExecute :: forall (m :: Type -> Type) backend. (MonadIO m, BackendCompatible SqlBackend backend) => Text -> [PersistValue] -> ReaderT backend m ()
- rawExecuteCount :: forall (m :: Type -> Type) backend. (MonadIO m, BackendCompatible SqlBackend backend) => Text -> [PersistValue] -> ReaderT backend m Int64
- rawQuery :: forall (m :: Type -> Type) env. (MonadResource m, MonadReader env m, BackendCompatible SqlBackend env) => Text -> [PersistValue] -> ConduitM () [PersistValue] m ()
- rawQueryRes :: forall (m1 :: Type -> Type) (m2 :: Type -> Type) env. (MonadIO m1, MonadIO m2, BackendCompatible SqlBackend env) => Text -> [PersistValue] -> ReaderT env m1 (Acquire (ConduitM () [PersistValue] m2 ()))
- rawSql :: forall a (m :: Type -> Type) backend. (RawSql a, MonadIO m, BackendCompatible SqlBackend backend) => Text -> [PersistValue] -> ReaderT backend m [a]
- askLogFunc :: (MonadUnliftIO m, MonadLogger m) => m LogFunc
- close' :: BackendCompatible SqlBackend backend => backend -> IO ()
- createSqlPool :: (MonadLogger m, MonadUnliftIO m, BackendCompatible SqlBackend backend) => (LogFunc -> IO backend) -> Int -> m (Pool backend)
- liftSqlPersistMPool :: (MonadIO m, BackendCompatible SqlBackend backend) => ReaderT backend (NoLoggingT (ResourceT IO)) a -> Pool backend -> m a
- runSqlConn :: (MonadUnliftIO m, BackendCompatible SqlBackend backend) => ReaderT backend m a -> backend -> m a
- runSqlPersistM :: BackendCompatible SqlBackend backend => ReaderT backend (NoLoggingT (ResourceT IO)) a -> backend -> IO a
- runSqlPersistMPool :: BackendCompatible SqlBackend backend => ReaderT backend (NoLoggingT (ResourceT IO)) a -> Pool backend -> IO a
- runSqlPool :: (MonadUnliftIO m, BackendCompatible SqlBackend backend) => ReaderT backend m a -> Pool backend -> m a
- withSqlConn :: (MonadUnliftIO m, MonadLogger m, BackendCompatible SqlBackend backend) => (LogFunc -> IO backend) -> (backend -> m a) -> m a
- withSqlPool :: (MonadLogger m, MonadUnliftIO m, BackendCompatible SqlBackend backend) => (LogFunc -> IO backend) -> Int -> (Pool backend -> m a) -> m a
- readToUnknown :: forall (m :: Type -> Type) a. Monad m => ReaderT SqlReadBackend m a -> ReaderT SqlBackend m a
- readToWrite :: forall (m :: Type -> Type) a. Monad m => ReaderT SqlReadBackend m a -> ReaderT SqlWriteBackend m a
- writeToUnknown :: forall (m :: Type -> Type) a. Monad m => ReaderT SqlWriteBackend m a -> ReaderT SqlBackend m a
- entityKeyFields :: EntityDef -> [FieldDef]
- entityPrimary :: EntityDef -> Maybe CompositeDef
- fromPersistValueText :: PersistValue -> Either Text Text
- keyAndEntityFields :: EntityDef -> [FieldDef]
- toEmbedEntityDef :: EntityDef -> EmbedEntityDef
- type PersistStore a = PersistStoreWrite a
- type PersistUnique a = PersistUniqueWrite a
- class (PersistStoreWrite backend, PersistEntity record, BaseBackend backend ~ PersistEntityBackend record) => DeleteCascade record backend where
- deleteCascade :: forall (m :: Type -> Type). MonadIO m => Key record -> ReaderT backend m ()
- class PersistConfig c where
- type PersistConfigBackend c :: (Type -> Type) -> Type -> Type
- type PersistConfigPool c
- loadConfig :: Value -> Parser c
- applyEnv :: c -> IO c
- createPoolConfig :: c -> IO (PersistConfigPool c)
- runPool :: MonadUnliftIO m => c -> PersistConfigBackend c m a -> PersistConfigPool c -> m a
- type family BackendSpecificUpdate backend record
- data Entity record = Entity {}
- class (PersistField (Key record), ToJSON (Key record), FromJSON (Key record), Show (Key record), Read (Key record), Eq (Key record), Ord (Key record)) => PersistEntity record where
- type PersistEntityBackend record
- data Key record
- data EntityField record :: Type -> Type
- data Unique record
- keyToValues :: Key record -> [PersistValue]
- keyFromValues :: [PersistValue] -> Either Text (Key record)
- persistIdField :: EntityField record (Key record)
- entityDef :: Monad m => m record -> EntityDef
- persistFieldDef :: EntityField record typ -> FieldDef
- toPersistFields :: record -> [SomePersistField]
- fromPersistValues :: [PersistValue] -> Either Text record
- persistUniqueKeys :: record -> [Unique record]
- persistUniqueToFieldNames :: Unique record -> [(HaskellName, DBName)]
- persistUniqueToValues :: Unique record -> [PersistValue]
- fieldLens :: EntityField record field -> forall (f :: Type -> Type). Functor f => (field -> f field) -> Entity record -> f (Entity record)
- class PersistField a where
- toPersistValue :: a -> PersistValue
- fromPersistValue :: PersistValue -> Either Text a
- data SomePersistField = PersistField a => SomePersistField a
- class (PersistCore backend, PersistStoreRead backend) => PersistQueryRead backend where
- selectSourceRes :: forall record (m1 :: Type -> Type) (m2 :: Type -> Type). (PersistRecordBackend record backend, MonadIO m1, MonadIO m2) => [Filter record] -> [SelectOpt record] -> ReaderT backend m1 (Acquire (ConduitM () (Entity record) m2 ()))
- selectFirst :: forall (m :: Type -> Type) record. (MonadIO m, PersistRecordBackend record backend) => [Filter record] -> [SelectOpt record] -> ReaderT backend m (Maybe (Entity record))
- selectKeysRes :: forall (m1 :: Type -> Type) (m2 :: Type -> Type) record. (MonadIO m1, MonadIO m2, PersistRecordBackend record backend) => [Filter record] -> [SelectOpt record] -> ReaderT backend m1 (Acquire (ConduitM () (Key record) m2 ()))
- class (PersistQueryRead backend, PersistStoreWrite backend) => PersistQueryWrite backend where
- updateWhere :: forall (m :: Type -> Type) record. (MonadIO m, PersistRecordBackend record backend) => [Filter record] -> [Update record] -> ReaderT backend m ()
- deleteWhere :: forall (m :: Type -> Type) record. (MonadIO m, PersistRecordBackend record backend) => [Filter record] -> ReaderT backend m ()
- class BackendCompatible sup sub where
- projectBackend :: sub -> sup
- data family BackendKey backend
- class HasPersistBackend backend where
- type BaseBackend backend
- persistBackend :: backend -> BaseBackend backend
- class HasPersistBackend backend => IsPersistBackend backend
- class PersistCore backend where
- data BackendKey backend
- type PersistRecordBackend record backend = (PersistEntity record, PersistEntityBackend record ~ BaseBackend backend)
- class (Show (BackendKey backend), Read (BackendKey backend), Eq (BackendKey backend), Ord (BackendKey backend), PersistCore backend, PersistField (BackendKey backend), ToJSON (BackendKey backend), FromJSON (BackendKey backend)) => PersistStoreRead backend where
- get :: forall (m :: Type -> Type) record. (MonadIO m, PersistRecordBackend record backend) => Key record -> ReaderT backend m (Maybe record)
- getMany :: forall (m :: Type -> Type) record. (MonadIO m, PersistRecordBackend record backend) => [Key record] -> ReaderT backend m (Map (Key record) record)
- class (Show (BackendKey backend), Read (BackendKey backend), Eq (BackendKey backend), Ord (BackendKey backend), PersistStoreRead backend, PersistField (BackendKey backend), ToJSON (BackendKey backend), FromJSON (BackendKey backend)) => PersistStoreWrite backend where
- insert :: forall (m :: Type -> Type) record. (MonadIO m, PersistRecordBackend record backend) => record -> ReaderT backend m (Key record)
- insert_ :: forall (m :: Type -> Type) record. (MonadIO m, PersistRecordBackend record backend) => record -> ReaderT backend m ()
- insertMany :: forall (m :: Type -> Type) record. (MonadIO m, PersistRecordBackend record backend) => [record] -> ReaderT backend m [Key record]
- insertMany_ :: forall (m :: Type -> Type) record. (MonadIO m, PersistRecordBackend record backend) => [record] -> ReaderT backend m ()
- insertEntityMany :: forall (m :: Type -> Type) record. (MonadIO m, PersistRecordBackend record backend) => [Entity record] -> ReaderT backend m ()
- insertKey :: forall (m :: Type -> Type) record. (MonadIO m, PersistRecordBackend record backend) => Key record -> record -> ReaderT backend m ()
- repsert :: forall (m :: Type -> Type) record. (MonadIO m, PersistRecordBackend record backend) => Key record -> record -> ReaderT backend m ()
- repsertMany :: forall (m :: Type -> Type) record. (MonadIO m, PersistRecordBackend record backend) => [(Key record, record)] -> ReaderT backend m ()
- replace :: forall (m :: Type -> Type) record. (MonadIO m, PersistRecordBackend record backend) => Key record -> record -> ReaderT backend m ()
- updateGet :: forall (m :: Type -> Type) record. (MonadIO m, PersistRecordBackend record backend) => Key record -> [Update record] -> ReaderT backend m record
- class (PersistEntity record, PersistEntityBackend record ~ backend, PersistCore backend) => ToBackendKey backend record where
- toBackendKey :: Key record -> BackendKey backend
- fromBackendKey :: BackendKey backend -> Key record
- class (PersistCore backend, PersistStoreRead backend) => PersistUniqueRead backend where
- getBy :: forall (m :: Type -> Type) record. (MonadIO m, PersistRecordBackend record backend) => Unique record -> ReaderT backend m (Maybe (Entity record))
- class (PersistUniqueRead backend, PersistStoreWrite backend) => PersistUniqueWrite backend where
- deleteBy :: forall (m :: Type -> Type) record. (MonadIO m, PersistRecordBackend record backend) => Unique record -> ReaderT backend m ()
- insertUnique :: forall (m :: Type -> Type) record. (MonadIO m, PersistRecordBackend record backend) => record -> ReaderT backend m (Maybe (Key record))
- upsert :: forall (m :: Type -> Type) record. (MonadIO m, PersistRecordBackend record backend, OnlyOneUniqueKey record) => record -> [Update record] -> ReaderT backend m (Entity record)
- upsertBy :: forall (m :: Type -> Type) record. (MonadIO m, PersistRecordBackend record backend) => Unique record -> record -> [Update record] -> ReaderT backend m (Entity record)
- putMany :: forall (m :: Type -> Type) record. (MonadIO m, PersistRecordBackend record backend) => [record] -> ReaderT backend m ()
- class PersistField a => PersistFieldSql a where
- class RawSql a where
- rawSqlCols :: (DBName -> Text) -> a -> (Int, [Text])
- rawSqlColCountReason :: a -> String
- rawSqlProcessRow :: [PersistValue] -> Either Text a
- type CautiousMigration = [(Bool, Sql)]
- data Column = Column {}
- type ConnectionPool = Pool SqlBackend
- type Migration = WriterT [Text] (WriterT CautiousMigration (ReaderT SqlBackend IO)) ()
- data PersistentSqlException
- newtype Single a = Single {
- unSingle :: a
- type Sql = Text
- type SqlPersistM = SqlPersistT (NoLoggingT (ResourceT IO))
- type SqlPersistT = ReaderT SqlBackend
- data InsertSqlResult
- = ISRSingle Text
- | ISRInsertGet Text Text
- | ISRManyKeys Text [PersistValue]
- type IsSqlBackend backend = (IsPersistBackend backend, BaseBackend backend ~ SqlBackend)
- type LogFunc = Loc -> LogSource -> LogLevel -> LogStr -> IO ()
- data SqlBackend = SqlBackend {
- connPrepare :: Text -> IO Statement
- connInsertSql :: EntityDef -> [PersistValue] -> InsertSqlResult
- connInsertManySql :: Maybe (EntityDef -> [[PersistValue]] -> InsertSqlResult)
- connUpsertSql :: Maybe (EntityDef -> NonEmpty UniqueDef -> Text -> Text)
- connPutManySql :: Maybe (EntityDef -> Int -> Text)
- connStmtMap :: IORef (Map Text Statement)
- connClose :: IO ()
- connMigrateSql :: [EntityDef] -> (Text -> IO Statement) -> EntityDef -> IO (Either [Text] [(Bool, Text)])
- connBegin :: (Text -> IO Statement) -> Maybe IsolationLevel -> IO ()
- connCommit :: (Text -> IO Statement) -> IO ()
- connRollback :: (Text -> IO Statement) -> IO ()
- connEscapeName :: DBName -> Text
- connNoLimit :: Text
- connRDBMS :: Text
- connLimitOffset :: (Int, Int) -> Bool -> Text -> Text
- connLogFunc :: LogFunc
- connMaxParams :: Maybe Int
- connRepsertManySql :: Maybe (EntityDef -> Int -> Text)
- type SqlBackendCanRead backend = (BackendCompatible SqlBackend backend, PersistQueryRead backend, PersistStoreRead backend, PersistUniqueRead backend)
- type SqlBackendCanWrite backend = (SqlBackendCanRead backend, PersistQueryWrite backend, PersistStoreWrite backend, PersistUniqueWrite backend)
- newtype SqlReadBackend = SqlReadBackend {}
- type SqlReadT (m :: Type -> Type) a = forall backend. SqlBackendCanRead backend => ReaderT backend m a
- newtype SqlWriteBackend = SqlWriteBackend {}
- type SqlWriteT (m :: Type -> Type) a = forall backend. SqlBackendCanWrite backend => ReaderT backend m a
- data Statement = Statement {
- stmtFinalize :: IO ()
- stmtReset :: IO ()
- stmtExecute :: [PersistValue] -> IO Int64
- stmtQuery :: forall (m :: Type -> Type). MonadIO m => [PersistValue] -> Acquire (ConduitM () [PersistValue] m ())
- type Attr = Text
- data Checkmark
- data CompositeDef = CompositeDef {
- compositeFields :: ![FieldDef]
- compositeAttrs :: ![Attr]
- newtype DBName = DBName {
- unDBName :: Text
- data EmbedEntityDef = EmbedEntityDef {}
- data EmbedFieldDef = EmbedFieldDef {
- emFieldDB :: !DBName
- emFieldEmbed :: Maybe EmbedEntityDef
- emFieldCycle :: Maybe HaskellName
- data EntityDef = EntityDef {
- entityHaskell :: !HaskellName
- entityDB :: !DBName
- entityId :: !FieldDef
- entityAttrs :: ![Attr]
- entityFields :: ![FieldDef]
- entityUniques :: ![UniqueDef]
- entityForeigns :: ![ForeignDef]
- entityDerives :: ![Text]
- entityExtra :: !(Map Text [ExtraLine])
- entitySum :: !Bool
- entityComments :: !(Maybe Text)
- type ExtraLine = [Text]
- data FieldDef = FieldDef {
- fieldHaskell :: !HaskellName
- fieldDB :: !DBName
- fieldType :: !FieldType
- fieldSqlType :: !SqlType
- fieldAttrs :: ![Attr]
- fieldStrict :: !Bool
- fieldReference :: !ReferenceDef
- fieldComments :: !(Maybe Text)
- data FieldType
- data ForeignDef = ForeignDef {}
- type ForeignFieldDef = (HaskellName, DBName)
- newtype HaskellName = HaskellName {
- unHaskellName :: Text
- data IsNullable
- data OnlyUniqueException = OnlyUniqueException String
- data PersistException
- = PersistError Text
- | PersistMarshalError Text
- | PersistInvalidField Text
- | PersistForeignConstraintUnmet Text
- | PersistMongoDBError Text
- | PersistMongoDBUnsupported Text
- data PersistFilter
- data PersistUpdate
- data PersistValue
- = PersistText Text
- | PersistByteString ByteString
- | PersistInt64 Int64
- | PersistDouble Double
- | PersistRational Rational
- | PersistBool Bool
- | PersistDay Day
- | PersistTimeOfDay TimeOfDay
- | PersistUTCTime UTCTime
- | PersistNull
- | PersistList [PersistValue]
- | PersistMap [(Text, PersistValue)]
- | PersistObjectId ByteString
- | PersistArray [PersistValue]
- | PersistDbSpecific ByteString
- data ReferenceDef
- data SqlType
- data UniqueDef = UniqueDef {
- uniqueHaskell :: !HaskellName
- uniqueDBName :: !DBName
- uniqueFields :: ![(HaskellName, DBName)]
- uniqueAttrs :: ![Attr]
- data UpdateException
- = KeyNotFound String
- | UpsertError String
- data WhyNullable
Setup
If you're already using persistent
, then you're ready to use
esqueleto
, no further setup is needed. If you're just
starting a new project and would like to use esqueleto
, take
a look at persistent
's book first
(http://www.yesodweb.com/book/persistent) to learn how to
define your schema.
Introduction
The main goals of esqueleto
are to:
- Be easily translatable to SQL. When you take a look at a
esqueleto
query, you should be able to know exactly how the SQL query will end up. (As opposed to being a relational algebra EDSL such as HaskellDB, which is non-trivial to translate into SQL.) - Support the most widely used SQL features. We'd like you to be
able to use
esqueleto
for all of your queries, no exceptions. Send a pull request or open an issue on our project page (https://github.com/prowdsponsor/esqueleto) if there's anything missing that you'd like to see. - Be as type-safe as possible. We strive to provide as many type checks as possible. If you get bitten by some invalid code that type-checks, please open an issue on our project page so we can take a look.
However, it is not a goal to be able to write portable SQL.
We do not try to hide the differences between DBMSs from you,
and esqueleto
code that works for one database may not work
on another. This is a compromise we have to make in order to
give you as much control over the raw SQL as possible without
losing too much convenience. This also means that you may
type-check a query that doesn't work on your DBMS.
Getting started
We like clean, easy-to-read EDSLs. However, in order to achieve this goal we've used a lot of type hackery, leading to some hard-to-read type signatures. On this section, we'll try to build some intuition about the syntax.
For the following examples, we'll use this example schema:
share [mkPersist sqlSettings, mkMigrate "migrateAll"] [persist| Person name String age Int Maybe deriving Eq Show BlogPost title String authorId PersonId deriving Eq Show Follow follower PersonId followed PersonId deriving Eq Show |]
Most of esqueleto
was created with SELECT
statements in
mind, not only because they're the most common but also
because they're the most complex kind of statement. The most
simple kind of SELECT
would be:
SELECT * FROM Person
In esqueleto
, we may write the same query above as:
do people <-select
$from
$ \person -> do return person liftIO $ mapM_ (putStrLn . personName . entityVal) people
The expression above has type SqlPersist m ()
, while
people
has type [Entity Person]
. The query above will be
translated into exactly the same query we wrote manually, but
instead of SELECT *
it will list all entity fields (using
*
is not robust). Note that esqueleto
knows that we want
an Entity Person
just because of the personName
that we're
printing later.
However, most of the time we need to filter our queries using
WHERE
. For example:
SELECT * FROM Person WHERE Person.name = "John"
In esqueleto
, we may write the same query above as:
select
$from
$ \p -> dowhere_
(p^.
PersonName==.
val
"John") return p
Although esqueleto
's code is a bit more noisy, it's has
almost the same structure (save from the return
). The
(
operator is used to project a field from an entity.
The field name is the same one generated by ^.
)persistent
's
Template Haskell functions. We use val
to lift a constant
Haskell value into the SQL query.
Another example would be:
SELECT * FROM Person WHERE Person.age >= 18
In esqueleto
, we may write the same query above as:
select
$from
$ \p -> dowhere_
(p^.
PersonAge>=.
just
(val
18)) return p
Since age
is an optional Person
field, we use just
to lift
into val
18 :: SqlExpr (Value Int)just (
.val
18) ::
SqlExpr (Value (Maybe Int))
Implicit joins are represented by tuples. For example, to get the list of all blog posts and their authors, we could write:
SELECT BlogPost.*, Person.* FROM BlogPost, Person WHERE BlogPost.authorId = Person.id ORDER BY BlogPost.title ASC
In esqueleto
, we may write the same query above as:
select
$from
$ \(b, p) -> dowhere_
(b^.
BlogPostAuthorId==.
p^.
PersonId)orderBy
[asc
(b^.
BlogPostTitle)] return (b, p)
However, you may want your results to include people who don't
have any blog posts as well using a LEFT OUTER JOIN
:
SELECT Person.*, BlogPost.* FROM Person LEFT OUTER JOIN BlogPost ON Person.id = BlogPost.authorId ORDER BY Person.name ASC, BlogPost.title ASC
In esqueleto
, we may write the same query above as:
select
$from
$ \(p `LeftOuterJoin
` mb) -> doon
(just
(p^.
PersonId)==.
mb?.
BlogPostAuthorId)orderBy
[asc
(p^.
PersonName),asc
(mb?.
BlogPostTitle)] return (p, mb)
On a LEFT OUTER JOIN
the entity on the right hand side may
not exist (i.e. there may be a Person
without any
BlogPost
s), so while p :: SqlExpr (Entity Person)
, we have
mb :: SqlExpr (Maybe (Entity BlogPost))
. The whole
expression above has type SqlPersist m [(Entity Person, Maybe
(Entity BlogPost))]
. Instead of using (^.)
, we used
(
to project a field from a ?.
)Maybe (Entity a)
.
We are by no means limited to joins of two tables, nor by
joins of different tables. For example, we may want a list
of the Follow
entity:
SELECT P1.*, Follow.*, P2.* FROM Person AS P1 INNER JOIN Follow ON P1.id = Follow.follower INNER JOIN Person AS P2 ON P2.id = Follow.followed
In esqueleto
, we may write the same query above as:
select
$from
$ \(p1 `InnerJoin
` f `InnerJoin
` p2) -> doon
(p1^.
PersonId==.
f^.
FollowFollower)on
(p2^.
PersonId==.
f^.
FollowFollowed) return (p1, f, p2)
We also currently support UPDATE
and DELETE
statements.
For example:
doupdate
$ \p -> doset
p [ PersonName=.
val
"João" ]where_
(p^.
PersonName==.
val
"Joao")delete
$from
$ \p -> dowhere_
(p^.
PersonAge<.
just
(val
14))
The results of queries can also be used for insertions.
In SQL
, we might write the following, inserting a new blog
post for every user:
INSERT INTO BlogPost SELECT ('Group Blog Post', id) FROM Person
In esqueleto
, we may write the same query above as:
insertSelect
$from
$ \p-> return $ BlogPost<#
"Group Blog Post"<&>
(p^.
PersonId)
Individual insertions can be performed through Persistent's
insert
function, reexported for convenience.
esqueleto
's Language
on :: SqlExpr (Value Bool) -> SqlQuery () Source #
An ON
clause, useful to describe how two tables are related. Cross joins
and tuple-joins do not need an on
clause, but InnerJoin
and the various
outer joins do.
If you don't include an on
clause (or include too many!) then a runtime
exception will be thrown.
As an example, consider this simple join:
select
$from
$ \(foo `InnerJoin
` bar) -> doon
(foo^.
FooId==.
bar^.
BarFooId) ...
We need to specify the clause for joining the two columns together. If we had this:
select
$from
$ \(foo `CrossJoin
` bar) -> do ...
Then we can safely omit the on
clause, because the cross join will make
pairs of all records possible.
You can do multiple on
clauses in a query. This query joins three tables,
and has two on
clauses:
select
$from
$ \(foo `InnerJoin
` bar `InnerJoin
` baz) -> doon
(baz^.
BazId==.
bar^.
BarBazId)on
(foo^.
FooId==.
bar^.
BarFooId) ...
Old versions of esqueleto required that you provide the on
clauses in
reverse order. This restriction has been lifted - you can now provide on
clauses in any order, and the SQL should work itself out. The above query is
now totally equivalent to this:
select
$from
$ \(foo `InnerJoin
` bar `InnerJoin
` baz) -> doon
(foo^.
FooId==.
bar^.
BarFooId)on
(baz^.
BazId==.
bar^.
BarBazId) ...
groupBy :: ToSomeValues a => a -> SqlQuery () Source #
GROUP BY
clause. You can enclose multiple columns
in a tuple.
select $from
\(foo `InnerJoin
` bar) -> doon
(foo^.
FooBarId==.
bar^.
BarId)groupBy
(bar^.
BarId, bar^.
BarName) return (bar^.
BarId, bar^.
BarName, countRows)
With groupBy you can sort by aggregate functions, like so
(we used let
to restrict the more general countRows
to
SqlSqlExpr (Value Int)
to avoid ambiguity---the second use of
countRows
has its type restricted by the :: Int
below):
r <- select $from
\(foo `InnerJoin
` bar) -> doon
(foo^.
FooBarId==.
bar^.
BarId)groupBy
$ bar^.
BarName let countRows' =countRows
orderBy
[asc
countRows'] return (bar^.
BarName, countRows') forM_ r $ \(Value
name,Value
count) -> do print name print (count :: Int)
Need more columns?
The ToSomeValues
class is defined for SqlExpr
and tuples of SqlExpr
s.
We only have definitions for up to 8 elements in a tuple right now, so it's
possible that you may need to have more than 8 elements.
For example, consider a query with a groupBy
call like this:
groupBy (e0, e1, e2, e3, e4, e5, e6, e7)
This is the biggest you can get with a single tuple. However, you can easily nest the tuples to add more:
groupBy ((e0, e1, e2, e3, e4, e5, e6, e7), e8, e9)
orderBy :: [SqlExpr OrderBy] -> SqlQuery () Source #
ORDER BY
clause. See also asc
and desc
.
Multiple calls to orderBy
get concatenated on the final
query, including distinctOnOrderBy
.
rand :: SqlExpr OrderBy Source #
Deprecated: Since 2.6.0: rand
ordering function is not uniform across all databases! To avoid accidental partiality it will be removed in the next major version.
ORDER BY random()
clause.
Since: 1.3.10
asc :: PersistField a => SqlExpr (Value a) -> SqlExpr OrderBy Source #
Ascending order of this field or SqlExpression.
desc :: PersistField a => SqlExpr (Value a) -> SqlExpr OrderBy Source #
Descending order of this field or SqlExpression.
distinctOn :: [SqlExpr DistinctOn] -> SqlQuery a -> SqlQuery a Source #
DISTINCT ON
. Change the current SELECT
into
SELECT DISTINCT ON (SqlExpressions)
. For example:
select $from
\foo ->distinctOn
[don
(foo ^. FooName),don
(foo ^. FooState)] $ do ...
You can also chain different calls to distinctOn
. The
above is equivalent to:
select $from
\foo ->distinctOn
[don
(foo ^. FooName)] $distinctOn
[don
(foo ^. FooState)] $ do ...
Each call to distinctOn
adds more SqlExpressions. Calls to
distinctOn
override any calls to distinct
.
Note that PostgreSQL requires the SqlExpressions on DISTINCT
ON
to be the first ones to appear on a ORDER BY
. This is
not managed automatically by esqueleto, keeping its spirit
of trying to be close to raw SQL.
Supported by PostgreSQL only.
Since: 2.2.4
don :: SqlExpr (Value a) -> SqlExpr DistinctOn Source #
Erase an SqlExpression's type so that it's suitable to
be used by distinctOn
.
Since: 2.2.4
distinctOnOrderBy :: [SqlExpr OrderBy] -> SqlQuery a -> SqlQuery a Source #
A convenience function that calls both distinctOn
and
orderBy
. In other words,
distinctOnOrderBy
[asc foo, desc bar, desc quux] $ do
...
is the same as:
distinctOn
[don foo, don bar, don quux] $ doorderBy
[asc foo, desc bar, desc quux] ...
Since: 2.2.4
locking :: LockingKind -> SqlQuery () Source #
Add a locking clause to the query. Please read
LockingKind
documentation and your RDBMS manual.
If multiple calls to locking
are made on the same query,
the last one is used.
Since: 2.2.7
sub_select :: PersistField a => SqlQuery (SqlExpr (Value a)) -> SqlExpr (Value a) Source #
Deprecated: sub_select sub_select is an unsafe function to use. If used with a SqlQuery that returns 0 results, then it may return NULL despite not mentioning Maybe in the return type. If it returns more than 1 result, then it will throw a SQL error. Instead, consider using one of the following alternatives: - subSelect: attaches a LIMIT 1 and the Maybe return type, totally safe. - subSelectMaybe: Attaches a LIMIT 1, useful for a query that already has a Maybe in the return type. - subSelectCount: Performs a count of the query - this is always safe. - subSelectUnsafe: Performs no checks or guarantees. Safe to use with countRows and friends.
Execute a subquery SELECT
in an SqlExpression. Returns a
simple value so should be used only when the SELECT
query
is guaranteed to return just one row.
Deprecated in 3.2.0.
(^.) :: forall typ val. (PersistEntity val, PersistField typ) => SqlExpr (Entity val) -> EntityField val typ -> SqlExpr (Value typ) infixl 9 Source #
Project a field of an entity.
(?.) :: (PersistEntity val, PersistField typ) => SqlExpr (Maybe (Entity val)) -> EntityField val typ -> SqlExpr (Value (Maybe typ)) Source #
Project a field of an entity that may be null.
val :: PersistField typ => typ -> SqlExpr (Value typ) Source #
Lift a constant value from Haskell-land to the query.
isNothing :: PersistField typ => SqlExpr (Value (Maybe typ)) -> SqlExpr (Value Bool) Source #
IS NULL
comparison.
joinV :: SqlExpr (Value (Maybe (Maybe typ))) -> SqlExpr (Value (Maybe typ)) Source #
Join nested Maybe
s in a Value
into one. This is useful when
calling aggregate functions on nullable fields.
withNonNull :: PersistField typ => SqlExpr (Value (Maybe typ)) -> (SqlExpr (Value typ) -> SqlQuery a) -> SqlQuery a Source #
Project an SqlExpression that may be null, guarding against null cases.
countDistinct :: Num a => SqlExpr (Value typ) -> SqlExpr (Value a) Source #
COUNT(DISTINCT x)
.
Since: 2.4.1
(==.) :: PersistField typ => SqlExpr (Value typ) -> SqlExpr (Value typ) -> SqlExpr (Value Bool) infix 4 Source #
(>=.) :: PersistField typ => SqlExpr (Value typ) -> SqlExpr (Value typ) -> SqlExpr (Value Bool) infix 4 Source #
(>.) :: PersistField typ => SqlExpr (Value typ) -> SqlExpr (Value typ) -> SqlExpr (Value Bool) infix 4 Source #
(<=.) :: PersistField typ => SqlExpr (Value typ) -> SqlExpr (Value typ) -> SqlExpr (Value Bool) infix 4 Source #
(<.) :: PersistField typ => SqlExpr (Value typ) -> SqlExpr (Value typ) -> SqlExpr (Value Bool) infix 4 Source #
(!=.) :: PersistField typ => SqlExpr (Value typ) -> SqlExpr (Value typ) -> SqlExpr (Value Bool) infix 4 Source #
between :: PersistField a => SqlExpr (Value a) -> (SqlExpr (Value a), SqlExpr (Value a)) -> SqlExpr (Value Bool) Source #
BETWEEN
.
@since: 3.1.0
(+.) :: PersistField a => SqlExpr (Value a) -> SqlExpr (Value a) -> SqlExpr (Value a) infixl 6 Source #
(-.) :: PersistField a => SqlExpr (Value a) -> SqlExpr (Value a) -> SqlExpr (Value a) infixl 6 Source #
(/.) :: PersistField a => SqlExpr (Value a) -> SqlExpr (Value a) -> SqlExpr (Value a) infixl 7 Source #
(*.) :: PersistField a => SqlExpr (Value a) -> SqlExpr (Value a) -> SqlExpr (Value a) infixl 7 Source #
round_ :: (PersistField a, Num a, PersistField b, Num b) => SqlExpr (Value a) -> SqlExpr (Value b) Source #
ceiling_ :: (PersistField a, Num a, PersistField b, Num b) => SqlExpr (Value a) -> SqlExpr (Value b) Source #
floor_ :: (PersistField a, Num a, PersistField b, Num b) => SqlExpr (Value a) -> SqlExpr (Value b) Source #
sum_ :: (PersistField a, PersistField b) => SqlExpr (Value a) -> SqlExpr (Value (Maybe b)) Source #
avg_ :: (PersistField a, PersistField b) => SqlExpr (Value a) -> SqlExpr (Value (Maybe b)) Source #
castNum :: (Num a, Num b) => SqlExpr (Value a) -> SqlExpr (Value b) Source #
Allow a number of one type to be used as one of another type via an implicit cast. An explicit cast is not made, this function changes only the types on the Haskell side.
Caveat: Trying to use castNum
from Double
to Int
will not result in an integer, the original fractional
number will still be used! Use round_
, ceiling_
or
floor_
instead.
Safety: This operation is mostly safe due to the Num
constraint between the types and the fact that RDBMSs
usually allow numbers of different types to be used
interchangeably. However, there may still be issues with
the query not being accepted by the RDBMS or persistent
not being able to parse it.
Since: 2.2.9
castNumM :: (Num a, Num b) => SqlExpr (Value (Maybe a)) -> SqlExpr (Value (Maybe b)) Source #
Same as castNum
, but for nullable values.
Since: 2.2.9
coalesce :: PersistField a => [SqlExpr (Value (Maybe a))] -> SqlExpr (Value (Maybe a)) Source #
COALESCE
function. Evaluates the arguments in order and
returns the value of the first non-NULL SqlExpression, or NULL
(Nothing) otherwise. Some RDBMSs (such as SQLite) require
at least two arguments; please refer to the appropriate
documentation.
Since: 1.4.3
coalesceDefault :: PersistField a => [SqlExpr (Value (Maybe a))] -> SqlExpr (Value a) -> SqlExpr (Value a) Source #
Like coalesce
, but takes a non-nullable SqlExpression
placed at the end of the SqlExpression list, which guarantees
a non-NULL result.
Since: 1.4.3
upper_ :: SqlString s => SqlExpr (Value s) -> SqlExpr (Value s) Source #
UPPER
function.
Since: 3.3.0
ltrim_ :: SqlString s => SqlExpr (Value s) -> SqlExpr (Value s) Source #
LTRIM
function.
Since: 3.3.0
rtrim_ :: SqlString s => SqlExpr (Value s) -> SqlExpr (Value s) Source #
RTRIM
function.
Since: 3.3.0
length_ :: (SqlString s, Num a) => SqlExpr (Value s) -> SqlExpr (Value a) Source #
LENGTH
function.
Since: 3.3.0
left_ :: (SqlString s, Num a) => (SqlExpr (Value s), SqlExpr (Value a)) -> SqlExpr (Value s) Source #
LEFT
function.
Since: 3.3.0
right_ :: (SqlString s, Num a) => (SqlExpr (Value s), SqlExpr (Value a)) -> SqlExpr (Value s) Source #
RIGHT
function.
Since: 3.3.0
like :: SqlString s => SqlExpr (Value s) -> SqlExpr (Value s) -> SqlExpr (Value Bool) infixr 2 Source #
LIKE
operator.
ilike :: SqlString s => SqlExpr (Value s) -> SqlExpr (Value s) -> SqlExpr (Value Bool) infixr 2 Source #
ILIKE
operator (case-insensitive LIKE
).
Supported by PostgreSQL only.
Since: 2.2.3
concat_ :: SqlString s => [SqlExpr (Value s)] -> SqlExpr (Value s) Source #
The CONCAT
function with a variable number of
parameters. Supported by MySQL and PostgreSQL.
(++.) :: SqlString s => SqlExpr (Value s) -> SqlExpr (Value s) -> SqlExpr (Value s) infixr 5 Source #
The ||
string concatenation operator (named after
Haskell's ++
in order to avoid naming clash with ||.
).
Supported by SQLite and PostgreSQL.
castString :: (SqlString s, SqlString r) => SqlExpr (Value s) -> SqlExpr (Value r) Source #
Cast a string type into Text
. This function
is very useful if you want to use newtype
s, or if you want
to apply functions such as like
to strings of different
types.
Safety: This is a slightly unsafe function, especially if
you have defined your own instances of SqlString
. Also,
since Maybe
is an instance of SqlString
, it's possible
to turn a nullable value into a non-nullable one. Avoid
using this function if possible.
subList_select :: PersistField a => SqlQuery (SqlExpr (Value a)) -> SqlExpr (ValueList a) Source #
Execute a subquery SELECT
in an SqlExpression. Returns a
list of values.
valList :: PersistField typ => [typ] -> SqlExpr (ValueList typ) Source #
Lift a list of constant value from Haskell-land to the query.
justList :: SqlExpr (ValueList typ) -> SqlExpr (ValueList (Maybe typ)) Source #
Same as just
but for ValueList
. Most of the time you
won't need it, though, because you can use just
from
inside subList_select
or Just
from inside valList
.
Since: 2.2.12
in_ :: PersistField typ => SqlExpr (Value typ) -> SqlExpr (ValueList typ) -> SqlExpr (Value Bool) Source #
IN
operator. For example if you want to select all Person
s by a list
of IDs:
SELECT * FROM Person WHERE Person.id IN (?)
In esqueleto
, we may write the same query above as:
select $from
$ \person -> dowhere_
$ person^.
PersonId `in_
`valList
personIds return person
Where personIds
is of type [Key Person]
.
notIn :: PersistField typ => SqlExpr (Value typ) -> SqlExpr (ValueList typ) -> SqlExpr (Value Bool) Source #
NOT IN
operator.
set :: PersistEntity val => SqlExpr (Entity val) -> [SqlExpr (Update val)] -> SqlQuery () Source #
SET
clause used on UPDATE
s. Note that while it's not
a type error to use this function on a SELECT
, it will
most certainly result in a runtime error.
(=.) :: (PersistEntity val, PersistField typ) => EntityField val typ -> SqlExpr (Value typ) -> SqlExpr (Update val) infixr 3 Source #
(+=.) :: (PersistEntity val, PersistField a) => EntityField val a -> SqlExpr (Value a) -> SqlExpr (Update val) infixr 3 Source #
(-=.) :: (PersistEntity val, PersistField a) => EntityField val a -> SqlExpr (Value a) -> SqlExpr (Update val) infixr 3 Source #
(*=.) :: (PersistEntity val, PersistField a) => EntityField val a -> SqlExpr (Value a) -> SqlExpr (Update val) infixr 3 Source #
(/=.) :: (PersistEntity val, PersistField a) => EntityField val a -> SqlExpr (Value a) -> SqlExpr (Update val) infixr 3 Source #
case_ :: PersistField a => [(SqlExpr (Value Bool), SqlExpr (Value a))] -> SqlExpr (Value a) -> SqlExpr (Value a) Source #
CASE
statement. For example:
select $ return $case_
[when_
(exists
$from
$ \p -> dowhere_
(p^.
PersonName==.
val
"Mike"))then_
(sub_select
$from
$ \v -> do let sub =from
$ \c -> dowhere_
(c^.
PersonName==.
val
"Mike") return (c^.
PersonFavNum)where_
(v^.
PersonFavNum >.sub_select
sub) return $count
(v^.
PersonName) +.val
(1 :: Int)) ] (else_
$val
(-1))
This query is a bit complicated, but basically it checks if a person
named "Mike"
exists, and if that person does, run the subquery to find
out how many people have a ranking (by Fav Num) higher than "Mike"
.
NOTE: There are a few things to be aware about this statement.
- This only implements the full CASE statement, it does not implement the "simple" CASE statement.
- At least one
when_
andthen_
is mandatory otherwise it will emit an error. - The
else_
is also mandatory, unlike the SQL statement in which if theELSE
is omitted it will return aNULL
. You can reproduce this vianothing
.
Since: 2.1.2
toBaseId :: ToBaseId ent => SqlExpr (Value (Key ent)) -> SqlExpr (Value (Key (BaseEnt ent))) Source #
Convert an entity's key into another entity's.
This function is to be used when you change an entity's Id
to be
that of another entity. For example:
Bar barNum Int Foo bar BarId fooNum Int Primary bar
In this example, Bar is said to be the BaseEnt(ity), and Foo the child. To model this in Esqueleto, declare:
instance ToBaseId Foo where type BaseEnt Foo = Bar toBaseIdWitness barId = FooKey barId
Now you're able to write queries such as:
select
$from
$ (bar `InnerJoin
` foo) -> doon
(toBaseId
(foo^.
FooId)==.
bar^.
BarId) return (bar, foo)
Note: this function may be unsafe to use in conditions not like the one of the example above.
Since: 2.4.3
subSelect :: PersistField a => SqlQuery (SqlExpr (Value a)) -> SqlExpr (Value (Maybe a)) Source #
Execute a subquery SELECT
in a SqlExpr
. The query passed to this
function will only return a single result - it has a LIMIT 1
passed in to
the query to make it safe, and the return type is Maybe
to indicate that
the subquery might result in 0 rows.
If you find yourself writing
, then consider using
joinV
. subSelect
subSelectMaybe
.
If you're performing a countRows
, then you can use subSelectCount
which
is safe.
If you know that the subquery will always return exactly one row (eg
a foreign key constraint guarantees that you'll get exactly one row), then
consider subSelectUnsafe
, along with a comment explaining why it is safe.
Since: 3.2.0
subSelectMaybe :: PersistField a => SqlQuery (SqlExpr (Value (Maybe a))) -> SqlExpr (Value (Maybe a)) Source #
Execute a subquery SELECT
in a SqlExpr
. This function is a shorthand
for the common
idiom, where you are calling
joinV
. subSelect
subSelect
on an expression that would be Maybe
already.
As an example, you would use this function when calling sum_
or max_
,
which have Maybe
in the result type (for a 0 row query).
Since: 3.2.0
subSelectCount :: (Num a, PersistField a) => SqlQuery ignored -> SqlExpr (Value a) Source #
Performs a COUNT
of the given query in a subSelect
manner. This is
always guaranteed to return a result value, and is completely safe.
Since: 3.2.0
Arguments
:: (BackendCompatible SqlBackend (PersistEntityBackend val1), PersistEntity val1, PersistEntity val2, PersistField a) | |
=> SqlExpr (Entity val2) | An expression representing the table you have access to now. |
-> EntityField val2 (Key val1) | The foreign key field on the table. |
-> (SqlExpr (Entity val1) -> SqlExpr (Value a)) | A function to extract a value from the foreign reference table. |
-> SqlExpr (Value a) |
Performs a sub-select using the given foreign key on the entity. This is useful to extract values that are known to be present by the database schema.
As an example, consider the following persistent definition:
User profile ProfileId Profile name Text
The following query will return the name of the user.
getUserWithName =select
$from
$ user ->pure
(user,subSelectForeign
user UserProfile (^. ProfileName)
Since: 3.2.0
subSelectList :: PersistField a => SqlQuery (SqlExpr (Value a)) -> SqlExpr (ValueList a) Source #
Execute a subquery SELECT
in a SqlExpr
that returns a list. This is an
alias for subList_select
and is provided for symmetry with the other safe
subselect functions.
Since: 3.2.0
subSelectUnsafe :: PersistField a => SqlQuery (SqlExpr (Value a)) -> SqlExpr (Value a) Source #
Execute a subquery SELECT
in a SqlExpr
. This function is unsafe,
because it can throw runtime exceptions in two cases:
- If the query passed has 0 result rows, then it will return a
NULL
value. Thepersistent
parsing operations will fail on an unexpectedNULL
. - If the query passed returns more than one row, then the SQL engine will fail with an error like "More than one row returned by a subquery used as an expression".
This function is safe if you guarantee that exactly one row will be returned,
or if the result already has a Maybe
type for some reason.
For variants with the safety encoded already, see subSelect
and
subSelectMaybe
. For the most common safe use of this, see subSelectCount
.
Since: 3.2.0
when_ :: expr (Value Bool) -> () -> expr a -> (expr (Value Bool), expr a) Source #
Syntax sugar for case_
.
Since: 2.1.2
from :: From a => (a -> SqlQuery b) -> SqlQuery b Source #
FROM
clause: bring entities into scope.
This function internally uses two type classes in order to provide some flexibility of how you may call it. Internally we refer to these type classes as the two different magics.
The innermost magic allows you to use from
with the
following types:
expr (Entity val)
, which brings a single entity into scope.expr (Maybe (Entity val))
, which brings a single entity that may beNULL
into scope. Used forOUTER JOIN
s.- A
JOIN
of any other two types allowed by the innermost magic, where aJOIN
may be anInnerJoin
, aCrossJoin
, aLeftOuterJoin
, aRightOuterJoin
, or aFullOuterJoin
. TheJOINs
have left fixity.
The outermost magic allows you to use from
on any tuples of
types supported by innermost magic (and also tuples of tuples,
and so on), up to 8-tuples.
Note that using from
for the same entity twice does work and
corresponds to a self-join. You don't even need to use two
different calls to from
, you may use a JOIN
or a tuple.
The following are valid examples of uses of from
(the types
of the arguments of the lambda are inside square brackets):
from
$ \person -> ...from
$ \(person, blogPost) -> ...from
$ \(p `LeftOuterJoin
` mb) -> ...from
$ \(p1 `InnerJoin
` f `InnerJoin
` p2) -> ...from
$ \((p1 `InnerJoin
` f) `InnerJoin
` p2) -> ...
The types of the arguments to the lambdas above are, respectively:
person :: ( Esqueleto query expr backend , PersistEntity Person , PersistEntityBackend Person ~ backend ) => expr (Entity Person) (person, blogPost) :: (...) => (expr (Entity Person), expr (Entity BlogPost)) (p `LeftOuterJoin
` mb) :: (...) => InnerJoin (expr (Entity Person)) (expr (Maybe (Entity BlogPost))) (p1 `InnerJoin
` f `InnerJoin
` p2) :: (...) => InnerJoin (InnerJoin (expr (Entity Person)) (expr (Entity Follow))) (expr (Entity Person)) (p1 `InnerJoin
` (f `InnerJoin
` p2)) :: :: (...) => InnerJoin (expr (Entity Person)) (InnerJoin (expr (Entity Follow)) (expr (Entity Person)))
Note that some backends may not support all kinds of JOIN
s.
A single value (as opposed to a whole entity). You may use
(
or ^.
)(
to get a ?.
)Value
from an Entity
.
Instances
A list of single values. There's a limited set of functions
able to work with this data type (such as subList_select
,
valList
, in_
and exists
).
Constructors
ValueList a |
Instances
Eq a => Eq (ValueList a) Source # | |
Ord a => Ord (ValueList a) Source # | |
Defined in Database.Esqueleto.Internal.Internal | |
Show a => Show (ValueList a) Source # | |
data DistinctOn Source #
Phantom type used by distinctOn
and don
.
data LockingKind Source #
Different kinds of locking clauses supported by locking
.
Note that each RDBMS has different locking support. The
constructors of this datatype specify only the syntax of the
locking mechanism, not its semantics. For example, even
though both MySQL and PostgreSQL support ForUpdate
, there
are no guarantees that they will behave the same.
Since: 2.2.7
Constructors
ForUpdate |
Since: 2.2.7 |
ForUpdateSkipLocked |
Since: 2.2.7 |
ForShare |
Since: 2.2.7 |
LockInShareMode |
Since: 2.2.7 |
class PersistField a => SqlString a Source #
Phantom class of data types that are treated as strings by the RDBMS. It has no methods because it's only used to avoid type errors such as trying to concatenate integers.
If you have a custom data type or newtype
, feel free to make
it an instance of this class.
Since: 2.4.0
Instances
SqlString Text Source # | Since: 2.3.0 |
Defined in Database.Esqueleto.Internal.Internal | |
SqlString Text Source # | Since: 2.3.0 |
Defined in Database.Esqueleto.Internal.Internal | |
SqlString ByteString Source # | Since: 2.3.0 |
Defined in Database.Esqueleto.Internal.Internal | |
SqlString Html Source # | Since: 2.3.0 |
Defined in Database.Esqueleto.Internal.Internal | |
a ~ Char => SqlString [a] Source # | Since: 2.3.0 |
Defined in Database.Esqueleto.Internal.Internal | |
SqlString a => SqlString (Maybe a) Source # | Since: 2.4.0 |
Defined in Database.Esqueleto.Internal.Internal |
Joins
data InnerJoin a b infixl 2 Source #
Data type that represents an INNER JOIN
(see LeftOuterJoin
for an example).
Constructors
a `InnerJoin` b infixl 2 |
Instances
data CrossJoin a b infixl 2 Source #
Data type that represents a CROSS JOIN
(see LeftOuterJoin
for an example).
Constructors
a `CrossJoin` b infixl 2 |
data LeftOuterJoin a b infixl 2 Source #
Data type that represents a LEFT OUTER JOIN
. For example,
select $from
$ \(person `LeftOuterJoin
` pet) -> ...
is translated into
SELECT ... FROM Person LEFT OUTER JOIN Pet ...
See also: from
.
Constructors
a `LeftOuterJoin` b infixl 2 |
Instances
IsJoinKind LeftOuterJoin Source # | |
Defined in Database.Esqueleto.Internal.Internal Methods smartJoin :: a -> b -> LeftOuterJoin a b Source # reifyJoinKind :: LeftOuterJoin a b -> JoinKind Source # | |
FromPreprocess (LeftOuterJoin a b) => From (LeftOuterJoin a b) Source # | |
Defined in Database.Esqueleto.Internal.Internal Methods from_ :: SqlQuery (LeftOuterJoin a b) Source # | |
(ToFrom a, ToFromT a ~ a', ToFrom b, ToFromT b ~ b', ToMaybe b', mb ~ ToMaybeT b') => ToFrom (LeftOuterJoin a (b, (a' :& mb) -> SqlExpr (Value Bool))) Source # | |
Defined in Database.Esqueleto.Experimental | |
ToFrom (LeftOuterJoin a b) Source # | |
Defined in Database.Esqueleto.Experimental Methods toFrom :: LeftOuterJoin a b -> From (ToFromT (LeftOuterJoin a b)) Source # |
data RightOuterJoin a b infixl 2 Source #
Data type that represents a RIGHT OUTER JOIN
(see LeftOuterJoin
for an example).
Constructors
a `RightOuterJoin` b infixl 2 |
Instances
IsJoinKind RightOuterJoin Source # | |
Defined in Database.Esqueleto.Internal.Internal Methods smartJoin :: a -> b -> RightOuterJoin a b Source # reifyJoinKind :: RightOuterJoin a b -> JoinKind Source # | |
FromPreprocess (RightOuterJoin a b) => From (RightOuterJoin a b) Source # | |
Defined in Database.Esqueleto.Internal.Internal Methods from_ :: SqlQuery (RightOuterJoin a b) Source # | |
(ToFrom a, ToFromT a ~ a', ToFrom b, ToFromT b ~ b', ToMaybe a', ma ~ ToMaybeT a') => ToFrom (RightOuterJoin a (b, (ma :& b') -> SqlExpr (Value Bool))) Source # | |
Defined in Database.Esqueleto.Experimental | |
ToFrom (RightOuterJoin a b) Source # | |
Defined in Database.Esqueleto.Experimental Methods toFrom :: RightOuterJoin a b -> From (ToFromT (RightOuterJoin a b)) Source # |
data FullOuterJoin a b infixl 2 Source #
Data type that represents a FULL OUTER JOIN
(see LeftOuterJoin
for an example).
Constructors
a `FullOuterJoin` b infixl 2 |
Instances
IsJoinKind FullOuterJoin Source # | |
Defined in Database.Esqueleto.Internal.Internal Methods smartJoin :: a -> b -> FullOuterJoin a b Source # reifyJoinKind :: FullOuterJoin a b -> JoinKind Source # | |
FromPreprocess (FullOuterJoin a b) => From (FullOuterJoin a b) Source # | |
Defined in Database.Esqueleto.Internal.Internal Methods from_ :: SqlQuery (FullOuterJoin a b) Source # | |
(ToFrom a, ToFromT a ~ a', ToFrom b, ToFromT b ~ b', ToMaybe a', ma ~ ToMaybeT a', ToMaybe b', mb ~ ToMaybeT b') => ToFrom (FullOuterJoin a (b, (ma :& mb) -> SqlExpr (Value Bool))) Source # | |
Defined in Database.Esqueleto.Experimental | |
ToFrom (FullOuterJoin a b) Source # | |
Defined in Database.Esqueleto.Experimental Methods toFrom :: FullOuterJoin a b -> From (ToFromT (FullOuterJoin a b)) Source # |
(Internal) A kind of JOIN
.
Constructors
InnerJoinKind | INNER JOIN |
CrossJoinKind | CROSS JOIN |
LeftOuterJoinKind | LEFT OUTER JOIN |
RightOuterJoinKind | RIGHT OUTER JOIN |
FullOuterJoinKind | FULL OUTER JOIN |
data OnClauseWithoutMatchingJoinException Source #
Exception thrown whenever on
is used to create an ON
clause but no matching JOIN
is found.
Constructors
OnClauseWithoutMatchingJoinException String |
Instances
SQL backend
SQL backend for esqueleto
using SqlPersistT
.
An expression on the SQL backend.
There are many comments describing the constructors of this data type. However, Haddock doesn't like GADTs, so you'll have to read them by hitting "Source".
Instances
type SqlEntity ent = (PersistEntity ent, PersistEntityBackend ent ~ SqlBackend) Source #
Constraint synonym for persistent
entities whose backend
is SqlPersistT
.
select :: (SqlSelect a r, MonadIO m) => SqlQuery a -> SqlReadT m [r] Source #
Execute an esqueleto
SELECT
query inside persistent
's
SqlPersistT
monad and return a list of rows.
We've seen that from
has some magic about which kinds of
things you may bring into scope. This select
function also
has some magic for which kinds of things you may bring back to
Haskell-land by using SqlQuery
's return
:
- You may return a
SqlExpr (
for an entityEntity
v)v
(i.e., like the*
in SQL), which is then returned to Haskell-land as justEntity v
. - You may return a
SqlExpr (Maybe (Entity v))
for an entityv
that may beNULL
, which is then returned to Haskell-land asMaybe (Entity v)
. Used forOUTER JOIN
s. - You may return a
SqlExpr (
for a valueValue
t)t
(i.e., a single column), wheret
is any instance ofPersistField
, which is then returned to Haskell-land asValue t
. You may useValue
to return projections of anEntity
(see(
and^.
)(
) or to return any other value calculated on the query (e.g.,?.
)countRows
orsubSelect
).
The SqlSelect a r
class has functional dependencies that
allow type information to flow both from a
to r
and
vice-versa. This means that you'll almost never have to give
any type signatures for esqueleto
queries. For example, the
query
alone is ambiguous, but
in the context ofselect
$ from $ \p -> return p
do ps <-select
$from
$ \p -> return p liftIO $ mapM_ (putStrLn . personName . entityVal) ps
we are able to infer from that single personName . entityVal
function composition that the p
inside the query is of type
SqlExpr (Entity Person)
.
selectSource :: (SqlSelect a r, BackendCompatible SqlBackend backend, IsPersistBackend backend, PersistQueryRead backend, PersistStoreRead backend, PersistUniqueRead backend, MonadResource m) => SqlQuery a -> ConduitT () r (ReaderT backend m) () Source #
Execute an esqueleto
SELECT
query inside persistent
's
SqlPersistT
monad and return a Source
of rows.
delete :: MonadIO m => SqlQuery () -> SqlWriteT m () Source #
Execute an esqueleto
DELETE
query inside persistent
's
SqlPersistT
monad. Note that currently there are no type
checks for statements that should not appear on a DELETE
query.
Example of usage:
delete
$from
$ \appointment ->where_
(appointment^.
AppointmentDate<.
val
now)
Unlike select
, there is a useful way of using delete
that
will lead to type ambiguities. If you want to delete all rows
(i.e., no where_
clause), you'll have to use a type signature:
delete
$from
$ \(appointment ::SqlExpr
(Entity
Appointment)) -> return ()
deleteCount :: MonadIO m => SqlQuery () -> SqlWriteT m Int64 Source #
Same as delete
, but returns the number of rows affected.
update :: (MonadIO m, PersistEntity val, BackendCompatible SqlBackend (PersistEntityBackend val)) => (SqlExpr (Entity val) -> SqlQuery ()) -> SqlWriteT m () Source #
Execute an esqueleto
UPDATE
query inside persistent
's
SqlPersistT
monad. Note that currently there are no type
checks for statements that should not appear on a UPDATE
query.
Example of usage:
update
$ \p -> doset
p [ PersonAge=.
just
(val
thisYear) -. p^.
PersonBorn ]where_
$ isNothing (p^.
PersonAge)
updateCount :: (MonadIO m, PersistEntity val, BackendCompatible SqlBackend (PersistEntityBackend val)) => (SqlExpr (Entity val) -> SqlQuery ()) -> SqlWriteT m Int64 Source #
Same as update
, but returns the number of rows affected.
insertSelect :: (MonadIO m, PersistEntity a) => SqlQuery (SqlExpr (Insertion a)) -> SqlWriteT m () Source #
Insert a PersistField
for every selected value.
Since: 2.4.2
insertSelectCount :: (MonadIO m, PersistEntity a) => SqlQuery (SqlExpr (Insertion a)) -> SqlWriteT m Int64 Source #
Insert a PersistField
for every selected value, return the count afterward
(<#) :: (a -> b) -> SqlExpr (Value a) -> SqlExpr (Insertion b) Source #
Apply a PersistField
constructor to SqlExpr Value
arguments.
(<&>) :: SqlExpr (Insertion (a -> b)) -> SqlExpr (Value a) -> SqlExpr (Insertion b) Source #
Apply extra SqlExpr Value
arguments to a PersistField
constructor
Rendering Queries
Arguments
:: (SqlSelect a r, BackendCompatible SqlBackend backend, Monad m) | |
=> Mode | |
-> SqlQuery a | The SQL query you want to render. |
-> ReaderT backend m (Text, [PersistValue]) |
Renders a SqlQuery
into a Text
value along with the list of
PersistValue
s that would be supplied to the database for ?
placeholders.
You must ensure that the Mode
you pass to this function corresponds with
the actual SqlQuery
. If you pass a query that uses incompatible features
(like an INSERT
statement with a SELECT
mode) then you'll get a weird
result.
Since: 3.1.1
Arguments
:: (SqlSelect a r, BackendCompatible SqlBackend backend, Monad m) | |
=> SqlQuery a | The SQL query you want to render. |
-> ReaderT backend m (Text, [PersistValue]) |
Renders a SqlQuery
into a Text
value along with the list of
PersistValue
s that would be supplied to the database for ?
placeholders.
You must ensure that the Mode
you pass to this function corresponds with
the actual SqlQuery
. If you pass a query that uses incompatible features
(like an INSERT
statement with a SELECT
mode) then you'll get a weird
result.
Since: 3.1.1
Arguments
:: (SqlSelect a r, BackendCompatible SqlBackend backend, Monad m) | |
=> SqlQuery a | The SQL query you want to render. |
-> ReaderT backend m (Text, [PersistValue]) |
Renders a SqlQuery
into a Text
value along with the list of
PersistValue
s that would be supplied to the database for ?
placeholders.
You must ensure that the Mode
you pass to this function corresponds with
the actual SqlQuery
. If you pass a query that uses incompatible features
(like an INSERT
statement with a SELECT
mode) then you'll get a weird
result.
Since: 3.1.1
Arguments
:: (SqlSelect a r, BackendCompatible SqlBackend backend, Monad m) | |
=> SqlQuery a | The SQL query you want to render. |
-> ReaderT backend m (Text, [PersistValue]) |
Renders a SqlQuery
into a Text
value along with the list of
PersistValue
s that would be supplied to the database for ?
placeholders.
You must ensure that the Mode
you pass to this function corresponds with
the actual SqlQuery
. If you pass a query that uses incompatible features
(like an INSERT
statement with a SELECT
mode) then you'll get a weird
result.
Since: 3.1.1
renderQueryInsertInto Source #
Arguments
:: (SqlSelect a r, BackendCompatible SqlBackend backend, Monad m) | |
=> SqlQuery a | The SQL query you want to render. |
-> ReaderT backend m (Text, [PersistValue]) |
Renders a SqlQuery
into a Text
value along with the list of
PersistValue
s that would be supplied to the database for ?
placeholders.
You must ensure that the Mode
you pass to this function corresponds with
the actual SqlQuery
. If you pass a query that uses incompatible features
(like an INSERT
statement with a SELECT
mode) then you'll get a weird
result.
Since: 3.1.1
Internal.Language
Minimal complete definition
Instances
RDBMS-specific modules
There are many differences between SQL syntax and functions
supported by different RDBMSs. Since version 2.2.8,
esqueleto
includes modules containing functions that are
specific to a given RDBMS.
- PostgreSQL: Database.Esqueleto.PostgreSQL.
In order to use these functions, you need to explicitly import their corresponding modules, they're not re-exported here.
Helpers
valkey :: (ToBackendKey SqlBackend entity, PersistField (Key entity)) => Int64 -> SqlExpr (Value (Key entity)) Source #
valkey i =
(https://github.com/prowdsponsor/esqueleto/issues/9).val
. toSqlKey
valJ :: PersistField (Key entity) => Value (Key entity) -> SqlExpr (Value (Key entity)) Source #
valJ
is like val
but for something that is already a Value
. The use
case it was written for was, given a Value
lift the Key
for that Value
into the query expression in a type safe way. However, the implementation is
more generic than that so we call it valJ
.
Its important to note that the input entity and the output entity are constrained to be the same by the type signature on the function (https://github.com/prowdsponsor/esqueleto/pull/69).
Since: 1.4.2
associateJoin :: forall e1 e0. Ord (Key e0) => [(Entity e0, e1)] -> Map (Key e0) (e0, [e1]) Source #
Avoid N+1 queries and join entities into a map structure
getFoosAndNestedBarsFromParent :: ParentId -> (Map (Key Foo) (Foo, [Maybe (Entity Bar)]))
getFoosAndNestedBarsFromParent parentId =
fmap
associateJoin $ select
$
from
$ \(foo `LeftOuterJoin
` bar) -> do
on
(bar ?.
BarFooId ==.
foo ^.
FooId)
where_
(foo ^.
FooParentId ==.
val
parentId)
pure
(foo, bar)
Since: 3.1.2
Re-exports
We re-export many symbols from persistent
for convenince:
- "Store functions" from Database.Persist.
- Everything from Database.Persist.Class except for
PersistQuery
anddelete
(usedeleteKey
instead). - Everything from Database.Persist.Types except for
Update
,SelectOpt
,BackendSpecificFilter
andFilter
. - Everything from Database.Persist.Sql except for
deleteWhereCount
andupdateWhereCount
.
deleteKey :: (PersistStore backend, BaseBackend backend ~ PersistEntityBackend val, MonadIO m, PersistEntity val) => Key val -> ReaderT backend m () Source #
toJsonText :: ToJSON j => j -> Text #
entityIdFromJSON :: (PersistEntity record, FromJSON record) => Value -> Parser (Entity record) #
entityIdToJSON :: (PersistEntity record, ToJSON record) => Entity record -> Value #
entityValues :: PersistEntity record => Entity record -> [PersistValue] #
fromPersistValueJSON :: FromJSON a => PersistValue -> Either Text a #
keyValueEntityFromJSON :: (PersistEntity record, FromJSON record) => Value -> Parser (Entity record) #
keyValueEntityToJSON :: (PersistEntity record, ToJSON record) => Entity record -> Value #
toPersistValueJSON :: ToJSON a => a -> PersistValue #
selectKeys :: forall backend (m :: Type -> Type) record. (PersistQueryRead backend, MonadResource m, PersistRecordBackend record backend, MonadReader backend m) => [Filter record] -> [SelectOpt record] -> ConduitM () (Key record) m () #
belongsTo :: forall backend ent1 ent2 (m :: Type -> Type). (PersistStoreRead backend, PersistEntity ent1, PersistRecordBackend ent2 backend, MonadIO m) => (ent1 -> Maybe (Key ent2)) -> ent1 -> ReaderT backend m (Maybe ent2) #
belongsToJust :: forall backend ent1 ent2 (m :: Type -> Type). (PersistStoreRead backend, PersistEntity ent1, PersistRecordBackend ent2 backend, MonadIO m) => (ent1 -> Key ent2) -> ent1 -> ReaderT backend m ent2 #
getEntity :: forall backend e (m :: Type -> Type). (PersistStoreRead backend, PersistRecordBackend e backend, MonadIO m) => Key e -> ReaderT backend m (Maybe (Entity e)) #
getJust :: forall backend record (m :: Type -> Type). (PersistStoreRead backend, PersistRecordBackend record backend, MonadIO m) => Key record -> ReaderT backend m record #
getJustEntity :: forall record backend (m :: Type -> Type). (PersistEntityBackend record ~ BaseBackend backend, MonadIO m, PersistEntity record, PersistStoreRead backend) => Key record -> ReaderT backend m (Entity record) #
insertEntity :: forall backend e (m :: Type -> Type). (PersistStoreWrite backend, PersistRecordBackend e backend, MonadIO m) => e -> ReaderT backend m (Entity e) #
insertRecord :: forall record backend (m :: Type -> Type). (PersistEntityBackend record ~ BaseBackend backend, PersistEntity record, MonadIO m, PersistStoreWrite backend) => record -> ReaderT backend m record #
liftPersist :: (MonadIO m, MonadReader backend m) => ReaderT backend IO b -> m b #
checkUnique :: forall (m :: Type -> Type) record backend. (MonadIO m, PersistRecordBackend record backend, PersistUniqueRead backend) => record -> ReaderT backend m (Maybe (Unique record)) #
getByValue :: forall record (m :: Type -> Type) backend. (MonadIO m, PersistUniqueRead backend, PersistRecordBackend record backend, AtLeastOneUniqueKey record) => record -> ReaderT backend m (Maybe (Entity record)) #
insertBy :: forall (m :: Type -> Type) backend record. (MonadIO m, PersistUniqueWrite backend, PersistRecordBackend record backend, AtLeastOneUniqueKey record) => record -> ReaderT backend m (Either (Entity record) (Key record)) #
insertUniqueEntity :: forall (m :: Type -> Type) record backend. (MonadIO m, PersistRecordBackend record backend, PersistUniqueWrite backend) => record -> ReaderT backend m (Maybe (Entity record)) #
onlyUnique :: forall (m :: Type -> Type) backend record. (MonadIO m, PersistUniqueWrite backend, PersistRecordBackend record backend, OnlyOneUniqueKey record) => record -> ReaderT backend m (Unique record) #
replaceUnique :: forall (m :: Type -> Type) record backend. (MonadIO m, Eq (Unique record), PersistRecordBackend record backend, PersistUniqueWrite backend) => Key record -> record -> ReaderT backend m (Maybe (Unique record)) #
transactionSave :: forall (m :: Type -> Type). MonadIO m => ReaderT SqlBackend m () #
transactionUndo :: forall (m :: Type -> Type). MonadIO m => ReaderT SqlBackend m () #
defaultAttribute :: [Attr] -> Maybe Text #
getMigration :: forall (m :: Type -> Type). MonadIO m => Migration -> ReaderT SqlBackend m [Sql] #
parseMigration :: forall (m :: Type -> Type). MonadIO m => Migration -> ReaderT SqlBackend m (Either [Text] CautiousMigration) #
parseMigration' :: forall (m :: Type -> Type). MonadIO m => Migration -> ReaderT SqlBackend m CautiousMigration #
printMigration :: forall (m :: Type -> Type). MonadIO m => Migration -> ReaderT SqlBackend m () #
runMigration :: forall (m :: Type -> Type). MonadIO m => Migration -> ReaderT SqlBackend m () #
runMigrationSilent :: forall (m :: Type -> Type). MonadUnliftIO m => Migration -> ReaderT SqlBackend m [Text] #
runMigrationUnsafe :: forall (m :: Type -> Type). MonadIO m => Migration -> ReaderT SqlBackend m () #
showMigration :: forall (m :: Type -> Type). MonadIO m => Migration -> ReaderT SqlBackend m [Text] #
decorateSQLWithLimitOffset :: Text -> (Int, Int) -> Bool -> Text -> Text #
fieldDBName :: PersistEntity record => EntityField record typ -> DBName #
fromSqlKey :: ToBackendKey SqlBackend record => Key record -> Int64 #
getFieldName :: forall record typ (m :: Type -> Type) backend. (PersistEntity record, PersistEntityBackend record ~ SqlBackend, BackendCompatible SqlBackend backend, Monad m) => EntityField record typ -> ReaderT backend m Text #
getTableName :: forall record (m :: Type -> Type) backend. (PersistEntity record, BackendCompatible SqlBackend backend, Monad m) => record -> ReaderT backend m Text #
tableDBName :: PersistEntity record => record -> DBName #
toSqlKey :: ToBackendKey SqlBackend record => Int64 -> Key record #
withRawQuery :: forall (m :: Type -> Type) a. MonadIO m => Text -> [PersistValue] -> ConduitM [PersistValue] Void IO a -> ReaderT SqlBackend m a #
getStmtConn :: SqlBackend -> Text -> IO Statement #
rawExecute :: forall (m :: Type -> Type) backend. (MonadIO m, BackendCompatible SqlBackend backend) => Text -> [PersistValue] -> ReaderT backend m () #
rawExecuteCount :: forall (m :: Type -> Type) backend. (MonadIO m, BackendCompatible SqlBackend backend) => Text -> [PersistValue] -> ReaderT backend m Int64 #
rawQuery :: forall (m :: Type -> Type) env. (MonadResource m, MonadReader env m, BackendCompatible SqlBackend env) => Text -> [PersistValue] -> ConduitM () [PersistValue] m () #
rawQueryRes :: forall (m1 :: Type -> Type) (m2 :: Type -> Type) env. (MonadIO m1, MonadIO m2, BackendCompatible SqlBackend env) => Text -> [PersistValue] -> ReaderT env m1 (Acquire (ConduitM () [PersistValue] m2 ())) #
rawSql :: forall a (m :: Type -> Type) backend. (RawSql a, MonadIO m, BackendCompatible SqlBackend backend) => Text -> [PersistValue] -> ReaderT backend m [a] #
askLogFunc :: (MonadUnliftIO m, MonadLogger m) => m LogFunc #
close' :: BackendCompatible SqlBackend backend => backend -> IO () #
createSqlPool :: (MonadLogger m, MonadUnliftIO m, BackendCompatible SqlBackend backend) => (LogFunc -> IO backend) -> Int -> m (Pool backend) #
liftSqlPersistMPool :: (MonadIO m, BackendCompatible SqlBackend backend) => ReaderT backend (NoLoggingT (ResourceT IO)) a -> Pool backend -> m a #
runSqlConn :: (MonadUnliftIO m, BackendCompatible SqlBackend backend) => ReaderT backend m a -> backend -> m a #
runSqlPersistM :: BackendCompatible SqlBackend backend => ReaderT backend (NoLoggingT (ResourceT IO)) a -> backend -> IO a #
runSqlPersistMPool :: BackendCompatible SqlBackend backend => ReaderT backend (NoLoggingT (ResourceT IO)) a -> Pool backend -> IO a #
runSqlPool :: (MonadUnliftIO m, BackendCompatible SqlBackend backend) => ReaderT backend m a -> Pool backend -> m a #
withSqlConn :: (MonadUnliftIO m, MonadLogger m, BackendCompatible SqlBackend backend) => (LogFunc -> IO backend) -> (backend -> m a) -> m a #
withSqlPool :: (MonadLogger m, MonadUnliftIO m, BackendCompatible SqlBackend backend) => (LogFunc -> IO backend) -> Int -> (Pool backend -> m a) -> m a #
readToUnknown :: forall (m :: Type -> Type) a. Monad m => ReaderT SqlReadBackend m a -> ReaderT SqlBackend m a #
readToWrite :: forall (m :: Type -> Type) a. Monad m => ReaderT SqlReadBackend m a -> ReaderT SqlWriteBackend m a #
writeToUnknown :: forall (m :: Type -> Type) a. Monad m => ReaderT SqlWriteBackend m a -> ReaderT SqlBackend m a #
entityKeyFields :: EntityDef -> [FieldDef] #
entityPrimary :: EntityDef -> Maybe CompositeDef #
fromPersistValueText :: PersistValue -> Either Text Text #
keyAndEntityFields :: EntityDef -> [FieldDef] #
type PersistStore a = PersistStoreWrite a #
type PersistUnique a = PersistUniqueWrite a #
class (PersistStoreWrite backend, PersistEntity record, BaseBackend backend ~ PersistEntityBackend record) => DeleteCascade record backend where #
Methods
deleteCascade :: forall (m :: Type -> Type). MonadIO m => Key record -> ReaderT backend m () #
class PersistConfig c where #
Minimal complete definition
Associated Types
type PersistConfigBackend c :: (Type -> Type) -> Type -> Type #
type PersistConfigPool c #
Methods
loadConfig :: Value -> Parser c #
createPoolConfig :: c -> IO (PersistConfigPool c) #
runPool :: MonadUnliftIO m => c -> PersistConfigBackend c m a -> PersistConfigPool c -> m a #
Instances
(PersistConfig c1, PersistConfig c2, PersistConfigPool c1 ~ PersistConfigPool c2, PersistConfigBackend c1 ~ PersistConfigBackend c2) => PersistConfig (Either c1 c2) | |
Defined in Database.Persist.Class.PersistConfig Associated Types type PersistConfigBackend (Either c1 c2) :: (Type -> Type) -> Type -> Type # type PersistConfigPool (Either c1 c2) # Methods loadConfig :: Value -> Parser (Either c1 c2) # applyEnv :: Either c1 c2 -> IO (Either c1 c2) # createPoolConfig :: Either c1 c2 -> IO (PersistConfigPool (Either c1 c2)) # runPool :: MonadUnliftIO m => Either c1 c2 -> PersistConfigBackend (Either c1 c2) m a -> PersistConfigPool (Either c1 c2) -> m a # |
type family BackendSpecificUpdate backend record #
Instances
class (PersistField (Key record), ToJSON (Key record), FromJSON (Key record), Show (Key record), Read (Key record), Eq (Key record), Ord (Key record)) => PersistEntity record where #
Methods
keyToValues :: Key record -> [PersistValue] #
keyFromValues :: [PersistValue] -> Either Text (Key record) #
persistIdField :: EntityField record (Key record) #
entityDef :: Monad m => m record -> EntityDef #
persistFieldDef :: EntityField record typ -> FieldDef #
toPersistFields :: record -> [SomePersistField] #
fromPersistValues :: [PersistValue] -> Either Text record #
persistUniqueKeys :: record -> [Unique record] #
persistUniqueToFieldNames :: Unique record -> [(HaskellName, DBName)] #
persistUniqueToValues :: Unique record -> [PersistValue] #
fieldLens :: EntityField record field -> forall (f :: Type -> Type). Functor f => (field -> f field) -> Entity record -> f (Entity record) #
class PersistField a where #
Instances
data SomePersistField #
Constructors
PersistField a => SomePersistField a |
Instances
PersistField SomePersistField | |
Defined in Database.Persist.Class.PersistField Methods toPersistValue :: SomePersistField -> PersistValue # fromPersistValue :: PersistValue -> Either Text SomePersistField # |
class (PersistCore backend, PersistStoreRead backend) => PersistQueryRead backend where #
Minimal complete definition
selectSourceRes, selectKeysRes, count
Methods
selectSourceRes :: forall record (m1 :: Type -> Type) (m2 :: Type -> Type). (PersistRecordBackend record backend, MonadIO m1, MonadIO m2) => [Filter record] -> [SelectOpt record] -> ReaderT backend m1 (Acquire (ConduitM () (Entity record) m2 ())) #
selectFirst :: forall (m :: Type -> Type) record. (MonadIO m, PersistRecordBackend record backend) => [Filter record] -> [SelectOpt record] -> ReaderT backend m (Maybe (Entity record)) #
selectKeysRes :: forall (m1 :: Type -> Type) (m2 :: Type -> Type) record. (MonadIO m1, MonadIO m2, PersistRecordBackend record backend) => [Filter record] -> [SelectOpt record] -> ReaderT backend m1 (Acquire (ConduitM () (Key record) m2 ())) #
class (PersistQueryRead backend, PersistStoreWrite backend) => PersistQueryWrite backend where #
Methods
updateWhere :: forall (m :: Type -> Type) record. (MonadIO m, PersistRecordBackend record backend) => [Filter record] -> [Update record] -> ReaderT backend m () #
deleteWhere :: forall (m :: Type -> Type) record. (MonadIO m, PersistRecordBackend record backend) => [Filter record] -> ReaderT backend m () #
class BackendCompatible sup sub where #
Methods
projectBackend :: sub -> sup #
data family BackendKey backend #
Instances
newtype BackendKey SqlBackend | |
Defined in Database.Persist.Sql.Orphan.PersistStore | |
newtype BackendKey SqlReadBackend | |
Defined in Database.Persist.Sql.Orphan.PersistStore | |
newtype BackendKey SqlWriteBackend | |
Defined in Database.Persist.Sql.Orphan.PersistStore |
class HasPersistBackend backend where #
Associated Types
type BaseBackend backend #
Methods
persistBackend :: backend -> BaseBackend backend #
Instances
HasPersistBackend SqlBackend | |
Defined in Database.Persist.Sql.Types.Internal Associated Types type BaseBackend SqlBackend # Methods | |
HasPersistBackend SqlReadBackend | |
Defined in Database.Persist.Sql.Types.Internal Associated Types type BaseBackend SqlReadBackend # Methods persistBackend :: SqlReadBackend -> BaseBackend SqlReadBackend # | |
HasPersistBackend SqlWriteBackend | |
Defined in Database.Persist.Sql.Types.Internal Associated Types type BaseBackend SqlWriteBackend # Methods persistBackend :: SqlWriteBackend -> BaseBackend SqlWriteBackend # |
class HasPersistBackend backend => IsPersistBackend backend #
Minimal complete definition
mkPersistBackend
Instances
IsPersistBackend SqlBackend | |
Defined in Database.Persist.Sql.Types.Internal Methods | |
IsPersistBackend SqlReadBackend | |
Defined in Database.Persist.Sql.Types.Internal Methods mkPersistBackend :: BaseBackend SqlReadBackend -> SqlReadBackend | |
IsPersistBackend SqlWriteBackend | |
Defined in Database.Persist.Sql.Types.Internal Methods mkPersistBackend :: BaseBackend SqlWriteBackend -> SqlWriteBackend |
class PersistCore backend #
Associated Types
data BackendKey backend #
type PersistRecordBackend record backend = (PersistEntity record, PersistEntityBackend record ~ BaseBackend backend) #
class (Show (BackendKey backend), Read (BackendKey backend), Eq (BackendKey backend), Ord (BackendKey backend), PersistCore backend, PersistField (BackendKey backend), ToJSON (BackendKey backend), FromJSON (BackendKey backend)) => PersistStoreRead backend where #
Minimal complete definition
Methods
get :: forall (m :: Type -> Type) record. (MonadIO m, PersistRecordBackend record backend) => Key record -> ReaderT backend m (Maybe record) #
getMany :: forall (m :: Type -> Type) record. (MonadIO m, PersistRecordBackend record backend) => [Key record] -> ReaderT backend m (Map (Key record) record) #
class (Show (BackendKey backend), Read (BackendKey backend), Eq (BackendKey backend), Ord (BackendKey backend), PersistStoreRead backend, PersistField (BackendKey backend), ToJSON (BackendKey backend), FromJSON (BackendKey backend)) => PersistStoreWrite backend where #
Methods
insert :: forall (m :: Type -> Type) record. (MonadIO m, PersistRecordBackend record backend) => record -> ReaderT backend m (Key record) #
insert_ :: forall (m :: Type -> Type) record. (MonadIO m, PersistRecordBackend record backend) => record -> ReaderT backend m () #
insertMany :: forall (m :: Type -> Type) record. (MonadIO m, PersistRecordBackend record backend) => [record] -> ReaderT backend m [Key record] #
insertMany_ :: forall (m :: Type -> Type) record. (MonadIO m, PersistRecordBackend record backend) => [record] -> ReaderT backend m () #
insertEntityMany :: forall (m :: Type -> Type) record. (MonadIO m, PersistRecordBackend record backend) => [Entity record] -> ReaderT backend m () #
insertKey :: forall (m :: Type -> Type) record. (MonadIO m, PersistRecordBackend record backend) => Key record -> record -> ReaderT backend m () #
repsert :: forall (m :: Type -> Type) record. (MonadIO m, PersistRecordBackend record backend) => Key record -> record -> ReaderT backend m () #
repsertMany :: forall (m :: Type -> Type) record. (MonadIO m, PersistRecordBackend record backend) => [(Key record, record)] -> ReaderT backend m () #
replace :: forall (m :: Type -> Type) record. (MonadIO m, PersistRecordBackend record backend) => Key record -> record -> ReaderT backend m () #
updateGet :: forall (m :: Type -> Type) record. (MonadIO m, PersistRecordBackend record backend) => Key record -> [Update record] -> ReaderT backend m record #
class (PersistEntity record, PersistEntityBackend record ~ backend, PersistCore backend) => ToBackendKey backend record where #
Methods
toBackendKey :: Key record -> BackendKey backend #
fromBackendKey :: BackendKey backend -> Key record #
class (PersistCore backend, PersistStoreRead backend) => PersistUniqueRead backend where #
class (PersistUniqueRead backend, PersistStoreWrite backend) => PersistUniqueWrite backend where #
Minimal complete definition
Methods
deleteBy :: forall (m :: Type -> Type) record. (MonadIO m, PersistRecordBackend record backend) => Unique record -> ReaderT backend m () #
insertUnique :: forall (m :: Type -> Type) record. (MonadIO m, PersistRecordBackend record backend) => record -> ReaderT backend m (Maybe (Key record)) #
upsert :: forall (m :: Type -> Type) record. (MonadIO m, PersistRecordBackend record backend, OnlyOneUniqueKey record) => record -> [Update record] -> ReaderT backend m (Entity record) #
upsertBy :: forall (m :: Type -> Type) record. (MonadIO m, PersistRecordBackend record backend) => Unique record -> record -> [Update record] -> ReaderT backend m (Entity record) #
putMany :: forall (m :: Type -> Type) record. (MonadIO m, PersistRecordBackend record backend) => [record] -> ReaderT backend m () #
class PersistField a => PersistFieldSql a where #
Instances
Methods
rawSqlCols :: (DBName -> Text) -> a -> (Int, [Text]) #
rawSqlColCountReason :: a -> String #
rawSqlProcessRow :: [PersistValue] -> Either Text a #
Instances
RawSql a => RawSql (Maybe a) | |
Defined in Database.Persist.Sql.Class Methods rawSqlCols :: (DBName -> Text) -> Maybe a -> (Int, [Text]) # rawSqlColCountReason :: Maybe a -> String # rawSqlProcessRow :: [PersistValue] -> Either Text (Maybe a) # | |
(PersistEntity record, PersistEntityBackend record ~ backend, IsPersistBackend backend) => RawSql (Entity record) | |
Defined in Database.Persist.Sql.Class Methods rawSqlCols :: (DBName -> Text) -> Entity record -> (Int, [Text]) # rawSqlColCountReason :: Entity record -> String # rawSqlProcessRow :: [PersistValue] -> Either Text (Entity record) # | |
(PersistEntity a, PersistEntityBackend a ~ backend, IsPersistBackend backend) => RawSql (Key a) | |
Defined in Database.Persist.Sql.Class Methods rawSqlCols :: (DBName -> Text) -> Key a -> (Int, [Text]) # rawSqlColCountReason :: Key a -> String # rawSqlProcessRow :: [PersistValue] -> Either Text (Key a) # | |
PersistField a => RawSql (Single a) | |
Defined in Database.Persist.Sql.Class Methods rawSqlCols :: (DBName -> Text) -> Single a -> (Int, [Text]) # rawSqlColCountReason :: Single a -> String # rawSqlProcessRow :: [PersistValue] -> Either Text (Single a) # | |
(RawSql a, RawSql b) => RawSql (a, b) | |
Defined in Database.Persist.Sql.Class Methods rawSqlCols :: (DBName -> Text) -> (a, b) -> (Int, [Text]) # rawSqlColCountReason :: (a, b) -> String # rawSqlProcessRow :: [PersistValue] -> Either Text (a, b) # | |
(PersistEntity record, KnownSymbol prefix, PersistEntityBackend record ~ backend, IsPersistBackend backend) => RawSql (EntityWithPrefix prefix record) | |
Defined in Database.Persist.Sql.Class Methods rawSqlCols :: (DBName -> Text) -> EntityWithPrefix prefix record -> (Int, [Text]) # rawSqlColCountReason :: EntityWithPrefix prefix record -> String # rawSqlProcessRow :: [PersistValue] -> Either Text (EntityWithPrefix prefix record) # | |
(RawSql a, RawSql b, RawSql c) => RawSql (a, b, c) | |
Defined in Database.Persist.Sql.Class Methods rawSqlCols :: (DBName -> Text) -> (a, b, c) -> (Int, [Text]) # rawSqlColCountReason :: (a, b, c) -> String # rawSqlProcessRow :: [PersistValue] -> Either Text (a, b, c) # | |
(RawSql a, RawSql b, RawSql c, RawSql d) => RawSql (a, b, c, d) | |
Defined in Database.Persist.Sql.Class Methods rawSqlCols :: (DBName -> Text) -> (a, b, c, d) -> (Int, [Text]) # rawSqlColCountReason :: (a, b, c, d) -> String # rawSqlProcessRow :: [PersistValue] -> Either Text (a, b, c, d) # | |
(RawSql a, RawSql b, RawSql c, RawSql d, RawSql e) => RawSql (a, b, c, d, e) | |
Defined in Database.Persist.Sql.Class Methods rawSqlCols :: (DBName -> Text) -> (a, b, c, d, e) -> (Int, [Text]) # rawSqlColCountReason :: (a, b, c, d, e) -> String # rawSqlProcessRow :: [PersistValue] -> Either Text (a, b, c, d, e) # | |
(RawSql a, RawSql b, RawSql c, RawSql d, RawSql e, RawSql f) => RawSql (a, b, c, d, e, f) | |
Defined in Database.Persist.Sql.Class Methods rawSqlCols :: (DBName -> Text) -> (a, b, c, d, e, f) -> (Int, [Text]) # rawSqlColCountReason :: (a, b, c, d, e, f) -> String # rawSqlProcessRow :: [PersistValue] -> Either Text (a, b, c, d, e, f) # | |
(RawSql a, RawSql b, RawSql c, RawSql d, RawSql e, RawSql f, RawSql g) => RawSql (a, b, c, d, e, f, g) | |
Defined in Database.Persist.Sql.Class Methods rawSqlCols :: (DBName -> Text) -> (a, b, c, d, e, f, g) -> (Int, [Text]) # rawSqlColCountReason :: (a, b, c, d, e, f, g) -> String # rawSqlProcessRow :: [PersistValue] -> Either Text (a, b, c, d, e, f, g) # | |
(RawSql a, RawSql b, RawSql c, RawSql d, RawSql e, RawSql f, RawSql g, RawSql h) => RawSql (a, b, c, d, e, f, g, h) | |
Defined in Database.Persist.Sql.Class Methods rawSqlCols :: (DBName -> Text) -> (a, b, c, d, e, f, g, h) -> (Int, [Text]) # rawSqlColCountReason :: (a, b, c, d, e, f, g, h) -> String # rawSqlProcessRow :: [PersistValue] -> Either Text (a, b, c, d, e, f, g, h) # | |
(RawSql a, RawSql b, RawSql c, RawSql d, RawSql e, RawSql f, RawSql g, RawSql h, RawSql i) => RawSql (a, b, c, d, e, f, g, h, i) | |
Defined in Database.Persist.Sql.Class Methods rawSqlCols :: (DBName -> Text) -> (a, b, c, d, e, f, g, h, i) -> (Int, [Text]) # rawSqlColCountReason :: (a, b, c, d, e, f, g, h, i) -> String # rawSqlProcessRow :: [PersistValue] -> Either Text (a, b, c, d, e, f, g, h, i) # | |
(RawSql a, RawSql b, RawSql c, RawSql d, RawSql e, RawSql f, RawSql g, RawSql h, RawSql i, RawSql j) => RawSql (a, b, c, d, e, f, g, h, i, j) | |
Defined in Database.Persist.Sql.Class Methods rawSqlCols :: (DBName -> Text) -> (a, b, c, d, e, f, g, h, i, j) -> (Int, [Text]) # rawSqlColCountReason :: (a, b, c, d, e, f, g, h, i, j) -> String # rawSqlProcessRow :: [PersistValue] -> Either Text (a, b, c, d, e, f, g, h, i, j) # | |
(RawSql a, RawSql b, RawSql c, RawSql d, RawSql e, RawSql f, RawSql g, RawSql h, RawSql i, RawSql j, RawSql k) => RawSql (a, b, c, d, e, f, g, h, i, j, k) | |
Defined in Database.Persist.Sql.Class Methods rawSqlCols :: (DBName -> Text) -> (a, b, c, d, e, f, g, h, i, j, k) -> (Int, [Text]) # rawSqlColCountReason :: (a, b, c, d, e, f, g, h, i, j, k) -> String # rawSqlProcessRow :: [PersistValue] -> Either Text (a, b, c, d, e, f, g, h, i, j, k) # | |
(RawSql a, RawSql b, RawSql c, RawSql d, RawSql e, RawSql f, RawSql g, RawSql h, RawSql i, RawSql j, RawSql k, RawSql l) => RawSql (a, b, c, d, e, f, g, h, i, j, k, l) | |
Defined in Database.Persist.Sql.Class Methods rawSqlCols :: (DBName -> Text) -> (a, b, c, d, e, f, g, h, i, j, k, l) -> (Int, [Text]) # rawSqlColCountReason :: (a, b, c, d, e, f, g, h, i, j, k, l) -> String # rawSqlProcessRow :: [PersistValue] -> Either Text (a, b, c, d, e, f, g, h, i, j, k, l) # |
type CautiousMigration = [(Bool, Sql)] #
type ConnectionPool = Pool SqlBackend #
type Migration = WriterT [Text] (WriterT CautiousMigration (ReaderT SqlBackend IO)) () #
data PersistentSqlException #
Constructors
StatementAlreadyFinalized Text | |
Couldn'tGetSQLConnection |
Instances
Show PersistentSqlException | |
Defined in Database.Persist.Sql.Types Methods showsPrec :: Int -> PersistentSqlException -> ShowS show :: PersistentSqlException -> String showList :: [PersistentSqlException] -> ShowS | |
Exception PersistentSqlException | |
Defined in Database.Persist.Sql.Types Methods toException :: PersistentSqlException -> SomeException # fromException :: SomeException -> Maybe PersistentSqlException # displayException :: PersistentSqlException -> String # |
Instances
Eq a => Eq (Single a) | |
Ord a => Ord (Single a) | |
Defined in Database.Persist.Sql.Types | |
Read a => Read (Single a) | |
Defined in Database.Persist.Sql.Types | |
Show a => Show (Single a) | |
PersistField a => RawSql (Single a) | |
Defined in Database.Persist.Sql.Class Methods rawSqlCols :: (DBName -> Text) -> Single a -> (Int, [Text]) # rawSqlColCountReason :: Single a -> String # rawSqlProcessRow :: [PersistValue] -> Either Text (Single a) # |
type SqlPersistM = SqlPersistT (NoLoggingT (ResourceT IO)) #
type SqlPersistT = ReaderT SqlBackend #
data InsertSqlResult #
Constructors
ISRSingle Text | |
ISRInsertGet Text Text | |
ISRManyKeys Text [PersistValue] |
type IsSqlBackend backend = (IsPersistBackend backend, BaseBackend backend ~ SqlBackend) #
data SqlBackend #
Constructors
SqlBackend | |
Fields
|
Instances
HasPersistBackend SqlBackend | |
Defined in Database.Persist.Sql.Types.Internal Associated Types type BaseBackend SqlBackend # Methods | |
IsPersistBackend SqlBackend | |
Defined in Database.Persist.Sql.Types.Internal Methods | |
newtype BackendKey SqlBackend | |
Defined in Database.Persist.Sql.Orphan.PersistStore | |
type BaseBackend SqlBackend | |
Defined in Database.Persist.Sql.Types.Internal |
type SqlBackendCanRead backend = (BackendCompatible SqlBackend backend, PersistQueryRead backend, PersistStoreRead backend, PersistUniqueRead backend) #
type SqlBackendCanWrite backend = (SqlBackendCanRead backend, PersistQueryWrite backend, PersistStoreWrite backend, PersistUniqueWrite backend) #
newtype SqlReadBackend #
Constructors
SqlReadBackend | |
Fields |
Instances
HasPersistBackend SqlReadBackend | |
Defined in Database.Persist.Sql.Types.Internal Associated Types type BaseBackend SqlReadBackend # Methods persistBackend :: SqlReadBackend -> BaseBackend SqlReadBackend # | |
IsPersistBackend SqlReadBackend | |
Defined in Database.Persist.Sql.Types.Internal Methods mkPersistBackend :: BaseBackend SqlReadBackend -> SqlReadBackend | |
newtype BackendKey SqlReadBackend | |
Defined in Database.Persist.Sql.Orphan.PersistStore | |
type BaseBackend SqlReadBackend | |
Defined in Database.Persist.Sql.Types.Internal |
type SqlReadT (m :: Type -> Type) a = forall backend. SqlBackendCanRead backend => ReaderT backend m a #
newtype SqlWriteBackend #
Constructors
SqlWriteBackend | |
Fields |
Instances
HasPersistBackend SqlWriteBackend | |
Defined in Database.Persist.Sql.Types.Internal Associated Types type BaseBackend SqlWriteBackend # Methods persistBackend :: SqlWriteBackend -> BaseBackend SqlWriteBackend # | |
IsPersistBackend SqlWriteBackend | |
Defined in Database.Persist.Sql.Types.Internal Methods mkPersistBackend :: BaseBackend SqlWriteBackend -> SqlWriteBackend | |
newtype BackendKey SqlWriteBackend | |
Defined in Database.Persist.Sql.Orphan.PersistStore | |
type BaseBackend SqlWriteBackend | |
Defined in Database.Persist.Sql.Types.Internal |
type SqlWriteT (m :: Type -> Type) a = forall backend. SqlBackendCanWrite backend => ReaderT backend m a #
Constructors
Statement | |
Fields
|
Instances
Bounded Checkmark | |
Defined in Database.Persist.Types.Base | |
Enum Checkmark | |
Defined in Database.Persist.Types.Base | |
Eq Checkmark | |
Ord Checkmark | |
Defined in Database.Persist.Types.Base | |
Read Checkmark | |
Defined in Database.Persist.Types.Base | |
Show Checkmark | |
PersistField Checkmark | |
Defined in Database.Persist.Class.PersistField Methods toPersistValue :: Checkmark -> PersistValue # fromPersistValue :: PersistValue -> Either Text Checkmark # | |
PersistFieldSql Checkmark | |
Defined in Database.Persist.Sql.Class | |
FromHttpApiData Checkmark | |
Defined in Database.Persist.Types.Base Methods parseUrlPiece :: Text -> Either Text Checkmark parseHeader :: ByteString -> Either Text Checkmark parseQueryParam :: Text -> Either Text Checkmark | |
PathPiece Checkmark | |
Defined in Database.Persist.Types.Base | |
ToHttpApiData Checkmark | |
Defined in Database.Persist.Types.Base Methods toUrlPiece :: Checkmark -> Text toEncodedUrlPiece :: Checkmark -> Builder toHeader :: Checkmark -> ByteString toQueryParam :: Checkmark -> Text |
data CompositeDef #
Constructors
CompositeDef | |
Fields
|
Instances
Eq CompositeDef | |
Defined in Database.Persist.Types.Base | |
Ord CompositeDef | |
Defined in Database.Persist.Types.Base Methods compare :: CompositeDef -> CompositeDef -> Ordering (<) :: CompositeDef -> CompositeDef -> Bool (<=) :: CompositeDef -> CompositeDef -> Bool (>) :: CompositeDef -> CompositeDef -> Bool (>=) :: CompositeDef -> CompositeDef -> Bool max :: CompositeDef -> CompositeDef -> CompositeDef min :: CompositeDef -> CompositeDef -> CompositeDef | |
Read CompositeDef | |
Defined in Database.Persist.Types.Base Methods readsPrec :: Int -> ReadS CompositeDef readList :: ReadS [CompositeDef] readPrec :: ReadPrec CompositeDef readListPrec :: ReadPrec [CompositeDef] | |
Show CompositeDef | |
Defined in Database.Persist.Types.Base Methods showsPrec :: Int -> CompositeDef -> ShowS show :: CompositeDef -> String showList :: [CompositeDef] -> ShowS |
Instances
Eq DBName | |
Ord DBName | |
Read DBName | |
Defined in Database.Persist.Types.Base | |
Show DBName | |
data EmbedEntityDef #
Constructors
EmbedEntityDef | |
Fields |
Instances
Eq EmbedEntityDef | |
Defined in Database.Persist.Types.Base Methods (==) :: EmbedEntityDef -> EmbedEntityDef -> Bool (/=) :: EmbedEntityDef -> EmbedEntityDef -> Bool | |
Ord EmbedEntityDef | |
Defined in Database.Persist.Types.Base Methods compare :: EmbedEntityDef -> EmbedEntityDef -> Ordering (<) :: EmbedEntityDef -> EmbedEntityDef -> Bool (<=) :: EmbedEntityDef -> EmbedEntityDef -> Bool (>) :: EmbedEntityDef -> EmbedEntityDef -> Bool (>=) :: EmbedEntityDef -> EmbedEntityDef -> Bool max :: EmbedEntityDef -> EmbedEntityDef -> EmbedEntityDef min :: EmbedEntityDef -> EmbedEntityDef -> EmbedEntityDef | |
Read EmbedEntityDef | |
Defined in Database.Persist.Types.Base Methods readsPrec :: Int -> ReadS EmbedEntityDef readList :: ReadS [EmbedEntityDef] readPrec :: ReadPrec EmbedEntityDef readListPrec :: ReadPrec [EmbedEntityDef] | |
Show EmbedEntityDef | |
Defined in Database.Persist.Types.Base Methods showsPrec :: Int -> EmbedEntityDef -> ShowS show :: EmbedEntityDef -> String showList :: [EmbedEntityDef] -> ShowS |
data EmbedFieldDef #
Constructors
EmbedFieldDef | |
Fields
|
Instances
Eq EmbedFieldDef | |
Defined in Database.Persist.Types.Base | |
Ord EmbedFieldDef | |
Defined in Database.Persist.Types.Base Methods compare :: EmbedFieldDef -> EmbedFieldDef -> Ordering (<) :: EmbedFieldDef -> EmbedFieldDef -> Bool (<=) :: EmbedFieldDef -> EmbedFieldDef -> Bool (>) :: EmbedFieldDef -> EmbedFieldDef -> Bool (>=) :: EmbedFieldDef -> EmbedFieldDef -> Bool max :: EmbedFieldDef -> EmbedFieldDef -> EmbedFieldDef min :: EmbedFieldDef -> EmbedFieldDef -> EmbedFieldDef | |
Read EmbedFieldDef | |
Defined in Database.Persist.Types.Base Methods readsPrec :: Int -> ReadS EmbedFieldDef readList :: ReadS [EmbedFieldDef] readPrec :: ReadPrec EmbedFieldDef readListPrec :: ReadPrec [EmbedFieldDef] | |
Show EmbedFieldDef | |
Defined in Database.Persist.Types.Base Methods showsPrec :: Int -> EmbedFieldDef -> ShowS show :: EmbedFieldDef -> String showList :: [EmbedFieldDef] -> ShowS |
Constructors
EntityDef | |
Fields
|
Instances
Eq EntityDef | |
Ord EntityDef | |
Defined in Database.Persist.Types.Base | |
Read EntityDef | |
Defined in Database.Persist.Types.Base | |
Show EntityDef | |
Constructors
FieldDef | |
Fields
|
Instances
Eq FieldDef | |
Ord FieldDef | |
Defined in Database.Persist.Types.Base | |
Read FieldDef | |
Defined in Database.Persist.Types.Base | |
Show FieldDef | |
Instances
Eq FieldType | |
Ord FieldType | |
Defined in Database.Persist.Types.Base | |
Read FieldType | |
Defined in Database.Persist.Types.Base | |
Show FieldType | |
data ForeignDef #
Constructors
ForeignDef | |
Fields
|
Instances
Eq ForeignDef | |
Defined in Database.Persist.Types.Base | |
Ord ForeignDef | |
Defined in Database.Persist.Types.Base Methods compare :: ForeignDef -> ForeignDef -> Ordering (<) :: ForeignDef -> ForeignDef -> Bool (<=) :: ForeignDef -> ForeignDef -> Bool (>) :: ForeignDef -> ForeignDef -> Bool (>=) :: ForeignDef -> ForeignDef -> Bool max :: ForeignDef -> ForeignDef -> ForeignDef min :: ForeignDef -> ForeignDef -> ForeignDef | |
Read ForeignDef | |
Defined in Database.Persist.Types.Base Methods readsPrec :: Int -> ReadS ForeignDef readList :: ReadS [ForeignDef] readPrec :: ReadPrec ForeignDef readListPrec :: ReadPrec [ForeignDef] | |
Show ForeignDef | |
Defined in Database.Persist.Types.Base Methods showsPrec :: Int -> ForeignDef -> ShowS show :: ForeignDef -> String showList :: [ForeignDef] -> ShowS |
type ForeignFieldDef = (HaskellName, DBName) #
newtype HaskellName #
Constructors
HaskellName | |
Fields
|
Instances
Eq HaskellName | |
Defined in Database.Persist.Types.Base | |
Ord HaskellName | |
Defined in Database.Persist.Types.Base Methods compare :: HaskellName -> HaskellName -> Ordering (<) :: HaskellName -> HaskellName -> Bool (<=) :: HaskellName -> HaskellName -> Bool (>) :: HaskellName -> HaskellName -> Bool (>=) :: HaskellName -> HaskellName -> Bool max :: HaskellName -> HaskellName -> HaskellName min :: HaskellName -> HaskellName -> HaskellName | |
Read HaskellName | |
Defined in Database.Persist.Types.Base Methods readsPrec :: Int -> ReadS HaskellName readList :: ReadS [HaskellName] readPrec :: ReadPrec HaskellName readListPrec :: ReadPrec [HaskellName] | |
Show HaskellName | |
Defined in Database.Persist.Types.Base Methods showsPrec :: Int -> HaskellName -> ShowS show :: HaskellName -> String showList :: [HaskellName] -> ShowS |
data IsNullable #
Constructors
Nullable !WhyNullable | |
NotNullable |
Instances
Eq IsNullable | |
Defined in Database.Persist.Types.Base | |
Show IsNullable | |
Defined in Database.Persist.Types.Base Methods showsPrec :: Int -> IsNullable -> ShowS show :: IsNullable -> String showList :: [IsNullable] -> ShowS |
data OnlyUniqueException #
Constructors
OnlyUniqueException String |
Instances
Show OnlyUniqueException | |
Defined in Database.Persist.Types.Base Methods showsPrec :: Int -> OnlyUniqueException -> ShowS show :: OnlyUniqueException -> String showList :: [OnlyUniqueException] -> ShowS | |
Exception OnlyUniqueException | |
Defined in Database.Persist.Types.Base Methods toException :: OnlyUniqueException -> SomeException # fromException :: SomeException -> Maybe OnlyUniqueException # displayException :: OnlyUniqueException -> String # |
data PersistException #
Constructors
PersistError Text | |
PersistMarshalError Text | |
PersistInvalidField Text | |
PersistForeignConstraintUnmet Text | |
PersistMongoDBError Text | |
PersistMongoDBUnsupported Text |
Instances
Show PersistException | |
Defined in Database.Persist.Types.Base Methods showsPrec :: Int -> PersistException -> ShowS show :: PersistException -> String showList :: [PersistException] -> ShowS | |
Exception PersistException | |
Defined in Database.Persist.Types.Base Methods toException :: PersistException -> SomeException # fromException :: SomeException -> Maybe PersistException # displayException :: PersistException -> String # | |
Error PersistException | |
Defined in Database.Persist.Types.Base |
data PersistFilter #
Instances
Read PersistFilter | |
Defined in Database.Persist.Types.Base Methods readsPrec :: Int -> ReadS PersistFilter readList :: ReadS [PersistFilter] readPrec :: ReadPrec PersistFilter readListPrec :: ReadPrec [PersistFilter] | |
Show PersistFilter | |
Defined in Database.Persist.Types.Base Methods showsPrec :: Int -> PersistFilter -> ShowS show :: PersistFilter -> String showList :: [PersistFilter] -> ShowS |
data PersistUpdate #
Instances
Read PersistUpdate | |
Defined in Database.Persist.Types.Base Methods readsPrec :: Int -> ReadS PersistUpdate readList :: ReadS [PersistUpdate] readPrec :: ReadPrec PersistUpdate readListPrec :: ReadPrec [PersistUpdate] | |
Show PersistUpdate | |
Defined in Database.Persist.Types.Base Methods showsPrec :: Int -> PersistUpdate -> ShowS show :: PersistUpdate -> String showList :: [PersistUpdate] -> ShowS |
data PersistValue #
Constructors
PersistText Text | |
PersistByteString ByteString | |
PersistInt64 Int64 | |
PersistDouble Double | |
PersistRational Rational | |
PersistBool Bool | |
PersistDay Day | |
PersistTimeOfDay TimeOfDay | |
PersistUTCTime UTCTime | |
PersistNull | |
PersistList [PersistValue] | |
PersistMap [(Text, PersistValue)] | |
PersistObjectId ByteString | |
PersistArray [PersistValue] | |
PersistDbSpecific ByteString |
Instances
data ReferenceDef #
Constructors
NoReference | |
ForeignRef !HaskellName !FieldType | |
EmbedRef EmbedEntityDef | |
CompositeRef CompositeDef | |
SelfReference |
Instances
Eq ReferenceDef | |
Defined in Database.Persist.Types.Base | |
Ord ReferenceDef | |
Defined in Database.Persist.Types.Base Methods compare :: ReferenceDef -> ReferenceDef -> Ordering (<) :: ReferenceDef -> ReferenceDef -> Bool (<=) :: ReferenceDef -> ReferenceDef -> Bool (>) :: ReferenceDef -> ReferenceDef -> Bool (>=) :: ReferenceDef -> ReferenceDef -> Bool max :: ReferenceDef -> ReferenceDef -> ReferenceDef min :: ReferenceDef -> ReferenceDef -> ReferenceDef | |
Read ReferenceDef | |
Defined in Database.Persist.Types.Base Methods readsPrec :: Int -> ReadS ReferenceDef readList :: ReadS [ReferenceDef] readPrec :: ReadPrec ReferenceDef readListPrec :: ReadPrec [ReferenceDef] | |
Show ReferenceDef | |
Defined in Database.Persist.Types.Base Methods showsPrec :: Int -> ReferenceDef -> ShowS show :: ReferenceDef -> String showList :: [ReferenceDef] -> ShowS |
Constructors
SqlString | |
SqlInt32 | |
SqlInt64 | |
SqlReal | |
SqlNumeric Word32 Word32 | |
SqlBool | |
SqlDay | |
SqlTime | |
SqlDayTime | |
SqlBlob | |
SqlOther Text |
Instances
Eq SqlType | |
Ord SqlType | |
Read SqlType | |
Defined in Database.Persist.Types.Base | |
Show SqlType | |
Constructors
UniqueDef | |
Fields
|
Instances
Eq UniqueDef | |
Ord UniqueDef | |
Defined in Database.Persist.Types.Base | |
Read UniqueDef | |
Defined in Database.Persist.Types.Base | |
Show UniqueDef | |
data UpdateException #
Constructors
KeyNotFound String | |
UpsertError String |
Instances
Show UpdateException | |
Defined in Database.Persist.Types.Base Methods showsPrec :: Int -> UpdateException -> ShowS show :: UpdateException -> String showList :: [UpdateException] -> ShowS | |
Exception UpdateException | |
Defined in Database.Persist.Types.Base Methods toException :: UpdateException -> SomeException # fromException :: SomeException -> Maybe UpdateException # displayException :: UpdateException -> String # |
data WhyNullable #
Constructors
ByMaybeAttr | |
ByNullableAttr |
Instances
Eq WhyNullable | |
Defined in Database.Persist.Types.Base | |
Show WhyNullable | |
Defined in Database.Persist.Types.Base Methods showsPrec :: Int -> WhyNullable -> ShowS show :: WhyNullable -> String showList :: [WhyNullable] -> ShowS |