-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Monad transformer for the persistent API -- -- A monad transformer and mtl-style type class for using the persistent -- API directly in your monad transformer stack. @package persistent-mtl @version 0.5.1 -- | Defines the MonadRerunnableIO type class that is functionally -- equivalent to MonadIO, but use of it requires the user to -- explicitly acknowledge that the given IO operation can be rerun. module Control.Monad.IO.Rerunnable -- | A copy of MonadIO to explicitly allow only IO operations that -- are rerunnable, e.g. in the context of a SQL transaction. class (Monad m) => MonadRerunnableIO m -- | Lift the given IO operation to m. -- -- The given IO operation may be rerun, so use of this function requires -- manually verifying that the given IO operation is rerunnable. rerunnableIO :: MonadRerunnableIO m => IO a -> m a instance Control.Monad.IO.Rerunnable.MonadRerunnableIO GHC.Types.IO instance Control.Monad.IO.Rerunnable.MonadRerunnableIO m => Control.Monad.IO.Rerunnable.MonadRerunnableIO (Control.Monad.Trans.Reader.ReaderT r m) instance Control.Monad.IO.Rerunnable.MonadRerunnableIO m => Control.Monad.IO.Rerunnable.MonadRerunnableIO (Control.Monad.Trans.Except.ExceptT e m) instance Control.Monad.IO.Rerunnable.MonadRerunnableIO m => Control.Monad.IO.Rerunnable.MonadRerunnableIO (Control.Monad.Trans.Identity.IdentityT m) instance Control.Monad.IO.Rerunnable.MonadRerunnableIO m => Control.Monad.IO.Rerunnable.MonadRerunnableIO (Control.Monad.Trans.Maybe.MaybeT m) instance (GHC.Base.Monoid w, Control.Monad.IO.Rerunnable.MonadRerunnableIO m) => Control.Monad.IO.Rerunnable.MonadRerunnableIO (Control.Monad.Trans.RWS.Lazy.RWST r w s m) instance (GHC.Base.Monoid w, Control.Monad.IO.Rerunnable.MonadRerunnableIO m) => Control.Monad.IO.Rerunnable.MonadRerunnableIO (Control.Monad.Trans.RWS.Strict.RWST r w s m) instance Control.Monad.IO.Rerunnable.MonadRerunnableIO m => Control.Monad.IO.Rerunnable.MonadRerunnableIO (Control.Monad.Trans.State.Lazy.StateT s m) instance Control.Monad.IO.Rerunnable.MonadRerunnableIO m => Control.Monad.IO.Rerunnable.MonadRerunnableIO (Control.Monad.Trans.State.Strict.StateT s m) instance (GHC.Base.Monoid w, Control.Monad.IO.Rerunnable.MonadRerunnableIO m) => Control.Monad.IO.Rerunnable.MonadRerunnableIO (Control.Monad.Trans.Writer.Lazy.WriterT w m) instance (GHC.Base.Monoid w, Control.Monad.IO.Rerunnable.MonadRerunnableIO m) => Control.Monad.IO.Rerunnable.MonadRerunnableIO (Control.Monad.Trans.Writer.Strict.WriterT w m) instance Control.Monad.IO.Rerunnable.MonadRerunnableIO m => Control.Monad.IO.Rerunnable.MonadRerunnableIO (Control.Monad.Trans.Resource.Internal.ResourceT m) -- | Defines the MonadRerunnableTrans type class that is -- functionally equivalent to MonadTrans, but use of it requires -- the user to explicitly acknowledge that lifting the given action can -- be rerun. module Control.Monad.Trans.Rerunnable -- | A copy of MonadTrans to explicitly allow only lifting actions -- that are rerunnable, e.g. in the context of a SQL transaction. class MonadRerunnableTrans t -- | Lift the given action. -- -- The given action may be rerun, so use of this function requires -- manually verifying that the given action is rerunnable. rerunnableLift :: (MonadRerunnableTrans t, Monad m) => m a -> t m a instance Control.Monad.Trans.Rerunnable.MonadRerunnableTrans (Control.Monad.Trans.Reader.ReaderT r) instance Control.Monad.Trans.Rerunnable.MonadRerunnableTrans (Control.Monad.Trans.Except.ExceptT e) instance Control.Monad.Trans.Rerunnable.MonadRerunnableTrans Control.Monad.Trans.Identity.IdentityT instance Control.Monad.Trans.Rerunnable.MonadRerunnableTrans Control.Monad.Trans.Maybe.MaybeT instance GHC.Base.Monoid w => Control.Monad.Trans.Rerunnable.MonadRerunnableTrans (Control.Monad.Trans.RWS.Lazy.RWST r w s) instance GHC.Base.Monoid w => Control.Monad.Trans.Rerunnable.MonadRerunnableTrans (Control.Monad.Trans.RWS.Strict.RWST r w s) instance Control.Monad.Trans.Rerunnable.MonadRerunnableTrans (Control.Monad.Trans.State.Lazy.StateT s) instance Control.Monad.Trans.Rerunnable.MonadRerunnableTrans (Control.Monad.Trans.State.Strict.StateT s) instance GHC.Base.Monoid w => Control.Monad.Trans.Rerunnable.MonadRerunnableTrans (Control.Monad.Trans.Writer.Lazy.WriterT w) instance GHC.Base.Monoid w => Control.Monad.Trans.Rerunnable.MonadRerunnableTrans (Control.Monad.Trans.Writer.Strict.WriterT w) instance Control.Monad.Trans.Rerunnable.MonadRerunnableTrans Control.Monad.Trans.Resource.Internal.ResourceT module Database.Persist.Monad.Internal.PersistentShim -- | A type class which is used to witness that a type is safe to insert -- into the database without providing a primary key. -- -- The TemplateHaskell function mkPersist will generate -- instances of this class for any entity that it works on. If the entity -- has a default primary key, then it provides a regular instance. If the -- entity has a Primary natural key, then this works fine. But -- if the entity has an Id column with no default=, -- then this does a TypeError and forces the user to use -- insertKey. class SafeToInsert a -- | Defines the SqlQueryRep data type that contains a constructor -- corresponding to a persistent function. -- -- This file is autogenerated, to keep it in sync with -- Database.Persist.Monad.Shim. module Database.Persist.Monad.SqlQueryRep -- | The data type containing a constructor for each persistent function -- we'd like to lift into MonadSqlQuery. -- -- The record type parameter contains the PersistEntity -- types used in a given function. -- -- We're using a free-monads-like technique here to allow us to -- introspect persistent functions in MonadSqlQuery, e.g. to mock -- out persistent calls in tests. data SqlQueryRep record a -- | Constructor corresponding to get [Get] :: PersistRecordBackend record SqlBackend => Key record -> SqlQueryRep record (Maybe record) -- | Constructor corresponding to getMany [GetMany] :: PersistRecordBackend record SqlBackend => [Key record] -> SqlQueryRep record (Map (Key record) record) -- | Constructor corresponding to getJust [GetJust] :: PersistRecordBackend record SqlBackend => Key record -> SqlQueryRep record record -- | Constructor corresponding to getJustEntity [GetJustEntity] :: PersistRecordBackend record SqlBackend => Key record -> SqlQueryRep record (Entity record) -- | Constructor corresponding to getEntity [GetEntity] :: PersistRecordBackend record SqlBackend => Key record -> SqlQueryRep record (Maybe (Entity record)) -- | Constructor corresponding to belongsTo [BelongsTo] :: (PersistEntity record1, PersistRecordBackend record2 SqlBackend) => (record1 -> Maybe (Key record2)) -> record1 -> SqlQueryRep (record1, record2) (Maybe record2) -- | Constructor corresponding to belongsToJust [BelongsToJust] :: (PersistEntity record1, PersistRecordBackend record2 SqlBackend) => (record1 -> Key record2) -> record1 -> SqlQueryRep (record1, record2) record2 -- | Constructor corresponding to insert [Insert] :: (PersistRecordBackend record SqlBackend, SafeToInsert record) => record -> SqlQueryRep record (Key record) -- | Constructor corresponding to insert_ [Insert_] :: (PersistRecordBackend record SqlBackend, SafeToInsert record) => record -> SqlQueryRep record () -- | Constructor corresponding to insertMany [InsertMany] :: (PersistRecordBackend record SqlBackend, SafeToInsert record) => [record] -> SqlQueryRep record [Key record] -- | Constructor corresponding to insertMany_ [InsertMany_] :: (PersistRecordBackend record SqlBackend, SafeToInsert record) => [record] -> SqlQueryRep record () -- | Constructor corresponding to insertEntityMany [InsertEntityMany] :: PersistRecordBackend record SqlBackend => [Entity record] -> SqlQueryRep record () -- | Constructor corresponding to insertKey [InsertKey] :: PersistRecordBackend record SqlBackend => Key record -> record -> SqlQueryRep record () -- | Constructor corresponding to repsert [Repsert] :: PersistRecordBackend record SqlBackend => Key record -> record -> SqlQueryRep record () -- | Constructor corresponding to repsertMany [RepsertMany] :: PersistRecordBackend record SqlBackend => [(Key record, record)] -> SqlQueryRep record () -- | Constructor corresponding to replace [Replace] :: PersistRecordBackend record SqlBackend => Key record -> record -> SqlQueryRep record () -- | Constructor corresponding to delete [Delete] :: PersistRecordBackend record SqlBackend => Key record -> SqlQueryRep record () -- | Constructor corresponding to update [Update] :: PersistRecordBackend record SqlBackend => Key record -> [Update record] -> SqlQueryRep record () -- | Constructor corresponding to updateGet [UpdateGet] :: PersistRecordBackend record SqlBackend => Key record -> [Update record] -> SqlQueryRep record record -- | Constructor corresponding to insertEntity [InsertEntity] :: (PersistRecordBackend record SqlBackend, SafeToInsert record) => record -> SqlQueryRep record (Entity record) -- | Constructor corresponding to insertRecord [InsertRecord] :: (PersistRecordBackend record SqlBackend, SafeToInsert record) => record -> SqlQueryRep record record -- | Constructor corresponding to getBy [GetBy] :: PersistRecordBackend record SqlBackend => Unique record -> SqlQueryRep record (Maybe (Entity record)) -- | Constructor corresponding to getByValue [GetByValue] :: (PersistRecordBackend record SqlBackend, AtLeastOneUniqueKey record) => record -> SqlQueryRep record (Maybe (Entity record)) -- | Constructor corresponding to checkUnique [CheckUnique] :: PersistRecordBackend record SqlBackend => record -> SqlQueryRep record (Maybe (Unique record)) -- | Constructor corresponding to checkUniqueUpdateable [CheckUniqueUpdateable] :: PersistRecordBackend record SqlBackend => Entity record -> SqlQueryRep record (Maybe (Unique record)) -- | Constructor corresponding to deleteBy [DeleteBy] :: PersistRecordBackend record SqlBackend => Unique record -> SqlQueryRep record () -- | Constructor corresponding to insertUnique [InsertUnique] :: (PersistRecordBackend record SqlBackend, SafeToInsert record) => record -> SqlQueryRep record (Maybe (Key record)) -- | Constructor corresponding to upsert [Upsert] :: (PersistRecordBackend record SqlBackend, OnlyOneUniqueKey record, SafeToInsert record) => record -> [Update record] -> SqlQueryRep record (Entity record) -- | Constructor corresponding to upsertBy [UpsertBy] :: (PersistRecordBackend record SqlBackend, SafeToInsert record) => Unique record -> record -> [Update record] -> SqlQueryRep record (Entity record) -- | Constructor corresponding to putMany [PutMany] :: (PersistRecordBackend record SqlBackend, SafeToInsert record) => [record] -> SqlQueryRep record () -- | Constructor corresponding to insertBy [InsertBy] :: (PersistRecordBackend record SqlBackend, AtLeastOneUniqueKey record, SafeToInsert record) => record -> SqlQueryRep record (Either (Entity record) (Key record)) -- | Constructor corresponding to insertUniqueEntity [InsertUniqueEntity] :: (PersistRecordBackend record SqlBackend, SafeToInsert record) => record -> SqlQueryRep record (Maybe (Entity record)) -- | Constructor corresponding to replaceUnique [ReplaceUnique] :: (PersistRecordBackend record SqlBackend, Eq (Unique record), Eq record) => Key record -> record -> SqlQueryRep record (Maybe (Unique record)) -- | Constructor corresponding to onlyUnique [OnlyUnique] :: (PersistRecordBackend record SqlBackend, OnlyOneUniqueKey record) => record -> SqlQueryRep record (Unique record) -- | Constructor corresponding to selectSourceRes [SelectSourceRes] :: (MonadIO m2, PersistRecordBackend record SqlBackend) => [Filter record] -> [SelectOpt record] -> SqlQueryRep record (Acquire (ConduitM () (Entity record) m2 ())) -- | Constructor corresponding to selectFirst [SelectFirst] :: PersistRecordBackend record SqlBackend => [Filter record] -> [SelectOpt record] -> SqlQueryRep record (Maybe (Entity record)) -- | Constructor corresponding to selectKeysRes [SelectKeysRes] :: (MonadIO m2, PersistRecordBackend record SqlBackend) => [Filter record] -> [SelectOpt record] -> SqlQueryRep record (Acquire (ConduitM () (Key record) m2 ())) -- | Constructor corresponding to count [Count] :: PersistRecordBackend record SqlBackend => [Filter record] -> SqlQueryRep record Int -- | Constructor corresponding to exists [Exists] :: PersistRecordBackend record SqlBackend => [Filter record] -> SqlQueryRep record Bool -- | Constructor corresponding to selectList [SelectList] :: PersistRecordBackend record SqlBackend => [Filter record] -> [SelectOpt record] -> SqlQueryRep record [Entity record] -- | Constructor corresponding to selectKeysList [SelectKeysList] :: PersistRecordBackend record SqlBackend => [Filter record] -> [SelectOpt record] -> SqlQueryRep record [Key record] -- | Constructor corresponding to updateWhere [UpdateWhere] :: PersistRecordBackend record SqlBackend => [Filter record] -> [Update record] -> SqlQueryRep record () -- | Constructor corresponding to deleteWhere [DeleteWhere] :: PersistRecordBackend record SqlBackend => [Filter record] -> SqlQueryRep record () -- | Constructor corresponding to deleteWhereCount [DeleteWhereCount] :: PersistRecordBackend record SqlBackend => [Filter record] -> SqlQueryRep record Int64 -- | Constructor corresponding to updateWhereCount [UpdateWhereCount] :: PersistRecordBackend record SqlBackend => [Filter record] -> [Update record] -> SqlQueryRep record Int64 -- | Constructor corresponding to parseMigration [ParseMigration] :: HasCallStack => Migration -> SqlQueryRep Void (Either [Text] CautiousMigration) -- | Constructor corresponding to parseMigration' [ParseMigration'] :: HasCallStack => Migration -> SqlQueryRep Void CautiousMigration -- | Constructor corresponding to printMigration [PrintMigration] :: HasCallStack => Migration -> SqlQueryRep Void () -- | Constructor corresponding to showMigration [ShowMigration] :: HasCallStack => Migration -> SqlQueryRep Void [Text] -- | Constructor corresponding to getMigration [GetMigration] :: HasCallStack => Migration -> SqlQueryRep Void [Sql] -- | Constructor corresponding to runMigration [RunMigration] :: () => Migration -> SqlQueryRep Void () -- | Constructor corresponding to runMigrationQuiet [RunMigrationQuiet] :: () => Migration -> SqlQueryRep Void [Text] -- | Constructor corresponding to runMigrationSilent [RunMigrationSilent] :: () => Migration -> SqlQueryRep Void [Text] -- | Constructor corresponding to runMigrationUnsafe [RunMigrationUnsafe] :: () => Migration -> SqlQueryRep Void () -- | Constructor corresponding to runMigrationUnsafeQuiet [RunMigrationUnsafeQuiet] :: HasCallStack => Migration -> SqlQueryRep Void [Text] -- | Constructor corresponding to getFieldName [GetFieldName] :: PersistRecordBackend record SqlBackend => EntityField record typ -> SqlQueryRep record Text -- | Constructor corresponding to getTableName [GetTableName] :: PersistRecordBackend record SqlBackend => record -> SqlQueryRep record Text -- | Constructor corresponding to withRawQuery [WithRawQuery] :: () => Text -> [PersistValue] -> ConduitM [PersistValue] Void IO a -> SqlQueryRep Void a -- | Constructor corresponding to rawQueryRes [RawQueryRes] :: MonadIO m2 => Text -> [PersistValue] -> SqlQueryRep Void (Acquire (ConduitM () [PersistValue] m2 ())) -- | Constructor corresponding to rawExecute [RawExecute] :: () => Text -> [PersistValue] -> SqlQueryRep Void () -- | Constructor corresponding to rawExecuteCount [RawExecuteCount] :: () => Text -> [PersistValue] -> SqlQueryRep Void Int64 -- | Constructor corresponding to rawSql [RawSql] :: RawSql a => Text -> [PersistValue] -> SqlQueryRep Void [a] -- | Constructor corresponding to transactionSave [TransactionSave] :: () => SqlQueryRep Void () -- | Constructor corresponding to transactionSaveWithIsolation [TransactionSaveWithIsolation] :: () => IsolationLevel -> SqlQueryRep Void () -- | Constructor corresponding to transactionUndo [TransactionUndo] :: () => SqlQueryRep Void () -- | Constructor corresponding to transactionUndoWithIsolation [TransactionUndoWithIsolation] :: () => IsolationLevel -> SqlQueryRep Void () -- | Constructor for lifting an arbitrary SqlPersistT action into -- SqlQueryRep. [UnsafeLiftSql] :: Text -> (forall m. MonadIO m => SqlPersistT m a) -> SqlQueryRep Void a -- | A helper to execute the actual persistent function -- corresponding to each SqlQueryRep data constructor. runSqlQueryRep :: MonadUnliftIO m => SqlQueryRep record a -> SqlPersistT m a instance Data.Typeable.Internal.Typeable record => GHC.Show.Show (Database.Persist.Monad.SqlQueryRep.SqlQueryRep record a) -- | Defines the MonadSqlQuery type class that a monad can make an -- instance of in order to interpret how to run a SqlQueryRep sent -- by a lifted function from Database.Persist.Monad.Shim. module Database.Persist.Monad.Class -- | The type-class for monads that can run persistent database queries. class (Monad m, MonadSqlQuery (TransactionM m)) => MonadSqlQuery m where { type TransactionM m :: Type -> Type; } -- | Interpret the given SQL query operation. runQueryRep :: (MonadSqlQuery m, Typeable record) => SqlQueryRep record a -> m a -- | Run all queries in the given action using the same database -- connection. withTransaction :: MonadSqlQuery m => TransactionM m a -> m a instance Database.Persist.Monad.Class.MonadSqlQuery m => Database.Persist.Monad.Class.MonadSqlQuery (Control.Monad.Trans.Reader.ReaderT r m) instance Database.Persist.Monad.Class.MonadSqlQuery m => Database.Persist.Monad.Class.MonadSqlQuery (Control.Monad.Trans.Except.ExceptT e m) instance Database.Persist.Monad.Class.MonadSqlQuery m => Database.Persist.Monad.Class.MonadSqlQuery (Control.Monad.Trans.Identity.IdentityT m) instance Database.Persist.Monad.Class.MonadSqlQuery m => Database.Persist.Monad.Class.MonadSqlQuery (Control.Monad.Trans.Maybe.MaybeT m) instance (GHC.Base.Monoid w, Database.Persist.Monad.Class.MonadSqlQuery m) => Database.Persist.Monad.Class.MonadSqlQuery (Control.Monad.Trans.RWS.Lazy.RWST r w s m) instance (GHC.Base.Monoid w, Database.Persist.Monad.Class.MonadSqlQuery m) => Database.Persist.Monad.Class.MonadSqlQuery (Control.Monad.Trans.RWS.Strict.RWST r w s m) instance Database.Persist.Monad.Class.MonadSqlQuery m => Database.Persist.Monad.Class.MonadSqlQuery (Control.Monad.Trans.State.Lazy.StateT s m) instance Database.Persist.Monad.Class.MonadSqlQuery m => Database.Persist.Monad.Class.MonadSqlQuery (Control.Monad.Trans.State.Strict.StateT s m) instance (GHC.Base.Monoid w, Database.Persist.Monad.Class.MonadSqlQuery m) => Database.Persist.Monad.Class.MonadSqlQuery (Control.Monad.Trans.Writer.Lazy.WriterT w m) instance (GHC.Base.Monoid w, Database.Persist.Monad.Class.MonadSqlQuery m) => Database.Persist.Monad.Class.MonadSqlQuery (Control.Monad.Trans.Writer.Strict.WriterT w m) -- | Defines all the persistent functions lifted into -- MonadSqlQuery. -- -- This file is autogenerated, to keep it in sync with -- Database.Persist.Monad.SqlQueryRep. module Database.Persist.Monad.Shim -- | The lifted version of get get :: (PersistRecordBackend record SqlBackend, Typeable record, MonadSqlQuery m) => Key record -> m (Maybe record) -- | The lifted version of getMany getMany :: (PersistRecordBackend record SqlBackend, Typeable record, MonadSqlQuery m) => [Key record] -> m (Map (Key record) record) -- | The lifted version of getJust getJust :: (PersistRecordBackend record SqlBackend, Typeable record, MonadSqlQuery m) => Key record -> m record -- | The lifted version of getJustEntity getJustEntity :: (PersistRecordBackend record SqlBackend, Typeable record, MonadSqlQuery m) => Key record -> m (Entity record) -- | The lifted version of getEntity getEntity :: (PersistRecordBackend record SqlBackend, Typeable record, MonadSqlQuery m) => Key record -> m (Maybe (Entity record)) -- | The lifted version of belongsTo belongsTo :: (PersistEntity record1, PersistRecordBackend record2 SqlBackend, Typeable record1, Typeable record2, MonadSqlQuery m) => (record1 -> Maybe (Key record2)) -> record1 -> m (Maybe record2) -- | The lifted version of belongsToJust belongsToJust :: (PersistEntity record1, PersistRecordBackend record2 SqlBackend, Typeable record1, Typeable record2, MonadSqlQuery m) => (record1 -> Key record2) -> record1 -> m record2 -- | The lifted version of insert insert :: (PersistRecordBackend record SqlBackend, SafeToInsert record, Typeable record, MonadSqlQuery m) => record -> m (Key record) -- | The lifted version of insert_ insert_ :: (PersistRecordBackend record SqlBackend, SafeToInsert record, Typeable record, MonadSqlQuery m) => record -> m () -- | The lifted version of insertMany insertMany :: (PersistRecordBackend record SqlBackend, SafeToInsert record, Typeable record, MonadSqlQuery m) => [record] -> m [Key record] -- | The lifted version of insertMany_ insertMany_ :: (PersistRecordBackend record SqlBackend, SafeToInsert record, Typeable record, MonadSqlQuery m) => [record] -> m () -- | The lifted version of insertEntityMany insertEntityMany :: (PersistRecordBackend record SqlBackend, Typeable record, MonadSqlQuery m) => [Entity record] -> m () -- | The lifted version of insertKey insertKey :: (PersistRecordBackend record SqlBackend, Typeable record, MonadSqlQuery m) => Key record -> record -> m () -- | The lifted version of repsert repsert :: (PersistRecordBackend record SqlBackend, Typeable record, MonadSqlQuery m) => Key record -> record -> m () -- | The lifted version of repsertMany repsertMany :: (PersistRecordBackend record SqlBackend, Typeable record, MonadSqlQuery m) => [(Key record, record)] -> m () -- | The lifted version of replace replace :: (PersistRecordBackend record SqlBackend, Typeable record, MonadSqlQuery m) => Key record -> record -> m () -- | The lifted version of delete delete :: (PersistRecordBackend record SqlBackend, Typeable record, MonadSqlQuery m) => Key record -> m () -- | The lifted version of update update :: (PersistRecordBackend record SqlBackend, Typeable record, MonadSqlQuery m) => Key record -> [Update record] -> m () -- | The lifted version of updateGet updateGet :: (PersistRecordBackend record SqlBackend, Typeable record, MonadSqlQuery m) => Key record -> [Update record] -> m record -- | The lifted version of insertEntity insertEntity :: (PersistRecordBackend record SqlBackend, SafeToInsert record, Typeable record, MonadSqlQuery m) => record -> m (Entity record) -- | The lifted version of insertRecord insertRecord :: (PersistRecordBackend record SqlBackend, SafeToInsert record, Typeable record, MonadSqlQuery m) => record -> m record -- | The lifted version of getBy getBy :: (PersistRecordBackend record SqlBackend, Typeable record, MonadSqlQuery m) => Unique record -> m (Maybe (Entity record)) -- | The lifted version of getByValue getByValue :: (PersistRecordBackend record SqlBackend, AtLeastOneUniqueKey record, Typeable record, MonadSqlQuery m) => record -> m (Maybe (Entity record)) -- | The lifted version of checkUnique checkUnique :: (PersistRecordBackend record SqlBackend, Typeable record, MonadSqlQuery m) => record -> m (Maybe (Unique record)) -- | The lifted version of checkUniqueUpdateable checkUniqueUpdateable :: (PersistRecordBackend record SqlBackend, Typeable record, MonadSqlQuery m) => Entity record -> m (Maybe (Unique record)) -- | The lifted version of deleteBy deleteBy :: (PersistRecordBackend record SqlBackend, Typeable record, MonadSqlQuery m) => Unique record -> m () -- | The lifted version of insertUnique insertUnique :: (PersistRecordBackend record SqlBackend, SafeToInsert record, Typeable record, MonadSqlQuery m) => record -> m (Maybe (Key record)) -- | The lifted version of upsert upsert :: (PersistRecordBackend record SqlBackend, OnlyOneUniqueKey record, SafeToInsert record, Typeable record, MonadSqlQuery m) => record -> [Update record] -> m (Entity record) -- | The lifted version of upsertBy upsertBy :: (PersistRecordBackend record SqlBackend, SafeToInsert record, Typeable record, MonadSqlQuery m) => Unique record -> record -> [Update record] -> m (Entity record) -- | The lifted version of putMany putMany :: (PersistRecordBackend record SqlBackend, SafeToInsert record, Typeable record, MonadSqlQuery m) => [record] -> m () -- | The lifted version of insertBy insertBy :: (PersistRecordBackend record SqlBackend, AtLeastOneUniqueKey record, SafeToInsert record, Typeable record, MonadSqlQuery m) => record -> m (Either (Entity record) (Key record)) -- | The lifted version of insertUniqueEntity insertUniqueEntity :: (PersistRecordBackend record SqlBackend, SafeToInsert record, Typeable record, MonadSqlQuery m) => record -> m (Maybe (Entity record)) -- | The lifted version of replaceUnique replaceUnique :: (PersistRecordBackend record SqlBackend, Eq (Unique record), Eq record, Typeable record, MonadSqlQuery m) => Key record -> record -> m (Maybe (Unique record)) -- | The lifted version of onlyUnique onlyUnique :: (PersistRecordBackend record SqlBackend, OnlyOneUniqueKey record, Typeable record, MonadSqlQuery m) => record -> m (Unique record) -- | The lifted version of selectSourceRes selectSourceRes :: (MonadIO m2, PersistRecordBackend record SqlBackend, Typeable record, MonadSqlQuery m) => [Filter record] -> [SelectOpt record] -> m (Acquire (ConduitM () (Entity record) m2 ())) -- | The lifted version of selectFirst selectFirst :: (PersistRecordBackend record SqlBackend, Typeable record, MonadSqlQuery m) => [Filter record] -> [SelectOpt record] -> m (Maybe (Entity record)) -- | The lifted version of selectKeysRes selectKeysRes :: (MonadIO m2, PersistRecordBackend record SqlBackend, Typeable record, MonadSqlQuery m) => [Filter record] -> [SelectOpt record] -> m (Acquire (ConduitM () (Key record) m2 ())) -- | The lifted version of count count :: (PersistRecordBackend record SqlBackend, Typeable record, MonadSqlQuery m) => [Filter record] -> m Int -- | The lifted version of exists exists :: (PersistRecordBackend record SqlBackend, Typeable record, MonadSqlQuery m) => [Filter record] -> m Bool -- | The lifted version of selectSource selectSource :: (PersistRecordBackend record SqlBackend, MonadResource m, Typeable record, MonadSqlQuery m) => [Filter record] -> [SelectOpt record] -> ConduitM () (Entity record) m () -- | The lifted version of selectKeys selectKeys :: (PersistRecordBackend record SqlBackend, MonadResource m, Typeable record, MonadSqlQuery m) => [Filter record] -> [SelectOpt record] -> ConduitM () (Key record) m () -- | The lifted version of selectList selectList :: (PersistRecordBackend record SqlBackend, Typeable record, MonadSqlQuery m) => [Filter record] -> [SelectOpt record] -> m [Entity record] -- | The lifted version of selectKeysList selectKeysList :: (PersistRecordBackend record SqlBackend, Typeable record, MonadSqlQuery m) => [Filter record] -> [SelectOpt record] -> m [Key record] -- | The lifted version of updateWhere updateWhere :: (PersistRecordBackend record SqlBackend, Typeable record, MonadSqlQuery m) => [Filter record] -> [Update record] -> m () -- | The lifted version of deleteWhere deleteWhere :: (PersistRecordBackend record SqlBackend, Typeable record, MonadSqlQuery m) => [Filter record] -> m () -- | The lifted version of deleteWhereCount deleteWhereCount :: (PersistRecordBackend record SqlBackend, Typeable record, MonadSqlQuery m) => [Filter record] -> m Int64 -- | The lifted version of updateWhereCount updateWhereCount :: (PersistRecordBackend record SqlBackend, Typeable record, MonadSqlQuery m) => [Filter record] -> [Update record] -> m Int64 -- | The lifted version of parseMigration parseMigration :: (HasCallStack, MonadSqlQuery m) => Migration -> m (Either [Text] CautiousMigration) -- | The lifted version of parseMigration' parseMigration' :: (HasCallStack, MonadSqlQuery m) => Migration -> m CautiousMigration -- | The lifted version of printMigration printMigration :: (HasCallStack, MonadSqlQuery m) => Migration -> m () -- | The lifted version of showMigration showMigration :: (HasCallStack, MonadSqlQuery m) => Migration -> m [Text] -- | The lifted version of getMigration getMigration :: (HasCallStack, MonadSqlQuery m) => Migration -> m [Sql] -- | The lifted version of runMigration runMigration :: MonadSqlQuery m => Migration -> m () -- | The lifted version of runMigrationQuiet runMigrationQuiet :: MonadSqlQuery m => Migration -> m [Text] -- | The lifted version of runMigrationSilent runMigrationSilent :: MonadSqlQuery m => Migration -> m [Text] -- | The lifted version of runMigrationUnsafe runMigrationUnsafe :: MonadSqlQuery m => Migration -> m () -- | The lifted version of runMigrationUnsafeQuiet runMigrationUnsafeQuiet :: (HasCallStack, MonadSqlQuery m) => Migration -> m [Text] -- | The lifted version of getFieldName getFieldName :: (PersistRecordBackend record SqlBackend, Typeable record, MonadSqlQuery m) => EntityField record typ -> m Text -- | The lifted version of getTableName getTableName :: (PersistRecordBackend record SqlBackend, Typeable record, MonadSqlQuery m) => record -> m Text -- | The lifted version of withRawQuery withRawQuery :: MonadSqlQuery m => Text -> [PersistValue] -> ConduitM [PersistValue] Void IO a -> m a -- | The lifted version of rawQueryRes rawQueryRes :: (MonadIO m2, MonadSqlQuery m) => Text -> [PersistValue] -> m (Acquire (ConduitM () [PersistValue] m2 ())) -- | The lifted version of rawQuery rawQuery :: (MonadResource m, MonadSqlQuery m) => Text -> [PersistValue] -> ConduitM () [PersistValue] m () -- | The lifted version of rawExecute rawExecute :: MonadSqlQuery m => Text -> [PersistValue] -> m () -- | The lifted version of rawExecuteCount rawExecuteCount :: MonadSqlQuery m => Text -> [PersistValue] -> m Int64 -- | The lifted version of rawSql rawSql :: (RawSql a, MonadSqlQuery m) => Text -> [PersistValue] -> m [a] -- | The lifted version of transactionSave transactionSave :: MonadSqlQuery m => m () -- | The lifted version of transactionSaveWithIsolation transactionSaveWithIsolation :: MonadSqlQuery m => IsolationLevel -> m () -- | The lifted version of transactionUndo transactionUndo :: MonadSqlQuery m => m () -- | The lifted version of transactionUndoWithIsolation transactionUndoWithIsolation :: MonadSqlQuery m => IsolationLevel -> m () -- | Lift an arbitrary SqlPersistT action into MonadSqlQuery. -- -- This is unsafe because the action may be rerun. This function should -- primarily be used to interop with other libraries built on top of -- persistent. -- -- Example usage: -- --
--   -- | Run an esqueleto select.
--   select :: (MonadSqlQuery m, E.SqlSelect a r) => E.SqlQuery a -> m [r]
--   select q = unsafeLiftSql "esqueleto-select" (E.select q)
--   
unsafeLiftSql :: MonadSqlQuery m => Text -> (forall m2. MonadIO m2 => SqlPersistT m2 a) -> m a -- | A helper for functions that return a conduit. fromAcquire :: MonadResource m => m (Acquire (ConduitM i o m a)) -> ConduitM i o m a module Database.Persist.Monad.Internal.SqlTransaction -- | The monad that tracks transaction state. -- -- Conceptually equivalent to SqlPersistT, but restricts IO -- operations, for two reasons: -- --
    --
  1. Forking a thread that uses the same SqlBackend as the -- current thread causes Bad Things to happen.
  2. --
  3. Transactions may need to be retried, in which case IO operations -- in a transaction are required to be rerunnable.
  4. --
-- -- You shouldn't need to explicitly use this type; your functions should -- only declare the MonadSqlQuery constraint. newtype SqlTransaction m a UnsafeSqlTransaction :: ReaderT SqlTransactionEnv m a -> SqlTransaction m a [unSqlTransaction] :: SqlTransaction m a -> ReaderT SqlTransactionEnv m a data SqlTransactionEnv SqlTransactionEnv :: SqlBackend -> (SomeException -> Bool) -> SqlTransactionEnv [sqlBackend] :: SqlTransactionEnv -> SqlBackend [ignoreCatch] :: SqlTransactionEnv -> SomeException -> Bool runSqlTransaction :: MonadUnliftIO m => SqlTransactionEnv -> SqlTransaction m a -> m a -- | Like normal catch, except ignores errors specified by -- ignoreCatch. catchSqlTransaction :: (MonadUnliftIO m, Exception e) => SqlTransaction m a -> (e -> SqlTransaction m a) -> SqlTransaction m a instance Control.Monad.Trans.Rerunnable.MonadRerunnableTrans Database.Persist.Monad.Internal.SqlTransaction.SqlTransaction instance Control.Monad.IO.Rerunnable.MonadRerunnableIO m => Control.Monad.IO.Rerunnable.MonadRerunnableIO (Database.Persist.Monad.Internal.SqlTransaction.SqlTransaction m) instance Control.Monad.Fix.MonadFix m => Control.Monad.Fix.MonadFix (Database.Persist.Monad.Internal.SqlTransaction.SqlTransaction m) instance GHC.Base.Monad m => GHC.Base.Monad (Database.Persist.Monad.Internal.SqlTransaction.SqlTransaction m) instance GHC.Base.Applicative m => GHC.Base.Applicative (Database.Persist.Monad.Internal.SqlTransaction.SqlTransaction m) instance GHC.Base.Functor m => GHC.Base.Functor (Database.Persist.Monad.Internal.SqlTransaction.SqlTransaction m) instance ((TypeError ...), GHC.Base.Monad m) => Control.Monad.IO.Class.MonadIO (Database.Persist.Monad.Internal.SqlTransaction.SqlTransaction m) instance (Database.Persist.Monad.Class.MonadSqlQuery m, Control.Monad.IO.Unlift.MonadUnliftIO m) => Database.Persist.Monad.Class.MonadSqlQuery (Database.Persist.Monad.Internal.SqlTransaction.SqlTransaction m) -- | Defines the SqlQueryT monad transformer, which has a -- MonadSqlQuery instance to execute persistent database -- operations. Also provides easy transaction management with -- withTransaction, which supports retrying with exponential -- backoff and restricts IO actions to only allow IO actions explicitly -- marked as rerunnable. -- -- Usage: -- --
--   myFunction :: (MonadSqlQuery m, MonadIO m) => m ()
--   myFunction = do
--     insert_ $ Person { name = "Alice", age = Just 25 }
--     insert_ $ Person { name = "Bob", age = Nothing }
--   
--     -- some other business logic
--   
--     personList <- selectList [] []
--     liftIO $ print (personList :: [Person])
--   
--     -- everything in here will run in a transaction
--     withTransaction $ do
--       selectFirst [PersonAge >. 30] [] >>= \case
--         Nothing -> insert_ $ Person { name = "Claire", age = Just 50 }
--         Just (Entity key person) -> replace key person{ age = Just (age person - 10) }
--   
--       -- liftIO doesn't work in here, since transactions can be retried.
--       -- Use rerunnableIO to run IO actions, after verifying that the IO action
--       -- can be rerun if the transaction needs to be retried.
--       rerunnableIO $ putStrLn "Transaction is finished!"
--   
--     -- some more business logic
--   
--     return ()
--   
module Database.Persist.Monad -- | The type-class for monads that can run persistent database queries. class (Monad m, MonadSqlQuery (TransactionM m)) => MonadSqlQuery m -- | Run all queries in the given action using the same database -- connection. withTransaction :: MonadSqlQuery m => TransactionM m a -> m a -- | The monad transformer that implements MonadSqlQuery. newtype SqlQueryT m a SqlQueryT :: ReaderT SqlQueryEnv m a -> SqlQueryT m a [unSqlQueryT] :: SqlQueryT m a -> ReaderT SqlQueryEnv m a mapSqlQueryT :: (m a -> n b) -> SqlQueryT m a -> SqlQueryT n b -- | Run the SqlQueryT monad transformer with the given backend. runSqlQueryT :: Pool SqlBackend -> SqlQueryT m a -> m a -- | Run the SqlQueryT monad transformer with the explicitly -- provided environment. runSqlQueryTWith :: SqlQueryEnv -> SqlQueryT m a -> m a -- | Environment to configure running SqlQueryT. -- -- For simple usage, you can just use runSqlQueryT, but for more -- advanced usage, including the ability to retry transactions, use -- mkSqlQueryEnv with runSqlQueryTWith. data SqlQueryEnv SqlQueryEnv :: Pool SqlBackend -> (SomeException -> Bool) -> Int -> (SomeException -> IO ()) -> SqlQueryEnv -- | The pool for your persistent backend. Get this from -- withSqlitePool or the equivalent for your backend. [backendPool] :: SqlQueryEnv -> Pool SqlBackend -- | Retry a transaction when an exception matches this predicate. Will -- retry with an exponential backoff. -- -- Defaults to always returning False (i.e. never retry) [retryIf] :: SqlQueryEnv -> SomeException -> Bool -- | The number of times to retry, if retryIf is satisfied. -- -- Defaults to 10. [retryLimit] :: SqlQueryEnv -> Int -- | A callback to run if retryIf returns True. Useful for logging. [retryCallback] :: SqlQueryEnv -> SomeException -> IO () -- | Build a SqlQueryEnv from the default. -- -- Usage: -- --
--   let env = mkSqlQueryEnv pool $ \env -> env { retryIf = 10 }
--   in runSqlQueryTWith env m
--   
--   
mkSqlQueryEnv :: Pool SqlBackend -> (SqlQueryEnv -> SqlQueryEnv) -> SqlQueryEnv getSqlBackendPool :: Monad m => SqlQueryT m (Pool SqlBackend) -- | The monad that tracks transaction state. -- -- Conceptually equivalent to SqlPersistT, but restricts IO -- operations, for two reasons: -- --
    --
  1. Forking a thread that uses the same SqlBackend as the -- current thread causes Bad Things to happen.
  2. --
  3. Transactions may need to be retried, in which case IO operations -- in a transaction are required to be rerunnable.
  4. --
-- -- You shouldn't need to explicitly use this type; your functions should -- only declare the MonadSqlQuery constraint. data SqlTransaction m a -- | Errors that can occur when running a SQL transaction. data TransactionError -- | The retry limit was reached when retrying a transaction. RetryLimitExceeded :: TransactionError -- | Like normal catch, except ignores errors specified by -- ignoreCatch. catchSqlTransaction :: (MonadUnliftIO m, Exception e) => SqlTransaction m a -> (e -> SqlTransaction m a) -> SqlTransaction m a instance Control.Monad.Logger.MonadLogger m => Control.Monad.Logger.MonadLogger (Database.Persist.Monad.SqlQueryT m) instance Control.Monad.Catch.MonadMask m => Control.Monad.Catch.MonadMask (Database.Persist.Monad.SqlQueryT m) instance Control.Monad.Catch.MonadCatch m => Control.Monad.Catch.MonadCatch (Database.Persist.Monad.SqlQueryT m) instance Control.Monad.Catch.MonadThrow m => Control.Monad.Catch.MonadThrow (Database.Persist.Monad.SqlQueryT m) instance Control.Monad.IO.Rerunnable.MonadRerunnableIO m => Control.Monad.IO.Rerunnable.MonadRerunnableIO (Database.Persist.Monad.SqlQueryT m) instance Control.Monad.Trans.Resource.Internal.MonadResource m => Control.Monad.Trans.Resource.Internal.MonadResource (Database.Persist.Monad.SqlQueryT m) instance Control.Monad.Trans.Class.MonadTrans Database.Persist.Monad.SqlQueryT instance Control.Monad.IO.Class.MonadIO m => Control.Monad.IO.Class.MonadIO (Database.Persist.Monad.SqlQueryT m) instance Control.Monad.Fix.MonadFix m => Control.Monad.Fix.MonadFix (Database.Persist.Monad.SqlQueryT m) instance GHC.Base.Monad m => GHC.Base.Monad (Database.Persist.Monad.SqlQueryT m) instance GHC.Base.Applicative m => GHC.Base.Applicative (Database.Persist.Monad.SqlQueryT m) instance GHC.Base.Functor m => GHC.Base.Functor (Database.Persist.Monad.SqlQueryT m) instance GHC.Classes.Eq Database.Persist.Monad.TransactionError instance GHC.Show.Show Database.Persist.Monad.TransactionError instance Control.Monad.IO.Unlift.MonadUnliftIO m => Database.Persist.Monad.Class.MonadSqlQuery (Database.Persist.Monad.SqlQueryT m) instance GHC.Exception.Type.Exception Database.Persist.Monad.TransactionError instance Control.Monad.IO.Unlift.MonadUnliftIO m => Control.Monad.IO.Unlift.MonadUnliftIO (Database.Persist.Monad.SqlQueryT m) instance Control.Monad.Reader.Class.MonadReader r m => Control.Monad.Reader.Class.MonadReader r (Database.Persist.Monad.SqlQueryT m) -- | Defines MockSqlQueryT, which one can use in tests in order to -- mock out persistent database queries called in production -- code. module Database.Persist.Monad.TestUtils -- | A monad transformer for testing functions that use -- MonadSqlQuery. data MockSqlQueryT m a -- | Runs a MockSqlQueryT monad transformer using the given mocks. -- -- When a database query is executed, the first mock that returns a -- Just is returned. If no mocks match the query, an error is -- thrown. See SqlQueryRep for the constructors available to match -- against. Most of the time, you'll want to use withRecord to -- only match queries against a specific record type (e.g. only -- match selectList calls for the Person entity). -- -- Usage: -- --
--   myFunction :: MonadSqlQuery m => m [String]
--   myFunction = map personName $ selectList [PersonAge >. 25] []
--   
--   let persons = [Person ...]
--   result <- runMockSqlQueryT myFunction
--     [ withRecord @Person $ \case
--         SelectList _ _ -> Just persons
--         _ -> Nothing
--     , withRecord @Post $ \case
--         Insert Post{ name = "post1" } -> Just $ toSqlKey 1
--         _ -> Nothing
--     , mockQuery $ \case
--         RawExecuteCount "DELETE FROM person WHERE name = 'Alice'" [] -> Just 1
--         _ -> Nothing
--     ]
--   
--   
runMockSqlQueryT :: MockSqlQueryT m a -> [MockQuery] -> m a -- | A helper for defining a mocked database query against a specific -- record type. Designed to be used with TypeApplications. -- -- Most SqlQueryRep constructors are in the context of a specific -- record type, like Person. This helper only matches -- mocked database queries that are querying the record you specify. -- -- Some constructors reference multiple record types, like -- BelongsTo. Look at the type to see the record you need to match -- against. For example, -- --
--   withRecord @(Person, Post) $ \case
--     BelongsTo _ _ -> ...
--   
--   
-- -- would match the function call -- --
--   belongsTo :: (Person -> Maybe (Key Post)) -> Person -> SqlQueryRep (Person, Post) (Maybe Post)
--   
--   
withRecord :: forall record. Typeable record => (forall a. SqlQueryRep record a -> Maybe a) -> MockQuery -- | A helper for defining a mocked database query. -- -- This does not do any matching on the record type, so it is -- mostly useful for queries that don't use the record type, -- like rawExecute. mockQuery :: (forall record a. Typeable record => SqlQueryRep record a -> Maybe a) -> MockQuery -- | A mocked query to use in runMockSqlQueryT. -- -- Use withRecord or another helper to create a MockQuery. data MockQuery -- | A helper for mocking a selectSource or selectSourceRes -- call. -- -- Usage: -- --
--   mockSelectSource $ \filters opts ->
--     if null filters && null opts
--       then
--         let person1 = [Entity (toSqlKey 1) $ Person "Alice"]
--             person2 = [Entity (toSqlKey 2) $ Person "Bob"]
--         in Just [person1, person2]
--       else Nothing
--   
--   
mockSelectSource :: forall record. Typeable record => ([Filter record] -> [SelectOpt record] -> Maybe [Entity record]) -> MockQuery -- | A helper for mocking a selectKeys or selectKeysRes call. -- -- Usage: -- --
--   mockSelectKeys $ \filters opts ->
--     if null filters && null opts
--       then Just $ map toSqlKey [1, 2]
--       else Nothing
--   
--   
mockSelectKeys :: forall record. Typeable record => ([Filter record] -> [SelectOpt record] -> Maybe [Key record]) -> MockQuery -- | A helper for mocking a withRawQuery call. -- -- Usage: -- --
--   mockWithRawQuery $ \sql vals ->
--     if sql == "SELECT id, name FROM person"
--       then
--         let row1 = [toPersistValue 1, toPersistValue "Alice"]
--             row2 = [toPersistValue 2, toPersistValue "Bob"]
--         in Just [row1, row2]
--       else Nothing
--   
--   
mockWithRawQuery :: (Text -> [PersistValue] -> Maybe [[PersistValue]]) -> MockQuery -- | A helper for mocking a rawQuery or rawQueryRes call. -- -- Usage: -- --
--   mockRawQuery $ \sql vals ->
--     if sql == "SELECT id, name FROM person"
--       then
--         let row1 = [toPersistValue 1, toPersistValue "Alice"]
--             row2 = [toPersistValue 2, toPersistValue "Bob"]
--         in Just [row1, row2]
--       else Nothing
--   
--   
mockRawQuery :: (Text -> [PersistValue] -> Maybe [[PersistValue]]) -> MockQuery -- | A helper for mocking a rawSql call. -- -- Usage: -- --
--   mockRawSql $ \sql vals ->
--     if sql == "SELECT id, name FROM person"
--       then
--         let row1 = [toPersistValue 1, toPersistValue "Alice"]
--             row2 = [toPersistValue 2, toPersistValue "Bob"]
--         in Just [row1, row2]
--       else Nothing
--   
--   
mockRawSql :: (Text -> [PersistValue] -> Maybe [[PersistValue]]) -> MockQuery -- | The data type containing a constructor for each persistent function -- we'd like to lift into MonadSqlQuery. -- -- The record type parameter contains the PersistEntity -- types used in a given function. -- -- We're using a free-monads-like technique here to allow us to -- introspect persistent functions in MonadSqlQuery, e.g. to mock -- out persistent calls in tests. data SqlQueryRep record a -- | Constructor corresponding to get [Get] :: PersistRecordBackend record SqlBackend => Key record -> SqlQueryRep record (Maybe record) -- | Constructor corresponding to getMany [GetMany] :: PersistRecordBackend record SqlBackend => [Key record] -> SqlQueryRep record (Map (Key record) record) -- | Constructor corresponding to getJust [GetJust] :: PersistRecordBackend record SqlBackend => Key record -> SqlQueryRep record record -- | Constructor corresponding to getJustEntity [GetJustEntity] :: PersistRecordBackend record SqlBackend => Key record -> SqlQueryRep record (Entity record) -- | Constructor corresponding to getEntity [GetEntity] :: PersistRecordBackend record SqlBackend => Key record -> SqlQueryRep record (Maybe (Entity record)) -- | Constructor corresponding to belongsTo [BelongsTo] :: (PersistEntity record1, PersistRecordBackend record2 SqlBackend) => (record1 -> Maybe (Key record2)) -> record1 -> SqlQueryRep (record1, record2) (Maybe record2) -- | Constructor corresponding to belongsToJust [BelongsToJust] :: (PersistEntity record1, PersistRecordBackend record2 SqlBackend) => (record1 -> Key record2) -> record1 -> SqlQueryRep (record1, record2) record2 -- | Constructor corresponding to insert [Insert] :: (PersistRecordBackend record SqlBackend, SafeToInsert record) => record -> SqlQueryRep record (Key record) -- | Constructor corresponding to insert_ [Insert_] :: (PersistRecordBackend record SqlBackend, SafeToInsert record) => record -> SqlQueryRep record () -- | Constructor corresponding to insertMany [InsertMany] :: (PersistRecordBackend record SqlBackend, SafeToInsert record) => [record] -> SqlQueryRep record [Key record] -- | Constructor corresponding to insertMany_ [InsertMany_] :: (PersistRecordBackend record SqlBackend, SafeToInsert record) => [record] -> SqlQueryRep record () -- | Constructor corresponding to insertEntityMany [InsertEntityMany] :: PersistRecordBackend record SqlBackend => [Entity record] -> SqlQueryRep record () -- | Constructor corresponding to insertKey [InsertKey] :: PersistRecordBackend record SqlBackend => Key record -> record -> SqlQueryRep record () -- | Constructor corresponding to repsert [Repsert] :: PersistRecordBackend record SqlBackend => Key record -> record -> SqlQueryRep record () -- | Constructor corresponding to repsertMany [RepsertMany] :: PersistRecordBackend record SqlBackend => [(Key record, record)] -> SqlQueryRep record () -- | Constructor corresponding to replace [Replace] :: PersistRecordBackend record SqlBackend => Key record -> record -> SqlQueryRep record () -- | Constructor corresponding to delete [Delete] :: PersistRecordBackend record SqlBackend => Key record -> SqlQueryRep record () -- | Constructor corresponding to update [Update] :: PersistRecordBackend record SqlBackend => Key record -> [Update record] -> SqlQueryRep record () -- | Constructor corresponding to updateGet [UpdateGet] :: PersistRecordBackend record SqlBackend => Key record -> [Update record] -> SqlQueryRep record record -- | Constructor corresponding to insertEntity [InsertEntity] :: (PersistRecordBackend record SqlBackend, SafeToInsert record) => record -> SqlQueryRep record (Entity record) -- | Constructor corresponding to insertRecord [InsertRecord] :: (PersistRecordBackend record SqlBackend, SafeToInsert record) => record -> SqlQueryRep record record -- | Constructor corresponding to getBy [GetBy] :: PersistRecordBackend record SqlBackend => Unique record -> SqlQueryRep record (Maybe (Entity record)) -- | Constructor corresponding to getByValue [GetByValue] :: (PersistRecordBackend record SqlBackend, AtLeastOneUniqueKey record) => record -> SqlQueryRep record (Maybe (Entity record)) -- | Constructor corresponding to checkUnique [CheckUnique] :: PersistRecordBackend record SqlBackend => record -> SqlQueryRep record (Maybe (Unique record)) -- | Constructor corresponding to checkUniqueUpdateable [CheckUniqueUpdateable] :: PersistRecordBackend record SqlBackend => Entity record -> SqlQueryRep record (Maybe (Unique record)) -- | Constructor corresponding to deleteBy [DeleteBy] :: PersistRecordBackend record SqlBackend => Unique record -> SqlQueryRep record () -- | Constructor corresponding to insertUnique [InsertUnique] :: (PersistRecordBackend record SqlBackend, SafeToInsert record) => record -> SqlQueryRep record (Maybe (Key record)) -- | Constructor corresponding to upsert [Upsert] :: (PersistRecordBackend record SqlBackend, OnlyOneUniqueKey record, SafeToInsert record) => record -> [Update record] -> SqlQueryRep record (Entity record) -- | Constructor corresponding to upsertBy [UpsertBy] :: (PersistRecordBackend record SqlBackend, SafeToInsert record) => Unique record -> record -> [Update record] -> SqlQueryRep record (Entity record) -- | Constructor corresponding to putMany [PutMany] :: (PersistRecordBackend record SqlBackend, SafeToInsert record) => [record] -> SqlQueryRep record () -- | Constructor corresponding to insertBy [InsertBy] :: (PersistRecordBackend record SqlBackend, AtLeastOneUniqueKey record, SafeToInsert record) => record -> SqlQueryRep record (Either (Entity record) (Key record)) -- | Constructor corresponding to insertUniqueEntity [InsertUniqueEntity] :: (PersistRecordBackend record SqlBackend, SafeToInsert record) => record -> SqlQueryRep record (Maybe (Entity record)) -- | Constructor corresponding to replaceUnique [ReplaceUnique] :: (PersistRecordBackend record SqlBackend, Eq (Unique record), Eq record) => Key record -> record -> SqlQueryRep record (Maybe (Unique record)) -- | Constructor corresponding to onlyUnique [OnlyUnique] :: (PersistRecordBackend record SqlBackend, OnlyOneUniqueKey record) => record -> SqlQueryRep record (Unique record) -- | Constructor corresponding to selectSourceRes [SelectSourceRes] :: (MonadIO m2, PersistRecordBackend record SqlBackend) => [Filter record] -> [SelectOpt record] -> SqlQueryRep record (Acquire (ConduitM () (Entity record) m2 ())) -- | Constructor corresponding to selectFirst [SelectFirst] :: PersistRecordBackend record SqlBackend => [Filter record] -> [SelectOpt record] -> SqlQueryRep record (Maybe (Entity record)) -- | Constructor corresponding to selectKeysRes [SelectKeysRes] :: (MonadIO m2, PersistRecordBackend record SqlBackend) => [Filter record] -> [SelectOpt record] -> SqlQueryRep record (Acquire (ConduitM () (Key record) m2 ())) -- | Constructor corresponding to count [Count] :: PersistRecordBackend record SqlBackend => [Filter record] -> SqlQueryRep record Int -- | Constructor corresponding to exists [Exists] :: PersistRecordBackend record SqlBackend => [Filter record] -> SqlQueryRep record Bool -- | Constructor corresponding to selectList [SelectList] :: PersistRecordBackend record SqlBackend => [Filter record] -> [SelectOpt record] -> SqlQueryRep record [Entity record] -- | Constructor corresponding to selectKeysList [SelectKeysList] :: PersistRecordBackend record SqlBackend => [Filter record] -> [SelectOpt record] -> SqlQueryRep record [Key record] -- | Constructor corresponding to updateWhere [UpdateWhere] :: PersistRecordBackend record SqlBackend => [Filter record] -> [Update record] -> SqlQueryRep record () -- | Constructor corresponding to deleteWhere [DeleteWhere] :: PersistRecordBackend record SqlBackend => [Filter record] -> SqlQueryRep record () -- | Constructor corresponding to deleteWhereCount [DeleteWhereCount] :: PersistRecordBackend record SqlBackend => [Filter record] -> SqlQueryRep record Int64 -- | Constructor corresponding to updateWhereCount [UpdateWhereCount] :: PersistRecordBackend record SqlBackend => [Filter record] -> [Update record] -> SqlQueryRep record Int64 -- | Constructor corresponding to parseMigration [ParseMigration] :: HasCallStack => Migration -> SqlQueryRep Void (Either [Text] CautiousMigration) -- | Constructor corresponding to parseMigration' [ParseMigration'] :: HasCallStack => Migration -> SqlQueryRep Void CautiousMigration -- | Constructor corresponding to printMigration [PrintMigration] :: HasCallStack => Migration -> SqlQueryRep Void () -- | Constructor corresponding to showMigration [ShowMigration] :: HasCallStack => Migration -> SqlQueryRep Void [Text] -- | Constructor corresponding to getMigration [GetMigration] :: HasCallStack => Migration -> SqlQueryRep Void [Sql] -- | Constructor corresponding to runMigration [RunMigration] :: () => Migration -> SqlQueryRep Void () -- | Constructor corresponding to runMigrationQuiet [RunMigrationQuiet] :: () => Migration -> SqlQueryRep Void [Text] -- | Constructor corresponding to runMigrationSilent [RunMigrationSilent] :: () => Migration -> SqlQueryRep Void [Text] -- | Constructor corresponding to runMigrationUnsafe [RunMigrationUnsafe] :: () => Migration -> SqlQueryRep Void () -- | Constructor corresponding to runMigrationUnsafeQuiet [RunMigrationUnsafeQuiet] :: HasCallStack => Migration -> SqlQueryRep Void [Text] -- | Constructor corresponding to getFieldName [GetFieldName] :: PersistRecordBackend record SqlBackend => EntityField record typ -> SqlQueryRep record Text -- | Constructor corresponding to getTableName [GetTableName] :: PersistRecordBackend record SqlBackend => record -> SqlQueryRep record Text -- | Constructor corresponding to withRawQuery [WithRawQuery] :: () => Text -> [PersistValue] -> ConduitM [PersistValue] Void IO a -> SqlQueryRep Void a -- | Constructor corresponding to rawQueryRes [RawQueryRes] :: MonadIO m2 => Text -> [PersistValue] -> SqlQueryRep Void (Acquire (ConduitM () [PersistValue] m2 ())) -- | Constructor corresponding to rawExecute [RawExecute] :: () => Text -> [PersistValue] -> SqlQueryRep Void () -- | Constructor corresponding to rawExecuteCount [RawExecuteCount] :: () => Text -> [PersistValue] -> SqlQueryRep Void Int64 -- | Constructor corresponding to rawSql [RawSql] :: RawSql a => Text -> [PersistValue] -> SqlQueryRep Void [a] -- | Constructor corresponding to transactionSave [TransactionSave] :: () => SqlQueryRep Void () -- | Constructor corresponding to transactionSaveWithIsolation [TransactionSaveWithIsolation] :: () => IsolationLevel -> SqlQueryRep Void () -- | Constructor corresponding to transactionUndo [TransactionUndo] :: () => SqlQueryRep Void () -- | Constructor corresponding to transactionUndoWithIsolation [TransactionUndoWithIsolation] :: () => IsolationLevel -> SqlQueryRep Void () -- | Constructor for lifting an arbitrary SqlPersistT action into -- SqlQueryRep. [UnsafeLiftSql] :: Text -> (forall m. MonadIO m => SqlPersistT m a) -> SqlQueryRep Void a instance Control.Monad.Trans.Resource.Internal.MonadResource m => Control.Monad.Trans.Resource.Internal.MonadResource (Database.Persist.Monad.TestUtils.MockSqlQueryT m) instance Control.Monad.IO.Class.MonadIO m => Control.Monad.IO.Class.MonadIO (Database.Persist.Monad.TestUtils.MockSqlQueryT m) instance GHC.Base.Monad m => GHC.Base.Monad (Database.Persist.Monad.TestUtils.MockSqlQueryT m) instance GHC.Base.Applicative m => GHC.Base.Applicative (Database.Persist.Monad.TestUtils.MockSqlQueryT m) instance GHC.Base.Functor m => GHC.Base.Functor (Database.Persist.Monad.TestUtils.MockSqlQueryT m) instance Control.Monad.IO.Class.MonadIO m => Database.Persist.Monad.Class.MonadSqlQuery (Database.Persist.Monad.TestUtils.MockSqlQueryT m) -- | Defines all the persistent functions lifted into -- MonadSqlQuery, and re-exports a version of the -- Database.Persist.Sql module replacing each function with the -- lifted version. -- -- This file is autogenerated, to keep it in sync with -- Database.Persist.Monad.Shim. module Database.Persist.Sql.Shim -- | Run an action against the database during a migration. Can be useful -- for eg creating Postgres extensions: -- --
--   runSqlCommand $ rawExecute "CREATE EXTENSION IF NOT EXISTS "uuid-ossp";" []
--   
runSqlCommand :: SqlPersistT IO () -> Migration -- | Add a CautiousMigration (aka a [(Bool, -- Text)]) to the migration plan. addMigrations :: CautiousMigration -> Migration -- | Add a migration to the migration plan. addMigration :: Bool -> Sql -> Migration -- | Report multiple errors in a Migration. reportErrors :: [Text] -> Migration -- | Report a single error in a Migration. reportError :: Text -> Migration -- | Given a list of old entity definitions and a new EntityDef in -- val, this creates a Migration to update the old list -- of definitions with the new one. migrate :: [EntityDef] -> EntityDef -> Migration type Sql = Text -- | A list of SQL operations, marked with a safety flag. If the -- Bool is True, then the operation is *unsafe* - it might -- be destructive, or otherwise not idempotent. If the Bool is -- False, then the operation is *safe*, and can be run repeatedly -- without issues. type CautiousMigration = [(Bool, Sql)] -- | A Migration is a four level monad stack consisting of: -- -- type Migration = WriterT [Text] WriterT CautiousMigration ReaderT SqlBackend IO () -- | An exception indicating that Persistent refused to run some unsafe -- migrations. Contains a list of pairs where the Bool tracks whether the -- migration was unsafe (True means unsafe), and the Sql is the sql -- statement for the migration. newtype PersistUnsafeMigrationException PersistUnsafeMigrationException :: [(Bool, Sql)] -> PersistUnsafeMigrationException -- | Generates sql for limit and offset for postgres, sqlite and mysql. decorateSQLWithLimitOffset :: Text -> (Int, Int) -> Text -> Text -- | Render a [SelectOpt record] made up *only* of -- Asc and Desc constructors into a Text value -- suitable for inclusion into a SQL query. orderClause :: PersistEntity val => Maybe FilterTablePrefix -> SqlBackend -> [SelectOpt val] -> Text -- | Render a [Filter record] into a Text value -- suitable for inclusion into a SQL query, as well as the -- [PersistValue] to properly fill in the ? -- place holders. filterClauseWithVals :: PersistEntity val => Maybe FilterTablePrefix -> SqlBackend -> [Filter val] -> (Text, [PersistValue]) -- | Render a [Filter record] into a Text value -- suitable for inclusion into a SQL query. filterClause :: PersistEntity val => Maybe FilterTablePrefix -> SqlBackend -> [Filter val] -> Text -- | Used when determining how to prefix a column name in a WHERE -- clause. data FilterTablePrefix -- | Prefix the column with the table name. This is useful if the column -- name might be ambiguous. PrefixTableName :: FilterTablePrefix -- | Prefix the column name with the EXCLUDED keyword. This is -- used with the Postgresql backend when doing ON CONFLICT DO -- UPDATE clauses - see the documentation on upsertWhere -- and upsertManyWhere. PrefixExcluded :: FilterTablePrefix -- | useful for a backend to implement fieldName by adding escaping fieldDBName :: PersistEntity record => EntityField record typ -> FieldNameDB -- | useful for a backend to implement tableName by adding escaping tableDBName :: PersistEntity record => record -> EntityNameDB fromSqlKey :: ToBackendKey SqlBackend record => Key record -> Int64 toSqlKey :: ToBackendKey SqlBackend record => Int64 -> Key record close' :: BackendCompatible SqlBackend backend => backend -> IO () -- | Create a connection and run sql queries within it. This function -- automatically closes the connection on it's completion. -- --

Example usage

-- --
--   {-# LANGUAGE GADTs #-}
--   {-# LANGUAGE ScopedTypeVariables #-}
--   {-# LANGUAGE OverloadedStrings #-}
--   {-# LANGUAGE MultiParamTypeClasses #-}
--   {-# LANGUAGE TypeFamilies#-}
--   {-# LANGUAGE TemplateHaskell#-}
--   {-# LANGUAGE QuasiQuotes#-}
--   {-# LANGUAGE GeneralizedNewtypeDeriving #-}
--   
--   import Control.Monad.IO.Class  (liftIO)
--   import Control.Monad.Logger
--   import Conduit
--   import Database.Persist
--   import Database.Sqlite
--   import Database.Persist.Sqlite
--   import Database.Persist.TH
--   
--   share [mkPersist sqlSettings, mkMigrate "migrateAll"] [persistLowerCase|
--   Person
--     name String
--     age Int Maybe
--     deriving Show
--   |]
--   
--   openConnection :: LogFunc -> IO SqlBackend
--   openConnection logfn = do
--    conn <- open "/home/sibi/test.db"
--    wrapConnection conn logfn
--   
--   main :: IO ()
--   main = do
--     runNoLoggingT $ runResourceT $ withSqlConn openConnection (\backend ->
--                                         flip runSqlConn backend $ do
--                                           runMigration migrateAll
--                                           insert_ $ Person "John doe" $ Just 35
--                                           insert_ $ Person "Divya" $ Just 36
--                                           (pers :: [Entity Person]) <- selectList [] []
--                                           liftIO $ print pers
--                                           return ()
--                                        )
--   
-- -- On executing it, you get this output: -- --
--   Migrating: CREATE TABLE "person"("id" INTEGER PRIMARY KEY,"name" VARCHAR NOT NULL,"age" INTEGER NULL)
--   [Entity {entityKey = PersonKey {unPersonKey = SqlBackendKey {unSqlBackendKey = 1}}, entityVal = Person {personName = "John doe", personAge = Just 35}},Entity {entityKey = PersonKey {unPersonKey = SqlBackendKey {unSqlBackendKey = 2}}, entityVal = Person {personName = "Hema", personAge = Just 36}}]
--   
withSqlConn :: forall backend m a. (MonadUnliftIO m, MonadLoggerIO m, BackendCompatible SqlBackend backend) => (LogFunc -> IO backend) -> (backend -> m a) -> m a -- | Creates a pool of connections to a SQL database. createSqlPoolWithConfig :: (MonadLoggerIO m, MonadUnliftIO m, BackendCompatible SqlBackend backend) => (LogFunc -> IO backend) -> ConnectionPoolConfig -> m (Pool backend) createSqlPool :: forall backend m. (MonadLoggerIO m, MonadUnliftIO m, BackendCompatible SqlBackend backend) => (LogFunc -> IO backend) -> Int -> m (Pool backend) -- | Creates a pool of connections to a SQL database which can be used by -- the Pool backend -> m a function. After the function -- completes, the connections are destroyed. withSqlPoolWithConfig :: forall backend m a. (MonadLoggerIO m, MonadUnliftIO m, BackendCompatible SqlBackend backend) => (LogFunc -> IO backend) -> ConnectionPoolConfig -> (Pool backend -> m a) -> m a withSqlPool :: forall backend m a. (MonadLoggerIO m, MonadUnliftIO m, BackendCompatible SqlBackend backend) => (LogFunc -> IO backend) -> Int -> (Pool backend -> m a) -> m a liftSqlPersistMPool :: forall backend m a. (MonadIO m, BackendCompatible SqlBackend backend) => ReaderT backend (NoLoggingT (ResourceT IO)) a -> Pool backend -> m a runSqlPersistMPool :: BackendCompatible SqlBackend backend => ReaderT backend (NoLoggingT (ResourceT IO)) a -> Pool backend -> IO a runSqlPersistM :: BackendCompatible SqlBackend backend => ReaderT backend (NoLoggingT (ResourceT IO)) a -> backend -> IO a -- | Like runSqlConn, but supports specifying an isolation level. runSqlConnWithIsolation :: forall backend m a. (MonadUnliftIO m, BackendCompatible SqlBackend backend) => ReaderT backend m a -> backend -> IsolationLevel -> m a runSqlConn :: forall backend m a. (MonadUnliftIO m, BackendCompatible SqlBackend backend) => ReaderT backend m a -> backend -> m a -- | Like acquireSqlConn, but lets you specify an explicit isolation -- level. acquireSqlConnWithIsolation :: (MonadReader backend m, BackendCompatible SqlBackend backend) => IsolationLevel -> m (Acquire backend) -- | Starts a new transaction on the connection. When the acquired -- connection is released the transaction is committed and the connection -- returned to the pool. -- -- Upon an exception the transaction is rolled back and the connection -- destroyed. -- -- This is equivalent to runSqlConn but does not incur the -- MonadUnliftIO constraint, meaning it can be used within, for -- example, a Conduit pipeline. acquireSqlConn :: (MonadReader backend m, BackendCompatible SqlBackend backend) => m (Acquire backend) -- | This function is how runSqlPoolWithHooks is defined. -- -- It's currently the most general function for using a SQL pool. runSqlPoolWithExtensibleHooks :: forall backend m a. (MonadUnliftIO m, BackendCompatible SqlBackend backend) => ReaderT backend m a -> Pool backend -> Maybe IsolationLevel -> SqlPoolHooks m backend -> m a -- | This function is how runSqlPool and -- runSqlPoolNoTransaction are defined. In addition to the action -- to be performed and the Pool of conections to use, we give you -- the opportunity to provide three actions - initialize, afterwards, and -- onException. runSqlPoolWithHooks :: forall backend m a before after onException. (MonadUnliftIO m, BackendCompatible SqlBackend backend) => ReaderT backend m a -> Pool backend -> Maybe IsolationLevel -> (backend -> m before) -> (backend -> m after) -> (backend -> SomeException -> m onException) -> m a -- | Like runSqlPool, but does not surround the action in a -- transaction. This action might leave your database in a weird state. runSqlPoolNoTransaction :: forall backend m a. (MonadUnliftIO m, BackendCompatible SqlBackend backend) => ReaderT backend m a -> Pool backend -> Maybe IsolationLevel -> m a -- | Like runSqlPool, but supports specifying an isolation level. runSqlPoolWithIsolation :: forall backend m a. (MonadUnliftIO m, BackendCompatible SqlBackend backend) => ReaderT backend m a -> Pool backend -> IsolationLevel -> m a -- | Get a connection from the pool, run the given action, and then return -- the connection to the pool. -- -- This function performs the given action in a transaction. If an -- exception occurs during the action, then the transaction is rolled -- back. -- -- Note: This function previously timed out after 2 seconds, but this -- behavior was buggy and caused more problems than it solved. Since -- version 2.1.2, it performs no timeout checks. runSqlPool :: forall backend m a. (MonadUnliftIO m, BackendCompatible SqlBackend backend) => ReaderT backend m a -> Pool backend -> m a getStmtConn :: SqlBackend -> Text -> IO Statement -- | A helper function to tell GHC what the EntityWithPrefix prefix -- should be. This allows you to use a type application to specify the -- prefix, instead of specifying the etype on the result. -- -- As an example, here's code that uses this: -- --
--   myQuery :: SqlPersistM [Entity Person]
--   myQuery = fmap (unPrefix @"p") $ rawSql query []
--     where
--       query = "SELECT ?? FROM person AS p"
--   
unPrefix :: forall (prefix :: Symbol) record. EntityWithPrefix prefix record -> Entity record -- | Class for data types that may be retrived from a rawSql -- query. class RawSql a -- | Number of columns that this data type needs and the list of -- substitutions for SELECT placeholders ??. rawSqlCols :: RawSql a => (Text -> Text) -> a -> (Int, [Text]) -- | A string telling the user why the column count is what it is. rawSqlColCountReason :: RawSql a => a -> String -- | Transform a row of the result into the data type. rawSqlProcessRow :: RawSql a => [PersistValue] -> Either Text a -- | This newtype wrapper is useful when selecting an entity out of the -- database and you want to provide a prefix to the table being selected. -- -- Consider this raw SQL query: -- --
--   SELECT ??
--   FROM my_long_table_name AS mltn
--   INNER JOIN other_table AS ot
--      ON mltn.some_col = ot.other_col
--   WHERE ...
--   
-- -- We don't want to refer to my_long_table_name every time, so -- we create an alias. If we want to select it, we have to tell the raw -- SQL quasi-quoter that we expect the entity to be prefixed with some -- other name. -- -- We can give the above query a type with this, like: -- --
--   getStuff :: SqlPersistM [EntityWithPrefix "mltn" MyLongTableName]
--   getStuff = rawSql queryText []
--   
-- -- The EntityWithPrefix bit is a boilerplate newtype wrapper, so -- you can remove it with unPrefix, like this: -- --
--   getStuff :: SqlPersistM [Entity MyLongTableName]
--   getStuff = unPrefix @"mltn" <$> rawSql queryText []
--   
-- -- The symbol is a "type application" and requires the -- TypeApplications@ language extension. newtype EntityWithPrefix (prefix :: Symbol) record EntityWithPrefix :: Entity record -> EntityWithPrefix (prefix :: Symbol) record [unEntityWithPrefix] :: EntityWithPrefix (prefix :: Symbol) record -> Entity record -- | Tells Persistent what database column type should be used to store a -- Haskell type. -- --

Examples

-- --
Simple Boolean Alternative
-- --
--   data Switch = On | Off
--     deriving (Show, Eq)
--   
--   instance PersistField Switch where
--     toPersistValue s = case s of
--       On -> PersistBool True
--       Off -> PersistBool False
--     fromPersistValue (PersistBool b) = if b then Right On else Right Off
--     fromPersistValue x = Left $ "File.hs: When trying to deserialize a Switch: expected PersistBool, received: " <> T.pack (show x)
--   
--   instance PersistFieldSql Switch where
--     sqlType _ = SqlBool
--   
-- --
Non-Standard Database Types
-- -- If your database supports non-standard types, such as Postgres' -- uuid, you can use SqlOther to use them: -- --
--   import qualified Data.UUID as UUID
--   instance PersistField UUID where
--     toPersistValue = PersistLiteralEncoded . toASCIIBytes
--     fromPersistValue (PersistLiteralEncoded uuid) =
--       case fromASCIIBytes uuid of
--         Nothing -> Left $ "Model/CustomTypes.hs: Failed to deserialize a UUID; received: " <> T.pack (show uuid)
--         Just uuid' -> Right uuid'
--     fromPersistValue x = Left $ "File.hs: When trying to deserialize a UUID: expected PersistLiteralEncoded, received: "-- >  <> T.pack (show x)
--   
--   instance PersistFieldSql UUID where
--     sqlType _ = SqlOther "uuid"
--   
-- --
User Created Database Types
-- -- Similarly, some databases support creating custom types, e.g. -- Postgres' DOMAIN and ENUM features. You can use -- SqlOther to specify a custom type: -- --
--   CREATE DOMAIN ssn AS text
--         CHECK ( value ~ '^[0-9]{9}$');
--   
-- --
--   instance PersistFieldSQL SSN where
--     sqlType _ = SqlOther "ssn"
--   
-- --
--   CREATE TYPE rainbow_color AS ENUM ('red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet');
--   
-- --
--   instance PersistFieldSQL RainbowColor where
--     sqlType _ = SqlOther "rainbow_color"
--   
class PersistField a => PersistFieldSql a sqlType :: PersistFieldSql a => Proxy a -> SqlType -- | FIXME What's this exactly? limitOffsetOrder :: PersistEntity val => [SelectOpt val] -> (Int, Int, [SelectOpt val]) -- | A more general way to convert instances of ToJSON type class to -- strict text Text. toJsonText :: ToJSON j => j -> Text -- | Convert map (list of tuples) into textual representation of JSON -- object. This is a type-constrained synonym for toJsonText. mapToJSON :: [(Text, PersistValue)] -> Text -- | Convert list of PersistValues into textual representation of -- JSON object. This is a type-constrained synonym for toJsonText. listToJSON :: [PersistValue] -> Text -- | The OR of two lists of filters. For example: -- --
--   selectList
--       ([ PersonAge >. 25
--        , PersonAge <. 30 ] ||.
--        [ PersonIncome >. 15000
--        , PersonIncome <. 25000 ])
--       []
--   
-- -- will filter records where a person's age is between 25 and 30 -- or a person's income is between (15000 and 25000). -- -- If you are looking for an (&&.) operator to do (A -- AND B AND (C OR D)) you can use the (++) operator -- instead as there is no (&&.). For example: -- --
--   selectList
--       ([ PersonAge >. 25
--        , PersonAge <. 30 ] ++
--       ([PersonCategory ==. 1] ||.
--        [PersonCategory ==. 5]))
--       []
--   
-- -- will filter records where a person's age is between 25 and 30 -- and (person's category is either 1 or 5). (||.) :: [Filter v] -> [Filter v] -> [Filter v] infixl 3 ||. -- | Check if value is not in given list. -- --

Examples

-- --
--   selectSimon :: MonadIO m => ReaderT SqlBackend m [Entity User]
--   selectSimon = selectList [UserAge /<-. [40]] []
--   
-- -- The above query when applied on dataset-1, will produce this: -- --
--   +-----+-----+-----+
--   |id   |name |age  |
--   +-----+-----+-----+
--   |2    |Simon|41   |
--   +-----+-----+-----+
--   
(/<-.) :: forall v typ. PersistField typ => EntityField v typ -> [typ] -> Filter v infix 4 /<-. -- | Check if value is in given list. -- --

Examples

-- --
--   selectUsers :: MonadIO m => ReaderT SqlBackend m [Entity User]
--   selectUsers = selectList [UserAge <-. [40, 41]] []
--   
-- -- The above query when applied on dataset-1, will produce this: -- --
--   +-----+-----+-----+
--   |id   |name |age  |
--   +-----+-----+-----+
--   |1    |SPJ  |40   |
--   +-----+-----+-----+
--   |2    |Simon|41   |
--   +-----+-----+-----+
--   
-- --
--   selectSPJ :: MonadIO m => ReaderT SqlBackend m [Entity User]
--   selectSPJ = selectList [UserAge <-. [40]] []
--   
-- -- The above query when applied on dataset-1, will produce this: -- --
--   +-----+-----+-----+
--   |id   |name |age  |
--   +-----+-----+-----+
--   |1    |SPJ  |40   |
--   +-----+-----+-----+
--   
(<-.) :: forall v typ. PersistField typ => EntityField v typ -> [typ] -> Filter v infix 4 <-. -- | Greater-than or equal check. -- --

Examples

-- --
--   selectGreaterEqualAge :: MonadIO m => ReaderT SqlBackend m [Entity User]
--   selectGreaterEqualAge = selectList [UserAge >=. 41 ] []
--   
-- -- The above query when applied on dataset-1, will produce this: -- --
--   +-----+-----+-----+
--   |id   |name |age  |
--   +-----+-----+-----+
--   |2    |Simon|41   |
--   +-----+-----+-----+
--   
(>=.) :: forall v typ. PersistField typ => EntityField v typ -> typ -> Filter v infix 4 >=. -- | Greater-than check. -- --

Examples

-- --
--   selectGreaterAge :: MonadIO m => ReaderT SqlBackend m [Entity User]
--   selectGreaterAge = selectList [UserAge >. 40 ] []
--   
-- -- The above query when applied on dataset-1, will produce this: -- --
--   +-----+-----+-----+
--   |id   |name |age  |
--   +-----+-----+-----+
--   |2    |Simon|41   |
--   +-----+-----+-----+
--   
(>.) :: forall v typ. PersistField typ => EntityField v typ -> typ -> Filter v infix 4 >. -- | Less-than or equal check. -- --

Examples

-- --
--   selectLessEqualAge :: MonadIO m => ReaderT SqlBackend m [Entity User]
--   selectLessEqualAge = selectList [UserAge <=. 40 ] []
--   
-- -- The above query when applied on dataset-1, will produce this: -- --
--   +-----+-----+-----+
--   |id   |name |age  |
--   +-----+-----+-----+
--   |1    |SPJ  |40   |
--   +-----+-----+-----+
--   
(<=.) :: forall v typ. PersistField typ => EntityField v typ -> typ -> Filter v infix 4 <=. -- | Less-than check. -- --

Examples

-- --
--   selectLessAge :: MonadIO m => ReaderT SqlBackend m [Entity User]
--   selectLessAge = selectList [UserAge <. 41 ] []
--   
-- -- The above query when applied on dataset-1, will produce this: -- --
--   +-----+-----+-----+
--   |id   |name |age  |
--   +-----+-----+-----+
--   |1    |SPJ  |40   |
--   +-----+-----+-----+
--   
(<.) :: forall v typ. PersistField typ => EntityField v typ -> typ -> Filter v infix 4 <. -- | Non-equality check. -- --

Examples

-- --
--   selectSimon :: MonadIO m => ReaderT SqlBackend m [Entity User]
--   selectSimon = selectList [UserName !=. "SPJ" ] []
--   
-- -- The above query when applied on dataset-1, will produce this: -- --
--   +-----+-----+-----+
--   |id   |name |age  |
--   +-----+-----+-----+
--   |2    |Simon|41   |
--   +-----+-----+-----+
--   
(!=.) :: forall v typ. PersistField typ => EntityField v typ -> typ -> Filter v infix 4 !=. -- | Check for equality. -- --

Examples

-- --
--   selectSPJ :: MonadIO m => ReaderT SqlBackend m [Entity User]
--   selectSPJ = selectList [UserName ==. "SPJ" ] []
--   
-- -- The above query when applied on dataset-1, will produce this: -- --
--   +-----+-----+-----+
--   |id   |name |age  |
--   +-----+-----+-----+
--   |1    |SPJ  |40   |
--   +-----+-----+-----+
--   
(==.) :: forall v typ. PersistField typ => EntityField v typ -> typ -> Filter v infix 4 ==. -- | Assign a field by division (/=). -- --

Examples

-- --
--   divideAge :: MonadIO m => ReaderT SqlBackend m ()
--   divideAge = updateWhere [UserName ==. "SPJ" ] [UserAge /=. 2]
--   
-- -- The above query when applied on dataset-1, will produce this: -- --
--   +-----+-----+---------+
--   |id   |name |age      |
--   +-----+-----+---------+
--   |1    |SPJ  |40 -> 20 |
--   +-----+-----+---------+
--   |2    |Simon|41       |
--   +-----+-----+---------+
--   
(/=.) :: forall v typ. PersistField typ => EntityField v typ -> typ -> Update v infixr 3 /=. -- | Assign a field by multiplication (*=). -- --

Examples

-- --
--   multiplyAge :: MonadIO m => ReaderT SqlBackend m ()
--   multiplyAge = updateWhere [UserName ==. "SPJ" ] [UserAge *=. 2]
--   
-- -- The above query when applied on dataset-1, will produce this: -- --
--   +-----+-----+--------+
--   |id   |name |age     |
--   +-----+-----+--------+
--   |1    |SPJ  |40 -> 80|
--   +-----+-----+--------+
--   |2    |Simon|41      |
--   +-----+-----+--------+
--   
(*=.) :: forall v typ. PersistField typ => EntityField v typ -> typ -> Update v infixr 3 *=. -- | Assign a field by subtraction (-=). -- --

Examples

-- --
--   subtractAge :: MonadIO m => ReaderT SqlBackend m ()
--   subtractAge = updateWhere [UserName ==. "SPJ" ] [UserAge -=. 1]
--   
-- -- The above query when applied on dataset-1, will produce this: -- --
--   +-----+-----+---------+
--   |id   |name |age      |
--   +-----+-----+---------+
--   |1    |SPJ  |40 -> 39 |
--   +-----+-----+---------+
--   |2    |Simon|41       |
--   +-----+-----+---------+
--   
(-=.) :: forall v typ. PersistField typ => EntityField v typ -> typ -> Update v infixr 3 -=. -- | Assign a field by addition (+=). -- --

Examples

-- --
--   addAge :: MonadIO m => ReaderT SqlBackend m ()
--   addAge = updateWhere [UserName ==. "SPJ" ] [UserAge +=. 1]
--   
-- -- The above query when applied on dataset-1, will produce this: -- --
--   +-----+-----+---------+
--   |id   |name |age      |
--   +-----+-----+---------+
--   |1    |SPJ  |40 -> 41 |
--   +-----+-----+---------+
--   |2    |Simon|41       |
--   +-----+-----+---------+
--   
(+=.) :: forall v typ. PersistField typ => EntityField v typ -> typ -> Update v infixr 3 +=. -- | Assign a field a value. -- --

Examples

-- --
--   updateAge :: MonadIO m => ReaderT SqlBackend m ()
--   updateAge = updateWhere [UserName ==. "SPJ" ] [UserAge =. 45]
--   
-- -- Similar to updateWhere which is shown in the above example you -- can use other functions present in the module -- Database.Persist.Class. Note that the first parameter of -- updateWhere is [Filter val] and second parameter is -- [Update val]. By comparing this with the type of ==. and -- =., you can see that they match up in the above usage. -- -- The above query when applied on dataset-1, will produce this: -- --
--   +-----+-----+--------+
--   |id   |name |age     |
--   +-----+-----+--------+
--   |1    |SPJ  |40 -> 45|
--   +-----+-----+--------+
--   |2    |Simon|41      |
--   +-----+-----+--------+
--   
(=.) :: forall v typ. PersistField typ => EntityField v typ -> typ -> Update v infixr 3 =. -- | Create the list of columns for the given entity. mkColumns :: [EntityDef] -> EntityDef -> BackendSpecificOverrides -> ([Column], [UniqueDef], [ForeignDef]) defaultAttribute :: [FieldAttr] -> Maybe Text -- | Creates an empty BackendSpecificOverrides (i.e. use the default -- behavior; no overrides) emptyBackendSpecificOverrides :: BackendSpecificOverrides -- | Set the backend's foreign key generation function to this value. setBackendSpecificForeignKeyName :: (EntityNameDB -> FieldNameDB -> ConstraintNameDB) -> BackendSpecificOverrides -> BackendSpecificOverrides -- | If the override is defined, then this returns a function that accepts -- an entity name and field name and provides the ConstraintNameDB -- for the foreign key constraint. -- -- An abstract accessor for the BackendSpecificOverrides getBackendSpecificForeignKeyName :: BackendSpecificOverrides -> Maybe (EntityNameDB -> FieldNameDB -> ConstraintNameDB) -- | Record of functions to override the default behavior in -- mkColumns. It is recommended you initialize this with -- emptyBackendSpecificOverrides and override the default values, -- so that as new fields are added, your code still compiles. -- -- For added safety, use the getBackendSpecific* and -- setBackendSpecific* functions, as a breaking change to the -- record field labels won't be reflected in a major version bump of the -- library. data BackendSpecificOverrides -- | Initializes a ConnectionPoolConfig with default values. See the -- documentation of ConnectionPoolConfig for each field's default -- value. defaultConnectionPoolConfig :: ConnectionPoolConfig data Column Column :: !FieldNameDB -> !Bool -> !SqlType -> !Maybe Text -> !Maybe Text -> !Maybe ConstraintNameDB -> !Maybe Integer -> !Maybe ColumnReference -> Column [cName] :: Column -> !FieldNameDB [cNull] :: Column -> !Bool [cSqlType] :: Column -> !SqlType [cDefault] :: Column -> !Maybe Text [cGenerated] :: Column -> !Maybe Text [cDefaultConstraintName] :: Column -> !Maybe ConstraintNameDB [cMaxLen] :: Column -> !Maybe Integer [cReference] :: Column -> !Maybe ColumnReference -- | This value specifies how a field references another table. data ColumnReference ColumnReference :: !EntityNameDB -> !ConstraintNameDB -> !FieldCascade -> ColumnReference -- | The table name that the [crTableName] :: ColumnReference -> !EntityNameDB -- | The name of the foreign key constraint. [crConstraintName] :: ColumnReference -> !ConstraintNameDB -- | Whether or not updates/deletions to the referenced table cascade to -- this table. [crFieldCascade] :: ColumnReference -> !FieldCascade data PersistentSqlException StatementAlreadyFinalized :: Text -> PersistentSqlException Couldn'tGetSQLConnection :: PersistentSqlException type SqlPersistT = ReaderT SqlBackend type SqlPersistM = SqlPersistT NoLoggingT ResourceT IO type ConnectionPool = Pool SqlBackend -- | Values to configure a pool of database connections. See -- Data.Pool for details. data ConnectionPoolConfig ConnectionPoolConfig :: Int -> NominalDiffTime -> Int -> ConnectionPoolConfig -- | How many stripes to divide the pool into. See Data.Pool for -- details. Default: 1. [connectionPoolConfigStripes] :: ConnectionPoolConfig -> Int -- | How long connections can remain idle before being disposed of, in -- seconds. Default: 600 [connectionPoolConfigIdleTimeout] :: ConnectionPoolConfig -> NominalDiffTime -- | How many connections should be held in the connection pool. Default: -- 10 [connectionPoolConfigSize] :: ConnectionPoolConfig -> Int -- | A single column (see rawSql). Any PersistField may -- be used here, including PersistValue (which does not do any -- processing). newtype Single a Single :: a -> Single a [unSingle] :: Single a -> a -- | Useful for running a read query against a backend with unknown -- capabilities. readToUnknown :: forall (m :: Type -> Type) a. Monad m => ReaderT SqlReadBackend m a -> ReaderT SqlBackend m a -- | Useful for running a read query against a backend with read and write -- capabilities. readToWrite :: forall (m :: Type -> Type) a. Monad m => ReaderT SqlReadBackend m a -> ReaderT SqlWriteBackend m a -- | Useful for running a write query against an untagged backend with -- unknown capabilities. writeToUnknown :: forall (m :: Type -> Type) a. Monad m => ReaderT SqlWriteBackend m a -> ReaderT SqlBackend m a -- | An SQL backend which can only handle read queries -- -- The constructor was exposed in 2.10.0. newtype SqlReadBackend SqlReadBackend :: SqlBackend -> SqlReadBackend [$sel:unSqlReadBackend:SqlReadBackend] :: SqlReadBackend -> SqlBackend -- | An SQL backend which can handle read or write queries -- -- The constructor was exposed in 2.10.0 newtype SqlWriteBackend SqlWriteBackend :: SqlBackend -> SqlWriteBackend [$sel:unSqlWriteBackend:SqlWriteBackend] :: SqlWriteBackend -> SqlBackend -- | A constraint synonym which witnesses that a backend is SQL and can run -- read queries. type SqlBackendCanRead backend = (BackendCompatible SqlBackend backend, PersistQueryRead backend, PersistStoreRead backend, PersistUniqueRead backend) -- | A constraint synonym which witnesses that a backend is SQL and can run -- read and write queries. type SqlBackendCanWrite backend = (SqlBackendCanRead backend, PersistQueryWrite backend, PersistStoreWrite backend, PersistUniqueWrite backend) -- | Like SqlPersistT but compatible with any SQL backend which -- can handle read queries. type SqlReadT (m :: Type -> Type) a = forall backend. SqlBackendCanRead backend => ReaderT backend m a -- | Like SqlPersistT but compatible with any SQL backend which -- can handle read and write queries. type SqlWriteT (m :: Type -> Type) a = forall backend. SqlBackendCanWrite backend => ReaderT backend m a -- | A backend which is a wrapper around SqlBackend. type IsSqlBackend backend = (IsPersistBackend backend, BaseBackend backend ~ SqlBackend) -- | A backwards-compatible alias for those that don't care about -- distinguishing between read and write queries. It signifies the -- assumption that, by default, a backend can write as well as read. type PersistUnique a = PersistUniqueWrite a -- | A backwards-compatible alias for those that don't care about -- distinguishing between read and write queries. It signifies the -- assumption that, by default, a backend can write as well as read. type PersistQuery a = PersistQueryWrite a -- | A backwards-compatible alias for those that don't care about -- distinguishing between read and write queries. It signifies the -- assumption that, by default, a backend can write as well as read. type PersistStore a = PersistStoreWrite a -- | Backends supporting conditional read operations. class (PersistCore backend, PersistStoreRead backend) => PersistQueryRead backend -- | Backends supporting conditional write operations class (PersistQueryRead backend, PersistStoreWrite backend) => PersistQueryWrite backend -- | Given a proxy for a PersistEntity record, this returns the sole -- UniqueDef for that entity. onlyOneUniqueDef :: (OnlyOneUniqueKey record, Monad proxy) => proxy record -> UniqueDef -- | Queries against Unique keys (other than the id Key). -- -- Please read the general Persistent documentation to learn how to -- create Unique keys. -- -- Using this with an Entity without a Unique key leads to undefined -- behavior. A few of these functions require a single -- Unique, so using an Entity with multiple Uniques is also -- undefined. In these cases persistent's goal is to throw an exception -- as soon as possible, but persistent is still transitioning to that. -- -- SQL backends automatically create uniqueness constraints, but for -- MongoDB you must manually place a unique index on a field to have a -- uniqueness constraint. class PersistStoreRead backend => PersistUniqueRead backend -- | Returns True if a record with this unique key exists, otherwise False. -- --

Example usage

-- -- With schema-1 and dataset-1: -- --
--   existsBySpjName :: MonadIO m  => ReaderT SqlBackend m Bool
--   existsBySpjName = existsBy $ UniqueUserName "SPJ"
--   
-- --
--   spjEntExists <- existsBySpjName
--   
-- -- The above query when applied on dataset-1, will return the -- value True. existsBy :: forall record (m :: Type -> Type). (PersistUniqueRead backend, MonadIO m, PersistRecordBackend record backend) => Unique record -> ReaderT backend m Bool -- | Some functions in this module (insertUnique, insertBy, -- and replaceUnique) first query the unique indexes to check for -- conflicts. You could instead optimistically attempt to perform the -- operation (e.g. replace instead of replaceUnique). -- However, -- -- class (PersistUniqueRead backend, PersistStoreWrite backend) => PersistUniqueWrite backend -- | Same as insertUnique but doesn't return a Key. -- --

Example usage

-- -- With schema-1 and dataset-1, we try to insert the -- following two records: -- --
--   linusId <- insertUnique_ $ User "Linus" 48
--   spjId   <- insertUnique_ $ User "SPJ" 90
--   
-- --
--   +-----+------+-----+
--   |id   |name  |age  |
--   +-----+------+-----+
--   |1    |SPJ   |40   |
--   +-----+------+-----+
--   |2    |Simon |41   |
--   +-----+------+-----+
--   |3    |Linus |48   |
--   +-----+------+-----+
--   
-- -- Linus's record was inserted to dataset-1, while SPJ wasn't -- because SPJ already exists in dataset-1. insertUnique_ :: forall record (m :: Type -> Type). (PersistUniqueWrite backend, MonadIO m, PersistRecordBackend record backend, SafeToInsert record) => record -> ReaderT backend m (Maybe ()) -- | This class is used to ensure that upsert is only called on -- records that have a single Unique key. The quasiquoter -- automatically generates working instances for appropriate records, and -- generates TypeError instances for records that have 0 or -- multiple unique keys. class PersistEntity record => OnlyOneUniqueKey record onlyUniqueP :: OnlyOneUniqueKey record => record -> Unique record -- | This is an error message. It is used when writing instances of -- OnlyOneUniqueKey for an entity that has no unique keys. type NoUniqueKeysError ty = 'Text "The entity " :<>: 'ShowType ty :<>: 'Text " does not have any unique keys." :$$: 'Text "The function you are trying to call requires a unique key " :<>: 'Text "to be defined on the entity." -- | This is an error message. It is used when an entity has multiple -- unique keys, and the function expects a single unique key. type MultipleUniqueKeysError ty = 'Text "The entity " :<>: 'ShowType ty :<>: 'Text " has multiple unique keys." :$$: 'Text "The function you are trying to call requires only a single " :<>: 'Text "unique key." :$$: 'Text "There is probably a variant of the function with 'By' " :<>: 'Text "appended that will allow you to select a unique key " :<>: 'Text "for the operation." -- | This class is used to ensure that functions requring at least one -- unique key are not called with records that have 0 unique keys. The -- quasiquoter automatically writes working instances for appropriate -- entities, and generates TypeError instances for records that -- have 0 unique keys. class PersistEntity record => AtLeastOneUniqueKey record requireUniquesP :: AtLeastOneUniqueKey record => record -> NonEmpty (Unique record) -- | A SqlBackend represents a handle or connection to a database. -- It contains functions and values that allow databases to have more -- optimized implementations, as well as references that benefit -- performance and sharing. -- -- Instead of using the SqlBackend constructor directly, use the -- mkSqlBackend function. -- -- A SqlBackend is *not* thread-safe. You should not assume that a -- SqlBackend can be shared among threads and run concurrent -- queries. This *will* result in problems. Instead, you should create a -- Pool SqlBackend, known as a -- ConnectionPool, and pass that around in multi-threaded -- applications. -- -- To run actions in the persistent library, you should use the -- runSqlConn function. If you're using a multithreaded -- application, use the runSqlPool function. data SqlBackend liftPersist :: (MonadIO m, MonadReader backend m) => ReaderT backend IO b -> m b -- | Run a query against a compatible backend, by projecting the backend -- -- This is a helper for using queries which run against a specific -- backend type that your backend is compatible with. withCompatibleBackend :: forall sup sub (m :: Type -> Type) a. BackendCompatible sup sub => ReaderT sup m a -> ReaderT sub m a -- | Run a query against a larger backend by plucking out BaseBackend -- backend -- -- This is a helper for reusing existing queries when expanding the -- backend type. withBaseBackend :: forall backend (m :: Type -> Type) a. HasPersistBackend backend => ReaderT (BaseBackend backend) m a -> ReaderT backend m a type family BaseBackend backend -- | Class which allows the plucking of a BaseBackend backend from -- some larger type. For example, instance HasPersistBackend -- (SqlReadBackend, Int) where type BaseBackend (SqlReadBackend, Int) = -- SqlBackend persistBackend = unSqlReadBackend . fst class HasPersistBackend backend where { type family BaseBackend backend; } persistBackend :: HasPersistBackend backend => backend -> BaseBackend backend -- | Class which witnesses that backend is essentially the same as -- BaseBackend backend. That is, they're isomorphic and -- backend is just some wrapper over BaseBackend -- backend. class HasPersistBackend backend => IsPersistBackend backend -- | This class witnesses that two backend are compatible, and that you can -- convert from the sub backend into the sup backend. -- This is similar to the HasPersistBackend and -- IsPersistBackend classes, but where you don't want to fix the -- type associated with the PersistEntityBackend of a record. -- -- Generally speaking, where you might have: -- --
--   foo ::
--     ( PersistEntity record
--     , PersistEntityBackend record ~ BaseBackend backend
--     , IsSqlBackend backend
--     )
--   
-- -- this can be replaced with: -- --
--   foo ::
--     ( PersistEntity record,
--     , PersistEntityBackend record ~ backend
--     , BackendCompatible SqlBackend backend
--     )
--   
-- -- This works for SqlReadBackend because of the instance -- BackendCompatible SqlBackend -- SqlReadBackend, without needing to go through the -- BaseBackend type family. -- -- Likewise, functions that are currently hardcoded to use -- SqlBackend can be generalized: -- --
--   -- before:
--   asdf :: ReaderT SqlBackend m ()
--   asdf = pure ()
--   
--   -- after:
--   asdf' :: BackendCompatible SqlBackend backend => ReaderT backend m ()
--   asdf' = withCompatibleBackend asdf
--   
class BackendCompatible sup sub projectBackend :: BackendCompatible sup sub => sub -> sup -- | A convenient alias for common type signatures type PersistRecordBackend record backend = (PersistEntity record, PersistEntityBackend record ~ BaseBackend backend) -- | ToBackendKey converts a PersistEntity Key into a -- BackendKey This can be used by each backend to convert between -- a Key and a plain Haskell type. For Sql, that is done with -- toSqlKey and fromSqlKey. -- -- By default, a PersistEntity uses the default BackendKey -- for its Key and is an instance of ToBackendKey -- -- A Key that instead uses a custom type will not be an instance -- of ToBackendKey. class (PersistEntity record, PersistEntityBackend record ~ backend, PersistCore backend) => ToBackendKey backend record toBackendKey :: ToBackendKey backend record => Key record -> BackendKey backend fromBackendKey :: ToBackendKey backend record => BackendKey backend -> Key record data family BackendKey backend class PersistCore backend where { data family BackendKey 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 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 -- | Convenience function for getting a free PersistField instance -- from a type with JSON instances. The JSON parser used will accept JSON -- values other that object and arrays. So, if your instance serializes -- the data to a JSON string, this will still work. -- -- Example usage in combination with toPersistValueJSON: -- --
--   instance PersistField MyData where
--     fromPersistValue = fromPersistValueJSON
--     toPersistValue = toPersistValueJSON
--   
fromPersistValueJSON :: FromJSON a => PersistValue -> Either Text a -- | Convenience function for getting a free PersistField instance -- from a type with JSON instances. -- -- Example usage in combination with fromPersistValueJSON: -- --
--   instance PersistField MyData where
--     fromPersistValue = fromPersistValueJSON
--     toPersistValue = toPersistValueJSON
--   
toPersistValueJSON :: ToJSON a => a -> PersistValue -- | Predefined parseJSON. The input JSON looks like {"id": 1, -- "name": ...}. -- -- The typical usage is: -- --
--   instance FromJSON (Entity User) where
--       parseJSON = entityIdFromJSON
--   
entityIdFromJSON :: (PersistEntity record, FromJSON record) => Value -> Parser (Entity record) -- | Predefined toJSON. The resulting JSON looks like {"id": -- 1, "name": ...}. -- -- The typical usage is: -- --
--   instance ToJSON (Entity User) where
--       toJSON = entityIdToJSON
--   
entityIdToJSON :: (PersistEntity record, ToJSON record) => Entity record -> Value -- | Predefined parseJSON. The input JSON looks like {"key": -- 1, "value": {"name": ...}}. -- -- The typical usage is: -- --
--   instance FromJSON (Entity User) where
--       parseJSON = keyValueEntityFromJSON
--   
keyValueEntityFromJSON :: (PersistEntity record, FromJSON record) => Value -> Parser (Entity record) -- | Predefined toJSON. The resulting JSON looks like {"key": -- 1, "value": {"name": ...}}. -- -- The typical usage is: -- --
--   instance ToJSON (Entity User) where
--       toJSON = keyValueEntityToJSON
--   
keyValueEntityToJSON :: (PersistEntity record, ToJSON record) => Entity record -> Value -- | Get list of values corresponding to given entity. entityValues :: PersistEntity record => Entity record -> [PersistValue] -- | Construct an Entity record by providing a value for -- each of the record's fields. -- -- These constructions are equivalent: -- --
--   entityMattConstructor, entityMattTabulate :: Entity User
--   entityMattConstructor =
--       Entity
--           { entityKey = toSqlKey 123
--           , entityVal =
--               User
--                   { userName = Matt
--                   , userAge = 33
--                   }
--           }
--   
--   entityMattTabulate =
--       tabulateEntity $ \case
--           UserId ->
--               toSqlKey 123
--           UserName ->
--               Matt
--           UserAge ->
--               33
--   
-- -- This is a specialization of tabulateEntityA, which allows you -- to construct an Entity by providing an Applicative -- action for each field instead of a regular function. tabulateEntity :: PersistEntity record => (forall a. () => EntityField record a -> a) -> Entity record -- | Unique keys besides the Key. data family Unique record -- | An EntityField is parameterised by the Haskell record it -- belongs to and the additional type of that field. -- -- As of persistent-2.11.0.0, it's possible to use the -- OverloadedLabels language extension to refer to -- EntityField values polymorphically. See the documentation on -- SymbolToField for more information. data family EntityField record :: Type -> Type -- | By default, a backend will automatically generate the key Instead you -- can specify a Primary key made up of unique values. data family Key record -- | Persistent allows multiple different backends (databases). type family PersistEntityBackend record -- | Persistent serialized Haskell records to the database. A Database -- Entity (A row in SQL, a document in MongoDB, etc) corresponds -- to a Key plus a Haskell record. -- -- For every Haskell record type stored in the database there is a -- corresponding PersistEntity instance. An instance of -- PersistEntity contains meta-data for the record. PersistEntity also -- helps abstract over different record types. That way the same query -- interface can return a PersistEntity, with each query returning -- different types of Haskell records. -- -- Some advanced type system capabilities are used to make this process -- type-safe. Persistent users usually don't need to understand the class -- associated data and functions. 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 { -- | Persistent allows multiple different backends (databases). type family PersistEntityBackend record; -- | By default, a backend will automatically generate the key Instead you -- can specify a Primary key made up of unique values. data family Key record; -- | An EntityField is parameterised by the Haskell record it -- belongs to and the additional type of that field. -- -- As of persistent-2.11.0.0, it's possible to use the -- OverloadedLabels language extension to refer to -- EntityField values polymorphically. See the documentation on -- SymbolToField for more information. data family EntityField record :: Type -> Type; -- | Unique keys besides the Key. data family Unique record; } -- | A lower-level key operation. keyToValues :: PersistEntity record => Key record -> [PersistValue] -- | A lower-level key operation. keyFromValues :: PersistEntity record => [PersistValue] -> Either Text (Key record) -- | A meta-operation to retrieve the Key EntityField. persistIdField :: PersistEntity record => EntityField record (Key record) -- | Retrieve the EntityDef meta-data for the record. entityDef :: PersistEntity record => proxy record -> EntityDef -- | Return meta-data for a given EntityField. persistFieldDef :: PersistEntity record => EntityField record typ -> FieldDef -- | A meta-operation to get the database fields of a record. toPersistFields :: PersistEntity record => record -> [PersistValue] -- | A lower-level operation to convert from database values to a Haskell -- record. fromPersistValues :: PersistEntity record => [PersistValue] -> Either Text record -- | This function allows you to build an Entity a by -- specifying an action that returns a value for the field in the -- callback function. Let's look at an example. -- --
--   parseFromEnvironmentVariables :: IO (Entity User)
--   parseFromEnvironmentVariables =
--       tabulateEntityA $ \userField ->
--           case userField of
--               UserName ->
--                   getEnv USER_NAME
--               UserAge -> do
--                   ageVar <- getEnv USER_AGE
--                   case readMaybe ageVar of
--                       Just age ->
--                           pure age
--                       Nothing ->
--                           error $ "Failed to parse Age from: " <> ageVar
--               UserAddressId -> do
--                   addressVar <- getEnv USER_ADDRESS_ID
--                   pure $ AddressKey addressVar
--   
tabulateEntityA :: (PersistEntity record, Applicative f) => (forall a. () => EntityField record a -> f a) -> f (Entity record) -- | A meta operation to retrieve all the Unique keys. persistUniqueKeys :: PersistEntity record => record -> [Unique record] -- | A lower level operation. persistUniqueToFieldNames :: PersistEntity record => Unique record -> NonEmpty (FieldNameHS, FieldNameDB) -- | A lower level operation. persistUniqueToValues :: PersistEntity record => Unique record -> [PersistValue] -- | Use a PersistField as a lens. fieldLens :: PersistEntity record => EntityField record field -> forall (f :: Type -> Type). Functor f => (field -> f field) -> Entity record -> f (Entity record) -- | Extract a Key record from a record value. -- Currently, this is only defined for entities using the -- Primary syntax for natural/composite keys. In a future -- version of persistent which incorporates the ID directly into -- the entity, this will always be Just. keyFromRecordM :: PersistEntity record => Maybe (record -> Key record) type family BackendSpecificUpdate backend record -- | Updating a database entity. -- -- Persistent users use combinators to create these. data Update record Update :: EntityField record typ -> typ -> PersistUpdate -> Update record [updateField] :: Update record -> EntityField record typ [updateValue] :: Update record -> typ [updateUpdate] :: Update record -> PersistUpdate BackendUpdate :: BackendSpecificUpdate (PersistEntityBackend record) record -> Update record -- | Query options. -- -- Persistent users use these directly. data SelectOpt record Asc :: EntityField record typ -> SelectOpt record Desc :: EntityField record typ -> SelectOpt record OffsetBy :: Int -> SelectOpt record LimitTo :: Int -> SelectOpt record type family BackendSpecificFilter backend record -- | Filters which are available for select, updateWhere -- and deleteWhere. Each filter constructor specifies the field -- being filtered on, the type of comparison applied (equals, not equals, -- etc) and the argument for the comparison. -- -- Persistent users use combinators to create these. -- -- Note that it's important to be careful about the PersistFilter -- that you are using, if you use this directly. For example, using the -- In PersistFilter requires that you have an array- or -- list-shaped EntityField. It is possible to construct values -- using this that will create malformed runtime values. data Filter record Filter :: EntityField record typ -> FilterValue typ -> PersistFilter -> Filter record [filterField] :: Filter record -> EntityField record typ [filterValue] :: Filter record -> FilterValue typ [filterFilter] :: Filter record -> PersistFilter -- | convenient for internal use, not needed for the API FilterAnd :: [Filter record] -> Filter record FilterOr :: [Filter record] -> Filter record BackendFilter :: BackendSpecificFilter (PersistEntityBackend record) record -> Filter record -- | Value to filter with. Highly dependant on the type of filter used. data FilterValue typ [FilterValue] :: forall typ. typ -> FilterValue typ [FilterValues] :: forall typ. [typ] -> FilterValue typ [UnsafeValue] :: forall a typ. PersistField a => a -> FilterValue typ -- | Datatype that represents an entity, with both its Key and its -- Haskell record representation. -- -- When using a SQL-based backend (such as SQLite or PostgreSQL), an -- Entity may take any number of columns depending on how many -- fields it has. In order to reconstruct your entity on the Haskell -- side, persistent needs all of your entity columns and in the -- right order. Note that you don't need to worry about this when using -- persistent's API since everything is handled correctly behind -- the scenes. -- -- However, if you want to issue a raw SQL command that returns an -- Entity, then you have to be careful with the column order. -- While you could use SELECT Entity.* WHERE ... and that would -- work most of the time, there are times when the order of the columns -- on your database is different from the order that persistent -- expects (for example, if you add a new field in the middle of you -- entity definition and then use the migration code -- -- persistent will expect the column to be in the middle, but -- your DBMS will put it as the last column). So, instead of using a -- query like the one above, you may use rawSql (from the -- Database.Persist.Sql module) with its /entity selection -- placeholder/ (a double question mark ??). Using -- rawSql the query above must be written as SELECT ?? WHERE -- ... Then rawSql will replace ?? with the list -- of all columns that we need from your entity in the right order. If -- your query returns two entities (i.e. (Entity backend a, Entity -- backend b)), then you must you use SELECT ??, ?? WHERE -- ..., and so on. data Entity record Entity :: Key record -> record -> Entity record [entityKey] :: Entity record -> Key record [entityVal] :: Entity record -> record -- | This type class is used with the OverloadedLabels extension -- to provide a more convenient means of using the EntityField -- type. EntityField definitions are prefixed with the type name -- to avoid ambiguity, but this ambiguity can result in verbose code. -- -- If you have a table User with a name Text field, -- then the corresponding EntityField is UserName. With -- this, we can write #name :: EntityField User Text. -- -- What's more fun is that the type is more general: it's actually -- #name :: (SymbolToField "name" rec typ) => EntityField rec -- typ -- -- Which means it is *polymorphic* over the actual record. This allows -- you to write code that can be generic over the tables, provided they -- have the right fields. class SymbolToField (sym :: Symbol) rec typ | sym rec -> typ symbolToField :: SymbolToField sym rec typ => EntityField rec typ -- | A type class which is used to witness that a type is safe to insert -- into the database without providing a primary key. -- -- The TemplateHaskell function mkPersist will generate -- instances of this class for any entity that it works on. If the entity -- has a default primary key, then it provides a regular instance. If the -- entity has a Primary natural key, then this works fine. But -- if the entity has an Id column with no default=, -- then this does a TypeError and forces the user to use -- insertKey. class SafeToInsert a -- | FIXME Add documentation to that. getPersistMap :: PersistValue -> Either Text [(Text, PersistValue)] -- | This class teaches Persistent how to take a custom type and marshal it -- to and from a PersistValue, allowing it to be stored in a -- database. -- --

Examples

-- --
Simple Newtype
-- -- You can use newtype to add more type safety/readability to a -- basis type like ByteString. In these cases, just derive -- PersistField and PersistFieldSql: -- --
--   {-# LANGUAGE GeneralizedNewtypeDeriving #-}
--   
--   newtype HashedPassword = HashedPassword ByteString
--     deriving (Eq, Show, PersistField, PersistFieldSql)
--   
-- --
Smart Constructor Newtype
-- -- In this example, we create a PersistField instance for a -- newtype following the "Smart Constructor" pattern. -- --
--   {-# LANGUAGE GeneralizedNewtypeDeriving #-}
--   import qualified Data.Text as T
--   import qualified Data.Char as C
--   
--   -- | An American Social Security Number
--   newtype SSN = SSN ErrorMessage
--    deriving (Eq, Show, PersistFieldSql)
--   
--   mkSSN :: ErrorMessage -> Either ErrorMessage SSN
--   mkSSN t = if (T.length t == 9) && (T.all C.isDigit t)
--    then Right $ SSN t
--    else Left $ "Invalid SSN: " <> t
--   
--   instance PersistField SSN where
--     toPersistValue (SSN t) = PersistText t
--     fromPersistValue (PersistText t) = mkSSN t
--     -- Handle cases where the database does not give us PersistText
--     fromPersistValue x = Left $ "File.hs: When trying to deserialize an SSN: expected PersistText, received: " <> T.pack (show x)
--   
-- -- Tips: -- -- class PersistField a toPersistValue :: PersistField a => a -> PersistValue fromPersistValue :: PersistField a => PersistValue -> Either Text a -- | Prior to persistent-2.11.0, we provided an instance of -- PersistField for the Natural type. This was in error, -- because Natural represents an infinite value, and databases -- don't have reasonable types for this. -- -- The instance for Natural used the Int64 underlying type, -- which will cause underflow and overflow errors. This type has the -- exact same code in the instances, and will work seamlessly. -- -- A more appropriate type for this is the Word series of types -- from Data.Word. These have a bounded size, are guaranteed to be -- non-negative, and are quite efficient for the database to store. newtype OverflowNatural OverflowNatural :: Natural -> OverflowNatural [unOverflowNatural] :: OverflowNatural -> Natural -- | Perform a mapping function over all of the entity fields, as -- determined by getEntityFieldsDatabase. overEntityFields :: ([FieldDef] -> [FieldDef]) -> EntityDef -> EntityDef getEntityKeyFields :: EntityDef -> NonEmpty FieldDef setEntityIdDef :: EntityIdDef -> EntityDef -> EntityDef -- | Set an entityId to be the given FieldDef. setEntityId :: FieldDef -> EntityDef -> EntityDef getEntityIdField :: EntityDef -> Maybe FieldDef getEntityId :: EntityDef -> EntityIdDef isEntitySum :: EntityDef -> Bool -- | This returns all of the FieldDef defined for the -- EntityDef, including those fields that are marked as -- MigrationOnly (and therefore only present in the database) or -- SafeToRemove (and a migration will drop the column if it -- exists in the database). -- -- For all the fields that are present on the Haskell-type, see -- getEntityFields. getEntityFieldsDatabase :: EntityDef -> [FieldDef] -- | Retrieve the list of FieldDef that makes up the fields of the -- entity. -- -- This does not return the fields for an Id column or an -- implicit id. It will return the key columns if you used the -- Primary syntax for defining the primary key. -- -- This does not return fields that are marked SafeToRemove or -- MigrationOnly - so it only returns fields that are -- represented in the Haskell type. If you need those fields, use -- getEntityFieldsDatabase. getEntityFields :: EntityDef -> [FieldDef] getEntityForeignDefs :: EntityDef -> [ForeignDef] getEntityComments :: EntityDef -> Maybe Text setEntityDBName :: EntityNameDB -> EntityDef -> EntityDef getEntityExtra :: EntityDef -> Map Text [[Text]] -- | Return the database name for the given entity. getEntityDBName :: EntityDef -> EntityNameDB -- | Retrieve the Haskell name of the given entity. getEntityHaskellName :: EntityDef -> EntityNameHS -- | Retrieve the list of UniqueDef from an EntityDef. As of -- version 2.14, this will also include the primary key on the entity, if -- one is defined. If you do not want the primary key, see -- getEntityUniquesNoPrimaryKey. getEntityUniques :: EntityDef -> [UniqueDef] -- | Retrieve the list of UniqueDef from an EntityDef. This -- does not include a Primary key, if one is defined. A future -- version of persistent will include a Primary key -- among the Unique constructors for the Entity. getEntityUniquesNoPrimaryKey :: EntityDef -> [UniqueDef] -- | Check if the field is `Maybe a` isFieldMaybe :: FieldDef -> Bool -- | Check if the field definition is nullable isFieldNullable :: FieldDef -> IsNullable -- | Add an attribute to the list of field attributes. addFieldAttr :: FieldAttr -> FieldDef -> FieldDef -- | Modify the list of field attributes. overFieldAttrs :: ([FieldAttr] -> [FieldAttr]) -> FieldDef -> FieldDef -- | Replace the FieldDef FieldAttr with the new list. setFieldAttrs :: [FieldAttr] -> FieldDef -> FieldDef type LogFunc = Loc -> LogSource -> LogLevel -> LogStr -> IO () data InsertSqlResult ISRSingle :: Text -> InsertSqlResult ISRInsertGet :: Text -> Text -> InsertSqlResult ISRManyKeys :: Text -> [PersistValue] -> InsertSqlResult -- | A Statement is a representation of a database query that has -- been prepared and stored on the server side. data Statement Statement :: IO () -> IO () -> ([PersistValue] -> IO Int64) -> (forall (m :: Type -> Type). MonadIO m => [PersistValue] -> Acquire (ConduitM () [PersistValue] m ())) -> Statement [stmtFinalize] :: Statement -> IO () [stmtReset] :: Statement -> IO () [stmtExecute] :: Statement -> [PersistValue] -> IO Int64 [stmtQuery] :: Statement -> forall (m :: Type -> Type). MonadIO m => [PersistValue] -> Acquire (ConduitM () [PersistValue] m ()) -- | Render a CascadeAction to Text such that it can be used -- in a SQL command. renderCascadeAction :: CascadeAction -> Text -- | Renders a FieldCascade value such that it can be used in SQL -- migrations. renderFieldCascade :: FieldCascade -> Text -- | A FieldCascade that does nothing. noCascade :: FieldCascade -- | Returns True if the FieldDef does not have a -- MigrationOnly or SafeToRemove flag from the -- QuasiQuoter. isHaskellField :: FieldDef -> Bool isFieldNotGenerated :: FieldDef -> Bool -- | Parse raw field attributes into structured form. Any unrecognized -- attributes will be preserved, identically as they are encountered, as -- FieldAttrOther values. parseFieldAttrs :: [Text] -> [FieldAttr] -- | Returns a NonEmpty list of FieldDef that correspond with -- the key columns for an EntityDef. keyAndEntityFields :: EntityDef -> NonEmpty FieldDef entityPrimary :: EntityDef -> Maybe CompositeDef -- | Return the [FieldDef] for the entity keys. entitiesPrimary :: EntityDef -> NonEmpty FieldDef fieldAttrsContainsNullable :: [FieldAttr] -> IsNullable -- | A Checkmark should be used as a field type whenever a -- uniqueness constraint should guarantee that a certain kind of record -- may appear at most once, but other kinds of records may appear any -- number of times. -- -- NOTE: You need to mark any Checkmark fields as -- nullable (see the following example). -- -- For example, suppose there's a Location entity that -- represents where a user has lived: -- --
--   Location
--       user    UserId
--       name    Text
--       current Checkmark nullable
--   
--       UniqueLocation user current
--   
-- -- The UniqueLocation constraint allows any number of -- Inactive Locations to be current. However, -- there may be at most one current Location per user -- (i.e., either zero or one per user). -- -- This data type works because of the way that SQL treats -- NULLable fields within uniqueness constraints. The SQL -- standard says that NULL values should be considered -- different, so we represent Inactive as SQL NULL, thus -- allowing any number of Inactive records. On the other hand, we -- represent Active as TRUE, so the uniqueness constraint -- will disallow more than one Active record. -- -- Note: There may be DBMSs that do not respect the SQL standard's -- treatment of NULL values on uniqueness constraints, please -- check if this data type works before relying on it. -- -- The SQL BOOLEAN type is used because it's the smallest data -- type available. Note that we never use FALSE, just -- TRUE and NULL. Provides the same behavior Maybe -- () would if () was a valid PersistField. data Checkmark -- | When used on a uniqueness constraint, there may be at most one -- Active record. Active :: Checkmark -- | When used on a uniqueness constraint, there may be any number of -- Inactive records. Inactive :: Checkmark data IsNullable Nullable :: !WhyNullable -> IsNullable NotNullable :: IsNullable -- | The reason why a field is nullable is very important. A field -- that is nullable because of a Maybe tag will have its type -- changed from A to Maybe A. OTOH, a field that is -- nullable because of a nullable tag will remain with the same -- type. data WhyNullable ByMaybeAttr :: WhyNullable ByNullableAttr :: WhyNullable -- | An EntityDef represents the information that -- persistent knows about an Entity. It uses this information to -- generate the Haskell datatype, the SQL migrations, and other relevant -- conversions. data EntityDef -- | The definition for the entity's primary key ID. data EntityIdDef -- | The entity has a single key column, and it is a surrogate key - that -- is, you can't go from rec -> Key rec. EntityIdField :: !FieldDef -> EntityIdDef -- | The entity has a natural key. This means you can write rec -> -- Key rec because all the key fields are present on the datatype. -- -- A natural key can have one or more columns. EntityIdNaturalKey :: !CompositeDef -> EntityIdDef type ExtraLine = [Text] type Attr = Text -- | Attributes that may be attached to fields that can affect migrations -- and serialization in backend-specific ways. -- -- While we endeavor to, we can't forsee all use cases for all backends, -- and so FieldAttr is extensible through its constructor -- FieldAttrOther. data FieldAttr -- | The Maybe keyword goes after the type. This indicates that the -- column is nullable, and the generated Haskell code will have a -- Maybe type for it. -- -- Example: -- --
--   User
--       name Text Maybe
--   
FieldAttrMaybe :: FieldAttr -- | This indicates that the column is nullable, but should not have a -- Maybe type. For this to work out, you need to ensure that the -- PersistField instance for the type in question can support a -- PersistNull value. -- --
--   data What = NoWhat | Hello Text
--   
--   instance PersistField What where
--       fromPersistValue PersistNull =
--           pure NoWhat
--       fromPersistValue pv =
--           Hello $ fromPersistValue pv
--   
--   instance PersistFieldSql What where
--       sqlType _ = SqlString
--   
--   User
--       what What nullable
--   
FieldAttrNullable :: FieldAttr -- | This tag means that the column will not be present on the Haskell -- code, but will not be removed from the database. Useful to deprecate -- fields in phases. -- -- You should set the column to be nullable in the database. Otherwise, -- inserts won't have values. -- --
--   User
--       oldName Text MigrationOnly
--       newName Text
--   
FieldAttrMigrationOnly :: FieldAttr -- | A SafeToRemove attribute is not present on the Haskell -- datatype, and the backend migrations should attempt to drop the column -- without triggering any unsafe migration warnings. -- -- Useful after you've used MigrationOnly to remove a column -- from the database in phases. -- --
--   User
--       oldName Text SafeToRemove
--       newName Text
--   
FieldAttrSafeToRemove :: FieldAttr -- | This attribute indicates that we should not create a foreign key -- reference from a column. By default, persistent will try and -- create a foreign key reference for a column if it can determine that -- the type of the column is a Key entity or an -- EntityId and the Entity's name was present in -- mkPersist. -- -- This is useful if you want to use the explicit foreign key syntax. -- --
--   Post
--       title    Text
--   
--   Comment
--       postId   PostId      noreference
--       Foreign Post fk_comment_post postId
--   
FieldAttrNoreference :: FieldAttr -- | This is set to specify precisely the database table the column refers -- to. -- --
--   Post
--       title    Text
--   
--   Comment
--       postId   PostId references="post"
--   
-- -- You should not need this - persistent should be capable of -- correctly determining the target table's name. If you do need this, -- please file an issue describing why. FieldAttrReference :: Text -> FieldAttr -- | Specify a name for the constraint on the foreign key reference for -- this table. -- --
--   Post
--       title    Text
--   
--   Comment
--       postId   PostId constraint="my_cool_constraint_name"
--   
FieldAttrConstraint :: Text -> FieldAttr -- | Specify the default value for a column. -- --
--   User
--       createdAt    UTCTime     default="NOW()"
--   
-- -- Note that a default= attribute does not mean you can omit the -- value while inserting. FieldAttrDefault :: Text -> FieldAttr -- | Specify a custom SQL type for the column. Generally, you should define -- a custom datatype with a custom PersistFieldSql instance -- instead of using this. -- --
--   User
--       uuid     Text    sqltype=UUID
--   
FieldAttrSqltype :: Text -> FieldAttr -- | Set a maximum length for a column. Useful for VARCHAR and indexes. -- --
--   User
--       name     Text    maxlen=200
--   
--       UniqueName name
--   
FieldAttrMaxlen :: Integer -> FieldAttr -- | Specify the database name of the column. -- --
--   User
--       blarghle     Int     sql="b_l_a_r_g_h_l_e"
--   
-- -- Useful for performing phased migrations, where one column is renamed -- to another column over time. FieldAttrSql :: Text -> FieldAttr -- | A grab bag of random attributes that were unrecognized by the parser. FieldAttrOther :: Text -> FieldAttr -- | A FieldType describes a field parsed from the QuasiQuoter and -- is used to determine the Haskell type in the generated code. -- -- name Text parses into FTTypeCon Nothing Text -- -- name T.Text parses into FTTypeCon (Just T -- Text) -- -- name (Jsonb User) parses into: -- --
--   FTApp (FTTypeCon Nothing Jsonb) (FTTypeCon Nothing User)
--   
data FieldType -- | Optional module and name. FTTypeCon :: Maybe Text -> Text -> FieldType FTLit :: FieldTypeLit -> FieldType FTTypePromoted :: Text -> FieldType FTApp :: FieldType -> FieldType -> FieldType FTList :: FieldType -> FieldType -- | There are 3 kinds of references 1) composite (to fields that exist in -- the record) 2) single field 3) embedded data ReferenceDef NoReference :: ReferenceDef -- | A ForeignRef has a late binding to the EntityDef it references via -- name and has the Haskell type of the foreign key in the form of -- FieldType ForeignRef :: !EntityNameHS -> ReferenceDef EmbedRef :: EntityNameHS -> ReferenceDef -- | A SelfReference stops an immediate cycle which causes non-termination -- at compile-time (issue #311). SelfReference :: ReferenceDef -- | An EmbedEntityDef is the same as an EntityDef But it is only used for -- fieldReference so it only has data needed for embedding data EmbedEntityDef EmbedEntityDef :: EntityNameHS -> [EmbedFieldDef] -> EmbedEntityDef [embeddedHaskell] :: EmbedEntityDef -> EntityNameHS [embeddedFields] :: EmbedEntityDef -> [EmbedFieldDef] -- | An EmbedFieldDef is the same as a FieldDef But it is only used for -- embeddedFields so it only has data needed for embedding data EmbedFieldDef EmbedFieldDef :: FieldNameDB -> Maybe (Either SelfEmbed EntityNameHS) -> EmbedFieldDef [emFieldDB] :: EmbedFieldDef -> FieldNameDB [emFieldEmbed] :: EmbedFieldDef -> Maybe (Either SelfEmbed EntityNameHS) -- | Type for storing the Uniqueness constraint in the Schema. Assume you -- have the following schema with a uniqueness constraint: -- --
--   Person
--     name String
--     age Int
--     UniqueAge age
--   
-- -- This will be represented as: -- --
--   UniqueDef
--       { uniqueHaskell = ConstraintNameHS (packPTH UniqueAge)
--       , uniqueDBName = ConstraintNameDB (packPTH "unique_age")
--       , uniqueFields = [(FieldNameHS (packPTH "age"), FieldNameDB (packPTH "age"))]
--       , uniqueAttrs = []
--       }
--   
data UniqueDef UniqueDef :: !ConstraintNameHS -> !ConstraintNameDB -> !NonEmpty (FieldNameHS, FieldNameDB) -> ![Attr] -> UniqueDef [uniqueHaskell] :: UniqueDef -> !ConstraintNameHS [uniqueDBName] :: UniqueDef -> !ConstraintNameDB [uniqueFields] :: UniqueDef -> !NonEmpty (FieldNameHS, FieldNameDB) [uniqueAttrs] :: UniqueDef -> ![Attr] data CompositeDef CompositeDef :: !NonEmpty FieldDef -> ![Attr] -> CompositeDef [compositeFields] :: CompositeDef -> !NonEmpty FieldDef [compositeAttrs] :: CompositeDef -> ![Attr] -- | Used instead of FieldDef to generate a smaller amount of code type ForeignFieldDef = (FieldNameHS, FieldNameDB) data ForeignDef ForeignDef :: !EntityNameHS -> !EntityNameDB -> !ConstraintNameHS -> !ConstraintNameDB -> !FieldCascade -> ![(ForeignFieldDef, ForeignFieldDef)] -> ![Attr] -> Bool -> Bool -> ForeignDef [foreignRefTableHaskell] :: ForeignDef -> !EntityNameHS [foreignRefTableDBName] :: ForeignDef -> !EntityNameDB [foreignConstraintNameHaskell] :: ForeignDef -> !ConstraintNameHS [foreignConstraintNameDBName] :: ForeignDef -> !ConstraintNameDB -- | Determine how the field will cascade on updates and deletions. [foreignFieldCascade] :: ForeignDef -> !FieldCascade [foreignFields] :: ForeignDef -> ![(ForeignFieldDef, ForeignFieldDef)] [foreignAttrs] :: ForeignDef -> ![Attr] [foreignNullable] :: ForeignDef -> Bool -- | Determines if the reference is towards a Primary Key or not. [foreignToPrimary] :: ForeignDef -> Bool -- | This datatype describes how a foreign reference field cascades deletes -- or updates. -- -- This type is used in both parsing the model definitions and performing -- migrations. A Nothing in either of the field values means that -- the user has not specified a CascadeAction. An unspecified -- CascadeAction is defaulted to Restrict when doing -- migrations. data FieldCascade FieldCascade :: !Maybe CascadeAction -> !Maybe CascadeAction -> FieldCascade [fcOnUpdate] :: FieldCascade -> !Maybe CascadeAction [fcOnDelete] :: FieldCascade -> !Maybe CascadeAction -- | An action that might happen on a deletion or update on a foreign key -- change. data CascadeAction Cascade :: CascadeAction Restrict :: CascadeAction SetNull :: CascadeAction SetDefault :: CascadeAction data PersistException -- | Generic Exception PersistError :: Text -> PersistException PersistMarshalError :: Text -> PersistException PersistInvalidField :: Text -> PersistException PersistForeignConstraintUnmet :: Text -> PersistException PersistMongoDBError :: Text -> PersistException PersistMongoDBUnsupported :: Text -> PersistException -- | A SQL data type. Naming attempts to reflect the underlying Haskell -- datatypes, eg SqlString instead of SqlVarchar. Different SQL databases -- may have different translations for these types. data SqlType SqlString :: SqlType SqlInt32 :: SqlType SqlInt64 :: SqlType SqlReal :: SqlType SqlNumeric :: Word32 -> Word32 -> SqlType SqlBool :: SqlType SqlDay :: SqlType SqlTime :: SqlType -- | Always uses UTC timezone SqlDayTime :: SqlType SqlBlob :: SqlType -- | a backend-specific name SqlOther :: Text -> SqlType data PersistFilter Eq :: PersistFilter Ne :: PersistFilter Gt :: PersistFilter Lt :: PersistFilter Ge :: PersistFilter Le :: PersistFilter In :: PersistFilter NotIn :: PersistFilter BackendSpecificFilter :: Text -> PersistFilter data UpdateException KeyNotFound :: String -> UpdateException UpsertError :: String -> UpdateException data PersistUpdate Assign :: PersistUpdate Add :: PersistUpdate Subtract :: PersistUpdate Multiply :: PersistUpdate Divide :: PersistUpdate BackendSpecificUpdate :: Text -> PersistUpdate -- | A FieldDef represents the inormation that persistent -- knows about a field of a datatype. This includes information used to -- parse the field out of the database and what the field corresponds to. data FieldDef FieldDef :: !FieldNameHS -> !FieldNameDB -> !FieldType -> !SqlType -> ![FieldAttr] -> !Bool -> !ReferenceDef -> !FieldCascade -> !Maybe Text -> !Maybe Text -> !Bool -> FieldDef -- | The name of the field. Note that this does not corresponds to the -- record labels generated for the particular entity - record labels are -- generated with the type name prefixed to the field, so a -- FieldDef that contains a FieldNameHS "name" for -- a type User will have a record field userName. [fieldHaskell] :: FieldDef -> !FieldNameHS -- | The name of the field in the database. For SQL databases, this -- corresponds to the column name. [fieldDB] :: FieldDef -> !FieldNameDB -- | The type of the field in Haskell. [fieldType] :: FieldDef -> !FieldType -- | The type of the field in a SQL database. [fieldSqlType] :: FieldDef -> !SqlType -- | User annotations for a field. These are provided with the ! -- operator. [fieldAttrs] :: FieldDef -> ![FieldAttr] -- | If this is True, then the Haskell datatype will have a strict -- record field. The default value for this is True. [fieldStrict] :: FieldDef -> !Bool [fieldReference] :: FieldDef -> !ReferenceDef -- | Defines how operations on the field cascade on to the referenced -- tables. This doesn't have any meaning if the fieldReference is -- set to NoReference or SelfReference. The cascade option -- here should be the same as the one obtained in the -- fieldReference. [fieldCascade] :: FieldDef -> !FieldCascade -- | Optional comments for a Field. [fieldComments] :: FieldDef -> !Maybe Text -- | Whether or not the field is a GENERATED column, and -- additionally the expression to use for generation. [fieldGenerated] :: FieldDef -> !Maybe Text -- | True if the field is an implicit ID column. False -- otherwise. [fieldIsImplicitIdColumn] :: FieldDef -> !Bool -- | Please refer to the documentation for the database in question for a -- full overview of the semantics of the varying isloation levels data IsolationLevel ReadUncommitted :: IsolationLevel ReadCommitted :: IsolationLevel RepeatableRead :: IsolationLevel Serializable :: IsolationLevel fromPersistValueText :: PersistValue -> Either Text Text -- | A raw value which can be stored in any backend and can be marshalled -- to and from a PersistField. data PersistValue PersistText :: Text -> PersistValue PersistByteString :: ByteString -> PersistValue PersistInt64 :: Int64 -> PersistValue PersistDouble :: Double -> PersistValue PersistRational :: Rational -> PersistValue PersistBool :: Bool -> PersistValue PersistDay :: Day -> PersistValue PersistTimeOfDay :: TimeOfDay -> PersistValue PersistUTCTime :: UTCTime -> PersistValue PersistNull :: PersistValue PersistList :: [PersistValue] -> PersistValue PersistMap :: [(Text, PersistValue)] -> PersistValue -- | Intended especially for MongoDB backend PersistObjectId :: ByteString -> PersistValue -- | Intended especially for PostgreSQL backend for text arrays PersistArray :: [PersistValue] -> PersistValue -- | This constructor is used to specify some raw literal value for the -- backend. The LiteralType value specifies how the value should -- be escaped. This can be used to make special, custom types avaialable -- in the back end. PersistLiteral_ :: LiteralType -> ByteString -> PersistValue -- | This pattern synonym used to be a data constructor for the -- PersistValue type. It was changed to be a pattern so that -- JSON-encoded database values could be parsed into their corresponding -- values. You should not use this, and instead prefer to pattern match -- on PersistLiteral_ directly. -- -- If you use this, it will overlap a patern match on the -- 'PersistLiteral_, PersistLiteral, and -- PersistLiteralEscaped patterns. If you need to disambiguate -- between these constructors, pattern match on PersistLiteral_ -- directly. pattern PersistDbSpecific :: ByteString -> PersistValue -- | This pattern synonym used to be a data constructor on -- PersistValue, but was changed into a catch-all pattern synonym -- to allow backwards compatiblity with database types. See the -- documentation on PersistDbSpecific for more details. pattern PersistLiteralEscaped :: ByteString -> PersistValue -- | This pattern synonym used to be a data constructor on -- PersistValue, but was changed into a catch-all pattern synonym -- to allow backwards compatiblity with database types. See the -- documentation on PersistDbSpecific for more details. pattern PersistLiteral :: ByteString -> PersistValue -- | A type that determines how a backend should handle the literal. data LiteralType -- | The accompanying value will be escaped before inserting into the -- database. This is the correct default choice to use. Escaped :: LiteralType -- | The accompanying value will not be escaped when inserting into the -- database. This is potentially dangerous - use this with care. Unescaped :: LiteralType -- | The DbSpecific constructor corresponds to the legacy -- PersistDbSpecific constructor. We need to keep this around -- because old databases may have serialized JSON representations that -- reference this. We don't want to break the ability of a database to -- load rows. DbSpecific :: LiteralType -- | Convenience operations for working with '-NameDB' types. class DatabaseName a escapeWith :: DatabaseName a => (Text -> str) -> a -> str -- | A FieldNameDB represents the datastore-side name that -- persistent will use for a field. newtype FieldNameDB FieldNameDB :: Text -> FieldNameDB [unFieldNameDB] :: FieldNameDB -> Text -- | A FieldNameHS represents the Haskell-side name that -- persistent will use for a field. newtype FieldNameHS FieldNameHS :: Text -> FieldNameHS [unFieldNameHS] :: FieldNameHS -> Text -- | An EntityNameHS represents the Haskell-side name that -- persistent will use for an entity. newtype EntityNameHS EntityNameHS :: Text -> EntityNameHS [unEntityNameHS] :: EntityNameHS -> Text -- | An EntityNameDB represents the datastore-side name that -- persistent will use for an entity. newtype EntityNameDB EntityNameDB :: Text -> EntityNameDB [unEntityNameDB] :: EntityNameDB -> Text -- | A ConstraintNameDB represents the datastore-side name that -- persistent will use for a constraint. newtype ConstraintNameDB ConstraintNameDB :: Text -> ConstraintNameDB [unConstraintNameDB] :: ConstraintNameDB -> Text -- | An ConstraintNameHS represents the Haskell-side name that -- persistent will use for a constraint. newtype ConstraintNameHS ConstraintNameHS :: Text -> ConstraintNameHS [unConstraintNameHS] :: ConstraintNameHS -> Text type family PersistConfigPool c type family PersistConfigBackend c :: Type -> Type -> Type -> Type -- | Represents a value containing all the configuration options for a -- specific backend. This abstraction makes it easier to write code that -- can easily swap backends. class PersistConfig c where { type family PersistConfigBackend c :: Type -> Type -> Type -> Type; type family PersistConfigPool c; } -- | Load the config settings from a Value, most likely taken from a -- YAML config file. loadConfig :: PersistConfig c => Value -> Parser c -- | Modify the config settings based on environment variables. applyEnv :: PersistConfig c => c -> IO c -- | Create a new connection pool based on the given config settings. createPoolConfig :: PersistConfig c => c -> IO (PersistConfigPool c) -- | Run a database action by taking a connection from the pool. runPool :: (PersistConfig c, MonadUnliftIO m) => c -> PersistConfigBackend c m a -> PersistConfigPool c -> m a -- | The lifted version of get get :: (PersistRecordBackend record SqlBackend, Typeable record, MonadSqlQuery m) => Key record -> m (Maybe record) -- | The lifted version of getMany getMany :: (PersistRecordBackend record SqlBackend, Typeable record, MonadSqlQuery m) => [Key record] -> m (Map (Key record) record) -- | The lifted version of getJust getJust :: (PersistRecordBackend record SqlBackend, Typeable record, MonadSqlQuery m) => Key record -> m record -- | The lifted version of getJustEntity getJustEntity :: (PersistRecordBackend record SqlBackend, Typeable record, MonadSqlQuery m) => Key record -> m (Entity record) -- | The lifted version of getEntity getEntity :: (PersistRecordBackend record SqlBackend, Typeable record, MonadSqlQuery m) => Key record -> m (Maybe (Entity record)) -- | The lifted version of belongsTo belongsTo :: (PersistEntity record1, PersistRecordBackend record2 SqlBackend, Typeable record1, Typeable record2, MonadSqlQuery m) => (record1 -> Maybe (Key record2)) -> record1 -> m (Maybe record2) -- | The lifted version of belongsToJust belongsToJust :: (PersistEntity record1, PersistRecordBackend record2 SqlBackend, Typeable record1, Typeable record2, MonadSqlQuery m) => (record1 -> Key record2) -> record1 -> m record2 -- | The lifted version of insert insert :: (PersistRecordBackend record SqlBackend, SafeToInsert record, Typeable record, MonadSqlQuery m) => record -> m (Key record) -- | The lifted version of insert_ insert_ :: (PersistRecordBackend record SqlBackend, SafeToInsert record, Typeable record, MonadSqlQuery m) => record -> m () -- | The lifted version of insertMany insertMany :: (PersistRecordBackend record SqlBackend, SafeToInsert record, Typeable record, MonadSqlQuery m) => [record] -> m [Key record] -- | The lifted version of insertMany_ insertMany_ :: (PersistRecordBackend record SqlBackend, SafeToInsert record, Typeable record, MonadSqlQuery m) => [record] -> m () -- | The lifted version of insertEntityMany insertEntityMany :: (PersistRecordBackend record SqlBackend, Typeable record, MonadSqlQuery m) => [Entity record] -> m () -- | The lifted version of insertKey insertKey :: (PersistRecordBackend record SqlBackend, Typeable record, MonadSqlQuery m) => Key record -> record -> m () -- | The lifted version of repsert repsert :: (PersistRecordBackend record SqlBackend, Typeable record, MonadSqlQuery m) => Key record -> record -> m () -- | The lifted version of repsertMany repsertMany :: (PersistRecordBackend record SqlBackend, Typeable record, MonadSqlQuery m) => [(Key record, record)] -> m () -- | The lifted version of replace replace :: (PersistRecordBackend record SqlBackend, Typeable record, MonadSqlQuery m) => Key record -> record -> m () -- | The lifted version of delete delete :: (PersistRecordBackend record SqlBackend, Typeable record, MonadSqlQuery m) => Key record -> m () -- | The lifted version of update update :: (PersistRecordBackend record SqlBackend, Typeable record, MonadSqlQuery m) => Key record -> [Update record] -> m () -- | The lifted version of updateGet updateGet :: (PersistRecordBackend record SqlBackend, Typeable record, MonadSqlQuery m) => Key record -> [Update record] -> m record -- | The lifted version of insertEntity insertEntity :: (PersistRecordBackend record SqlBackend, SafeToInsert record, Typeable record, MonadSqlQuery m) => record -> m (Entity record) -- | The lifted version of insertRecord insertRecord :: (PersistRecordBackend record SqlBackend, SafeToInsert record, Typeable record, MonadSqlQuery m) => record -> m record -- | The lifted version of getBy getBy :: (PersistRecordBackend record SqlBackend, Typeable record, MonadSqlQuery m) => Unique record -> m (Maybe (Entity record)) -- | The lifted version of getByValue getByValue :: (PersistRecordBackend record SqlBackend, AtLeastOneUniqueKey record, Typeable record, MonadSqlQuery m) => record -> m (Maybe (Entity record)) -- | The lifted version of checkUnique checkUnique :: (PersistRecordBackend record SqlBackend, Typeable record, MonadSqlQuery m) => record -> m (Maybe (Unique record)) -- | The lifted version of checkUniqueUpdateable checkUniqueUpdateable :: (PersistRecordBackend record SqlBackend, Typeable record, MonadSqlQuery m) => Entity record -> m (Maybe (Unique record)) -- | The lifted version of deleteBy deleteBy :: (PersistRecordBackend record SqlBackend, Typeable record, MonadSqlQuery m) => Unique record -> m () -- | The lifted version of insertUnique insertUnique :: (PersistRecordBackend record SqlBackend, SafeToInsert record, Typeable record, MonadSqlQuery m) => record -> m (Maybe (Key record)) -- | The lifted version of upsert upsert :: (PersistRecordBackend record SqlBackend, OnlyOneUniqueKey record, SafeToInsert record, Typeable record, MonadSqlQuery m) => record -> [Update record] -> m (Entity record) -- | The lifted version of upsertBy upsertBy :: (PersistRecordBackend record SqlBackend, SafeToInsert record, Typeable record, MonadSqlQuery m) => Unique record -> record -> [Update record] -> m (Entity record) -- | The lifted version of putMany putMany :: (PersistRecordBackend record SqlBackend, SafeToInsert record, Typeable record, MonadSqlQuery m) => [record] -> m () -- | The lifted version of insertBy insertBy :: (PersistRecordBackend record SqlBackend, AtLeastOneUniqueKey record, SafeToInsert record, Typeable record, MonadSqlQuery m) => record -> m (Either (Entity record) (Key record)) -- | The lifted version of insertUniqueEntity insertUniqueEntity :: (PersistRecordBackend record SqlBackend, SafeToInsert record, Typeable record, MonadSqlQuery m) => record -> m (Maybe (Entity record)) -- | The lifted version of replaceUnique replaceUnique :: (PersistRecordBackend record SqlBackend, Eq (Unique record), Eq record, Typeable record, MonadSqlQuery m) => Key record -> record -> m (Maybe (Unique record)) -- | The lifted version of onlyUnique onlyUnique :: (PersistRecordBackend record SqlBackend, OnlyOneUniqueKey record, Typeable record, MonadSqlQuery m) => record -> m (Unique record) -- | The lifted version of selectSourceRes selectSourceRes :: (MonadIO m2, PersistRecordBackend record SqlBackend, Typeable record, MonadSqlQuery m) => [Filter record] -> [SelectOpt record] -> m (Acquire (ConduitM () (Entity record) m2 ())) -- | The lifted version of selectFirst selectFirst :: (PersistRecordBackend record SqlBackend, Typeable record, MonadSqlQuery m) => [Filter record] -> [SelectOpt record] -> m (Maybe (Entity record)) -- | The lifted version of selectKeysRes selectKeysRes :: (MonadIO m2, PersistRecordBackend record SqlBackend, Typeable record, MonadSqlQuery m) => [Filter record] -> [SelectOpt record] -> m (Acquire (ConduitM () (Key record) m2 ())) -- | The lifted version of count count :: (PersistRecordBackend record SqlBackend, Typeable record, MonadSqlQuery m) => [Filter record] -> m Int -- | The lifted version of exists exists :: (PersistRecordBackend record SqlBackend, Typeable record, MonadSqlQuery m) => [Filter record] -> m Bool -- | The lifted version of selectSource selectSource :: (PersistRecordBackend record SqlBackend, MonadResource m, Typeable record, MonadSqlQuery m) => [Filter record] -> [SelectOpt record] -> ConduitM () (Entity record) m () -- | The lifted version of selectKeys selectKeys :: (PersistRecordBackend record SqlBackend, MonadResource m, Typeable record, MonadSqlQuery m) => [Filter record] -> [SelectOpt record] -> ConduitM () (Key record) m () -- | The lifted version of selectList selectList :: (PersistRecordBackend record SqlBackend, Typeable record, MonadSqlQuery m) => [Filter record] -> [SelectOpt record] -> m [Entity record] -- | The lifted version of selectKeysList selectKeysList :: (PersistRecordBackend record SqlBackend, Typeable record, MonadSqlQuery m) => [Filter record] -> [SelectOpt record] -> m [Key record] -- | The lifted version of updateWhere updateWhere :: (PersistRecordBackend record SqlBackend, Typeable record, MonadSqlQuery m) => [Filter record] -> [Update record] -> m () -- | The lifted version of deleteWhere deleteWhere :: (PersistRecordBackend record SqlBackend, Typeable record, MonadSqlQuery m) => [Filter record] -> m () -- | The lifted version of deleteWhereCount deleteWhereCount :: (PersistRecordBackend record SqlBackend, Typeable record, MonadSqlQuery m) => [Filter record] -> m Int64 -- | The lifted version of updateWhereCount updateWhereCount :: (PersistRecordBackend record SqlBackend, Typeable record, MonadSqlQuery m) => [Filter record] -> [Update record] -> m Int64 -- | The lifted version of parseMigration parseMigration :: (HasCallStack, MonadSqlQuery m) => Migration -> m (Either [Text] CautiousMigration) -- | The lifted version of parseMigration' parseMigration' :: (HasCallStack, MonadSqlQuery m) => Migration -> m CautiousMigration -- | The lifted version of printMigration printMigration :: (HasCallStack, MonadSqlQuery m) => Migration -> m () -- | The lifted version of showMigration showMigration :: (HasCallStack, MonadSqlQuery m) => Migration -> m [Text] -- | The lifted version of getMigration getMigration :: (HasCallStack, MonadSqlQuery m) => Migration -> m [Sql] -- | The lifted version of runMigration runMigration :: MonadSqlQuery m => Migration -> m () -- | The lifted version of runMigrationQuiet runMigrationQuiet :: MonadSqlQuery m => Migration -> m [Text] -- | The lifted version of runMigrationSilent runMigrationSilent :: MonadSqlQuery m => Migration -> m [Text] -- | The lifted version of runMigrationUnsafe runMigrationUnsafe :: MonadSqlQuery m => Migration -> m () -- | The lifted version of runMigrationUnsafeQuiet runMigrationUnsafeQuiet :: (HasCallStack, MonadSqlQuery m) => Migration -> m [Text] -- | The lifted version of getFieldName getFieldName :: (PersistRecordBackend record SqlBackend, Typeable record, MonadSqlQuery m) => EntityField record typ -> m Text -- | The lifted version of getTableName getTableName :: (PersistRecordBackend record SqlBackend, Typeable record, MonadSqlQuery m) => record -> m Text -- | The lifted version of withRawQuery withRawQuery :: MonadSqlQuery m => Text -> [PersistValue] -> ConduitM [PersistValue] Void IO a -> m a -- | The lifted version of rawQueryRes rawQueryRes :: (MonadIO m2, MonadSqlQuery m) => Text -> [PersistValue] -> m (Acquire (ConduitM () [PersistValue] m2 ())) -- | The lifted version of rawQuery rawQuery :: (MonadResource m, MonadSqlQuery m) => Text -> [PersistValue] -> ConduitM () [PersistValue] m () -- | The lifted version of rawExecute rawExecute :: MonadSqlQuery m => Text -> [PersistValue] -> m () -- | The lifted version of rawExecuteCount rawExecuteCount :: MonadSqlQuery m => Text -> [PersistValue] -> m Int64 -- | The lifted version of rawSql rawSql :: (RawSql a, MonadSqlQuery m) => Text -> [PersistValue] -> m [a] -- | The lifted version of transactionSave transactionSave :: MonadSqlQuery m => m () -- | The lifted version of transactionSaveWithIsolation transactionSaveWithIsolation :: MonadSqlQuery m => IsolationLevel -> m () -- | The lifted version of transactionUndo transactionUndo :: MonadSqlQuery m => m () -- | The lifted version of transactionUndoWithIsolation transactionUndoWithIsolation :: MonadSqlQuery m => IsolationLevel -> m () -- | Lift an arbitrary SqlPersistT action into MonadSqlQuery. -- -- This is unsafe because the action may be rerun. This function should -- primarily be used to interop with other libraries built on top of -- persistent. -- -- Example usage: -- --
--   -- | Run an esqueleto select.
--   select :: (MonadSqlQuery m, E.SqlSelect a r) => E.SqlQuery a -> m [r]
--   select q = unsafeLiftSql "esqueleto-select" (E.select q)
--   
unsafeLiftSql :: MonadSqlQuery m => Text -> (forall m2. MonadIO m2 => SqlPersistT m2 a) -> m a