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

Safe Haskell | None

Database.Persist

Contents

- Store functions
- Query functions
- query combinators
- JSON Utilities
- Other utililities

Synopsis

- module Database.Persist.Class
- module Database.Persist.Types
- insertBy :: (PersistEntity v, PersistStore m, PersistUnique m, PersistMonadBackend m ~ PersistEntityBackend v) => v -> m (Either (Entity v) (Key v))
- getJust :: (PersistStore m, PersistEntity val, Show (Key val), PersistMonadBackend m ~ PersistEntityBackend val) => Key val -> m val
- belongsTo :: (PersistStore m, PersistEntity ent1, PersistEntity ent2, PersistMonadBackend m ~ PersistEntityBackend ent2) => (ent1 -> Maybe (Key ent2)) -> ent1 -> m (Maybe ent2)
- belongsToJust :: (PersistStore m, PersistEntity ent1, PersistEntity ent2, PersistMonadBackend m ~ PersistEntityBackend ent2) => (ent1 -> Key ent2) -> ent1 -> m ent2
- getByValue :: (PersistEntity v, PersistUnique m, PersistEntityBackend v ~ PersistMonadBackend m) => v -> m (Maybe (Entity v))
- 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 ()
- (=.) :: 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]
- listToJSON :: [PersistValue] -> Text
- mapToJSON :: [(Text, PersistValue)] -> Text
- getPersistMap :: PersistValue -> Either Text [(Text, PersistValue)]
- limitOffsetOrder :: PersistEntity val => [SelectOpt val] -> (Int, Int, [SelectOpt val])

# Documentation

module Database.Persist.Class

module Database.Persist.Types

# Store functions

insertBy :: (PersistEntity v, PersistStore m, PersistUnique m, PersistMonadBackend m ~ PersistEntityBackend v) => v -> m (Either (Entity v) (Key v))

Insert a value, checking for conflicts with any unique constraints. If a duplicate exists in the database, it is returned as `Left`. Otherwise, the new 'Key is returned as `Right`.

getJust :: (PersistStore m, PersistEntity val, Show (Key val), PersistMonadBackend m ~ PersistEntityBackend val) => Key val -> m val

Same as get, but for a non-null (not Maybe) foreign key Unsafe unless your database is enforcing that the foreign key is valid

belongsTo :: (PersistStore m, PersistEntity ent1, PersistEntity ent2, PersistMonadBackend m ~ PersistEntityBackend ent2) => (ent1 -> Maybe (Key ent2)) -> ent1 -> m (Maybe ent2)

belongsToJust :: (PersistStore m, PersistEntity ent1, PersistEntity ent2, PersistMonadBackend m ~ PersistEntityBackend ent2) => (ent1 -> Key ent2) -> ent1 -> m ent2

same as belongsTo, but uses `getJust` and therefore is similarly unsafe

getByValue :: (PersistEntity v, PersistUnique m, PersistEntityBackend v ~ PersistMonadBackend m) => v -> m (Maybe (Entity v))

A modification of `getBy`, which takes the `PersistEntity` itself instead of a `Unique` value. Returns a value matching one of the unique keys. This function makes the most sense on entities with a single `Unique` constructor.

# Query functions

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

# 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

# JSON Utilities

listToJSON :: [PersistValue] -> Text

mapToJSON :: [(Text, PersistValue)] -> Text

getPersistMap :: PersistValue -> Either Text [(Text, PersistValue)]

# Other utililities

limitOffsetOrder :: PersistEntity val => [SelectOpt val] -> (Int, Int, [SelectOpt val])