persistent-1.1.5.1: Type-safe, multi-backend data serialization.

Safe Haskell | None

Database.Persist.Query.GenericSql

Synopsis

- class PersistStore m => PersistQuery m where
  - update :: (PersistEntity val, PersistEntityBackend val ~ PersistMonadBackend m) => Key val -> [Update val] -> m ()
  - updateGet :: (PersistEntity val, PersistMonadBackend m ~ PersistEntityBackend val) => Key val -> [Update val] -> m val
  - updateWhere :: (PersistEntity val, PersistEntityBackend val ~ PersistMonadBackend m) => [Filter val] -> [Update val] -> m ()
  - deleteWhere :: (PersistEntity val, PersistEntityBackend val ~ PersistMonadBackend m) => [Filter val] -> m ()
  - selectSource :: (PersistEntity val, PersistEntityBackend val ~ PersistMonadBackend m) => [Filter val] -> [SelectOpt val] -> Source m (Entity val)
  - selectFirst :: (PersistEntity val, PersistEntityBackend val ~ PersistMonadBackend m) => [Filter val] -> [SelectOpt val] -> m (Maybe (Entity val))
  - selectKeys :: (PersistEntity val, PersistEntityBackend val ~ PersistMonadBackend m) => [Filter val] -> [SelectOpt val] -> Source m (Key val)
  - count :: (PersistEntity val, PersistEntityBackend val ~ PersistMonadBackend m) => [Filter val] -> m Int
- newtype SqlPersist m a = SqlPersist {
  - unSqlPersist :: ReaderT Connection m a
  }
- filterClauseNoWhere :: PersistEntity val => Bool -> Connection -> [Filter val] -> Text
- filterClauseNoWhereOrNull :: PersistEntity val => Bool -> Connection -> [Filter val] -> Text
- getFiltsValues :: forall val. PersistEntity val => Connection -> [Filter val] -> [PersistValue]
- selectSourceConn :: (PersistEntity val, MonadResource m, MonadLogger m, PersistEntityBackend val ~ SqlBackend, MonadBaseControl IO m) => Connection -> [Filter val] -> [SelectOpt val] -> Source m (Entity val)
- dummyFromFilts :: [Filter v] -> v
- orderClause :: PersistEntity val => Bool -> Connection -> SelectOpt val -> Text
- deleteWhereCount :: (PersistEntity val, MonadIO m, MonadLogger m) => [Filter val] -> SqlPersist m Int64
- updateWhereCount :: (PersistEntity val, MonadIO m, MonadLogger m) => [Filter val] -> [Update val] -> SqlPersist m Int64

# Documentation

class PersistStore m => PersistQuery m where

Methods

update :: (PersistEntity val, PersistEntityBackend val ~ PersistMonadBackend m) => Key val -> [Update val] -> m ()

Update individual fields on a specific record.

updateGet :: (PersistEntity val, PersistMonadBackend m ~ PersistEntityBackend val) => Key val -> [Update val] -> m val

Update individual fields on a specific record, and retrieve the updated value from the database.

Note that this function will throw an exception if the given key is not found in the database.

updateWhere :: (PersistEntity val, PersistEntityBackend val ~ PersistMonadBackend m) => [Filter val] -> [Update val] -> m ()

Update individual fields on any record matching the given criterion.

deleteWhere :: (PersistEntity val, PersistEntityBackend val ~ PersistMonadBackend m) => [Filter val] -> m ()

Delete all records matching the given criterion.

selectSource :: (PersistEntity val, PersistEntityBackend val ~ PersistMonadBackend m) => [Filter val] -> [SelectOpt val] -> Source m (Entity val)

Get all records matching the given criterion in the specified order. Returns also the identifiers.

selectFirst :: (PersistEntity val, PersistEntityBackend val ~ PersistMonadBackend m) => [Filter val] -> [SelectOpt val] -> m (Maybe (Entity val))

get just the first record for the criterion

selectKeys :: (PersistEntity val, PersistEntityBackend val ~ PersistMonadBackend m) => [Filter val] -> [SelectOpt val] -> Source m (Key val)

Get the `Key`s of all records matching the given criterion.

count :: (PersistEntity val, PersistEntityBackend val ~ PersistMonadBackend m) => [Filter val] -> m Int

The total number of records fulfilling the given criterion.

Instances

PersistQuery m => PersistQuery (ResourceT m) |
PersistQuery m => PersistQuery (LoggingT m) |
PersistQuery m => PersistQuery (ListT m) |
PersistQuery m => PersistQuery (MaybeT m) |
PersistQuery m => PersistQuery (IdentityT m) |
(MonadResource m, MonadLogger m) => PersistQuery (SqlPersist m) |
PersistQuery m => PersistQuery (ContT r m) |
(Error e, PersistQuery m) => PersistQuery (ErrorT e m) |
PersistQuery m => PersistQuery (ReaderT r m) |
PersistQuery m => PersistQuery (StateT s m) |
PersistQuery m => PersistQuery (StateT s m) |
(Monoid w, PersistQuery m) => PersistQuery (WriterT w m) |
(Monoid w, PersistQuery m) => PersistQuery (WriterT w m) |
PersistQuery m => PersistQuery (ConduitM i o m) |
(Monoid w, PersistQuery m) => PersistQuery (RWST r w s m) |
(Monoid w, PersistQuery m) => PersistQuery (RWST r w s m) |
PersistQuery m => PersistQuery (Pipe l i o u m) |

newtype SqlPersist m a

Constructors

SqlPersist |

Fields

unSqlPersist :: ReaderT Connection m a

Instances

MonadTrans SqlPersist |
MonadTransControl SqlPersist |
MonadBaseControl backend m => MonadBaseControl backend (SqlPersist m) |
MonadBase backend m => MonadBase backend (SqlPersist m) |
Monad m => Monad (SqlPersist m) |
Functor m => Functor (SqlPersist m) |
MonadPlus m => MonadPlus (SqlPersist m) |
Applicative m => Applicative (SqlPersist m) |
MonadThrow m => MonadThrow (SqlPersist m) |
MonadResource m => MonadResource (SqlPersist m) |
MonadLogger m => MonadLogger (SqlPersist m) |
MonadIO m => MonadIO (SqlPersist m) |
(MonadResource m, MonadLogger m) => PersistUnique (SqlPersist m) |
(MonadResource m, MonadLogger m) => PersistStore (SqlPersist m) |
(MonadIO m, MonadLogger m) => MonadSqlPersist (SqlPersist m) |
(MonadResource m, MonadLogger m) => PersistQuery (SqlPersist m) |

filterClauseNoWhere

Arguments

:: PersistEntity val |
=> Bool | include table name?
-> Connection |
-> [Filter val] |
-> Text |

filterClauseNoWhereOrNull

Arguments

:: PersistEntity val |
=> Bool | include table name?
-> Connection |
-> [Filter val] |
-> Text |

getFiltsValues :: forall val. PersistEntity val => Connection -> [Filter val] -> [PersistValue]

selectSourceConn :: (PersistEntity val, MonadResource m, MonadLogger m, PersistEntityBackend val ~ SqlBackend, MonadBaseControl IO m) => Connection -> [Filter val] -> [SelectOpt val] -> Source m (Entity val)

Equivalent to `selectSource`, but instead of getting the connection from the environment inside a `SqlPersist` monad, provide an explicit `Connection`. This can allow you to use the returned `Source` in an arbitrary monad.

dummyFromFilts :: [Filter v] -> v

orderClause

Arguments

:: PersistEntity val |
=> Bool | include the table name
-> Connection |
-> SelectOpt val |
-> Text |

deleteWhereCount :: (PersistEntity val, MonadIO m, MonadLogger m) => [Filter val] -> SqlPersist m Int64

Same as `deleteWhere`, but returns the number of rows affected.

Since 1.1.5

updateWhereCount :: (PersistEntity val, MonadIO m, MonadLogger m) => [Filter val] -> [Update val] -> SqlPersist m Int64

Same as `updateWhere`, but returns the number of rows affected.

Since 1.1.5