- class PersistField a where
- toPersistValue :: a -> PersistValue
- fromPersistValue :: PersistValue -> Either String a
- sqlType :: a -> SqlType
- isNullable :: a -> Bool
- class PersistEntity val where
- data Key val
- data Update val
- data Filter val
- data Order val
- data Unique val
- entityDef :: val -> EntityDef
- toPersistFields :: val -> [SomePersistField]
- fromPersistValues :: [PersistValue] -> Either String val
- halfDefined :: val
- toPersistKey :: Int64 -> Key val
- fromPersistKey :: Key val -> Int64
- showPersistKey :: Key val -> String
- persistFilterToFieldName :: Filter val -> String
- persistFilterToFilter :: Filter val -> PersistFilter
- persistFilterToValue :: Filter val -> Either PersistValue [PersistValue]
- persistOrderToFieldName :: Order val -> String
- persistOrderToOrder :: Order val -> PersistOrder
- persistUpdateToFieldName :: Update val -> String
- persistUpdateToValue :: Update val -> PersistValue
- persistUniqueToFieldNames :: Unique val -> [String]
- persistUniqueToValues :: Unique val -> [PersistValue]
- persistUniqueKeys :: val -> [Unique val]
- class Monad m => PersistBackend m where
- insert :: PersistEntity val => val -> m (Key val)
- replace :: PersistEntity val => Key val -> val -> m ()
- update :: PersistEntity val => Key val -> [Update val] -> m ()
- updateWhere :: PersistEntity val => [Filter val] -> [Update val] -> m ()
- delete :: PersistEntity val => Key val -> m ()
- deleteBy :: PersistEntity val => Unique val -> m ()
- deleteWhere :: PersistEntity val => [Filter val] -> m ()
- get :: PersistEntity val => Key val -> m (Maybe val)
- getBy :: PersistEntity val => Unique val -> m (Maybe (Key val, val))
- select :: PersistEntity val => [Filter val] -> [Order val] -> Int -> Int -> Enumerator (Key val, val) m a
- selectKeys :: PersistEntity val => [Filter val] -> Enumerator (Key val) m a
- count :: PersistEntity val => [Filter val] -> m Int
- mkPersist :: [EntityDef] -> Q [Dec]
- persist :: QuasiQuoter
- selectList :: (PersistEntity val, PersistBackend m, Monad m) => [Filter val] -> [Order val] -> Int -> Int -> m [(Key val, val)]
- insertBy :: (PersistEntity val, PersistBackend m) => val -> m (Key val, val)
- insertBy' :: (PersistEntity v, PersistBackend m) => v -> m (Either (Key v, v) (Key v))
- checkUnique :: (PersistEntity val, PersistBackend m) => val -> m Bool
Documentation
class PersistField a whereSource
A value which can be marshalled to and from a PersistValue
.
toPersistValue :: a -> PersistValueSource
fromPersistValue :: PersistValue -> Either String aSource
isNullable :: a -> BoolSource
class PersistEntity val whereSource
A single database entity. For example, if writing a blog application, a blog entry would be an entry, containing fields such as title and content.
The unique identifier associated with this entity. In general, backends also define a type synonym for this, such that "type MyEntityId = Key MyEntity".
Fields which can be updated using the update
and updateWhere
functions.
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.
How you can sort the results of a select
.
Unique keys in existence on this entity.
entityDef :: val -> EntityDefSource
toPersistFields :: val -> [SomePersistField]Source
fromPersistValues :: [PersistValue] -> Either String valSource
halfDefined :: valSource
toPersistKey :: Int64 -> Key valSource
fromPersistKey :: Key val -> Int64Source
showPersistKey :: Key val -> StringSource
persistFilterToFieldName :: Filter val -> StringSource
persistFilterToFilter :: Filter val -> PersistFilterSource
persistFilterToValue :: Filter val -> Either PersistValue [PersistValue]Source
persistOrderToFieldName :: Order val -> StringSource
persistOrderToOrder :: Order val -> PersistOrderSource
persistUpdateToFieldName :: Update val -> StringSource
persistUpdateToValue :: Update val -> PersistValueSource
persistUniqueToFieldNames :: Unique val -> [String]Source
persistUniqueToValues :: Unique val -> [PersistValue]Source
persistUniqueKeys :: val -> [Unique val]Source
class Monad m => PersistBackend m whereSource
insert :: PersistEntity val => val -> m (Key val)Source
Create a new record in the database, returning the newly created identifier.
replace :: PersistEntity val => Key val -> val -> m ()Source
Replace the record in the database with the given key. Result is undefined if such a record does not exist.
update :: PersistEntity val => Key val -> [Update val] -> m ()Source
Update individual fields on a specific record.
updateWhere :: PersistEntity val => [Filter val] -> [Update val] -> m ()Source
Update individual fields on any record matching the given criterion.
delete :: PersistEntity val => Key val -> m ()Source
Delete a specific record by identifier. Does nothing if record does not exist.
deleteBy :: PersistEntity val => Unique val -> m ()Source
Delete a specific record by unique key. Does nothing if no record matches.
deleteWhere :: PersistEntity val => [Filter val] -> m ()Source
Delete all records matching the given criterion.
get :: PersistEntity val => Key val -> m (Maybe val)Source
Get a record by identifier, if available.
getBy :: PersistEntity val => Unique val -> m (Maybe (Key val, val))Source
Get a record by unique key, if available. Returns also the identifier.
:: PersistEntity val | |
=> [Filter val] | |
-> [Order val] | |
-> Int | limit |
-> Int | offset |
-> Enumerator (Key val, val) m a |
Get all records matching the given criterion in the specified order. Returns also the identifiers.
selectKeys :: PersistEntity val => [Filter val] -> Enumerator (Key val) m aSource
Get the Key
s of all records matching the given criterion.
count :: PersistEntity val => [Filter val] -> m IntSource
The total number of records fulfilling the given criterion.
MonadCatchIO m => PersistBackend (SqlPersist m) |
mkPersist :: [EntityDef] -> Q [Dec]Source
Create data types and appropriate PersistEntity
instances for the given
EntityDef
s. Works well with the persist quasi-quoter.
Converts a quasi-quoted syntax into a list of entity definitions, to be used as input to the template haskell generation code (mkPersist).
:: (PersistEntity val, PersistBackend m, Monad m) | |
=> [Filter val] | |
-> [Order val] | |
-> Int | limit |
-> Int | offset |
-> m [(Key val, val)] |
Call select
but return the result as a list.
insertBy :: (PersistEntity val, PersistBackend m) => val -> m (Key val, val)Source
Try to insert the given entity; if another entity exists with the same unique key, return that entity; otherwise, return the newly created entity.
This function is deprecated in favor of insertBy'. In the next major version, this function will be replaced with that one.
insertBy' :: (PersistEntity v, PersistBackend m) => v -> m (Either (Key v, v) (Key v))Source
checkUnique :: (PersistEntity val, PersistBackend m) => val -> m BoolSource