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

Safe Haskell | None

Database.Persist.Query

Contents

- query combinators

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
- selectList :: (PersistEntity val, PersistQuery m, PersistEntityBackend val ~ PersistMonadBackend m) => [Filter val] -> [SelectOpt val] -> m [Entity val]
- selectKeysList :: (PersistEntity val, PersistQuery m, PersistEntityBackend val ~ PersistMonadBackend m) => [Filter val] -> [SelectOpt val] -> m [Key val]
- deleteCascadeWhere :: (DeleteCascade a m, PersistQuery m) => [Filter a] -> m ()
- data SelectOpt v
  - = forall typ . Asc (EntityField v typ)
  - | forall typ . Desc (EntityField v typ)
  - | OffsetBy Int
  - | LimitTo Int
- data Filter v
  - = forall typ . PersistField typ => Filter {
    - filterField :: EntityField v typ
    - filterValue :: Either typ [typ]
    - filterFilter :: PersistFilter
    }
  - | FilterAnd [Filter v]
  - | FilterOr [Filter v]
  - | BackendFilter (BackendSpecificFilter (PersistEntityBackend v) v)
- (=.) :: forall v typ. PersistField typ => EntityField v typ -> typ -> Update v
- (+=.) :: forall v typ. PersistField typ => EntityField v typ -> typ -> Update v
- (-=.) :: forall v typ. PersistField typ => EntityField v typ -> typ -> Update v
- (*=.) :: forall v typ. PersistField typ => EntityField v typ -> typ -> Update v
- (/=.) :: forall v typ. PersistField typ => EntityField v typ -> typ -> Update v
- (==.) :: forall v typ. PersistField typ => EntityField v typ -> typ -> Filter v
- (!=.) :: forall v typ. PersistField typ => EntityField v typ -> typ -> Filter v
- (<.) :: forall v typ. PersistField typ => EntityField v typ -> typ -> Filter v
- (>.) :: forall v typ. PersistField typ => EntityField v typ -> typ -> Filter v
- (<=.) :: forall v typ. PersistField typ => EntityField v typ -> typ -> Filter v
- (>=.) :: forall v typ. PersistField typ => EntityField v typ -> typ -> Filter v
- (<-.) :: forall v typ. PersistField typ => EntityField v typ -> [typ] -> Filter v
- (/<-.) :: forall v typ. PersistField typ => EntityField v typ -> [typ] -> Filter v
- (||.) :: forall v. [Filter v] -> [Filter v] -> [Filter v]

# 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) |

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

Call `selectSource` but return the result as a list.

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

Call `selectKeys` but return the result as a list.

deleteCascadeWhere :: (DeleteCascade a m, PersistQuery m) => [Filter a] -> m ()

data SelectOpt v

Constructors

forall typ . Asc (EntityField v typ) |
forall typ . Desc (EntityField v typ) |
OffsetBy Int |
LimitTo Int |

data Filter v

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.

Constructors

forall typ . PersistField typ => Filter |
Fields filterField :: EntityField v typ filterValue :: Either typ [typ] filterFilter :: PersistFilter
FilterAnd [Filter v] | convenient for internal use, not needed for the API
FilterOr [Filter v] |
BackendFilter (BackendSpecificFilter (PersistEntityBackend v) v) |

# query combinators

(=.) :: forall v typ. PersistField typ => EntityField v typ -> typ -> Update v

assign a field a value

(+=.) :: forall v typ. PersistField typ => EntityField v typ -> typ -> Update v

assign a field by addition (+=)

(-=.) :: forall v typ. PersistField typ => EntityField v typ -> typ -> Update v

assign a field by subtraction (-=)

(*=.) :: forall v typ. PersistField typ => EntityField v typ -> typ -> Update v

assign a field by multiplication (*=)

(/=.) :: forall v typ. PersistField typ => EntityField v typ -> typ -> Update v

assign a field by division (/=)

(==.) :: forall v typ. PersistField typ => EntityField v typ -> typ -> Filter v

(!=.) :: forall v typ. PersistField typ => EntityField v typ -> typ -> Filter v

(<.) :: forall v typ. PersistField typ => EntityField v typ -> typ -> Filter v

(>.) :: forall v typ. PersistField typ => EntityField v typ -> typ -> Filter v

(<=.) :: forall v typ. PersistField typ => EntityField v typ -> typ -> Filter v

(>=.) :: forall v typ. PersistField typ => EntityField v typ -> typ -> Filter v

(<-.) :: forall v typ. PersistField typ => EntityField v typ -> [typ] -> Filter v

In

(/<-.) :: forall v typ. PersistField typ => EntityField v typ -> [typ] -> Filter v

NotIn

(||.) :: forall v. [Filter v] -> [Filter v] -> [Filter v]

the OR of two lists of filters