persistent-sql-lifted-0.4.3.1: Monad classes for running queries with Persistent and Esqueleto
Safe HaskellSafe-Inferred
LanguageGHC2021

Database.Persist.Sql.Lifted.Persistent

Description

Wrappers that apply liftSql to Persistent utilities of the same name.

Synopsis

Documentation

checkUnique Source #

Arguments

:: forall a m. (HasCallStack, MonadSqlBackend m, PersistEntity a, PersistEntityBackend a ~ SqlBackend) 
=> a 
-> m (Maybe (Unique a))

Nothing if the entity would be unique, and could thus safely be inserted. On a conflict, Just the conflicting key.

Check whether there are any conflicts for unique keys with this entity and existing entities in the database

checkUniqueUpdateable Source #

Arguments

:: forall a m. (HasCallStack, MonadSqlBackend m, PersistEntity a, PersistEntityBackend a ~ SqlBackend) 
=> Entity a 
-> m (Maybe (Unique a))

Nothing if the entity would stay unique, and could thus safely be updated. On a conflict, Just the conflicting key.

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.

count Source #

Arguments

:: forall a m. (HasCallStack, MonadSqlBackend m, PersistEntity a, PersistEntityBackend a ~ SqlBackend) 
=> [Filter a]

If you provide multiple values in the list, the conditions are ANDed together.

-> m Int 

The total number of records fulfilling the given criteria

delete :: forall a m. (HasCallStack, MonadSqlBackend m, PersistEntity a, PersistEntityBackend a ~ SqlBackend) => Key a -> m () Source #

Delete a specific record by identifier

Does nothing if record does not exist.

deleteBy :: forall a m. (HasCallStack, MonadSqlBackend m, PersistEntity a, PersistEntityBackend a ~ SqlBackend) => Unique a -> m () Source #

Delete a specific record by unique key

Does nothing if no record matches.

deleteWhere Source #

Arguments

:: forall a m. (HasCallStack, MonadSqlBackend m, PersistEntity a, PersistEntityBackend a ~ SqlBackend) 
=> [Filter a]

If you provide multiple values in the list, the conditions are ANDed together.

-> m () 

Delete all records matching the given criteria

deleteWhereCount Source #

Arguments

:: forall a m. (HasCallStack, MonadSqlBackend m, PersistEntity a, PersistEntityBackend a ~ SqlBackend) 
=> [Filter a]

If you provide multiple values in the list, the conditions are ANDed together.

-> m Int64

The number of rows affected

Delete all records matching the given criteria

exists Source #

Arguments

:: forall a m. (HasCallStack, MonadSqlBackend m, PersistEntity a, PersistEntityBackend a ~ SqlBackend) 
=> [Filter a]

If you provide multiple values in the list, the conditions are ANDed together.

-> m Bool 

Check if there is at least one record fulfilling the given criteria

existsBy :: forall a m. (HasCallStack, MonadSqlBackend m, PersistEntity a, PersistEntityBackend a ~ SqlBackend) => Unique a -> m Bool Source #

Check if a record with this unique key exists

get :: forall a m. (HasCallStack, MonadSqlBackend m, PersistEntity a, PersistEntityBackend a ~ SqlBackend) => Key a -> m (Maybe a) Source #

Get a record by identifier, if available

getBy :: forall a m. (HasCallStack, MonadSqlBackend m, PersistEntity a, PersistEntityBackend a ~ SqlBackend) => Unique a -> m (Maybe (Entity a)) Source #

Get a record by unique key, if available, returning both the identifier and the record

getByValue Source #

Arguments

:: forall a m. (AtLeastOneUniqueKey a, HasCallStack, MonadSqlBackend m, PersistEntityBackend a ~ SqlBackend) 
=> a 
-> m (Maybe (Entity a))

A record matching one of the unique keys.

getEntity :: forall a m. (HasCallStack, MonadSqlBackend m, PersistEntity a, PersistEntityBackend a ~ SqlBackend) => Key a -> m (Maybe (Entity a)) Source #

Get a record by identifier, if available

getFieldName :: forall a t m. (HasCallStack, MonadSqlBackend m, PersistEntity a, PersistEntityBackend a ~ SqlBackend) => EntityField a t -> m Text Source #

Get the SQL string for the field that an EntityField represents

getJust :: forall a m. (HasCallStack, MonadSqlBackend m, PersistEntity a, PersistEntityBackend a ~ SqlBackend) => Key a -> m a Source #

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. (HasCallStack, MonadSqlBackend m, PersistEntity a, PersistEntityBackend a ~ SqlBackend) => Key a -> m (Entity a) Source #

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.

getMany :: forall a m. (HasCallStack, MonadSqlBackend m, PersistEntity a, PersistEntityBackend a ~ SqlBackend) => [Key a] -> m (Map (Key a) a) Source #

Get many records by their respective identifiers, if available

getTableName :: forall a m. (HasCallStack, MonadSqlBackend m, PersistEntity a) => a -> m Text Source #

Get the SQL string for the table that a PersistEntity represents

insert Source #

Arguments

:: forall a m. (HasCallStack, MonadSqlBackend m, PersistEntity a, PersistEntityBackend a ~ SqlBackend, SafeToInsert a) 
=> a 
-> m (Key a)

The auto-increment ID that was generated

Create a new record in the database

insert_ :: forall a m. (HasCallStack, MonadSqlBackend m, PersistEntity a, PersistEntityBackend a ~ SqlBackend, SafeToInsert a) => a -> m () Source #

Create a new record in the database

insertBy Source #

Arguments

:: forall a m. (AtLeastOneUniqueKey a, HasCallStack, MonadSqlBackend m, PersistEntityBackend a ~ SqlBackend, SafeToInsert a) 
=> a 
-> m (Either (Entity a) (Key a))

If a duplicate exists in the database, it is returned as Left. Otherwise, the new Key is returned as Right.

Insert a value, checking for conflicts with any unique constraints

insertEntity :: forall a m. (HasCallStack, MonadSqlBackend m, PersistEntity a, PersistEntityBackend a ~ SqlBackend, SafeToInsert a) => a -> m (Entity a) Source #

Create a new record in the database, returning an auto-increment ID and the inserted record

insertEntityMany :: forall a m. (HasCallStack, MonadSqlBackend m, PersistEntity a, PersistEntityBackend a ~ SqlBackend) => [Entity a] -> m () Source #

Create multiple records in the database, with specified keys

insertKey :: forall a m. (HasCallStack, MonadSqlBackend m, PersistEntity a, PersistEntityBackend a ~ SqlBackend) => Key a -> a -> m () Source #

Create a new record in the database using the given key

insertMany :: forall a m. (HasCallStack, MonadSqlBackend m, PersistEntity a, PersistEntityBackend a ~ SqlBackend, SafeToInsert a) => [a] -> m [Key a] Source #

Create multiple records in the database and return their Keys

insertMany_ :: forall a m. (HasCallStack, MonadSqlBackend m, PersistEntity a, PersistEntityBackend a ~ SqlBackend, SafeToInsert a) => [a] -> m () Source #

Create multiple records in the database

insertRecord Source #

Arguments

:: forall a m. (HasCallStack, MonadSqlBackend m, PersistEntity a, PersistEntityBackend a ~ SqlBackend, SafeToInsert a) 
=> a 
-> m a

The record that was inserted

Create a new record in the database

insertUnique Source #

Arguments

:: forall a m. (HasCallStack, MonadSqlBackend m, PersistEntity a, PersistEntityBackend a ~ SqlBackend, SafeToInsert a) 
=> a 
-> m (Maybe (Key a))

An auto-increment ID, or Nothing when the record couldn't be inserted because of a uniqueness constraint

Create a new record in the database

insertUnique_ Source #

Arguments

:: forall a m. (HasCallStack, MonadSqlBackend m, PersistEntity a, PersistEntityBackend a ~ SqlBackend, SafeToInsert a) 
=> a 
-> m (Maybe ())

(), or Nothing when the record couldn't be inserted because of a uniqueness constraint

Create a new record in the database

insertUniqueEntity Source #

Arguments

:: forall a m. (HasCallStack, MonadSqlBackend m, PersistEntity a, PersistEntityBackend a ~ SqlBackend, SafeToInsert a) 
=> a 
-> m (Maybe (Entity a))

An auto-increment ID and the inserted record, or Nothing when the record couldn't be inserted because of a uniqueness constraint.

Create a new record in the database

onlyUnique :: forall a m. (HasCallStack, MonadSqlBackend m, OnlyOneUniqueKey a, PersistEntityBackend a ~ SqlBackend) => a -> m (Unique a) Source #

Return the single unique key for a record

putMany Source #

Arguments

:: forall a m. (HasCallStack, MonadSqlBackend m, PersistEntity a, PersistEntityBackend a ~ SqlBackend, SafeToInsert a) 
=> [a]

A list of the records you want to insert or replace.

-> m () 

Put many records into the database

  • Insert new records that do not exist (or violate any unique constraints);
  • Replace existing records (matching any unique constraint).

rawExecute Source #

Arguments

:: forall m. (HasCallStack, MonadSqlBackend m) 
=> Text

SQL statement, possibly with placeholders

-> [PersistValue]

Values to fill the placeholders

-> m () 

Execute a raw SQL statement

rawExecuteCount Source #

Arguments

:: forall m. (HasCallStack, MonadSqlBackend m) 
=> Text

SQL statement, possibly with placeholders

-> [PersistValue]

Values to fill the placeholders

-> m Int64

The number of rows modified

Execute a raw SQL statement

rawSql Source #

Arguments

:: forall a m. (HasCallStack, MonadSqlBackend m, RawSql a) 
=> Text

SQL statement, possibly with placeholders

-> [PersistValue]

Values to fill the placeholders

-> m [a] 

replace :: forall a m. (HasCallStack, MonadSqlBackend m, PersistEntity a, PersistEntityBackend a ~ SqlBackend) => Key a -> a -> m () Source #

Replace the record in the database with the given key

The result is undefined if such record does not exist.

replaceUnique Source #

Arguments

:: forall a m. (Eq (Unique a), HasCallStack, MonadSqlBackend m, PersistEntity a, PersistEntityBackend a ~ SqlBackend) 
=> Key a 
-> a 
-> m (Maybe (Unique a))

Nothing if the replacement was made. If uniqueness is violated, Just the Unique violation.

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.

repsert :: forall a m. (HasCallStack, MonadSqlBackend m, PersistEntity a, PersistEntityBackend a ~ SqlBackend) => Key a -> a -> m () Source #

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.

repsertMany :: forall a m. (HasCallStack, MonadSqlBackend m, PersistEntity a, PersistEntityBackend a ~ SqlBackend) => [(Key a, a)] -> m () Source #

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.

selectFirst Source #

Arguments

:: forall a m. (HasCallStack, MonadSqlBackend m, PersistEntity a, PersistEntityBackend a ~ SqlBackend) 
=> [Filter a]

If you provide multiple values in the list, the conditions are ANDed together.

-> [SelectOpt a] 
-> m (Maybe (Entity a)) 

Get just the first record for the criteria

selectKeysList Source #

Arguments

:: forall a m. (HasCallStack, MonadSqlBackend m, PersistEntity a, PersistEntityBackend a ~ SqlBackend) 
=> [Filter a]

If you provide multiple values in the list, the conditions are ANDed together.

-> [SelectOpt a] 
-> m [Key a] 

Get the Keys of all records matching the given criteria

selectList Source #

Arguments

:: forall a m. (HasCallStack, MonadSqlBackend m, PersistEntity a, PersistEntityBackend a ~ SqlBackend) 
=> [Filter a]

If you provide multiple values in the list, the conditions are ANDed together.

-> [SelectOpt a] 
-> m [Entity a]

Entities corresponding to the filters and options provided

transactionSave :: forall m. (HasCallStack, MonadSqlBackend m) => m () Source #

Commit the current transaction and begin a new one

transactionSaveWithIsolation Source #

Arguments

:: forall m. (HasCallStack, MonadSqlBackend m) 
=> IsolationLevel

Isolation level

-> m () 

Commit the current transaction and begin a new one

transactionUndo :: forall m. (HasCallStack, MonadSqlBackend m) => m () Source #

Roll back the current transaction and begin a new one

transactionUndoWithIsolation Source #

Arguments

:: forall m. (HasCallStack, MonadSqlBackend m) 
=> IsolationLevel

Isolation level

-> m () 

Roll back the current transaction and begin a new one

update :: forall a m. (HasCallStack, MonadSqlBackend m, PersistEntity a, PersistEntityBackend a ~ SqlBackend) => Key a -> [Update a] -> m () Source #

Update individual fields on a specific record

updateGet :: forall a m. (HasCallStack, MonadSqlBackend m, PersistEntity a, PersistEntityBackend a ~ SqlBackend) => Key a -> [Update a] -> m a Source #

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.

updateWhere Source #

Arguments

:: forall a m. (HasCallStack, MonadSqlBackend m, PersistEntity a, PersistEntityBackend a ~ SqlBackend) 
=> [Filter a]

If you provide multiple values in the list, the conditions are ANDed together.

-> [Update a] 
-> m () 

Update individual fields on any record matching the given criteria

updateWhereCount Source #

Arguments

:: forall a m. (HasCallStack, MonadSqlBackend m, PersistEntity a, PersistEntityBackend a ~ SqlBackend) 
=> [Filter a]

If you provide multiple values in the list, the conditions are ANDed together.

-> [Update a] 
-> m Int64

The number of rows affected

Update individual fields on any record matching the given criteria

upsert Source #

Arguments

:: forall a m. (HasCallStack, MonadSqlBackend m, OnlyOneUniqueKey a, PersistEntityBackend a ~ SqlBackend, SafeToInsert a) 
=> a

New record to insert

-> [Update a]

Updates to perform if the record already exists

-> m (Entity a)

The record in the database after the operation

Update based on a uniqueness constraint or insert:

  • Unsert the new record if it does not exist;
  • If the record exists (matched via it's uniqueness constraint), then update the existing record with the parameters which is passed on as list to the function.

upsertBy Source #

Arguments

:: forall a m. (HasCallStack, MonadSqlBackend m, PersistEntity a, PersistEntityBackend a ~ SqlBackend, SafeToInsert a) 
=> Unique a

Uniqueness constraint to find by

-> a

New record to insert

-> [Update a]

Updates to perform if the record already exists

-> m (Entity a)

The record in the database after the operation

Update based on a given uniqueness constraint or insert:

  • Insert the new record if it does not exist;
  • Update the existing record that matches the given uniqueness constraint.