Safe Haskell | None |
---|
This module defines the functions and datatypes used throughout the framework. Most of them are for the internal use
- class (PersistField v, PurePersistField (AutoKey v)) => PersistEntity v where
- data Field v :: ((* -> *) -> *) -> * -> *
- data Key v :: * -> *
- type AutoKey v
- type DefaultKey v
- entityDef :: v -> EntityDef
- toEntityPersistValues :: PersistBackend m => v -> m ([PersistValue] -> [PersistValue])
- fromEntityPersistValues :: PersistBackend m => [PersistValue] -> m (v, [PersistValue])
- getUniques :: DbDescriptor db => Proxy db -> v -> (Int, [(String, [PersistValue] -> [PersistValue])])
- entityFieldChain :: Field v c a -> FieldChain
- data PersistValue
- class PersistField a where
- persistName :: a -> String
- toPersistValues :: PersistBackend m => a -> m ([PersistValue] -> [PersistValue])
- fromPersistValues :: PersistBackend m => [PersistValue] -> m (a, [PersistValue])
- dbType :: a -> DbType
- class PersistField a => SinglePersistField a where
- toSinglePersistValue :: PersistBackend m => a -> m PersistValue
- fromSinglePersistValue :: PersistBackend m => PersistValue -> m a
- class PersistField a => PurePersistField a where
- toPurePersistValues :: DbDescriptor db => Proxy db -> a -> [PersistValue] -> [PersistValue]
- fromPurePersistValues :: DbDescriptor db => Proxy db -> [PersistValue] -> (a, [PersistValue])
- class (SinglePersistField a, PurePersistField a) => PrimitivePersistField a where
- toPrimitivePersistValue :: DbDescriptor db => Proxy db -> a -> PersistValue
- fromPrimitivePersistValue :: DbDescriptor db => Proxy db -> PersistValue -> a
- class PersistField v => Embedded v where
- data Selector v :: * -> *
- selectorNum :: Selector v a -> Int
- class Projection p r a | p -> r a where
- projectionFieldChains :: p -> [FieldChain] -> [FieldChain]
- projectionResult :: PersistBackend m => p -> [PersistValue] -> m (a, [PersistValue])
- data RestrictionHolder v c
- data Unique u
- data KeyForBackend db v = (DbDescriptor db, PersistEntity v) => KeyForBackend (AutoKeyType db)
- data BackendSpecific
- data ConstructorMarker v a
- data UniqueMarker v a
- data Proxy a
- data HFalse
- data HTrue
- newtype ZT = ZT ZonedTime
- delim :: Char
- data Cond v c
- data ExprRelation
- data Update v c = forall f a b . FieldLike f (RestrictionHolder v c) a => Update f (Expr v c b)
- (~>) :: (PersistEntity v, Constructor c, FieldLike f (RestrictionHolder v c) a, Embedded a) => f -> Selector a a' -> SubField v c a'
- toArith :: (PersistEntity v, FieldLike f (RestrictionHolder v c) a') => f -> Arith v c a'
- class Projection f r a => FieldLike f r a | f -> r a where
- fieldChain :: f -> FieldChain
- newtype SubField v c a = SubField ((String, DbType), [(String, EmbeddedDef)])
- data AutoKeyField v c where
- AutoKeyField :: (PersistEntity v, Constructor c) => AutoKeyField v c
- type FieldChain = ((String, DbType), [(String, EmbeddedDef)])
- class NeverNull a
- class Numeric a
- data Arith v c a
- data Expr v c a where
- ExprField :: (PersistEntity v, FieldLike f (RestrictionHolder v c) a') => f -> Expr v c f
- ExprArith :: PersistEntity v => Arith v c a -> Expr v c (Arith v c a)
- ExprPure :: forall v c a. PurePersistField a => a -> Expr v c a
- data Order v c
- = forall a f . FieldLike f (RestrictionHolder v c) a => Asc f
- | forall a f . FieldLike f (RestrictionHolder v c) a => Desc f
- class HasSelectOptions a v c | a -> v c where
- type HasLimit a
- type HasOffset a
- type HasOrder a
- getSelectOptions :: a -> SelectOptions v c (HasLimit a) (HasOffset a) (HasOrder a)
- data SelectOptions v c hasLimit hasOffset hasOrder = SelectOptions {
- condOptions :: Cond v c
- limitOptions :: Maybe Int
- offsetOptions :: Maybe Int
- orderOptions :: [Order v c]
- limitTo :: (HasSelectOptions a v c, HasLimit a ~ HFalse) => a -> Int -> SelectOptions v c HTrue (HasOffset a) (HasOrder a)
- offsetBy :: (HasSelectOptions a v c, HasOffset a ~ HFalse) => a -> Int -> SelectOptions v c (HasLimit a) HTrue (HasOrder a)
- orderBy :: (HasSelectOptions a v c, HasOrder a ~ HFalse) => a -> [Order v c] -> SelectOptions v c (HasLimit a) (HasOffset a) HTrue
- data DbType
- data EntityDef = EntityDef {
- entityName :: String
- typeParams :: [DbType]
- constructors :: [ConstructorDef]
- data EmbeddedDef = EmbeddedDef Bool [(String, DbType)]
- data ConstructorDef = ConstructorDef {
- constrNum :: Int
- constrName :: String
- constrAutoKeyName :: Maybe String
- constrParams :: [(String, DbType)]
- constrUniques :: [UniqueDef]
- class Constructor c where
- phantomConstrName :: c (a :: * -> *) -> String
- phantomConstrNum :: c (a :: * -> *) -> Int
- class (Constructor (UniqueConstr uKey), PurePersistField uKey) => IsUniqueKey uKey where
- type UniqueConstr uKey :: (* -> *) -> *
- extractUnique :: uKey ~ Key v u => v -> uKey
- uniqueNum :: uKey -> Int
- data UniqueDef = UniqueDef {
- uniqueName :: String
- uniqueType :: UniqueType
- uniqueFields :: [(String, DbType)]
- data UniqueType
- type SingleMigration = Either [String] [(Bool, Int, String)]
- type NamedMigrations = Map String SingleMigration
- type Migration m = StateT NamedMigrations m ()
- class (Monad m, DbDescriptor (PhantomDb m)) => PersistBackend m where
- type PhantomDb m
- insert :: PersistEntity v => v -> m (AutoKey v)
- insertBy :: (PersistEntity v, IsUniqueKey (Key v (Unique u))) => u (UniqueMarker v) -> v -> m (Either (AutoKey v) (AutoKey v))
- insertByAll :: PersistEntity v => v -> m (Either (AutoKey v) (AutoKey v))
- replace :: (PersistEntity v, PrimitivePersistField (Key v BackendSpecific)) => Key v BackendSpecific -> v -> m ()
- select :: (PersistEntity v, Constructor c, HasSelectOptions opts v c) => opts -> m [v]
- selectAll :: PersistEntity v => m [(AutoKey v, v)]
- get :: (PersistEntity v, PrimitivePersistField (Key v BackendSpecific)) => Key v BackendSpecific -> m (Maybe v)
- getBy :: (PersistEntity v, IsUniqueKey (Key v (Unique u))) => Key v (Unique u) -> m (Maybe v)
- update :: (PersistEntity v, Constructor c) => [Update v c] -> Cond v c -> m ()
- delete :: (PersistEntity v, Constructor c) => Cond v c -> m ()
- deleteByKey :: (PersistEntity v, PrimitivePersistField (Key v BackendSpecific)) => Key v BackendSpecific -> m ()
- count :: (PersistEntity v, Constructor c) => Cond v c -> m Int
- countAll :: PersistEntity v => v -> m Int
- project :: (PersistEntity v, Constructor c, Projection p (RestrictionHolder v c) a', HasSelectOptions opts v c) => p -> opts -> m [a']
- migrate :: PersistEntity v => v -> Migration m
- executeRaw :: Bool -> String -> [PersistValue] -> m ()
- queryRaw :: Bool -> String -> [PersistValue] -> (RowPopper m -> m a) -> m a
- insertList :: PersistField a => [a] -> m Int64
- getList :: PersistField a => Int64 -> m [a]
- class PrimitivePersistField (AutoKeyType a) => DbDescriptor a where
- type AutoKeyType a
- type RowPopper m = m (Maybe [PersistValue])
- newtype Monad m => DbPersist conn m a = DbPersist {
- unDbPersist :: ReaderT conn m a
- runDbPersist :: Monad m => DbPersist conn m a -> conn -> m a
Main types
class (PersistField v, PurePersistField (AutoKey v)) => PersistEntity v whereSource
Only instances of this class can be persisted in a database
data Field v :: ((* -> *) -> *) -> * -> *Source
This type is used for typesafe manipulation of separate fields of datatype v.
Each constructor in Field
corresponds to its field in a datatype v.
It is parametrised by constructor phantom type and field value type.
A unique identifier of a value stored in a database. This may be a primary key, a constraint or unique indices. The second parameter is the key description.
This type is the default autoincremented key for the entity. If entity does not have such key, AutoKey v = ().
type DefaultKey v Source
This type is the default key for the entity.
entityDef :: v -> EntityDefSource
Returns a complete description of the type
toEntityPersistValues :: PersistBackend m => v -> m ([PersistValue] -> [PersistValue])Source
Marshalls value to a list of PersistValue
ready for insert to a database
fromEntityPersistValues :: PersistBackend m => [PersistValue] -> m (v, [PersistValue])Source
Constructs the value from the list of PersistValue
getUniques :: DbDescriptor db => Proxy db -> v -> (Int, [(String, [PersistValue] -> [PersistValue])])Source
Returns constructor number and a list of uniques names and corresponding field values
entityFieldChain :: Field v c a -> FieldChainSource
Is internally used by FieldLike Field instance We could avoid this function if class FieldLike allowed FieldLike Fields Data or FieldLike (Fields Data). However that would require additional extensions in user-space code
data PersistValue Source
A raw value which can be stored in any backend and can be marshalled to
and from a PersistField
.
class PersistField a whereSource
Represents everything which can be put into a database. This data can be stored in multiple columns and tables. To get value of those columns we might need to access another table. That is why the result type is monadic.
persistName :: a -> StringSource
Return name of the type. If it is polymorhic, the names of parameter types are separated with delim
symbol
toPersistValues :: PersistBackend m => a -> m ([PersistValue] -> [PersistValue])Source
Convert a value into something which can be stored in a database column. Note that for complex datatypes it may insert them to return identifier
fromPersistValues :: PersistBackend m => [PersistValue] -> m (a, [PersistValue])Source
Constructs a value from a PersistValue
. For complex datatypes it may query the database
Description of value type
PersistField Bool | |
PersistField Double | |
PersistField Int | |
PersistField Int8 | |
PersistField Int16 | |
PersistField Int32 | |
PersistField Int64 | |
PersistField Word8 | |
PersistField Word16 | |
PersistField Word32 | |
PersistField Word64 | |
PersistField String | |
PersistField () | |
PersistField ByteString | |
PersistField Text | |
PersistField ZonedTime | |
PersistField TimeOfDay | |
PersistField UTCTime | |
PersistField Day | |
PersistField a => PersistField [a] | |
(PersistField a, NeverNull a) => PersistField (Maybe a) | |
(PersistField a, PersistField b) => PersistField (a, b) | |
(DbDescriptor db, PersistEntity v) => PersistField (KeyForBackend db v) | |
(PersistField a, PersistField b, PersistField c) => PersistField (a, b, c) | |
(PersistField a, PersistField b, PersistField c, PersistField d) => PersistField (a, b, c, d) | |
(PersistField a, PersistField b, PersistField c, PersistField d, PersistField e) => PersistField (a, b, c, d, e) |
class PersistField a => SinglePersistField a whereSource
Represents all datatypes that map into a single column. Getting value for that column might require monadic actions to access other tables.
toSinglePersistValue :: PersistBackend m => a -> m PersistValueSource
fromSinglePersistValue :: PersistBackend m => PersistValue -> m aSource
(PersistField a, PrimitivePersistField a) => SinglePersistField a | |
(PersistField (Maybe a), SinglePersistField a, NeverNull a) => SinglePersistField (Maybe a) |
class PersistField a => PurePersistField a whereSource
Represents all datatypes that map into several columns. Getting values for those columns is pure.
toPurePersistValues :: DbDescriptor db => Proxy db -> a -> [PersistValue] -> [PersistValue]Source
fromPurePersistValues :: DbDescriptor db => Proxy db -> [PersistValue] -> (a, [PersistValue])Source
PurePersistField () | |
(PersistField a, PrimitivePersistField a) => PurePersistField a | |
(PersistField (Maybe a), PrimitivePersistField a, NeverNull a) => PurePersistField (Maybe a) | |
(PersistField (a, b), PurePersistField a, PurePersistField b) => PurePersistField (a, b) | |
(PersistField (a, b, c), PurePersistField a, PurePersistField b, PurePersistField c) => PurePersistField (a, b, c) | |
(PersistField (a, b, c, d), PurePersistField a, PurePersistField b, PurePersistField c, PurePersistField d) => PurePersistField (a, b, c, d) | |
(PersistField (a, b, c, d, e), PurePersistField a, PurePersistField b, PurePersistField c, PurePersistField d, PurePersistField e) => PurePersistField (a, b, c, d, e) |
class (SinglePersistField a, PurePersistField a) => PrimitivePersistField a whereSource
Datatypes which can be converted directly to PersistValue
. The no-value parameter DbDescriptor db => Proxy db
allows conversion depend the database details while keeping it pure.
toPrimitivePersistValue :: DbDescriptor db => Proxy db -> a -> PersistValueSource
fromPrimitivePersistValue :: DbDescriptor db => Proxy db -> PersistValue -> aSource
class PersistField v => Embedded v whereSource
selectorNum :: Selector v a -> IntSource
(PersistField (a', b'), PersistField a', PersistField b') => Embedded (a', b') | |
(PersistField (a', b', c'), PersistField a', PersistField b', PersistField c') => Embedded (a', b', c') | |
(PersistField (a', b', c', d'), PersistField a', PersistField b', PersistField c', PersistField d') => Embedded (a', b', c', d') | |
(PersistField (a', b', c', d', e'), PersistField a', PersistField b', PersistField c', PersistField d', PersistField e') => Embedded (a', b', c', d', e') |
class Projection p r a | p -> r a whereSource
Any data that can be fetched from a database
projectionFieldChains :: p -> [FieldChain] -> [FieldChain]Source
It is like a fieldChain
for many fields. Difflist is used for concatenation efficiency.
projectionResult :: PersistBackend m => p -> [PersistValue] -> m (a, [PersistValue])Source
It is like fromPersistValues
. However, we cannot use it for projections in all cases. For the PersistEntity
instances fromPersistValues
expects entity id instead of the entity values.
data RestrictionHolder v c Source
(PersistEntity v, Constructor c) => Projection (c (ConstructorMarker v)) (RestrictionHolder v c) v | |
(PersistEntity v, Constructor c, PersistField (Key v BackendSpecific)) => Projection (AutoKeyField v c) (RestrictionHolder v c) (Key v BackendSpecific) | |
(PersistEntity v, Constructor c, PersistField a) => Projection (SubField v c a) (RestrictionHolder v c) a | |
(PersistEntity v, Constructor c, PersistField a) => Projection (Field v c a) (RestrictionHolder v c) a |
A holder for Unique constraints
(PersistEntity v, IsUniqueKey (Key v (Unique u)), ~ * r (RestrictionHolder v (UniqueConstr (Key v (Unique u))))) => Projection (u (UniqueMarker v)) r (Key v (Unique u)) |
data KeyForBackend db v Source
A holder for DB type in backend-specific keys
(DbDescriptor db, PersistEntity v) => KeyForBackend (AutoKeyType db) |
(SinglePersistField (KeyForBackend db v), PurePersistField (KeyForBackend db v), DbDescriptor db, PersistEntity v) => PrimitivePersistField (KeyForBackend db v) | |
(DbDescriptor db, PersistEntity v) => PersistField (KeyForBackend db v) | |
NeverNull (KeyForBackend db v) |
data BackendSpecific Source
Key marked with this type can have value for any backend
(PersistEntity v, Constructor c, PersistField (Key v BackendSpecific)) => Projection (AutoKeyField v c) (RestrictionHolder v c) (Key v BackendSpecific) |
data ConstructorMarker v a Source
A phantom datatype to make instance head diffirent c (ConstructorMarker, v)
(PersistEntity v, Constructor c) => Projection (c (ConstructorMarker v)) (RestrictionHolder v c) v |
data UniqueMarker v a Source
A phantom datatype to make instance head diffirent u (UniqueMarker, v)
~ * r (HFalse, Key v (Unique u)) => ExtractValue (u (UniqueMarker v)) r | |
(PersistEntity v, IsUniqueKey (Key v (Unique u)), Projection (u (UniqueMarker v)) r a') => FieldLike (u (UniqueMarker v)) r a' | |
(PersistEntity v, Constructor c, FieldLike (u (UniqueMarker v)) (RestrictionHolder v c) a', ~ ((* -> *) -> *) c' (UniqueConstr (Key v' (Unique u))), ~ * v v', IsUniqueKey (Key v' (Unique u)), ~ ((* -> *) -> *) c c') => Expression (u (UniqueMarker v)) v' c' | |
(PersistEntity v, IsUniqueKey (Key v (Unique u)), ~ * r (RestrictionHolder v (UniqueConstr (Key v (Unique u))))) => Projection (u (UniqueMarker v)) r (Key v (Unique u)) |
Constructing expressions
Represents condition for a query.
And (Cond v c) (Cond v c) | |
Or (Cond v c) (Cond v c) | |
Not (Cond v c) | |
forall a b . Compare ExprRelation (Expr v c a) (Expr v c b) |
HasSelectOptions (Cond v c) v c |
(~>) :: (PersistEntity v, Constructor c, FieldLike f (RestrictionHolder v c) a, Embedded a) => f -> Selector a a' -> SubField v c a'Source
Accesses fields of the embedded datatypes. For example, SomeField ==. ("abc", "def") ||. SomeField ~> Tuple2_0Selector ==. "def"
toArith :: (PersistEntity v, FieldLike f (RestrictionHolder v c) a') => f -> Arith v c a'Source
Convert field to an arithmetic value
class Projection f r a => FieldLike f r a | f -> r a whereSource
Generalises data that can occur in expressions (so far there are Field and SubField).
fieldChain :: f -> FieldChainSource
It is used to map field to column names. It can be either a column name for a regular field of non-embedded type or a list of this field and the outer fields in reverse order. Eg, fieldChain $ SomeField ~> Tuple2_0Selector may result in Right [("val0", DbString), ("some", DbEmbedded False [dbType "", dbType True])]. Function fieldChain can be simplified to f v c a -> [(String, DbType)]. Datatype Either is used for optimisation of the common case, eg Field v c Int.
(PersistEntity v, IsUniqueKey (Key v (Unique u)), Projection (u (UniqueMarker v)) r a') => FieldLike (u (UniqueMarker v)) r a' | |
(PersistEntity v, Constructor c, Projection (AutoKeyField v c) r a') => FieldLike (AutoKeyField v c) r a' | |
(PersistEntity v, Constructor c, Projection (SubField v c a) r a') => FieldLike (SubField v c a) r a' | |
(PersistEntity v, Constructor c, Projection (Field v c a) r a') => FieldLike (Field v c a) r a' |
SubField ((String, DbType), [(String, EmbeddedDef)]) |
~ * r (HFalse, a) => ExtractValue (SubField v c a) r | |
(PersistEntity v, Constructor c, Projection (SubField v c a) r a') => FieldLike (SubField v c a) r a' | |
(PersistEntity v, Constructor c, PersistField a, ~ * v v', ~ ((* -> *) -> *) c c') => Expression (SubField v c a) v' c' | |
(PersistEntity v, Constructor c, PersistField a) => Projection (SubField v c a) (RestrictionHolder v c) a |
data AutoKeyField v c whereSource
It can be used in expressions like a regular field. Note that the constructor should be specified for the condition.
For example, delete (AutoKeyField
or asTypeOf
(undefined :: f v SomeConstructor) ==. k)delete (AutoKeyField ==. k ||. SomeField ==. "DUPLICATE")
AutoKeyField :: (PersistEntity v, Constructor c) => AutoKeyField v c |
~ * r (HFalse, Key v BackendSpecific) => ExtractValue (AutoKeyField v c) r | |
(PersistEntity v, Constructor c, Projection (AutoKeyField v c) r a') => FieldLike (AutoKeyField v c) r a' | |
(PersistEntity v, Constructor c, PersistField (Key v' BackendSpecific), FieldLike (AutoKeyField v c) (RestrictionHolder v c) a', ~ * v v', ~ ((* -> *) -> *) c c') => Expression (AutoKeyField v c) v' c' | |
(PersistEntity v, Constructor c, PersistField (Key v BackendSpecific)) => Projection (AutoKeyField v c) (RestrictionHolder v c) (Key v BackendSpecific) |
type FieldChain = ((String, DbType), [(String, EmbeddedDef)])Source
Types which when converted to PersistValue
are never NULL.
Consider the type Maybe (Maybe a)
. Now Nothing is stored as NULL, so we cannot distinguish between Just Nothing and Nothing which is a problem.
The purpose of this class is to ban the inner Maybe's.
Maybe this class can be removed when support for inner Maybe's appears.
Arithmetic expressions which can include fields and literals
Plus (Arith v c a) (Arith v c a) | |
Minus (Arith v c a) (Arith v c a) | |
Mult (Arith v c a) (Arith v c a) | |
Abs (Arith v c a) | |
forall f . FieldLike f (RestrictionHolder v c) a => ArithField f | |
Lit Int64 |
(PersistEntity v, Constructor c) => Eq (Arith v c a) | |
(PersistEntity v, Constructor c, Numeric a) => Num (Arith v c a) | |
(PersistEntity v, Constructor c) => Show (Arith v c a) | |
~ * r (HFalse, a) => ExtractValue (Arith v c a) r | |
(PersistEntity v, Constructor c, PersistField a, ~ * v v', ~ ((* -> *) -> *) c c') => Expression (Arith v c a) v' c' |
Used to uniformly represent fields, constants and arithmetic expressions.
A value should be converted to Expr
for usage in expressions
ExprField :: (PersistEntity v, FieldLike f (RestrictionHolder v c) a') => f -> Expr v c f | |
ExprArith :: PersistEntity v => Arith v c a -> Expr v c (Arith v c a) | |
ExprPure :: forall v c a. PurePersistField a => a -> Expr v c a |
Defines sort order of a result-set
forall a f . FieldLike f (RestrictionHolder v c) a => Asc f | |
forall a f . FieldLike f (RestrictionHolder v c) a => Desc f |
class HasSelectOptions a v c | a -> v c whereSource
getSelectOptions :: a -> SelectOptions v c (HasLimit a) (HasOffset a) (HasOrder a)Source
HasSelectOptions (Cond v c) v c | |
HasSelectOptions (SelectOptions v c hasLimit hasOffset hasOrder) v c |
data SelectOptions v c hasLimit hasOffset hasOrder Source
SelectOptions | |
|
HasSelectOptions (SelectOptions v c hasLimit hasOffset hasOrder) v c |
limitTo :: (HasSelectOptions a v c, HasLimit a ~ HFalse) => a -> Int -> SelectOptions v c HTrue (HasOffset a) (HasOrder a)Source
offsetBy :: (HasSelectOptions a v c, HasOffset a ~ HFalse) => a -> Int -> SelectOptions v c (HasLimit a) HTrue (HasOrder a)Source
orderBy :: (HasSelectOptions a v c, HasOrder a ~ HFalse) => a -> [Order v c] -> SelectOptions v c (HasLimit a) (HasOffset a) HTrueSource
Type description
A DB data type. Naming attempts to reflect the underlying Haskell datatypes, eg DbString instead of DbVarchar. Different databases may have different translations for these types.
DbString | |
DbInt32 | |
DbInt64 | |
DbReal | |
DbBool | |
DbDay | |
DbTime | |
DbDayTime | |
DbDayTimeZoned | |
DbBlob | ByteString |
DbOther String | Name for a database type More complex types |
DbMaybe DbType | |
DbList String DbType | List table name and type of its argument |
DbEmbedded EmbeddedDef | |
DbEntity (Maybe (EmbeddedDef, String)) EntityDef | Nothing means autokey, Just contains a unique key definition and a name of unique constraint. |
Describes an ADT.
EntityDef | |
|
data EmbeddedDef Source
The first argument is a flag which defines if the field names should be concatenated with the outer field name (False) or used as is which provides full control over table column names (True). Value False should be the default value so that a datatype can be embedded without name conflict concern. The second argument list of field names and field types.
EmbeddedDef Bool [(String, DbType)] |
data ConstructorDef Source
Describes an entity constructor
ConstructorDef | |
|
class Constructor c whereSource
Phantom constructors are made instances of this class. This class should be used only by Template Haskell codegen
phantomConstrName :: c (a :: * -> *) -> StringSource
phantomConstrNum :: c (a :: * -> *) -> IntSource
class (Constructor (UniqueConstr uKey), PurePersistField uKey) => IsUniqueKey uKey whereSource
type UniqueConstr uKey :: (* -> *) -> *Source
Unique name and list of the field names that form a unique combination
UniqueDef | |
|
data UniqueType Source
Defines how to treat the unique set of fields for a datatype
Migration
type SingleMigration = Either [String] [(Bool, Int, String)]Source
Either error messages or migration queries with safety flag and execution order
type NamedMigrations = Map String SingleMigrationSource
Datatype names and corresponding migrations
type Migration m = StateT NamedMigrations m ()Source
Database
class (Monad m, DbDescriptor (PhantomDb m)) => PersistBackend m whereSource
A token which defines the DB type. For example, different monads working with Sqlite, return Sqlite type.
insert :: PersistEntity v => v -> m (AutoKey v)Source
Insert a new record to a database and return its Key
insertBy :: (PersistEntity v, IsUniqueKey (Key v (Unique u))) => u (UniqueMarker v) -> v -> m (Either (AutoKey v) (AutoKey v))Source
Try to insert a record and return Right newkey. If there is a constraint violation for the given constraint, Left oldkey is returned , where oldkey is an identifier of the record with the matching values.
insertByAll :: PersistEntity v => v -> m (Either (AutoKey v) (AutoKey v))Source
Try to insert a record and return Right newkey. If there is a constraint violation for any constraint, Left oldkey is returned , where oldkey is an identifier of the record with the matching values. Note that if several constraints are violated, a key of an arbitrary matching record is returned.
replace :: (PersistEntity v, PrimitivePersistField (Key v BackendSpecific)) => Key v BackendSpecific -> v -> m ()Source
Replace a record with the given autogenerated key. Result is undefined if the record does not exist.
select :: (PersistEntity v, Constructor c, HasSelectOptions opts v c) => opts -> m [v]Source
Return a list of the records satisfying the condition
selectAll :: PersistEntity v => m [(AutoKey v, v)]Source
Return a list of all records. Order is undefined. It is useful for datatypes with multiple constructors.
get :: (PersistEntity v, PrimitivePersistField (Key v BackendSpecific)) => Key v BackendSpecific -> m (Maybe v)Source
Fetch an entity from a database
getBy :: (PersistEntity v, IsUniqueKey (Key v (Unique u))) => Key v (Unique u) -> m (Maybe v)Source
Fetch an entity from a database by its unique key
update :: (PersistEntity v, Constructor c) => [Update v c] -> Cond v c -> m ()Source
Update the records satisfying the condition
delete :: (PersistEntity v, Constructor c) => Cond v c -> m ()Source
Remove the records satisfying the condition
deleteByKey :: (PersistEntity v, PrimitivePersistField (Key v BackendSpecific)) => Key v BackendSpecific -> m ()Source
Remove the record with given key. No-op if the record does not exist
count :: (PersistEntity v, Constructor c) => Cond v c -> m IntSource
Count total number of records satisfying the condition
countAll :: PersistEntity v => v -> m IntSource
Count total number of records with all constructors
project :: (PersistEntity v, Constructor c, Projection p (RestrictionHolder v c) a', HasSelectOptions opts v c) => p -> opts -> m [a']Source
Fetch projection of some fields
migrate :: PersistEntity v => v -> Migration mSource
Check database schema and create migrations for the entity and the entities it contains
:: Bool | keep in cache |
-> String | query |
-> [PersistValue] | positional parameters |
-> m () |
Execute raw query
:: Bool | keep in cache |
-> String | query |
-> [PersistValue] | positional parameters |
-> (RowPopper m -> m a) | results processing function |
-> m a |
Execute raw query with results
insertList :: PersistField a => [a] -> m Int64Source
getList :: PersistField a => Int64 -> m [a]Source
class PrimitivePersistField (AutoKeyType a) => DbDescriptor a Source
type AutoKeyType a Source
Type of the database default autoincremented key. For example, Sqlite has Int64
type RowPopper m = m (Maybe [PersistValue])Source
newtype Monad m => DbPersist conn m a Source
DbPersist | |
|
(Applicative IO, Applicative (DbPersist conn m), Monad IO, Monad (DbPersist conn m), MonadBase IO m) => MonadBase IO (DbPersist conn m) | |
(MonadBase IO (DbPersist conn m), MonadBaseControl IO m) => MonadBaseControl IO (DbPersist conn m) | |
MonadTrans (DbPersist conn) | |
MonadTrans (DbPersist conn) => MonadTransControl (DbPersist conn) | |
Monad m => Monad (DbPersist conn m) | |
Functor m => Functor (DbPersist conn m) | |
(Functor (DbPersist conn m), Applicative m) => Applicative (DbPersist conn m) | |
(Monad (DbPersist conn m), MonadIO m) => MonadIO (DbPersist conn m) |
runDbPersist :: Monad m => DbPersist conn m a -> conn -> m aSource