groundhog-0.12.0: Type-safe datatype-database mapping library.
Safe HaskellNone
LanguageHaskell2010

Database.Groundhog.Core

Description

This module defines the functions and datatypes used throughout the framework. Most of them are for the internal use

Synopsis

Main types

class (PurePersistField (AutoKey v), PurePersistField (DefaultKey v)) => PersistEntity v where Source #

Only instances of this class can be persisted in a database

Associated Types

data Field v :: ((Type -> Type) -> Type) -> Type -> Type 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.

data Key v :: Type -> Type Source #

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.

type AutoKey v Source #

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.

type IsSumType v Source #

It is HFalse for entity with one constructor and HTrue for sum types.

Methods

entityDef :: DbDescriptor db => proxy db -> v -> EntityDef Source #

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 :: v -> (Int, [(String, [PersistValue] -> [PersistValue])]) Source #

Returns constructor number and a list of uniques names and corresponding field values

entityFieldChain :: DbDescriptor db => proxy db -> Field v c a -> FieldChain Source #

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.

Constructors

PersistString String 
PersistText Text 
PersistByteString ByteString 
PersistInt64 Int64 
PersistDouble Double 
PersistBool Bool 
PersistDay Day 
PersistTimeOfDay TimeOfDay 
PersistUTCTime UTCTime 
PersistZonedTime ZT 
PersistNull 
PersistCustom Utf8 [PersistValue]

Creating some datatypes may require calling a function, using a special constructor, or other syntax. The string (which can have placeholders) is included into query without escaping. The recursive constructions are not allowed, i.e., [PersistValue] cannot contain PersistCustom values.

class PersistField a where Source #

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.

Methods

persistName :: a -> String Source #

Return name of the type. If it is polymorphic, 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

dbType :: DbDescriptor db => proxy db -> a -> DbType Source #

Description of value type. It depends on database so that we can have, for example, xml column type in Postgres and varchar type in other databases

Instances

Instances details
PersistField Bool Source # 
Instance details

Defined in Database.Groundhog.Instances

PersistField Double Source # 
Instance details

Defined in Database.Groundhog.Instances

PersistField Int Source # 
Instance details

Defined in Database.Groundhog.Instances

PersistField Int8 Source # 
Instance details

Defined in Database.Groundhog.Instances

PersistField Int16 Source # 
Instance details

Defined in Database.Groundhog.Instances

PersistField Int32 Source # 
Instance details

Defined in Database.Groundhog.Instances

PersistField Int64 Source # 
Instance details

Defined in Database.Groundhog.Instances

PersistField Word8 Source # 
Instance details

Defined in Database.Groundhog.Instances

PersistField Word16 Source # 
Instance details

Defined in Database.Groundhog.Instances

PersistField Word32 Source # 
Instance details

Defined in Database.Groundhog.Instances

PersistField Word64 Source # 
Instance details

Defined in Database.Groundhog.Instances

PersistField () Source # 
Instance details

Defined in Database.Groundhog.Instances

PersistField String Source # 
Instance details

Defined in Database.Groundhog.Instances

PersistField ByteString Source # 
Instance details

Defined in Database.Groundhog.Instances

PersistField ByteString Source # 
Instance details

Defined in Database.Groundhog.Instances

PersistField UTCTime Source # 
Instance details

Defined in Database.Groundhog.Instances

PersistField Text Source # 
Instance details

Defined in Database.Groundhog.Instances

PersistField Value Source # 
Instance details

Defined in Database.Groundhog.Instances

PersistField Text Source # 
Instance details

Defined in Database.Groundhog.Instances

PersistField ZonedTime Source # 
Instance details

Defined in Database.Groundhog.Instances

PersistField TimeOfDay Source # 
Instance details

Defined in Database.Groundhog.Instances

PersistField Day Source # 
Instance details

Defined in Database.Groundhog.Instances

PersistField a => PersistField [a] Source # 
Instance details

Defined in Database.Groundhog.Instances

(PersistField a, NeverNull a) => PersistField (Maybe a) Source # 
Instance details

Defined in Database.Groundhog.Instances

(PersistField a, PersistField b) => PersistField (a, b) Source # 
Instance details

Defined in Database.Groundhog.Instances

Methods

persistName :: (a, b) -> String Source #

toPersistValues :: PersistBackend m => (a, b) -> m ([PersistValue] -> [PersistValue]) Source #

fromPersistValues :: PersistBackend m => [PersistValue] -> m ((a, b), [PersistValue]) Source #

dbType :: DbDescriptor db => proxy db -> (a, b) -> DbType Source #

(DbDescriptor db, PersistEntity v, PersistField v) => PersistField (KeyForBackend db v) Source # 
Instance details

Defined in Database.Groundhog.Instances

(PersistField a, PersistField b, PersistField c) => PersistField (a, b, c) Source # 
Instance details

Defined in Database.Groundhog.Instances

Methods

persistName :: (a, b, c) -> String Source #

toPersistValues :: PersistBackend m => (a, b, c) -> m ([PersistValue] -> [PersistValue]) Source #

fromPersistValues :: PersistBackend m => [PersistValue] -> m ((a, b, c), [PersistValue]) Source #

dbType :: DbDescriptor db => proxy db -> (a, b, c) -> DbType Source #

(PersistField a, PersistField b, PersistField c, PersistField d) => PersistField (a, b, c, d) Source # 
Instance details

Defined in Database.Groundhog.Instances

Methods

persistName :: (a, b, c, d) -> String Source #

toPersistValues :: PersistBackend m => (a, b, c, d) -> m ([PersistValue] -> [PersistValue]) Source #

fromPersistValues :: PersistBackend m => [PersistValue] -> m ((a, b, c, d), [PersistValue]) Source #

dbType :: DbDescriptor db => proxy db -> (a, b, c, d) -> DbType Source #

(PersistField a, PersistField b, PersistField c, PersistField d, PersistField e) => PersistField (a, b, c, d, e) Source # 
Instance details

Defined in Database.Groundhog.Instances

Methods

persistName :: (a, b, c, d, e) -> String Source #

toPersistValues :: PersistBackend m => (a, b, c, d, e) -> m ([PersistValue] -> [PersistValue]) Source #

fromPersistValues :: PersistBackend m => [PersistValue] -> m ((a, b, c, d, e), [PersistValue]) Source #

dbType :: DbDescriptor db => proxy db -> (a, b, c, d, e) -> DbType Source #

class PersistField a => SinglePersistField a where Source #

Represents all datatypes that map into a single column. Getting value for that column might require monadic actions to access other tables.

class PersistField a => PurePersistField a where Source #

Represents all datatypes that map into several columns. Getting values for those columns is pure.

Instances

Instances details
PurePersistField () Source # 
Instance details

Defined in Database.Groundhog.Instances

(PersistField a, PrimitivePersistField a) => PurePersistField a Source # 
Instance details

Defined in Database.Groundhog.Instances

(PurePersistField a, PurePersistField b) => PurePersistField (a, b) Source # 
Instance details

Defined in Database.Groundhog.Instances

(PurePersistField a, PurePersistField b, PurePersistField c) => PurePersistField (a, b, c) Source # 
Instance details

Defined in Database.Groundhog.Instances

(PurePersistField a, PurePersistField b, PurePersistField c, PurePersistField d) => PurePersistField (a, b, c, d) Source # 
Instance details

Defined in Database.Groundhog.Instances

(PurePersistField a, PurePersistField b, PurePersistField c, PurePersistField d, PurePersistField e) => PurePersistField (a, b, c, d, e) Source # 
Instance details

Defined in Database.Groundhog.Instances

Methods

toPurePersistValues :: (a, b, c, d, e) -> [PersistValue] -> [PersistValue] Source #

fromPurePersistValues :: [PersistValue] -> ((a, b, c, d, e), [PersistValue]) Source #

class PersistField a => PrimitivePersistField a where Source #

Datatypes which can be converted directly to PersistValue

Instances

Instances details
PrimitivePersistField Bool Source # 
Instance details

Defined in Database.Groundhog.Instances

PrimitivePersistField Double Source # 
Instance details

Defined in Database.Groundhog.Instances

PrimitivePersistField Int Source # 
Instance details

Defined in Database.Groundhog.Instances

PrimitivePersistField Int8 Source # 
Instance details

Defined in Database.Groundhog.Instances

PrimitivePersistField Int16 Source # 
Instance details

Defined in Database.Groundhog.Instances

PrimitivePersistField Int32 Source # 
Instance details

Defined in Database.Groundhog.Instances

PrimitivePersistField Int64 Source # 
Instance details

Defined in Database.Groundhog.Instances

PrimitivePersistField Word8 Source # 
Instance details

Defined in Database.Groundhog.Instances

PrimitivePersistField Word16 Source # 
Instance details

Defined in Database.Groundhog.Instances

PrimitivePersistField Word32 Source # 
Instance details

Defined in Database.Groundhog.Instances

PrimitivePersistField Word64 Source # 
Instance details

Defined in Database.Groundhog.Instances

PrimitivePersistField String Source # 
Instance details

Defined in Database.Groundhog.Instances

PrimitivePersistField ByteString Source # 
Instance details

Defined in Database.Groundhog.Instances

PrimitivePersistField ByteString Source # 
Instance details

Defined in Database.Groundhog.Instances

PrimitivePersistField UTCTime Source # 
Instance details

Defined in Database.Groundhog.Instances

PrimitivePersistField Text Source # 
Instance details

Defined in Database.Groundhog.Instances

PrimitivePersistField Value Source # 
Instance details

Defined in Database.Groundhog.Instances

PrimitivePersistField Text Source # 
Instance details

Defined in Database.Groundhog.Instances

PrimitivePersistField ZonedTime Source # 
Instance details

Defined in Database.Groundhog.Instances

PrimitivePersistField TimeOfDay Source # 
Instance details

Defined in Database.Groundhog.Instances

PrimitivePersistField Day Source # 
Instance details

Defined in Database.Groundhog.Instances

(PrimitivePersistField a, NeverNull a) => PrimitivePersistField (Maybe a) Source # 
Instance details

Defined in Database.Groundhog.Instances

(DbDescriptor db, PersistEntity v, PersistField v) => PrimitivePersistField (KeyForBackend db v) Source # 
Instance details

Defined in Database.Groundhog.Instances

class PersistField v => Embedded v where Source #

Associated Types

data Selector v :: Type -> Type Source #

Methods

selectorNum :: Selector v a -> Int Source #

Instances

Instances details
(PersistField a', PersistField b') => Embedded (a', b') Source # 
Instance details

Defined in Database.Groundhog.Instances

Associated Types

data Selector (a', b') :: Type -> Type Source #

Methods

selectorNum :: Selector (a', b') a -> Int Source #

(PersistField a', PersistField b', PersistField c') => Embedded (a', b', c') Source # 
Instance details

Defined in Database.Groundhog.Instances

Associated Types

data Selector (a', b', c') :: Type -> Type Source #

Methods

selectorNum :: Selector (a', b', c') a -> Int Source #

(PersistField a', PersistField b', PersistField c', PersistField d') => Embedded (a', b', c', d') Source # 
Instance details

Defined in Database.Groundhog.Instances

Associated Types

data Selector (a', b', c', d') :: Type -> Type Source #

Methods

selectorNum :: Selector (a', b', c', d') a -> Int Source #

(PersistField a', PersistField b', PersistField c', PersistField d', PersistField e') => Embedded (a', b', c', d', e') Source # 
Instance details

Defined in Database.Groundhog.Instances

Associated Types

data Selector (a', b', c', d', e') :: Type -> Type Source #

Methods

selectorNum :: Selector (a', b', c', d', e') a -> Int Source #

class Projection p a | p -> a where Source #

Any data that can be fetched from a database

Associated Types

type ProjectionDb p db :: Constraint Source #

type ProjectionRestriction p r :: Constraint Source #

Methods

projectionExprs :: (DbDescriptor db, ProjectionDb p db, ProjectionRestriction p r) => p -> [UntypedExpr db r] -> [UntypedExpr db r] Source #

It returns multiple expressions that can be transformed into values which can be selected. 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.

Instances

Instances details
(PersistEntity v, IsUniqueKey k, k ~ Key v (Unique u)) => Projection (u (UniqueMarker v)) k Source # 
Instance details

Defined in Database.Groundhog.Instances

Associated Types

type ProjectionDb (u (UniqueMarker v)) db Source #

type ProjectionRestriction (u (UniqueMarker v)) r Source #

EntityConstr v c => Projection (c (ConstructorMarker v)) v Source # 
Instance details

Defined in Database.Groundhog.Instances

(EntityConstr v c, a ~ AutoKey v) => Projection (AutoKeyField v c) a Source # 
Instance details

Defined in Database.Groundhog.Instances

Associated Types

type ProjectionDb (AutoKeyField v c) db Source #

type ProjectionRestriction (AutoKeyField v c) r Source #

a ~ Bool => Projection (Cond db r) a Source # 
Instance details

Defined in Database.Groundhog.Instances

Associated Types

type ProjectionDb (Cond db r) db Source #

type ProjectionRestriction (Cond db r) r Source #

Methods

projectionExprs :: (DbDescriptor db0, ProjectionDb (Cond db r) db0, ProjectionRestriction (Cond db r) r0) => Cond db r -> [UntypedExpr db0 r0] -> [UntypedExpr db0 r0] Source #

projectionResult :: PersistBackend m => Cond db r -> [PersistValue] -> m (a, [PersistValue]) Source #

(Projection a1 a1', Projection a2 a2') => Projection (a1, a2) (a1', a2') Source # 
Instance details

Defined in Database.Groundhog.Instances

Associated Types

type ProjectionDb (a1, a2) db Source #

type ProjectionRestriction (a1, a2) r Source #

Methods

projectionExprs :: (DbDescriptor db, ProjectionDb (a1, a2) db, ProjectionRestriction (a1, a2) r) => (a1, a2) -> [UntypedExpr db r] -> [UntypedExpr db r] Source #

projectionResult :: PersistBackend m => (a1, a2) -> [PersistValue] -> m ((a1', a2'), [PersistValue]) Source #

PersistField a => Projection (Expr db r a) a Source # 
Instance details

Defined in Database.Groundhog.Instances

Associated Types

type ProjectionDb (Expr db r a) db Source #

type ProjectionRestriction (Expr db r a) r Source #

Methods

projectionExprs :: (DbDescriptor db0, ProjectionDb (Expr db r a) db0, ProjectionRestriction (Expr db r a) r0) => Expr db r a -> [UntypedExpr db0 r0] -> [UntypedExpr db0 r0] Source #

projectionResult :: PersistBackend m => Expr db r a -> [PersistValue] -> m (a, [PersistValue]) Source #

(EntityConstr v c, PersistField a) => Projection (Field v c a) a Source # 
Instance details

Defined in Database.Groundhog.Instances

Associated Types

type ProjectionDb (Field v c a) db Source #

type ProjectionRestriction (Field v c a) r Source #

Methods

projectionExprs :: (DbDescriptor db, ProjectionDb (Field v c a) db, ProjectionRestriction (Field v c a) r) => Field v c a -> [UntypedExpr db r] -> [UntypedExpr db r] Source #

projectionResult :: PersistBackend m => Field v c a -> [PersistValue] -> m (a, [PersistValue]) Source #

(Projection a1 a1', Projection a2 a2', Projection a3 a3') => Projection (a1, a2, a3) (a1', a2', a3') Source # 
Instance details

Defined in Database.Groundhog.Instances

Associated Types

type ProjectionDb (a1, a2, a3) db Source #

type ProjectionRestriction (a1, a2, a3) r Source #

Methods

projectionExprs :: (DbDescriptor db, ProjectionDb (a1, a2, a3) db, ProjectionRestriction (a1, a2, a3) r) => (a1, a2, a3) -> [UntypedExpr db r] -> [UntypedExpr db r] Source #

projectionResult :: PersistBackend m => (a1, a2, a3) -> [PersistValue] -> m ((a1', a2', a3'), [PersistValue]) Source #

(EntityConstr v c, PersistField a) => Projection (SubField db v c a) a Source # 
Instance details

Defined in Database.Groundhog.Instances

Associated Types

type ProjectionDb (SubField db v c a) db Source #

type ProjectionRestriction (SubField db v c a) r Source #

Methods

projectionExprs :: (DbDescriptor db0, ProjectionDb (SubField db v c a) db0, ProjectionRestriction (SubField db v c a) r) => SubField db v c a -> [UntypedExpr db0 r] -> [UntypedExpr db0 r] Source #

projectionResult :: PersistBackend m => SubField db v c a -> [PersistValue] -> m (a, [PersistValue]) Source #

(Projection a1 a1', Projection a2 a2', Projection a3 a3', Projection a4 a4') => Projection (a1, a2, a3, a4) (a1', a2', a3', a4') Source # 
Instance details

Defined in Database.Groundhog.Instances

Associated Types

type ProjectionDb (a1, a2, a3, a4) db Source #

type ProjectionRestriction (a1, a2, a3, a4) r Source #

Methods

projectionExprs :: (DbDescriptor db, ProjectionDb (a1, a2, a3, a4) db, ProjectionRestriction (a1, a2, a3, a4) r) => (a1, a2, a3, a4) -> [UntypedExpr db r] -> [UntypedExpr db r] Source #

projectionResult :: PersistBackend m => (a1, a2, a3, a4) -> [PersistValue] -> m ((a1', a2', a3', a4'), [PersistValue]) Source #

(Projection a1 a1', Projection a2 a2', Projection a3 a3', Projection a4 a4', Projection a5 a5') => Projection (a1, a2, a3, a4, a5) (a1', a2', a3', a4', a5') Source # 
Instance details

Defined in Database.Groundhog.Instances

Associated Types

type ProjectionDb (a1, a2, a3, a4, a5) db Source #

type ProjectionRestriction (a1, a2, a3, a4, a5) r Source #

Methods

projectionExprs :: (DbDescriptor db, ProjectionDb (a1, a2, a3, a4, a5) db, ProjectionRestriction (a1, a2, a3, a4, a5) r) => (a1, a2, a3, a4, a5) -> [UntypedExpr db r] -> [UntypedExpr db r] Source #

projectionResult :: PersistBackend m => (a1, a2, a3, a4, a5) -> [PersistValue] -> m ((a1', a2', a3', a4', a5'), [PersistValue]) Source #

class (Projection p a, ProjectionDb p db, ProjectionRestriction p r) => Projection' p db r a Source #

Instances

Instances details
(Projection p a, ProjectionDb p db, ProjectionRestriction p r) => Projection' p db r a Source # 
Instance details

Defined in Database.Groundhog.Core

data RestrictionHolder v (c :: (Type -> Type) -> Type) Source #

Instances

Instances details
type ProjectionRestriction (u (UniqueMarker v)) (RestrictionHolder v' c) Source # 
Instance details

Defined in Database.Groundhog.Instances

data Unique (u :: (Type -> Type) -> Type) Source #

A holder for Unique constraints

data KeyForBackend db v Source #

It allows to store autogenerated keys of one database in another if they have different datatype.

Constructors

(DbDescriptor db, PersistEntity v) => KeyForBackend (AutoKeyType db) 

data BackendSpecific Source #

Key marked with this type can have value for any backend

data ConstructorMarker v a Source #

A phantom datatype to make instance head different c (ConstructorMarker v)

data UniqueMarker v a Source #

A phantom datatype to make instance head different u (UniqueMarker v)

Instances

Instances details
(PersistEntity v, DbDescriptor db, IsUniqueKey k, k ~ Key v (Unique u), RestrictionHolder v c ~ r') => Expression db r' (u (UniqueMarker v)) Source # 
Instance details

Defined in Database.Groundhog.Expression

Methods

toExpr :: u (UniqueMarker v) -> UntypedExpr db r' Source #

(PersistEntity v, IsUniqueKey k, k ~ Key v (Unique u)) => FieldLike (u (UniqueMarker v)) k Source # 
Instance details

Defined in Database.Groundhog.Instances

Methods

fieldChain :: (DbDescriptor db, ProjectionDb (u (UniqueMarker v)) db) => proxy db -> u (UniqueMarker v) -> FieldChain Source #

(PersistEntity v, IsUniqueKey k, k ~ Key v (Unique u)) => Assignable (u (UniqueMarker v)) k Source # 
Instance details

Defined in Database.Groundhog.Instances

(PersistEntity v, IsUniqueKey k, k ~ Key v (Unique u)) => Projection (u (UniqueMarker v)) k Source # 
Instance details

Defined in Database.Groundhog.Instances

Associated Types

type ProjectionDb (u (UniqueMarker v)) db Source #

type ProjectionRestriction (u (UniqueMarker v)) r Source #

type ProjectionDb (u (UniqueMarker v)) db Source # 
Instance details

Defined in Database.Groundhog.Instances

type ProjectionDb (u (UniqueMarker v)) db = ()
type ProjectionRestriction (u (UniqueMarker v)) (RestrictionHolder v' c) Source # 
Instance details

Defined in Database.Groundhog.Instances

newtype ZT Source #

Avoid orphan instances.

Constructors

ZT ZonedTime 

Instances

Instances details
Eq ZT Source # 
Instance details

Defined in Database.Groundhog.Core

Methods

(==) :: ZT -> ZT -> Bool #

(/=) :: ZT -> ZT -> Bool #

Ord ZT Source # 
Instance details

Defined in Database.Groundhog.Core

Methods

compare :: ZT -> ZT -> Ordering #

(<) :: ZT -> ZT -> Bool #

(<=) :: ZT -> ZT -> Bool #

(>) :: ZT -> ZT -> Bool #

(>=) :: ZT -> ZT -> Bool #

max :: ZT -> ZT -> ZT #

min :: ZT -> ZT -> ZT #

Read ZT Source # 
Instance details

Defined in Database.Groundhog.Core

Show ZT Source # 
Instance details

Defined in Database.Groundhog.Core

Methods

showsPrec :: Int -> ZT -> ShowS #

show :: ZT -> String #

showList :: [ZT] -> ShowS #

newtype Utf8 Source #

Constructors

Utf8 Builder 

Instances

Instances details
Eq Utf8 Source # 
Instance details

Defined in Database.Groundhog.Core

Methods

(==) :: Utf8 -> Utf8 -> Bool #

(/=) :: Utf8 -> Utf8 -> Bool #

Ord Utf8 Source # 
Instance details

Defined in Database.Groundhog.Core

Methods

compare :: Utf8 -> Utf8 -> Ordering #

(<) :: Utf8 -> Utf8 -> Bool #

(<=) :: Utf8 -> Utf8 -> Bool #

(>) :: Utf8 -> Utf8 -> Bool #

(>=) :: Utf8 -> Utf8 -> Bool #

max :: Utf8 -> Utf8 -> Utf8 #

min :: Utf8 -> Utf8 -> Utf8 #

Read Utf8 Source # 
Instance details

Defined in Database.Groundhog.Core

Show Utf8 Source # 
Instance details

Defined in Database.Groundhog.Core

Methods

showsPrec :: Int -> Utf8 -> ShowS #

show :: Utf8 -> String #

showList :: [Utf8] -> ShowS #

IsString Utf8 Source # 
Instance details

Defined in Database.Groundhog.Core

Methods

fromString :: String -> Utf8 #

Semigroup Utf8 Source # 
Instance details

Defined in Database.Groundhog.Core

Methods

(<>) :: Utf8 -> Utf8 -> Utf8 #

sconcat :: NonEmpty Utf8 -> Utf8 #

stimes :: Integral b => b -> Utf8 -> Utf8 #

Monoid Utf8 Source # 
Instance details

Defined in Database.Groundhog.Core

Methods

mempty :: Utf8 #

mappend :: Utf8 -> Utf8 -> Utf8 #

mconcat :: [Utf8] -> Utf8 #

StringLike Utf8 Source # 
Instance details

Defined in Database.Groundhog.Generic.Sql

Methods

fromChar :: Char -> Utf8 Source #

Constructing expressions

data Cond db r Source #

Represents condition for a query.

Constructors

And (Cond db r) (Cond db r) 
Or (Cond db r) (Cond db r) 
Not (Cond db r) 
Compare ExprRelation (UntypedExpr db r) (UntypedExpr db r) 
CondRaw (QueryRaw db r) 
CondEmpty 

Instances

Instances details
(db' ~ db, r' ~ r) => Expression db' r' (Cond db r) Source # 
Instance details

Defined in Database.Groundhog.Expression

Methods

toExpr :: Cond db r -> UntypedExpr db' r' Source #

a ~ Bool => Projection (Cond db r) a Source # 
Instance details

Defined in Database.Groundhog.Instances

Associated Types

type ProjectionDb (Cond db r) db Source #

type ProjectionRestriction (Cond db r) r Source #

Methods

projectionExprs :: (DbDescriptor db0, ProjectionDb (Cond db r) db0, ProjectionRestriction (Cond db r) r0) => Cond db r -> [UntypedExpr db0 r0] -> [UntypedExpr db0 r0] Source #

projectionResult :: PersistBackend m => Cond db r -> [PersistValue] -> m (a, [PersistValue]) Source #

db' ~ db => HasSelectOptions (Cond db r) db' r Source # 
Instance details

Defined in Database.Groundhog.Core

Associated Types

type HasLimit (Cond db r) Source #

type HasOffset (Cond db r) Source #

type HasOrder (Cond db r) Source #

type HasDistinct (Cond db r) Source #

Methods

getSelectOptions :: Cond db r -> SelectOptions db' r (HasLimit (Cond db r)) (HasOffset (Cond db r)) (HasOrder (Cond db r)) (HasDistinct (Cond db r)) Source #

type HasLimit (Cond db r) Source # 
Instance details

Defined in Database.Groundhog.Core

type HasLimit (Cond db r) = HFalse
type HasOffset (Cond db r) Source # 
Instance details

Defined in Database.Groundhog.Core

type HasOffset (Cond db r) = HFalse
type HasOrder (Cond db r) Source # 
Instance details

Defined in Database.Groundhog.Core

type HasOrder (Cond db r) = HFalse
type HasDistinct (Cond db r) Source # 
Instance details

Defined in Database.Groundhog.Core

type HasDistinct (Cond db r) = HFalse
type ProjectionDb (Cond db r) db' Source # 
Instance details

Defined in Database.Groundhog.Instances

type ProjectionDb (Cond db r) db' = db ~ db'
type ProjectionRestriction (Cond db r) r' Source # 
Instance details

Defined in Database.Groundhog.Instances

type ProjectionRestriction (Cond db r) r' = r ~ r'

data ExprRelation Source #

Constructors

Eq 
Ne 
Gt 
Lt 
Ge 
Le 

Instances

Instances details
Show ExprRelation Source # 
Instance details

Defined in Database.Groundhog.Core

data Update db r Source #

Constructors

forall f a.(Assignable f a, Projection' f db r a) => Update f (UntypedExpr db r) 

(~>) :: (EntityConstr v c, FieldLike f a, DbDescriptor db, Projection' f db (RestrictionHolder v c) a, Embedded a) => f -> Selector a a' -> SubField db v c a' infixl 5 Source #

Accesses fields of the embedded datatypes. For example, SomeField ==. ("abc", "def") ||. SomeField ~> Tuple2_0Selector ==. "def"

class Assignable f a => FieldLike f a | f -> a where Source #

This subset of Assignable is for plain database fields.

Methods

fieldChain :: (DbDescriptor db, ProjectionDb f db) => proxy db -> f -> FieldChain Source #

Instances

Instances details
(PersistEntity v, IsUniqueKey k, k ~ Key v (Unique u)) => FieldLike (u (UniqueMarker v)) k Source # 
Instance details

Defined in Database.Groundhog.Instances

Methods

fieldChain :: (DbDescriptor db, ProjectionDb (u (UniqueMarker v)) db) => proxy db -> u (UniqueMarker v) -> FieldChain Source #

(EntityConstr v c, a ~ AutoKey v) => FieldLike (AutoKeyField v c) a Source # 
Instance details

Defined in Database.Groundhog.Instances

Methods

fieldChain :: (DbDescriptor db, ProjectionDb (AutoKeyField v c) db) => proxy db -> AutoKeyField v c -> FieldChain Source #

(EntityConstr v c, PersistField a) => FieldLike (Field v c a) a Source # 
Instance details

Defined in Database.Groundhog.Instances

Methods

fieldChain :: (DbDescriptor db, ProjectionDb (Field v c a) db) => proxy db -> Field v c a -> FieldChain Source #

(EntityConstr v c, PersistField a) => FieldLike (SubField db v c a) a Source # 
Instance details

Defined in Database.Groundhog.Instances

Methods

fieldChain :: (DbDescriptor db0, ProjectionDb (SubField db v c a) db0) => proxy db0 -> SubField db v c a -> FieldChain Source #

class Projection f a => Assignable f a | f -> a Source #

This subset of Projection instances is for things that behave like fields. Namely, they can occur in condition expressions (for example, Field and SubField) and on the left side of update statements. For example "lower(field)" is a valid Projection, but not Field like because it cannot be on the left side. Datatypes that index PostgreSQL arrays "arr[5]" or access composites "(comp).subfield" are valid instances of Assignable.

Instances

Instances details
(PersistEntity v, IsUniqueKey k, k ~ Key v (Unique u)) => Assignable (u (UniqueMarker v)) k Source # 
Instance details

Defined in Database.Groundhog.Instances

(EntityConstr v c, a ~ AutoKey v) => Assignable (AutoKeyField v c) a Source # 
Instance details

Defined in Database.Groundhog.Instances

(EntityConstr v c, PersistField a) => Assignable (Field v c a) a Source # 
Instance details

Defined in Database.Groundhog.Instances

(EntityConstr v c, PersistField a) => Assignable (SubField db v c a) a Source # 
Instance details

Defined in Database.Groundhog.Instances

newtype SubField db v (c :: (Type -> Type) -> Type) a Source #

Constructors

SubField FieldChain 

Instances

Instances details
(EntityConstr v c, DbDescriptor db, PersistField a, db' ~ db, RestrictionHolder v c ~ r') => Expression db' r' (SubField db v c a) Source # 
Instance details

Defined in Database.Groundhog.Expression

Methods

toExpr :: SubField db v c a -> UntypedExpr db' r' Source #

(EntityConstr v c, PersistField a) => FieldLike (SubField db v c a) a Source # 
Instance details

Defined in Database.Groundhog.Instances

Methods

fieldChain :: (DbDescriptor db0, ProjectionDb (SubField db v c a) db0) => proxy db0 -> SubField db v c a -> FieldChain Source #

(EntityConstr v c, PersistField a) => Assignable (SubField db v c a) a Source # 
Instance details

Defined in Database.Groundhog.Instances

(EntityConstr v c, PersistField a) => Projection (SubField db v c a) a Source # 
Instance details

Defined in Database.Groundhog.Instances

Associated Types

type ProjectionDb (SubField db v c a) db Source #

type ProjectionRestriction (SubField db v c a) r Source #

Methods

projectionExprs :: (DbDescriptor db0, ProjectionDb (SubField db v c a) db0, ProjectionRestriction (SubField db v c a) r) => SubField db v c a -> [UntypedExpr db0 r] -> [UntypedExpr db0 r] Source #

projectionResult :: PersistBackend m => SubField db v c a -> [PersistValue] -> m (a, [PersistValue]) Source #

type ProjectionDb (SubField db v c a) db' Source # 
Instance details

Defined in Database.Groundhog.Instances

type ProjectionDb (SubField db v c a) db' = db ~ db'
type ProjectionRestriction (SubField db v c a) r Source # 
Instance details

Defined in Database.Groundhog.Instances

data AutoKeyField v (c :: (Type -> Type) -> Type) where Source #

It can be used in expressions like a regular field. For example, delete (AutoKeyField ==. k) or delete (AutoKeyField ==. k ||. SomeField ==. "DUPLICATE")

Constructors

AutoKeyField :: AutoKeyField v c 

Instances

Instances details
(EntityConstr v c, DbDescriptor db, RestrictionHolder v c ~ r') => Expression db r' (AutoKeyField v c) Source # 
Instance details

Defined in Database.Groundhog.Expression

Methods

toExpr :: AutoKeyField v c -> UntypedExpr db r' Source #

(EntityConstr v c, a ~ AutoKey v) => FieldLike (AutoKeyField v c) a Source # 
Instance details

Defined in Database.Groundhog.Instances

Methods

fieldChain :: (DbDescriptor db, ProjectionDb (AutoKeyField v c) db) => proxy db -> AutoKeyField v c -> FieldChain Source #

(EntityConstr v c, a ~ AutoKey v) => Assignable (AutoKeyField v c) a Source # 
Instance details

Defined in Database.Groundhog.Instances

(EntityConstr v c, a ~ AutoKey v) => Projection (AutoKeyField v c) a Source # 
Instance details

Defined in Database.Groundhog.Instances

Associated Types

type ProjectionDb (AutoKeyField v c) db Source #

type ProjectionRestriction (AutoKeyField v c) r Source #

type ProjectionDb (AutoKeyField v c) db Source # 
Instance details

Defined in Database.Groundhog.Instances

type ProjectionDb (AutoKeyField v c) db = ()
type ProjectionRestriction (AutoKeyField v c) r Source # 
Instance details

Defined in Database.Groundhog.Instances

type FieldChain = ((String, DbType), [(String, EmbeddedDef)]) Source #

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 [("val0", DbString), ("some", DbEmbedded False [dbType "", dbType True])].

class NeverNull a Source #

Types which are never NULL when converted to PersistValue. 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.

Instances

Instances details
NeverNull Bool Source # 
Instance details

Defined in Database.Groundhog.Instances

NeverNull Double Source # 
Instance details

Defined in Database.Groundhog.Instances

NeverNull Int Source # 
Instance details

Defined in Database.Groundhog.Instances

NeverNull Int8 Source # 
Instance details

Defined in Database.Groundhog.Instances

NeverNull Int16 Source # 
Instance details

Defined in Database.Groundhog.Instances

NeverNull Int32 Source # 
Instance details

Defined in Database.Groundhog.Instances

NeverNull Int64 Source # 
Instance details

Defined in Database.Groundhog.Instances

NeverNull Word8 Source # 
Instance details

Defined in Database.Groundhog.Instances

NeverNull Word16 Source # 
Instance details

Defined in Database.Groundhog.Instances

NeverNull Word32 Source # 
Instance details

Defined in Database.Groundhog.Instances

NeverNull Word64 Source # 
Instance details

Defined in Database.Groundhog.Instances

NeverNull String Source # 
Instance details

Defined in Database.Groundhog.Instances

NeverNull ByteString Source # 
Instance details

Defined in Database.Groundhog.Instances

NeverNull ByteString Source # 
Instance details

Defined in Database.Groundhog.Instances

NeverNull UTCTime Source # 
Instance details

Defined in Database.Groundhog.Instances

NeverNull Text Source # 
Instance details

Defined in Database.Groundhog.Instances

NeverNull Value Source # 
Instance details

Defined in Database.Groundhog.Instances

NeverNull Text Source # 
Instance details

Defined in Database.Groundhog.Instances

NeverNull ZonedTime Source # 
Instance details

Defined in Database.Groundhog.Instances

NeverNull TimeOfDay Source # 
Instance details

Defined in Database.Groundhog.Instances

NeverNull Day Source # 
Instance details

Defined in Database.Groundhog.Instances

NeverNull (KeyForBackend db v) Source # 
Instance details

Defined in Database.Groundhog.Instances

PrimitivePersistField (Key v u) => NeverNull (Key v u) Source # 
Instance details

Defined in Database.Groundhog.Instances

data UntypedExpr db r where Source #

Used to uniformly represent fields, constants and more complex things, e.g., arithmetic expressions. A value should be converted to UntypedExpr for usage in expressions

Constructors

ExprRaw :: DbType -> QueryRaw db r -> UntypedExpr db r 
ExprField :: FieldChain -> UntypedExpr db r 
ExprPure :: forall db r a. PurePersistField a => a -> UntypedExpr db r 
ExprCond :: Cond db r -> UntypedExpr db r 

newtype Expr db r a Source #

Expr with phantom type helps to keep type safety in complex expressions

Constructors

Expr (UntypedExpr db r) 

Instances

Instances details
(PersistField a, db' ~ db, r' ~ r) => Expression db' r' (Expr db r a) Source # 
Instance details

Defined in Database.Groundhog.Expression

Methods

toExpr :: Expr db r a -> UntypedExpr db' r' Source #

(SqlDb db, PersistField a, Enum a) => Enum (Expr db r a) Source # 
Instance details

Defined in Database.Groundhog.Generic.Sql.Functions

Methods

succ :: Expr db r a -> Expr db r a #

pred :: Expr db r a -> Expr db r a #

toEnum :: Int -> Expr db r a #

fromEnum :: Expr db r a -> Int #

enumFrom :: Expr db r a -> [Expr db r a] #

enumFromThen :: Expr db r a -> Expr db r a -> [Expr db r a] #

enumFromTo :: Expr db r a -> Expr db r a -> [Expr db r a] #

enumFromThenTo :: Expr db r a -> Expr db r a -> Expr db r a -> [Expr db r a] #

Eq (Expr db r a) Source # 
Instance details

Defined in Database.Groundhog.Core

Methods

(==) :: Expr db r a -> Expr db r a -> Bool #

(/=) :: Expr db r a -> Expr db r a -> Bool #

(FloatingSqlDb db, PersistField a, Floating a) => Floating (Expr db r a) Source # 
Instance details

Defined in Database.Groundhog.Generic.Sql.Functions

Methods

pi :: Expr db r a #

exp :: Expr db r a -> Expr db r a #

log :: Expr db r a -> Expr db r a #

sqrt :: Expr db r a -> Expr db r a #

(**) :: Expr db r a -> Expr db r a -> Expr db r a #

logBase :: Expr db r a -> Expr db r a -> Expr db r a #

sin :: Expr db r a -> Expr db r a #

cos :: Expr db r a -> Expr db r a #

tan :: Expr db r a -> Expr db r a #

asin :: Expr db r a -> Expr db r a #

acos :: Expr db r a -> Expr db r a #

atan :: Expr db r a -> Expr db r a #

sinh :: Expr db r a -> Expr db r a #

cosh :: Expr db r a -> Expr db r a #

tanh :: Expr db r a -> Expr db r a #

asinh :: Expr db r a -> Expr db r a #

acosh :: Expr db r a -> Expr db r a #

atanh :: Expr db r a -> Expr db r a #

log1p :: Expr db r a -> Expr db r a #

expm1 :: Expr db r a -> Expr db r a #

log1pexp :: Expr db r a -> Expr db r a #

log1mexp :: Expr db r a -> Expr db r a #

(SqlDb db, PersistField a, Fractional a) => Fractional (Expr db r a) Source # 
Instance details

Defined in Database.Groundhog.Generic.Sql.Functions

Methods

(/) :: Expr db r a -> Expr db r a -> Expr db r a #

recip :: Expr db r a -> Expr db r a #

fromRational :: Rational -> Expr db r a #

(SqlDb db, PurePersistField a, Integral a) => Integral (Expr db r a) Source # 
Instance details

Defined in Database.Groundhog.Generic.Sql.Functions

Methods

quot :: Expr db r a -> Expr db r a -> Expr db r a #

rem :: Expr db r a -> Expr db r a -> Expr db r a #

div :: Expr db r a -> Expr db r a -> Expr db r a #

mod :: Expr db r a -> Expr db r a -> Expr db r a #

quotRem :: Expr db r a -> Expr db r a -> (Expr db r a, Expr db r a) #

divMod :: Expr db r a -> Expr db r a -> (Expr db r a, Expr db r a) #

toInteger :: Expr db r a -> Integer #

(SqlDb db, PersistField a, Num a) => Num (Expr db r a) Source # 
Instance details

Defined in Database.Groundhog.Generic.Sql.Functions

Methods

(+) :: Expr db r a -> Expr db r a -> Expr db r a #

(-) :: Expr db r a -> Expr db r a -> Expr db r a #

(*) :: Expr db r a -> Expr db r a -> Expr db r a #

negate :: Expr db r a -> Expr db r a #

abs :: Expr db r a -> Expr db r a #

signum :: Expr db r a -> Expr db r a #

fromInteger :: Integer -> Expr db r a #

(SqlDb db, PersistField a, Ord a) => Ord (Expr db r a) Source # 
Instance details

Defined in Database.Groundhog.Generic.Sql.Functions

Methods

compare :: Expr db r a -> Expr db r a -> Ordering #

(<) :: Expr db r a -> Expr db r a -> Bool #

(<=) :: Expr db r a -> Expr db r a -> Bool #

(>) :: Expr db r a -> Expr db r a -> Bool #

(>=) :: Expr db r a -> Expr db r a -> Bool #

max :: Expr db r a -> Expr db r a -> Expr db r a #

min :: Expr db r a -> Expr db r a -> Expr db r a #

(SqlDb db, PersistField a, Real a) => Real (Expr db r a) Source # 
Instance details

Defined in Database.Groundhog.Generic.Sql.Functions

Methods

toRational :: Expr db r a -> Rational #

Show (Expr db r a) Source # 
Instance details

Defined in Database.Groundhog.Core

Methods

showsPrec :: Int -> Expr db r a -> ShowS #

show :: Expr db r a -> String #

showList :: [Expr db r a] -> ShowS #

PersistField a => Projection (Expr db r a) a Source # 
Instance details

Defined in Database.Groundhog.Instances

Associated Types

type ProjectionDb (Expr db r a) db Source #

type ProjectionRestriction (Expr db r a) r Source #

Methods

projectionExprs :: (DbDescriptor db0, ProjectionDb (Expr db r a) db0, ProjectionRestriction (Expr db r a) r0) => Expr db r a -> [UntypedExpr db0 r0] -> [UntypedExpr db0 r0] Source #

projectionResult :: PersistBackend m => Expr db r a -> [PersistValue] -> m (a, [PersistValue]) Source #

type ProjectionDb (Expr db r a) db' Source # 
Instance details

Defined in Database.Groundhog.Instances

type ProjectionDb (Expr db r a) db' = db ~ db'
type ProjectionRestriction (Expr db r a) r' Source # 
Instance details

Defined in Database.Groundhog.Instances

type ProjectionRestriction (Expr db r a) r' = r ~ r'

data Order db r Source #

Defines sort order of a result-set

Constructors

forall a f.Projection' f db r a => Asc f 
forall a f.Projection' f db r a => Desc f 

class HasSelectOptions a db r | a -> db r where Source #

This class helps to check that limit, offset, or order clauses are added to condition only once.

Associated Types

type HasLimit a Source #

type HasOffset a Source #

type HasOrder a Source #

type HasDistinct a Source #

Instances

Instances details
db' ~ db => HasSelectOptions (Cond db r) db' r Source # 
Instance details

Defined in Database.Groundhog.Core

Associated Types

type HasLimit (Cond db r) Source #

type HasOffset (Cond db r) Source #

type HasOrder (Cond db r) Source #

type HasDistinct (Cond db r) Source #

Methods

getSelectOptions :: Cond db r -> SelectOptions db' r (HasLimit (Cond db r)) (HasOffset (Cond db r)) (HasOrder (Cond db r)) (HasDistinct (Cond db r)) Source #

db' ~ db => HasSelectOptions (SelectOptions db r hasLimit hasOffset hasOrder hasDistinct) db' r Source # 
Instance details

Defined in Database.Groundhog.Core

Associated Types

type HasLimit (SelectOptions db r hasLimit hasOffset hasOrder hasDistinct) Source #

type HasOffset (SelectOptions db r hasLimit hasOffset hasOrder hasDistinct) Source #

type HasOrder (SelectOptions db r hasLimit hasOffset hasOrder hasDistinct) Source #

type HasDistinct (SelectOptions db r hasLimit hasOffset hasOrder hasDistinct) Source #

Methods

getSelectOptions :: SelectOptions db r hasLimit hasOffset hasOrder hasDistinct -> SelectOptions db' r (HasLimit (SelectOptions db r hasLimit hasOffset hasOrder hasDistinct)) (HasOffset (SelectOptions db r hasLimit hasOffset hasOrder hasDistinct)) (HasOrder (SelectOptions db r hasLimit hasOffset hasOrder hasDistinct)) (HasDistinct (SelectOptions db r hasLimit hasOffset hasOrder hasDistinct)) Source #

data SelectOptions db r hasLimit hasOffset hasOrder hasDistinct Source #

Constructors

SelectOptions 

Fields

Instances

Instances details
db' ~ db => HasSelectOptions (SelectOptions db r hasLimit hasOffset hasOrder hasDistinct) db' r Source # 
Instance details

Defined in Database.Groundhog.Core

Associated Types

type HasLimit (SelectOptions db r hasLimit hasOffset hasOrder hasDistinct) Source #

type HasOffset (SelectOptions db r hasLimit hasOffset hasOrder hasDistinct) Source #

type HasOrder (SelectOptions db r hasLimit hasOffset hasOrder hasDistinct) Source #

type HasDistinct (SelectOptions db r hasLimit hasOffset hasOrder hasDistinct) Source #

Methods

getSelectOptions :: SelectOptions db r hasLimit hasOffset hasOrder hasDistinct -> SelectOptions db' r (HasLimit (SelectOptions db r hasLimit hasOffset hasOrder hasDistinct)) (HasOffset (SelectOptions db r hasLimit hasOffset hasOrder hasDistinct)) (HasOrder (SelectOptions db r hasLimit hasOffset hasOrder hasDistinct)) (HasDistinct (SelectOptions db r hasLimit hasOffset hasOrder hasDistinct)) Source #

type HasLimit (SelectOptions db r hasLimit hasOffset hasOrder hasDistinct) Source # 
Instance details

Defined in Database.Groundhog.Core

type HasLimit (SelectOptions db r hasLimit hasOffset hasOrder hasDistinct) = hasLimit
type HasOffset (SelectOptions db r hasLimit hasOffset hasOrder hasDistinct) Source # 
Instance details

Defined in Database.Groundhog.Core

type HasOffset (SelectOptions db r hasLimit hasOffset hasOrder hasDistinct) = hasOffset
type HasOrder (SelectOptions db r hasLimit hasOffset hasOrder hasDistinct) Source # 
Instance details

Defined in Database.Groundhog.Core

type HasOrder (SelectOptions db r hasLimit hasOffset hasOrder hasDistinct) = hasOrder
type HasDistinct (SelectOptions db r hasLimit hasOffset hasOrder hasDistinct) Source # 
Instance details

Defined in Database.Groundhog.Core

type HasDistinct (SelectOptions db r hasLimit hasOffset hasOrder hasDistinct) = hasDistinct

distinct :: (HasSelectOptions a db r, HasDistinct a ~ HFalse) => a -> SelectOptions db r (HasLimit a) (HasOffset a) (HasOrder a) HTrue Source #

Select DISTINCT rows. select $ distinct CondEmpty

Type description

These types describe the mapping between database schema and datatype. They hold table names, columns, constraints, etc. Some types below are parameterized by string type str and dbType. This is done to make them promotable to kind level.

data DbTypePrimitive' str Source #

A DB data type. Naming attempts to reflect the underlying Haskell datatypes, eg DbString instead of DbVarchar. Different databases may have different representations for these types.

Instances

Instances details
Eq str => Eq (DbTypePrimitive' str) Source # 
Instance details

Defined in Database.Groundhog.Core

Show str => Show (DbTypePrimitive' str) Source # 
Instance details

Defined in Database.Groundhog.Core

data DbType Source #

Constructors

DbTypePrimitive DbTypePrimitive Bool (Maybe String) (Maybe ParentTableReference)

type, nullable, default value, reference

DbEmbedded EmbeddedDef (Maybe ParentTableReference) 
DbList String DbType

List table name and type of its argument

Instances

Instances details
Eq DbType Source # 
Instance details

Defined in Database.Groundhog.Core

Methods

(==) :: DbType -> DbType -> Bool #

(/=) :: DbType -> DbType -> Bool #

Show DbType Source # 
Instance details

Defined in Database.Groundhog.Core

data EntityDef' str dbType Source #

Describes an ADT.

Constructors

EntityDef 

Fields

  • entityName :: str

    Entity name. entityName (entityDef v) == persistName v

  • entitySchema :: Maybe str

    Database schema for the entity table and tables of its constructors

  • typeParams :: [dbType]

    Named types of the instantiated polymorphic type parameters

  • constructors :: [ConstructorDef' str dbType]

    List of entity constructors definitions

Instances

Instances details
(Eq str, Eq dbType) => Eq (EntityDef' str dbType) Source # 
Instance details

Defined in Database.Groundhog.Core

Methods

(==) :: EntityDef' str dbType -> EntityDef' str dbType -> Bool #

(/=) :: EntityDef' str dbType -> EntityDef' str dbType -> Bool #

(Show str, Show dbType) => Show (EntityDef' str dbType) Source # 
Instance details

Defined in Database.Groundhog.Core

Methods

showsPrec :: Int -> EntityDef' str dbType -> ShowS #

show :: EntityDef' str dbType -> String #

showList :: [EntityDef' str dbType] -> ShowS #

data EmbeddedDef' str dbType 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.

Constructors

EmbeddedDef Bool [(str, dbType)] 

Instances

Instances details
(Eq str, Eq dbType) => Eq (EmbeddedDef' str dbType) Source # 
Instance details

Defined in Database.Groundhog.Core

Methods

(==) :: EmbeddedDef' str dbType -> EmbeddedDef' str dbType -> Bool #

(/=) :: EmbeddedDef' str dbType -> EmbeddedDef' str dbType -> Bool #

(Show str, Show dbType) => Show (EmbeddedDef' str dbType) Source # 
Instance details

Defined in Database.Groundhog.Core

Methods

showsPrec :: Int -> EmbeddedDef' str dbType -> ShowS #

show :: EmbeddedDef' str dbType -> String #

showList :: [EmbeddedDef' str dbType] -> ShowS #

newtype OtherTypeDef' str Source #

Stores a database type. The list contains two kinds of tokens for the type string. Backend will choose a string representation for DbTypePrimitive's, and the string literals will go to the type as-is. As the final step, these tokens are concatenated. For example, [Left "varchar(50)"] will become a string with max length and [Right DbInt64, Left "[]"] will become integer[] in PostgreSQL.

Constructors

OtherTypeDef [Either str (DbTypePrimitive' str)] 

Instances

Instances details
Eq str => Eq (OtherTypeDef' str) Source # 
Instance details

Defined in Database.Groundhog.Core

Methods

(==) :: OtherTypeDef' str -> OtherTypeDef' str -> Bool #

(/=) :: OtherTypeDef' str -> OtherTypeDef' str -> Bool #

Show str => Show (OtherTypeDef' str) Source # 
Instance details

Defined in Database.Groundhog.Core

data ConstructorDef' str dbType Source #

Describes an entity constructor

Constructors

ConstructorDef 

Fields

Instances

Instances details
(Eq str, Eq dbType) => Eq (ConstructorDef' str dbType) Source # 
Instance details

Defined in Database.Groundhog.Core

Methods

(==) :: ConstructorDef' str dbType -> ConstructorDef' str dbType -> Bool #

(/=) :: ConstructorDef' str dbType -> ConstructorDef' str dbType -> Bool #

(Show str, Show dbType) => Show (ConstructorDef' str dbType) Source # 
Instance details

Defined in Database.Groundhog.Core

Methods

showsPrec :: Int -> ConstructorDef' str dbType -> ShowS #

show :: ConstructorDef' str dbType -> String #

showList :: [ConstructorDef' str dbType] -> ShowS #

class Constructor c where Source #

Phantom constructors are made instances of this class. This class should be used only by Template Haskell codegen

Methods

phantomConstrNum :: c (a :: Type -> Type) -> Int Source #

Returns constructor index which can be used to get ConstructorDef from EntityDef

class PersistEntity v => EntityConstr v c where Source #

This class helps type inference in cases when query does not contain any fields which define the constructor, but the entity has only one. For example, in select $ AutoKeyField ==. k the condition would need type annotation with constructor name only if we select a sum type.

Methods

entityConstrNum :: proxy v -> c (a :: Type -> Type) -> Int Source #

Instances

Instances details
(PersistEntity v, EntityConstr' (IsSumType v) c) => EntityConstr v c Source # 
Instance details

Defined in Database.Groundhog.Instances

Methods

entityConstrNum :: forall proxy (a :: Type -> Type). proxy v -> c a -> Int Source #

class PurePersistField uKey => IsUniqueKey uKey where Source #

Methods

extractUnique :: uKey ~ Key v u => v -> uKey Source #

Creates value of unique key using the data extracted from the passed value

uniqueNum :: uKey -> Int Source #

Ordinal number of the unique constraint in the list returned by constrUniques

data UniqueDef' str field Source #

Unique name and list of the fields that form a unique combination. The fields are parametrized to reuse this datatype both with field and DbType and with column name

Constructors

UniqueDef 

Instances

Instances details
(Eq str, Eq field) => Eq (UniqueDef' str field) Source # 
Instance details

Defined in Database.Groundhog.Core

Methods

(==) :: UniqueDef' str field -> UniqueDef' str field -> Bool #

(/=) :: UniqueDef' str field -> UniqueDef' str field -> Bool #

(Show str, Show field) => Show (UniqueDef' str field) Source # 
Instance details

Defined in Database.Groundhog.Core

Methods

showsPrec :: Int -> UniqueDef' str field -> ShowS #

show :: UniqueDef' str field -> String #

showList :: [UniqueDef' str field] -> ShowS #

type UniqueDef = UniqueDef' String (Either (String, DbType) String) Source #

Field is either a pair of entity field name and its type or an expression which will be used in query as-is.

data UniqueType Source #

Defines how to treat the unique set of fields for a datatype

Constructors

UniqueConstraint 
UniqueIndex 
UniquePrimary Bool

is autoincremented

type ParentTableReference = (Either (EntityDef, Maybe String) ((Maybe String, String), [String]), Maybe ReferenceActionType, Maybe ReferenceActionType) Source #

The reference contains either EntityDef of the parent table and name of the unique constraint. Or for tables not mapped by Groundhog schema name, table name, and list of columns Reference to the autogenerated key of a mapped entity = (Left (entityDef, Nothing), onDelete, onUpdate) Reference to a unique key of a mapped entity = (Left (entityDef, Just uniqueKeyName), onDelete, onUpdate) Reference to a table that is not mapped = (Right ((schema, tableName), columns), onDelete, onUpdate)

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 SingleMigration Source #

Datatype names and corresponding migrations

Database

class (Monad m, MonadIO m, MonadFail m, ConnectionManager (Conn m), PersistBackendConn (Conn m)) => PersistBackend m where Source #

This class helps to shorten the type signatures of user monadic code. If your monad has several connections, e.g., for main and audit databases, create run*Db function runAuditDb :: Action conn a -> m a

Associated Types

type Conn m Source #

Methods

getConnection :: m (Conn m) Source #

Instances

Instances details
(Monad m, MonadIO m, MonadFail m, PersistBackendConn conn) => PersistBackend (ReaderT conn m) Source # 
Instance details

Defined in Database.Groundhog.Core

Associated Types

type Conn (ReaderT conn m) Source #

Methods

getConnection :: ReaderT conn m (Conn (ReaderT conn m)) Source #

class (DbDescriptor conn, ConnectionManager conn) => PersistBackendConn conn where Source #

Methods

insert :: (PersistEntity v, PersistBackend m, Conn m ~ conn) => v -> m (AutoKey v) Source #

Insert a new record to a database and return its autogenerated key or ()

insert_ :: (PersistEntity v, PersistBackend m, Conn m ~ conn) => v -> m () Source #

Insert a new record to a database. For some backends it may be faster than insert.

insertBy :: (PersistEntity v, IsUniqueKey (Key v (Unique u)), PersistBackend m, Conn m ~ conn) => 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, PersistBackend m, Conn m ~ conn) => 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), PersistBackend m, Conn m ~ conn) => Key v BackendSpecific -> v -> m () Source #

Replace a record with the given autogenerated key. Result is undefined if the record does not exist.

replaceBy :: (PersistEntity v, IsUniqueKey (Key v (Unique u)), PersistBackend m, Conn m ~ conn) => u (UniqueMarker v) -> v -> m () Source #

Replace a record. The unique key marker defines what unique key of the entity is used.

select :: (PersistEntity v, EntityConstr v c, HasSelectOptions opts conn (RestrictionHolder v c), PersistBackend m, Conn m ~ conn) => opts -> m [v] Source #

Return a list of the records satisfying the condition. Example: select $ (FirstField ==. "abc" &&. SecondField >. "def") `orderBy` [Asc ThirdField] `limitTo` 100

selectStream :: (PersistEntity v, EntityConstr v c, HasSelectOptions opts conn (RestrictionHolder v c), PersistBackend m, Conn m ~ conn) => opts -> m (RowStream v) Source #

Return a list of the records satisfying the condition. Example: select $ (FirstField ==. "abc" &&. SecondField >. "def") `orderBy` [Asc ThirdField] `limitTo` 100

selectAll :: (PersistEntity v, PersistBackend m, Conn m ~ conn) => m [(AutoKey v, v)] Source #

Return a list of all records. Order is undefined. It can be useful for datatypes with multiple constructors.

selectAllStream :: (PersistEntity v, PersistBackend m, Conn m ~ conn) => m (RowStream (AutoKey v, v)) Source #

Return a list of all records. Order is undefined. It can be useful for datatypes with multiple constructors.

get :: (PersistEntity v, PrimitivePersistField (Key v BackendSpecific), PersistBackend m, Conn m ~ conn) => Key v BackendSpecific -> m (Maybe v) Source #

Fetch an entity from a database

getBy :: (PersistEntity v, IsUniqueKey (Key v (Unique u)), PersistBackend m, Conn m ~ conn) => Key v (Unique u) -> m (Maybe v) Source #

Fetch an entity from a database by its unique key

update :: (PersistEntity v, EntityConstr v c, PersistBackend m, Conn m ~ conn) => [Update conn (RestrictionHolder v c)] -> Cond conn (RestrictionHolder v c) -> m () Source #

Update the records satisfying the condition. Example: update [FirstField =. "abc"] $ FirstField ==. "def"

delete :: (PersistEntity v, EntityConstr v c, PersistBackend m, Conn m ~ conn) => Cond conn (RestrictionHolder v c) -> m () Source #

Remove the records satisfying the condition

deleteBy :: (PersistEntity v, PrimitivePersistField (Key v BackendSpecific), PersistBackend m, Conn m ~ conn) => Key v BackendSpecific -> m () Source #

Remove the record with given key. No-op if the record does not exist

deleteAll :: (PersistEntity v, PersistBackend m, Conn m ~ conn) => v -> m () Source #

Remove all records. The entity parameter is used only for type inference.

count :: (PersistEntity v, EntityConstr v c, PersistBackend m, Conn m ~ conn) => Cond conn (RestrictionHolder v c) -> m Int Source #

Count total number of records satisfying the condition

countAll :: (PersistEntity v, PersistBackend m, Conn m ~ conn) => v -> m Int Source #

Count total number of records with all constructors. The entity parameter is used only for type inference

project :: (PersistEntity v, EntityConstr v c, Projection' p conn (RestrictionHolder v c) a, HasSelectOptions opts conn (RestrictionHolder v c), PersistBackend m, Conn m ~ conn) => p -> opts -> m [a] Source #

Fetch projection of some fields. Example: project (SecondField, ThirdField) $ (FirstField ==. "abc" &&. SecondField >. "def") `orderBy` [Asc ThirdField] `offsetBy` 100

projectStream :: (PersistEntity v, EntityConstr v c, Projection' p conn (RestrictionHolder v c) a, HasSelectOptions opts conn (RestrictionHolder v c), PersistBackend m, Conn m ~ conn) => p -> opts -> m (RowStream a) Source #

migrate :: (PersistEntity v, PersistBackend m, Conn m ~ conn) => v -> Migration m Source #

Check database schema and create migrations for the entity and the entities it contains

executeRaw Source #

Arguments

:: (PersistBackend m, Conn m ~ conn) 
=> Bool

keep in cache

-> String

query

-> [PersistValue]

positional parameters

-> m () 

Execute raw query

queryRaw Source #

Arguments

:: (PersistBackend m, Conn m ~ conn) 
=> Bool

keep in cache

-> String

query

-> [PersistValue]

positional parameters

-> m (RowStream [PersistValue]) 

Execute raw query with results

insertList :: (PersistField a, PersistBackend m, Conn m ~ conn) => [a] -> m Int64 Source #

getList :: (PersistField a, PersistBackend m, Conn m ~ conn) => Int64 -> m [a] Source #

type Action conn = ReaderT conn IO Source #

type TryAction e m conn = ReaderT conn (ExceptT e m) Source #

type RowStream a = Acquire (IO (Maybe a)) Source #

class PrimitivePersistField (AutoKeyType db) => DbDescriptor db where Source #

Associated Types

type AutoKeyType db Source #

Type of the database default auto-incremented key. For example, Sqlite has Int64

type QueryRaw db :: Type -> Type Source #

Value of this type can be used as a part of a query. For example, it can be RenderS for relational databases, or BSON for MongoDB.

Methods

backendName :: proxy db -> String Source #

Name of backend

Connections and transactions

class ExtractConnection cm conn | cm -> conn where Source #

Methods

extractConn :: (MonadBaseControl IO m, MonadIO m) => (conn -> m a) -> cm -> m a Source #

Extracts the connection. The connection manager can be a pool or the connection itself

class ConnectionManager conn where Source #

Connection manager provides connection to the passed function handles transations. Manager can be a connection itself, a pool, Snaplet in Snap, foundation datatype in Yesod, etc.

Methods

withConn :: (MonadBaseControl IO m, MonadIO m) => (conn -> m a) -> conn -> m a Source #

Opens the transaction.

class TryConnectionManager conn where Source #

Methods

tryWithConn :: (MonadBaseControl IO m, MonadIO m, MonadCatch m) => (conn -> n a) -> (n a -> m (Either SomeException a)) -> conn -> m (Either SomeException a) Source #

Tries the transaction, using a provided function which evaluates to an Either. Any Left result will cause transaction rollback.

class Savepoint conn where Source #

Methods

withConnSavepoint :: (MonadBaseControl IO m, MonadIO m) => String -> m a -> conn -> m a Source #

Wraps the passed action into a named savepoint

withSavepoint :: (PersistBackend m, MonadBaseControl IO m, MonadIO m, Savepoint (Conn m)) => String -> m a -> m a Source #

It helps to run withConnSavepoint within a monad. Make sure that transaction is open

runDb :: PersistBackend m => Action (Conn m) a -> m a Source #

It helps to run database operations within an application monad.

runDbConn :: (MonadIO m, MonadBaseControl IO m, ConnectionManager conn, ExtractConnection cm conn) => Action conn a -> cm -> m a Source #

Runs action within connection. It can handle a simple connection, a pool of them, etc.

runTryDbConn :: (MonadIO m, MonadBaseControl IO m, MonadCatch m, TryConnectionManager conn, ExtractConnection cm conn, Exception e) => TryAction e m conn a -> cm -> m (Either SomeException a) Source #

Runs TryAction within connection.

runTryDbConn' :: (MonadIO m, MonadBaseControl IO m, MonadCatch m, TryConnectionManager conn, ExtractConnection cm conn) => Action conn a -> cm -> m (Either SomeException a) Source #

Tries Action within connection.

runDb' :: PersistBackend m => Action (Conn m) a -> m a Source #

It helps to run database operations within an application monad. Unlike runDb it does not wrap action in transaction

runDbConn' :: (MonadIO m, MonadBaseControl IO m, ConnectionManager conn, ExtractConnection cm conn) => Action conn a -> cm -> m a Source #

It is similar to runDbConn but runs action without transaction.

flip withConn conn $ \conn -> liftIO $ do
  -- transaction is already opened by withConn at this point
  someIOAction
  runDbConn' (insert_ value) conn