-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Monad classes for running queries with Persistent and Esqueleto -- -- This package introduces two classes: MonadSqlBackend for monadic -- contexts in which a SqlBackend is available, and MonadSqlBackend for -- contexts in which we can execute a SQL transaction. -- -- Additionally, this package provides variants of query-running -- utilities from Persistent and Esqueleto which are concretized to use -- SqlBackend, generalized to a MonadSqlBackend m constraint rather than -- "ReaderT backend", and wrapped in checkpointCallStack so that -- exceptions will include call stacks. @package persistent-sql-lifted @version 0.1.0.0 module Database.Persist.Sql.Lifted.HasSqlBackend class HasSqlBackend a getSqlBackend :: HasSqlBackend a => a -> SqlBackend instance Database.Persist.Sql.Lifted.HasSqlBackend.HasSqlBackend Database.Persist.SqlBackend.Internal.SqlBackend module Database.Persist.Sql.Lifted.MonadSqlBackend -- | A monadic context in which a SQL backend is available for running -- database queries class MonadUnliftIO m => MonadSqlBackend m getSqlBackendM :: MonadSqlBackend m => m SqlBackend -- | Generalize from SqlPersistT to MonadSqlBackend liftSql :: (MonadSqlBackend m, HasCallStack) => ReaderT SqlBackend m a -> m a instance (Database.Persist.Sql.Lifted.HasSqlBackend.HasSqlBackend r, Control.Monad.IO.Unlift.MonadUnliftIO m) => Database.Persist.Sql.Lifted.MonadSqlBackend.MonadSqlBackend (Control.Monad.Trans.Reader.ReaderT r m) module Database.Persist.Sql.Lifted.MonadSqlTx -- | The constraint MonadSqlTx db m indicates that -- m is a monadic context that can run db actions, -- usually as a SQL transaction. Typically, this means that db -- needs a connection and m can provide one, e.g. from a -- connection pool. class (MonadSqlBackend db, MonadUnliftIO m) => MonadSqlTx db m | m -> db -- | Runs the action in a SQL transaction runSqlTx :: (MonadSqlTx db m, HasCallStack) => db a -> m a module Database.Persist.Sql.Lifted.Core -- | The constraint MonadSqlTx db m indicates that -- m is a monadic context that can run db actions, -- usually as a SQL transaction. Typically, this means that db -- needs a connection and m can provide one, e.g. from a -- connection pool. class (MonadSqlBackend db, MonadUnliftIO m) => MonadSqlTx db m | m -> db -- | Runs the action in a SQL transaction runSqlTx :: (MonadSqlTx db m, HasCallStack) => db a -> m a class HasSqlBackend a getSqlBackend :: HasSqlBackend a => a -> SqlBackend -- | 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 -- | A monadic context in which a SQL backend is available for running -- database queries class MonadUnliftIO m => MonadSqlBackend m getSqlBackendM :: MonadSqlBackend m => m SqlBackend -- | Generalize from SqlPersistT to MonadSqlBackend liftSql :: (MonadSqlBackend m, HasCallStack) => ReaderT SqlBackend m a -> m a -- | Wrappers that apply liftSql to Esqueleto utilities of the same -- name. module Database.Persist.Sql.Lifted.Esqueleto -- | Execute an Esqueleto DELETE query delete :: forall m. (MonadSqlBackend m, HasCallStack) => SqlQuery () -> m () -- | Execute an Esqueleto DELETE query deleteCount :: forall m. (MonadSqlBackend m, HasCallStack) => SqlQuery () -> m Int64 -- | Delete a specific record by identifier -- -- Does nothing if record does not exist. deleteKey :: forall a m. (PersistEntity a, PersistEntityBackend a ~ SqlBackend, MonadSqlBackend m, HasCallStack) => Key a -> m () -- | Insert a PersistField for every selected value insertSelect :: forall a m. (PersistEntity a, MonadSqlBackend m, HasCallStack) => SqlQuery (SqlExpr (Insertion a)) -> m () -- | Insert a PersistField for every selected value, returning the -- count insertSelectCount :: forall a m. (PersistEntity a, MonadSqlBackend m, HasCallStack) => SqlQuery (SqlExpr (Insertion a)) -> m Int64 -- | Renders a SqlQuery to Text along with the list of -- PersistValues that would be supplied to the database for -- ? placeholders renderQueryDelete :: forall a r m. (SqlSelect a r, MonadSqlBackend m, HasCallStack) => SqlQuery a -> m (Text, [PersistValue]) -- | Renders a SqlQuery to Text along with the list of -- PersistValues that would be supplied to the database for -- ? placeholders renderQueryInsertInto :: forall a r m. (SqlSelect a r, MonadSqlBackend m, HasCallStack) => SqlQuery a -> m (Text, [PersistValue]) -- | Renders a SqlQuery to Text along with the list of -- PersistValues that would be supplied to the database for -- ? placeholders renderQuerySelect :: forall a r m. (SqlSelect a r, MonadSqlBackend m, HasCallStack) => SqlQuery a -> m (Text, [PersistValue]) -- | Renders a SqlQuery to Text along with the list of -- PersistValues that would be supplied to the database for -- ? placeholders renderQueryToText :: forall a r m. (SqlSelect a r, MonadSqlBackend m, HasCallStack) => Mode -> SqlQuery a -> m (Text, [PersistValue]) -- | Renders a SqlQuery to Text along with the list of -- PersistValues that would be supplied to the database for -- ? placeholders renderQueryUpdate :: forall a r m. (SqlSelect a r, MonadSqlBackend m, HasCallStack) => SqlQuery a -> m (Text, [PersistValue]) -- | Execute an Esqueleto SELECT query select :: forall a r m. (SqlSelect a r, MonadSqlBackend m, HasCallStack) => SqlQuery a -> m [r] -- | Execute an Esqueleto SELECT query, getting only the first row selectOne :: forall a r m. (SqlSelect a r, MonadSqlBackend m, HasCallStack) => SqlQuery a -> m (Maybe r) -- | Execute an Esqueleto UPDATE query update :: forall a m. (PersistEntity a, PersistEntityBackend a ~ SqlBackend, MonadSqlBackend m, HasCallStack) => (SqlExpr (Entity a) -> SqlQuery ()) -> m () -- | Execute an Esqueleto UPDATE query, returning the count updateCount :: forall a m. (PersistEntity a, PersistEntityBackend a ~ SqlBackend, MonadSqlBackend m, HasCallStack) => (SqlExpr (Entity a) -> SqlQuery ()) -> m Int64 -- | Wrappers that apply liftSql to Persistent utilities of the same -- name. module Database.Persist.Sql.Lifted.Persistent -- | Check whether there are any conflicts for unique keys with this entity -- and existing entities in the database checkUnique :: forall a m. (PersistEntity a, PersistEntityBackend a ~ SqlBackend, MonadSqlBackend m, HasCallStack) => a -> m (Maybe (Unique a)) -- | Check whether there are any conflicts for unique keys with this entity -- and existing entities in the database -- -- This is useful for updating because it ignores conflicts when the -- particular entity already exists. checkUniqueUpdateable :: forall a m. (PersistEntity a, PersistEntityBackend a ~ SqlBackend, MonadSqlBackend m, HasCallStack) => Entity a -> m (Maybe (Unique a)) -- | The total number of records fulfilling the given criteria count :: forall a m. (PersistEntity a, PersistEntityBackend a ~ SqlBackend, MonadSqlBackend m, HasCallStack) => [Filter a] -> m Int -- | Delete a specific record by identifier -- -- Does nothing if record does not exist. delete :: forall a m. (PersistEntity a, PersistEntityBackend a ~ SqlBackend, MonadSqlBackend m, HasCallStack) => Key a -> m () -- | Delete a specific record by unique key -- -- Does nothing if no record matches. deleteBy :: forall a m. (PersistEntity a, PersistEntityBackend a ~ SqlBackend, MonadSqlBackend m, HasCallStack) => Unique a -> m () -- | Delete all records matching the given criteria deleteWhere :: forall a m. (PersistEntity a, PersistEntityBackend a ~ SqlBackend, MonadSqlBackend m, HasCallStack) => [Filter a] -> m () -- | Check if there is at least one record fulfilling the given criteria exists :: forall a m. (PersistEntity a, PersistEntityBackend a ~ SqlBackend, MonadSqlBackend m, HasCallStack) => [Filter a] -> m Bool -- | Get a record by identifier, if available get :: forall a m. (PersistEntity a, PersistEntityBackend a ~ SqlBackend, MonadSqlBackend m, HasCallStack) => Key a -> m (Maybe a) -- | Get a record by unique key, if available, returning both the -- identifier and the record getBy :: forall a m. (PersistEntity a, PersistEntityBackend a ~ SqlBackend, MonadSqlBackend m, HasCallStack) => Unique a -> m (Maybe (Entity a)) getByValue :: forall a m. (PersistEntityBackend a ~ SqlBackend, AtLeastOneUniqueKey a, MonadSqlBackend m, HasCallStack) => a -> m (Maybe (Entity a)) -- | Get a record by identifier, if available getEntity :: forall a m. (PersistEntity a, PersistEntityBackend a ~ SqlBackend, MonadSqlBackend m, HasCallStack) => Key a -> m (Maybe (Entity a)) -- | Get a record by identifier, if available, for a non-null (not -- Maybe) foreign key -- -- Unsafe unless your database is enforcing that the foreign key is -- valid. getJust :: forall a m. (PersistEntity a, PersistEntityBackend a ~ SqlBackend, MonadSqlBackend m, HasCallStack) => Key a -> m a -- | Get a record by identifier, if available, for a non-null (not -- Maybe) foreign key -- -- Unsafe unless your database is enforcing that the foreign key is -- valid. getJustEntity :: forall a m. (PersistEntity a, PersistEntityBackend a ~ SqlBackend, MonadSqlBackend m, HasCallStack) => Key a -> m (Entity a) -- | Get many records by their respective identifiers, if available getMany :: forall a m. (PersistEntity a, PersistEntityBackend a ~ SqlBackend, MonadSqlBackend m, HasCallStack) => [Key a] -> m (Map (Key a) a) -- | Create a new record in the database insert :: forall a m. (PersistEntity a, PersistEntityBackend a ~ SqlBackend, SafeToInsert a, MonadSqlBackend m, HasCallStack) => a -> m (Key a) -- | Create a new record in the database insert_ :: forall a m. (PersistEntity a, PersistEntityBackend a ~ SqlBackend, SafeToInsert a, MonadSqlBackend m, HasCallStack) => a -> m () -- | Insert a value, checking for conflicts with any unique constraints insertBy :: forall a m. (PersistEntityBackend a ~ SqlBackend, AtLeastOneUniqueKey a, SafeToInsert a, MonadSqlBackend m, HasCallStack) => a -> m (Either (Entity a) (Key a)) -- | Create a new record in the database, returning an auto-increment ID -- and the inserted record insertEntity :: forall a m. (PersistEntity a, PersistEntityBackend a ~ SqlBackend, SafeToInsert a, MonadSqlBackend m, HasCallStack) => a -> m (Entity a) -- | Create multiple records in the database, with specified keys insertEntityMany :: forall a m. (PersistEntity a, PersistEntityBackend a ~ SqlBackend, MonadSqlBackend m, HasCallStack) => [Entity a] -> m () -- | Create a new record in the database using the given key insertKey :: forall a m. (PersistEntity a, PersistEntityBackend a ~ SqlBackend, MonadSqlBackend m, HasCallStack) => Key a -> a -> m () -- | Create multiple records in the database and return their Keys insertMany :: forall a m. (PersistEntity a, PersistEntityBackend a ~ SqlBackend, SafeToInsert a, MonadSqlBackend m, HasCallStack) => [a] -> m [Key a] -- | Create multiple records in the database insertMany_ :: forall a m. (PersistEntity a, PersistEntityBackend a ~ SqlBackend, SafeToInsert a, MonadSqlBackend m, HasCallStack) => [a] -> m () -- | Create a new record in the database insertRecord :: forall a m. (PersistEntity a, PersistEntityBackend a ~ SqlBackend, SafeToInsert a, MonadSqlBackend m, HasCallStack) => a -> m a -- | Create a new record in the database insertUnique :: forall a m. (PersistEntity a, PersistEntityBackend a ~ SqlBackend, SafeToInsert a, MonadSqlBackend m, HasCallStack) => a -> m (Maybe (Key a)) -- | Create a new record in the database insertUniqueEntity :: forall a m. (PersistEntity a, PersistEntityBackend a ~ SqlBackend, SafeToInsert a, MonadSqlBackend m, HasCallStack) => a -> m (Maybe (Entity a)) -- | Return the single unique key for a record onlyUnique :: forall a m. (PersistEntityBackend a ~ SqlBackend, OnlyOneUniqueKey a, MonadSqlBackend m, HasCallStack) => a -> m (Unique a) -- | Put many records into the database -- -- putMany :: forall a m. (PersistEntity a, PersistEntityBackend a ~ SqlBackend, SafeToInsert a, MonadSqlBackend m, HasCallStack) => [a] -> m () -- | Replace the record in the database with the given key -- -- The result is undefined if such record does not exist. replace :: forall a m. (PersistEntity a, PersistEntityBackend a ~ SqlBackend, MonadSqlBackend m, HasCallStack) => Key a -> a -> m () -- | Attempt to replace the record of the given key with the given new -- record -- -- First query the unique fields to make sure the replacement maintains -- uniqueness constraints. replaceUnique :: forall a m. (PersistEntity a, PersistEntityBackend a ~ SqlBackend, Eq (Unique a), MonadSqlBackend m, HasCallStack) => Key a -> a -> m (Maybe (Unique a)) -- | Put the record in the database with the given key -- -- If a record with the given key does not exist then a new record will -- be inserted. repsert :: forall a m. (PersistEntity a, PersistEntityBackend a ~ SqlBackend, MonadSqlBackend m, HasCallStack) => Key a -> a -> m () -- | Put many entities into the database -- -- For each item, if a record with the given key does not exist then a -- new record will be inserted. repsertMany :: forall a m. (PersistEntity a, PersistEntityBackend a ~ SqlBackend, MonadSqlBackend m, HasCallStack) => [(Key a, a)] -> m () -- | Get just the first record for the criteria selectFirst :: forall a m. (PersistEntity a, PersistEntityBackend a ~ SqlBackend, MonadSqlBackend m, HasCallStack) => [Filter a] -> [SelectOpt a] -> m (Maybe (Entity a)) -- | Get the Keys of all records matching the given criteria selectKeys :: forall a m. (PersistEntity a, PersistEntityBackend a ~ SqlBackend, MonadSqlBackend m, MonadResource m, HasCallStack) => [Filter a] -> [SelectOpt a] -> ConduitT () (Key a) m () -- | Get the Keys of all records matching the given criteria selectKeysList :: forall a m. (PersistEntity a, PersistEntityBackend a ~ SqlBackend, MonadSqlBackend m, HasCallStack) => [Filter a] -> [SelectOpt a] -> m [Key a] selectList :: forall a m. (PersistEntity a, PersistEntityBackend a ~ SqlBackend, MonadSqlBackend m, HasCallStack) => [Filter a] -> [SelectOpt a] -> m [Entity a] -- | Update individual fields on a specific record update :: forall a m. (PersistEntity a, PersistEntityBackend a ~ SqlBackend, MonadSqlBackend m, HasCallStack) => Key a -> [Update a] -> m () -- | Update individual fields on a specific record, and retrieve the -- updated value from the database -- -- This function will throw an exception if the given key is not found in -- the database. updateGet :: forall a m. (PersistEntity a, PersistEntityBackend a ~ SqlBackend, MonadSqlBackend m, HasCallStack) => Key a -> [Update a] -> m a -- | Update individual fields on any record matching the given criteria updateWhere :: forall a m. (PersistEntity a, PersistEntityBackend a ~ SqlBackend, MonadSqlBackend m, HasCallStack) => [Filter a] -> [Update a] -> m () -- | Update based on a uniqueness constraint or insert: -- -- upsert :: forall a m. (PersistEntityBackend a ~ SqlBackend, SafeToInsert a, OnlyOneUniqueKey a, MonadSqlBackend m, HasCallStack) => a -> [Update a] -> m (Entity a) -- | Update based on a given uniqueness constraint or insert: -- -- upsertBy :: forall a m. (PersistEntity a, PersistEntityBackend a ~ SqlBackend, SafeToInsert a, MonadSqlBackend m, HasCallStack) => Unique a -> a -> [Update a] -> m (Entity a) -- | Re-exports from: -- -- -- -- There are a few name conflicts between Persistent and Esqueleto. Where -- conflicts occur, this module gives preference to Esqueleto. The -- following Persistent definitions are renamed: -- -- module Database.Persist.Sql.Lifted -- | The constraint MonadSqlTx db m indicates that -- m is a monadic context that can run db actions, -- usually as a SQL transaction. Typically, this means that db -- needs a connection and m can provide one, e.g. from a -- connection pool. class (MonadSqlBackend db, MonadUnliftIO m) => MonadSqlTx db m | m -> db -- | Runs the action in a SQL transaction runSqlTx :: (MonadSqlTx db m, HasCallStack) => db a -> m a class HasSqlBackend a getSqlBackend :: HasSqlBackend a => a -> SqlBackend -- | 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 -- | A monadic context in which a SQL backend is available for running -- database queries class MonadUnliftIO m => MonadSqlBackend m getSqlBackendM :: MonadSqlBackend m => m SqlBackend -- | Generalize from SqlPersistT to MonadSqlBackend liftSql :: (MonadSqlBackend m, HasCallStack) => ReaderT SqlBackend m a -> m a -- | Get a record by identifier, if available get :: forall a m. (PersistEntity a, PersistEntityBackend a ~ SqlBackend, MonadSqlBackend m, HasCallStack) => Key a -> m (Maybe a) -- | Get a record by unique key, if available, returning both the -- identifier and the record getBy :: forall a m. (PersistEntity a, PersistEntityBackend a ~ SqlBackend, MonadSqlBackend m, HasCallStack) => Unique a -> m (Maybe (Entity a)) getByValue :: forall a m. (PersistEntityBackend a ~ SqlBackend, AtLeastOneUniqueKey a, MonadSqlBackend m, HasCallStack) => a -> m (Maybe (Entity a)) -- | Get a record by identifier, if available getEntity :: forall a m. (PersistEntity a, PersistEntityBackend a ~ SqlBackend, MonadSqlBackend m, HasCallStack) => Key a -> m (Maybe (Entity a)) -- | Get a record by identifier, if available, for a non-null (not -- Maybe) foreign key -- -- Unsafe unless your database is enforcing that the foreign key is -- valid. getJust :: forall a m. (PersistEntity a, PersistEntityBackend a ~ SqlBackend, MonadSqlBackend m, HasCallStack) => Key a -> m a -- | Get a record by identifier, if available, for a non-null (not -- Maybe) foreign key -- -- Unsafe unless your database is enforcing that the foreign key is -- valid. getJustEntity :: forall a m. (PersistEntity a, PersistEntityBackend a ~ SqlBackend, MonadSqlBackend m, HasCallStack) => Key a -> m (Entity a) -- | Get many records by their respective identifiers, if available getMany :: forall a m. (PersistEntity a, PersistEntityBackend a ~ SqlBackend, MonadSqlBackend m, HasCallStack) => [Key a] -> m (Map (Key a) a) -- | Execute an Esqueleto SELECT query select :: forall a r m. (SqlSelect a r, MonadSqlBackend m, HasCallStack) => SqlQuery a -> m [r] -- | Execute an Esqueleto SELECT query, getting only the first row selectOne :: forall a r m. (SqlSelect a r, MonadSqlBackend m, HasCallStack) => SqlQuery a -> m (Maybe r) -- | Get just the first record for the criteria selectFirst :: forall a m. (PersistEntity a, PersistEntityBackend a ~ SqlBackend, MonadSqlBackend m, HasCallStack) => [Filter a] -> [SelectOpt a] -> m (Maybe (Entity a)) -- | Get the Keys of all records matching the given criteria selectKeys :: forall a m. (PersistEntity a, PersistEntityBackend a ~ SqlBackend, MonadSqlBackend m, MonadResource m, HasCallStack) => [Filter a] -> [SelectOpt a] -> ConduitT () (Key a) m () -- | Get the Keys of all records matching the given criteria selectKeysList :: forall a m. (PersistEntity a, PersistEntityBackend a ~ SqlBackend, MonadSqlBackend m, HasCallStack) => [Filter a] -> [SelectOpt a] -> m [Key a] selectList :: forall a m. (PersistEntity a, PersistEntityBackend a ~ SqlBackend, MonadSqlBackend m, HasCallStack) => [Filter a] -> [SelectOpt a] -> m [Entity a] -- | The total number of records fulfilling the given criteria count :: forall a m. (PersistEntity a, PersistEntityBackend a ~ SqlBackend, MonadSqlBackend m, HasCallStack) => [Filter a] -> m Int -- | Check if there is at least one record fulfilling the given criteria exists :: forall a m. (PersistEntity a, PersistEntityBackend a ~ SqlBackend, MonadSqlBackend m, HasCallStack) => [Filter a] -> m Bool -- | Insert a PersistField for every selected value insertSelect :: forall a m. (PersistEntity a, MonadSqlBackend m, HasCallStack) => SqlQuery (SqlExpr (Insertion a)) -> m () -- | Insert a PersistField for every selected value, returning the -- count insertSelectCount :: forall a m. (PersistEntity a, MonadSqlBackend m, HasCallStack) => SqlQuery (SqlExpr (Insertion a)) -> m Int64 -- | Create a new record in the database insert :: forall a m. (PersistEntity a, PersistEntityBackend a ~ SqlBackend, SafeToInsert a, MonadSqlBackend m, HasCallStack) => a -> m (Key a) -- | Create a new record in the database insert_ :: forall a m. (PersistEntity a, PersistEntityBackend a ~ SqlBackend, SafeToInsert a, MonadSqlBackend m, HasCallStack) => a -> m () -- | Insert a value, checking for conflicts with any unique constraints insertBy :: forall a m. (PersistEntityBackend a ~ SqlBackend, AtLeastOneUniqueKey a, SafeToInsert a, MonadSqlBackend m, HasCallStack) => a -> m (Either (Entity a) (Key a)) -- | Create a new record in the database, returning an auto-increment ID -- and the inserted record insertEntity :: forall a m. (PersistEntity a, PersistEntityBackend a ~ SqlBackend, SafeToInsert a, MonadSqlBackend m, HasCallStack) => a -> m (Entity a) -- | Create multiple records in the database, with specified keys insertEntityMany :: forall a m. (PersistEntity a, PersistEntityBackend a ~ SqlBackend, MonadSqlBackend m, HasCallStack) => [Entity a] -> m () -- | Create a new record in the database using the given key insertKey :: forall a m. (PersistEntity a, PersistEntityBackend a ~ SqlBackend, MonadSqlBackend m, HasCallStack) => Key a -> a -> m () -- | Create multiple records in the database and return their Keys insertMany :: forall a m. (PersistEntity a, PersistEntityBackend a ~ SqlBackend, SafeToInsert a, MonadSqlBackend m, HasCallStack) => [a] -> m [Key a] -- | Create multiple records in the database insertMany_ :: forall a m. (PersistEntity a, PersistEntityBackend a ~ SqlBackend, SafeToInsert a, MonadSqlBackend m, HasCallStack) => [a] -> m () -- | Create a new record in the database insertRecord :: forall a m. (PersistEntity a, PersistEntityBackend a ~ SqlBackend, SafeToInsert a, MonadSqlBackend m, HasCallStack) => a -> m a -- | Create a new record in the database insertUnique :: forall a m. (PersistEntity a, PersistEntityBackend a ~ SqlBackend, SafeToInsert a, MonadSqlBackend m, HasCallStack) => a -> m (Maybe (Key a)) -- | Create a new record in the database insertUniqueEntity :: forall a m. (PersistEntity a, PersistEntityBackend a ~ SqlBackend, SafeToInsert a, MonadSqlBackend m, HasCallStack) => a -> m (Maybe (Entity a)) -- | Execute an Esqueleto UPDATE query update :: forall a m. (PersistEntity a, PersistEntityBackend a ~ SqlBackend, MonadSqlBackend m, HasCallStack) => (SqlExpr (Entity a) -> SqlQuery ()) -> m () -- | Execute an Esqueleto UPDATE query, returning the count updateCount :: forall a m. (PersistEntity a, PersistEntityBackend a ~ SqlBackend, MonadSqlBackend m, HasCallStack) => (SqlExpr (Entity a) -> SqlQuery ()) -> m Int64 -- | Update individual fields on a specific record update' :: forall a m. (PersistEntity a, PersistEntityBackend a ~ SqlBackend, MonadSqlBackend m, HasCallStack) => Key a -> [Update a] -> m () -- | Update individual fields on a specific record, and retrieve the -- updated value from the database -- -- This function will throw an exception if the given key is not found in -- the database. updateGet :: forall a m. (PersistEntity a, PersistEntityBackend a ~ SqlBackend, MonadSqlBackend m, HasCallStack) => Key a -> [Update a] -> m a -- | Update individual fields on any record matching the given criteria updateWhere :: forall a m. (PersistEntity a, PersistEntityBackend a ~ SqlBackend, MonadSqlBackend m, HasCallStack) => [Filter a] -> [Update a] -> m () -- | Replace the record in the database with the given key -- -- The result is undefined if such record does not exist. replace :: forall a m. (PersistEntity a, PersistEntityBackend a ~ SqlBackend, MonadSqlBackend m, HasCallStack) => Key a -> a -> m () -- | Attempt to replace the record of the given key with the given new -- record -- -- First query the unique fields to make sure the replacement maintains -- uniqueness constraints. replaceUnique :: forall a m. (PersistEntity a, PersistEntityBackend a ~ SqlBackend, Eq (Unique a), MonadSqlBackend m, HasCallStack) => Key a -> a -> m (Maybe (Unique a)) -- | Put the record in the database with the given key -- -- If a record with the given key does not exist then a new record will -- be inserted. repsert :: forall a m. (PersistEntity a, PersistEntityBackend a ~ SqlBackend, MonadSqlBackend m, HasCallStack) => Key a -> a -> m () -- | Put many entities into the database -- -- For each item, if a record with the given key does not exist then a -- new record will be inserted. repsertMany :: forall a m. (PersistEntity a, PersistEntityBackend a ~ SqlBackend, MonadSqlBackend m, HasCallStack) => [(Key a, a)] -> m () -- | Update based on a uniqueness constraint or insert: -- -- upsert :: forall a m. (PersistEntityBackend a ~ SqlBackend, SafeToInsert a, OnlyOneUniqueKey a, MonadSqlBackend m, HasCallStack) => a -> [Update a] -> m (Entity a) -- | Update based on a given uniqueness constraint or insert: -- -- upsertBy :: forall a m. (PersistEntity a, PersistEntityBackend a ~ SqlBackend, SafeToInsert a, MonadSqlBackend m, HasCallStack) => Unique a -> a -> [Update a] -> m (Entity a) -- | Put many records into the database -- -- putMany :: forall a m. (PersistEntity a, PersistEntityBackend a ~ SqlBackend, SafeToInsert a, MonadSqlBackend m, HasCallStack) => [a] -> m () -- | Check whether there are any conflicts for unique keys with this entity -- and existing entities in the database checkUnique :: forall a m. (PersistEntity a, PersistEntityBackend a ~ SqlBackend, MonadSqlBackend m, HasCallStack) => a -> m (Maybe (Unique a)) -- | Check whether there are any conflicts for unique keys with this entity -- and existing entities in the database -- -- This is useful for updating because it ignores conflicts when the -- particular entity already exists. checkUniqueUpdateable :: forall a m. (PersistEntity a, PersistEntityBackend a ~ SqlBackend, MonadSqlBackend m, HasCallStack) => Entity a -> m (Maybe (Unique a)) -- | Return the single unique key for a record onlyUnique :: forall a m. (PersistEntityBackend a ~ SqlBackend, OnlyOneUniqueKey a, MonadSqlBackend m, HasCallStack) => a -> m (Unique a) -- | Execute an Esqueleto DELETE query delete :: forall m. (MonadSqlBackend m, HasCallStack) => SqlQuery () -> m () -- | Delete a specific record by identifier -- -- Does nothing if record does not exist. deleteKey :: forall a m. (PersistEntity a, PersistEntityBackend a ~ SqlBackend, MonadSqlBackend m, HasCallStack) => Key a -> m () -- | Delete a specific record by unique key -- -- Does nothing if no record matches. deleteBy :: forall a m. (PersistEntity a, PersistEntityBackend a ~ SqlBackend, MonadSqlBackend m, HasCallStack) => Unique a -> m () -- | Delete all records matching the given criteria deleteWhere :: forall a m. (PersistEntity a, PersistEntityBackend a ~ SqlBackend, MonadSqlBackend m, HasCallStack) => [Filter a] -> m () -- | Execute an Esqueleto DELETE query deleteCount :: forall m. (MonadSqlBackend m, HasCallStack) => SqlQuery () -> m Int64 -- | Renders a SqlQuery to Text along with the list of -- PersistValues that would be supplied to the database for -- ? placeholders renderQueryDelete :: forall a r m. (SqlSelect a r, MonadSqlBackend m, HasCallStack) => SqlQuery a -> m (Text, [PersistValue]) -- | Renders a SqlQuery to Text along with the list of -- PersistValues that would be supplied to the database for -- ? placeholders renderQueryInsertInto :: forall a r m. (SqlSelect a r, MonadSqlBackend m, HasCallStack) => SqlQuery a -> m (Text, [PersistValue]) -- | Renders a SqlQuery to Text along with the list of -- PersistValues that would be supplied to the database for -- ? placeholders renderQuerySelect :: forall a r m. (SqlSelect a r, MonadSqlBackend m, HasCallStack) => SqlQuery a -> m (Text, [PersistValue]) -- | Renders a SqlQuery to Text along with the list of -- PersistValues that would be supplied to the database for -- ? placeholders renderQueryToText :: forall a r m. (SqlSelect a r, MonadSqlBackend m, HasCallStack) => Mode -> SqlQuery a -> m (Text, [PersistValue]) -- | Renders a SqlQuery to Text along with the list of -- PersistValues that would be supplied to the database for -- ? placeholders renderQueryUpdate :: forall a r m. (SqlSelect a r, MonadSqlBackend m, HasCallStack) => SqlQuery a -> m (Text, [PersistValue])