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

Safe Haskell | None
Language | Haskell98

Database.Persist.Types

Synopsis

- data Checkmark
  - = Active
  - | Inactive
- data IsNullable
  - = Nullable !WhyNullable
  - | NotNullable
- data WhyNullable
  - = ByMaybeAttr
  - | ByNullableAttr
- data EntityDef = EntityDef {
  - entityHaskell :: !HaskellName
  - entityDB :: !DBName
  - entityId :: !FieldDef
  - entityAttrs :: ![Attr]
  - entityFields :: ![FieldDef]
  - entityUniques :: ![UniqueDef]
  - entityForeigns :: ![ForeignDef]
  - entityDerives :: ![Text]
  - entityExtra :: !(Map Text [ExtraLine])
  - entitySum :: !Bool
  }
- entityPrimary :: EntityDef -> Maybe CompositeDef
- entityKeyFields :: EntityDef -> [FieldDef]
- keyAndEntityFields :: EntityDef -> [FieldDef]
- type ExtraLine = [Text]
- newtype HaskellName = HaskellName {
  - unHaskellName :: Text
  }
- newtype DBName = DBName {
  - unDBName :: Text
  }
- type Attr = Text
- data FieldType
  - = FTTypeCon (Maybe Text) Text
  - | FTApp FieldType FieldType
  - | FTList FieldType
- data FieldDef = FieldDef {
  - fieldHaskell :: !HaskellName
  - fieldDB :: !DBName
  - fieldType :: !FieldType
  - fieldSqlType :: !SqlType
  - fieldAttrs :: ![Attr]
  - fieldStrict :: !Bool
  - fieldReference :: !ReferenceDef
  }
- data ReferenceDef
  - = NoReference
  - | ForeignRef !HaskellName !FieldType
  - | EmbedRef EmbedEntityDef
  - | CompositeRef CompositeDef
  - | SelfReference
- data EmbedEntityDef = EmbedEntityDef {
  - embeddedHaskell :: !HaskellName
  - embeddedFields :: ![EmbedFieldDef]
  }
- data EmbedFieldDef = EmbedFieldDef {
  - emFieldDB :: !DBName
  - emFieldEmbed :: Maybe EmbedEntityDef
  - emFieldCycle :: Maybe HaskellName
  }
- toEmbedEntityDef :: EntityDef -> EmbedEntityDef
- data UniqueDef = UniqueDef {
  - uniqueHaskell :: !HaskellName
  - uniqueDBName :: !DBName
  - uniqueFields :: ![(HaskellName, DBName)]
  - uniqueAttrs :: ![Attr]
  }
- data CompositeDef = CompositeDef {
  - compositeFields :: ![FieldDef]
  - compositeAttrs :: ![Attr]
  }
- type ForeignFieldDef = (HaskellName, DBName)
- data ForeignDef = ForeignDef {
  - foreignRefTableHaskell :: !HaskellName
  - foreignRefTableDBName :: !DBName
  - foreignConstraintNameHaskell :: !HaskellName
  - foreignConstraintNameDBName :: !DBName
  - foreignFields :: ![(ForeignFieldDef, ForeignFieldDef)]
  - foreignAttrs :: ![Attr]
  - foreignNullable :: Bool
  }
- data PersistException
  - = PersistError Text
  - | PersistMarshalError Text
  - | PersistInvalidField Text
  - | PersistForeignConstraintUnmet Text
  - | PersistMongoDBError Text
  - | PersistMongoDBUnsupported Text
- data PersistValue
  - = PersistText Text
  - | PersistByteString ByteString
  - | PersistInt64 Int64
  - | PersistDouble Double
  - | PersistRational Rational
  - | PersistBool Bool
  - | PersistDay Day
  - | PersistTimeOfDay TimeOfDay
  - | PersistUTCTime UTCTime
  - | PersistNull
  - | PersistList [PersistValue]
  - | PersistMap [(Text, PersistValue)]
  - | PersistObjectId ByteString
  - | PersistDbSpecific ByteString
- fromPersistValueText :: PersistValue -> Either Text Text
- data SqlType
  - = SqlString
  - | SqlInt32
  - | SqlInt64
  - | SqlReal
  - | SqlNumeric Word32 Word32
  - | SqlBool
  - | SqlDay
  - | SqlTime
  - | SqlDayTime
  - | SqlBlob
  - | SqlOther Text
- data PersistFilter
  - = Eq
  - | Ne
  - | Gt
  - | Lt
  - | Ge
  - | Le
  - | In
  - | NotIn
  - | BackendSpecificFilter Text
- data UpdateException
  - = KeyNotFound String
  - | UpsertError String
- data OnlyUniqueException = OnlyUniqueException String
- data PersistUpdate
  - = Assign
  - | Add
  - | Subtract
  - | Multiply
  - | Divide
  - | BackendSpecificUpdate Text
- data SomePersistField = PersistField a => SomePersistField a
- data Update record
  - = PersistField typ => Update {
    - updateField :: EntityField record typ
    - updateValue :: typ
    - updateUpdate :: PersistUpdate
    }
  - | BackendUpdate (BackendSpecificUpdate (PersistEntityBackend record) record)
- type family BackendSpecificUpdate backend record
- data SelectOpt record
  - = Asc (EntityField record typ)
  - | Desc (EntityField record typ)
  - | OffsetBy Int
  - | LimitTo Int
- data Filter record
  - = PersistField typ => Filter {
    - filterField :: EntityField record typ
    - filterValue :: Either typ [typ]
    - filterFilter :: PersistFilter
    }
  - | FilterAnd [Filter record]
  - | FilterOr [Filter record]
  - | BackendFilter (BackendSpecificFilter (PersistEntityBackend record) record)
- type family BackendSpecificFilter backend record
- data Entity record = PersistEntity record => Entity {
  - entityKey :: Key record
  - entityVal :: record
  }

# Documentation

data Checkmark #

A `Checkmark` should be used as a field type whenever a uniqueness constraint should guarantee that a certain kind of record may appear at most once, but other kinds of records may appear any number of times.

NOTE: You need to mark any `Checkmark` fields as `nullable` (see the following example).

For example, suppose there's a `Location` entity that represents where a user has lived:

    Location
        user    UserId
        name    Text
        current Checkmark nullable

        UniqueLocation user current

The `UniqueLocation` constraint allows any number of `Inactive` `Location`s to be `current`. However, there may be at most one `current` `Location` per user (i.e., either zero or one per user).

This data type works because of the way that SQL treats `NULL`able fields within uniqueness constraints. The SQL standard says that `NULL` values should be considered different, so we represent `Inactive` as SQL `NULL`, thus allowing any number of `Inactive` records. On the other hand, we represent `Active` as `TRUE`, so the uniqueness constraint will disallow more than one `Active` record.

Note: There may be DBMSs that do not respect the SQL standard's treatment of `NULL` values on uniqueness constraints, please check if this data type works before relying on it.

The SQL `BOOLEAN` type is used because it's the smallest data type available. Note that we never use `FALSE`, just `TRUE` and `NULL`. Provides the same behavior `Maybe ()` would if `()` was a valid `PersistField`.

Constructors

Active | When used on a uniqueness constraint, there may be at most one `Active` record.
Inactive | When used on a uniqueness constraint, there may be any number of `Inactive` records.

Instances

Bounded Checkmark # |
Methods minBound :: Checkmark # maxBound :: Checkmark #
Enum Checkmark # |
Methods succ :: Checkmark -> Checkmark # pred :: Checkmark -> Checkmark # toEnum :: Int -> Checkmark # fromEnum :: Checkmark -> Int # enumFrom :: Checkmark -> [Checkmark] # enumFromThen :: Checkmark -> Checkmark -> [Checkmark] # enumFromTo :: Checkmark -> Checkmark -> [Checkmark] # enumFromThenTo :: Checkmark -> Checkmark -> Checkmark -> [Checkmark] #
Eq Checkmark # |
Methods (==) :: Checkmark -> Checkmark -> Bool # (/=) :: Checkmark -> Checkmark -> Bool #
Ord Checkmark # |
Methods compare :: Checkmark -> Checkmark -> Ordering # (<) :: Checkmark -> Checkmark -> Bool # (<=) :: Checkmark -> Checkmark -> Bool # (>) :: Checkmark -> Checkmark -> Bool # (>=) :: Checkmark -> Checkmark -> Bool # max :: Checkmark -> Checkmark -> Checkmark # min :: Checkmark -> Checkmark -> Checkmark #
Read Checkmark # |
Methods readsPrec :: Int -> ReadS Checkmark # readList :: ReadS [Checkmark] # readPrec :: ReadPrec Checkmark # readListPrec :: ReadPrec [Checkmark] #
Show Checkmark # |
Methods showsPrec :: Int -> Checkmark -> ShowS # show :: Checkmark -> String # showList :: [Checkmark] -> ShowS #
ToHttpApiData Checkmark # |
Methods toUrlPiece :: Checkmark -> Text # toEncodedUrlPiece :: Checkmark -> Builder # toHeader :: Checkmark -> ByteString # toQueryParam :: Checkmark -> Text #
FromHttpApiData Checkmark # |
Methods parseUrlPiece :: Text -> Either Text Checkmark # parseHeader :: ByteString -> Either Text Checkmark # parseQueryParam :: Text -> Either Text Checkmark #
PathPiece Checkmark # |
Methods fromPathPiece :: Text -> Maybe Checkmark # toPathPiece :: Checkmark -> Text #
PersistField Checkmark # |
Methods toPersistValue :: Checkmark -> PersistValue # fromPersistValue :: PersistValue -> Either Text Checkmark #
PersistFieldSql Checkmark # |
Methods sqlType :: Proxy * Checkmark -> SqlType #

data IsNullable #

Constructors

Nullable !WhyNullable |
NotNullable |

Instances

Eq IsNullable # |
Methods (==) :: IsNullable -> IsNullable -> Bool # (/=) :: IsNullable -> IsNullable -> Bool #
Show IsNullable # |
Methods showsPrec :: Int -> IsNullable -> ShowS # show :: IsNullable -> String # showList :: [IsNullable] -> ShowS #

data WhyNullable #

The reason why a field is `nullable` is very important. A field that is nullable because of a `Maybe` tag will have its type changed from `A` to `Maybe A`. OTOH, a field that is nullable because of a `nullable` tag will remain with the same type.

Constructors

ByMaybeAttr |
ByNullableAttr |

Instances

Eq WhyNullable # |
Methods (==) :: WhyNullable -> WhyNullable -> Bool # (/=) :: WhyNullable -> WhyNullable -> Bool #
Show WhyNullable # |
Methods showsPrec :: Int -> WhyNullable -> ShowS # show :: WhyNullable -> String # showList :: [WhyNullable] -> ShowS #

data EntityDef #

Constructors

EntityDef |
Fields entityHaskell :: !HaskellName entityDB :: !DBName entityId :: !FieldDef entityAttrs :: ![Attr] entityFields :: ![FieldDef] entityUniques :: ![UniqueDef] entityForeigns :: ![ForeignDef] entityDerives :: ![Text] entityExtra :: !(Map Text [ExtraLine]) entitySum :: !Bool

Instances

Eq EntityDef # |
Methods (==) :: EntityDef -> EntityDef -> Bool # (/=) :: EntityDef -> EntityDef -> Bool #
Ord EntityDef # |
Methods compare :: EntityDef -> EntityDef -> Ordering # (<) :: EntityDef -> EntityDef -> Bool # (<=) :: EntityDef -> EntityDef -> Bool # (>) :: EntityDef -> EntityDef -> Bool # (>=) :: EntityDef -> EntityDef -> Bool # max :: EntityDef -> EntityDef -> EntityDef # min :: EntityDef -> EntityDef -> EntityDef #
Read EntityDef # |
Methods readsPrec :: Int -> ReadS EntityDef # readList :: ReadS [EntityDef] # readPrec :: ReadPrec EntityDef # readListPrec :: ReadPrec [EntityDef] #
Show EntityDef # |
Methods showsPrec :: Int -> EntityDef -> ShowS # show :: EntityDef -> String # showList :: [EntityDef] -> ShowS #

entityPrimary :: EntityDef -> Maybe CompositeDef #

entityKeyFields :: EntityDef -> [FieldDef] #

keyAndEntityFields :: EntityDef -> [FieldDef] #

type ExtraLine = [Text] #

newtype HaskellName #

Constructors

HaskellName |
Fields unHaskellName :: Text

Instances

Eq HaskellName # |
Methods (==) :: HaskellName -> HaskellName -> Bool # (/=) :: HaskellName -> HaskellName -> Bool #
Ord HaskellName # |
Methods compare :: HaskellName -> HaskellName -> Ordering # (<) :: HaskellName -> HaskellName -> Bool # (<=) :: HaskellName -> HaskellName -> Bool # (>) :: HaskellName -> HaskellName -> Bool # (>=) :: HaskellName -> HaskellName -> Bool # max :: HaskellName -> HaskellName -> HaskellName # min :: HaskellName -> HaskellName -> HaskellName #
Read HaskellName # |
Methods readsPrec :: Int -> ReadS HaskellName # readList :: ReadS [HaskellName] # readPrec :: ReadPrec HaskellName # readListPrec :: ReadPrec [HaskellName] #
Show HaskellName # |
Methods showsPrec :: Int -> HaskellName -> ShowS # show :: HaskellName -> String # showList :: [HaskellName] -> ShowS #

newtype DBName #

Constructors

DBName |
Fields unDBName :: Text

Instances

Eq DBName # |
Methods (==) :: DBName -> DBName -> Bool # (/=) :: DBName -> DBName -> Bool #
Ord DBName # |
Methods compare :: DBName -> DBName -> Ordering # (<) :: DBName -> DBName -> Bool # (<=) :: DBName -> DBName -> Bool # (>) :: DBName -> DBName -> Bool # (>=) :: DBName -> DBName -> Bool # max :: DBName -> DBName -> DBName # min :: DBName -> DBName -> DBName #
Read DBName # |
Methods readsPrec :: Int -> ReadS DBName # readList :: ReadS [DBName] # readPrec :: ReadPrec DBName # readListPrec :: ReadPrec [DBName] #
Show DBName # |
Methods showsPrec :: Int -> DBName -> ShowS # show :: DBName -> String # showList :: [DBName] -> ShowS #

type Attr = Text #

data FieldType #

Constructors

FTTypeCon (Maybe Text) Text | Optional module and name.
FTApp FieldType FieldType |
FTList FieldType |

Instances

Eq FieldType # |
Methods (==) :: FieldType -> FieldType -> Bool # (/=) :: FieldType -> FieldType -> Bool #
Ord FieldType # |
Methods compare :: FieldType -> FieldType -> Ordering # (<) :: FieldType -> FieldType -> Bool # (<=) :: FieldType -> FieldType -> Bool # (>) :: FieldType -> FieldType -> Bool # (>=) :: FieldType -> FieldType -> Bool # max :: FieldType -> FieldType -> FieldType # min :: FieldType -> FieldType -> FieldType #
Read FieldType # |
Methods readsPrec :: Int -> ReadS FieldType # readList :: ReadS [FieldType] # readPrec :: ReadPrec FieldType # readListPrec :: ReadPrec [FieldType] #
Show FieldType # |
Methods showsPrec :: Int -> FieldType -> ShowS # show :: FieldType -> String # showList :: [FieldType] -> ShowS #

data FieldDef #

Constructors

FieldDef |
Fields fieldHaskell :: !HaskellName name of the field fieldDB :: !DBName fieldType :: !FieldType fieldSqlType :: !SqlType fieldAttrs :: ![Attr] user annotations for a field fieldStrict :: !Bool a strict field in the data type. Default: true fieldReference :: !ReferenceDef

Instances

Eq FieldDef # |
Methods (==) :: FieldDef -> FieldDef -> Bool # (/=) :: FieldDef -> FieldDef -> Bool #
Ord FieldDef # |
Methods compare :: FieldDef -> FieldDef -> Ordering # (<) :: FieldDef -> FieldDef -> Bool # (<=) :: FieldDef -> FieldDef -> Bool # (>) :: FieldDef -> FieldDef -> Bool # (>=) :: FieldDef -> FieldDef -> Bool # max :: FieldDef -> FieldDef -> FieldDef # min :: FieldDef -> FieldDef -> FieldDef #
Read FieldDef # |
Methods readsPrec :: Int -> ReadS FieldDef # readList :: ReadS [FieldDef] # readPrec :: ReadPrec FieldDef # readListPrec :: ReadPrec [FieldDef] #
Show FieldDef # |
Methods showsPrec :: Int -> FieldDef -> ShowS # show :: FieldDef -> String # showList :: [FieldDef] -> ShowS #

data ReferenceDef #

There are 3 kinds of references 1) composite (to fields that exist in the record) 2) single field 3) embedded

Constructors

NoReference |
ForeignRef !HaskellName !FieldType | A ForeignRef has a late binding to the EntityDef it references via HaskellName and has the Haskell type of the foreign key in the form of FieldType
EmbedRef EmbedEntityDef |
CompositeRef CompositeDef |
SelfReference | A SelfReference stops an immediate cycle which causes non-termination at compile-time (issue #311).

Instances

Eq ReferenceDef # |
Methods (==) :: ReferenceDef -> ReferenceDef -> Bool # (/=) :: ReferenceDef -> ReferenceDef -> Bool #
Ord ReferenceDef # |
Methods compare :: ReferenceDef -> ReferenceDef -> Ordering # (<) :: ReferenceDef -> ReferenceDef -> Bool # (<=) :: ReferenceDef -> ReferenceDef -> Bool # (>) :: ReferenceDef -> ReferenceDef -> Bool # (>=) :: ReferenceDef -> ReferenceDef -> Bool # max :: ReferenceDef -> ReferenceDef -> ReferenceDef # min :: ReferenceDef -> ReferenceDef -> ReferenceDef #
Read ReferenceDef # |
Methods readsPrec :: Int -> ReadS ReferenceDef # readList :: ReadS [ReferenceDef] # readPrec :: ReadPrec ReferenceDef # readListPrec :: ReadPrec [ReferenceDef] #
Show ReferenceDef # |
Methods showsPrec :: Int -> ReferenceDef -> ShowS # show :: ReferenceDef -> String # showList :: [ReferenceDef] -> ShowS #

data EmbedEntityDef #

An EmbedEntityDef is the same as an EntityDef But it is only used for fieldReference so it only has data needed for embedding

Constructors

EmbedEntityDef |
Fields embeddedHaskell :: !HaskellName embeddedFields :: ![EmbedFieldDef]

Instances

Eq EmbedEntityDef # |
Methods (==) :: EmbedEntityDef -> EmbedEntityDef -> Bool # (/=) :: EmbedEntityDef -> EmbedEntityDef -> Bool #
Ord EmbedEntityDef # |
Methods compare :: EmbedEntityDef -> EmbedEntityDef -> Ordering # (<) :: EmbedEntityDef -> EmbedEntityDef -> Bool # (<=) :: EmbedEntityDef -> EmbedEntityDef -> Bool # (>) :: EmbedEntityDef -> EmbedEntityDef -> Bool # (>=) :: EmbedEntityDef -> EmbedEntityDef -> Bool # max :: EmbedEntityDef -> EmbedEntityDef -> EmbedEntityDef # min :: EmbedEntityDef -> EmbedEntityDef -> EmbedEntityDef #
Read EmbedEntityDef # |
Methods readsPrec :: Int -> ReadS EmbedEntityDef # readList :: ReadS [EmbedEntityDef] # readPrec :: ReadPrec EmbedEntityDef # readListPrec :: ReadPrec [EmbedEntityDef] #
Show EmbedEntityDef # |
Methods showsPrec :: Int -> EmbedEntityDef -> ShowS # show :: EmbedEntityDef -> String # showList :: [EmbedEntityDef] -> ShowS #

data EmbedFieldDef #

An EmbedFieldDef is the same as a FieldDef But it is only used for embeddedFields so it only has data needed for embedding

Constructors

EmbedFieldDef |
Fields emFieldDB :: !DBName emFieldEmbed :: Maybe EmbedEntityDef emFieldCycle :: Maybe HaskellName `emFieldEmbed` can create a cycle (issue #311) when a cycle is detected, `emFieldEmbed` will be Nothing and `emFieldCycle` will be Just

Instances

Eq EmbedFieldDef # |
Methods (==) :: EmbedFieldDef -> EmbedFieldDef -> Bool # (/=) :: EmbedFieldDef -> EmbedFieldDef -> Bool #
Ord EmbedFieldDef # |
Methods compare :: EmbedFieldDef -> EmbedFieldDef -> Ordering # (<) :: EmbedFieldDef -> EmbedFieldDef -> Bool # (<=) :: EmbedFieldDef -> EmbedFieldDef -> Bool # (>) :: EmbedFieldDef -> EmbedFieldDef -> Bool # (>=) :: EmbedFieldDef -> EmbedFieldDef -> Bool # max :: EmbedFieldDef -> EmbedFieldDef -> EmbedFieldDef # min :: EmbedFieldDef -> EmbedFieldDef -> EmbedFieldDef #
Read EmbedFieldDef # |
Methods readsPrec :: Int -> ReadS EmbedFieldDef # readList :: ReadS [EmbedFieldDef] # readPrec :: ReadPrec EmbedFieldDef # readListPrec :: ReadPrec [EmbedFieldDef] #
Show EmbedFieldDef # |
Methods showsPrec :: Int -> EmbedFieldDef -> ShowS # show :: EmbedFieldDef -> String # showList :: [EmbedFieldDef] -> ShowS #

toEmbedEntityDef :: EntityDef -> EmbedEntityDef #

data UniqueDef #

Constructors

UniqueDef |
Fields uniqueHaskell :: !HaskellName uniqueDBName :: !DBName uniqueFields :: ![(HaskellName, DBName)] uniqueAttrs :: ![Attr]

Instances

Eq UniqueDef # |
Methods (==) :: UniqueDef -> UniqueDef -> Bool # (/=) :: UniqueDef -> UniqueDef -> Bool #
Ord UniqueDef # |
Methods compare :: UniqueDef -> UniqueDef -> Ordering # (<) :: UniqueDef -> UniqueDef -> Bool # (<=) :: UniqueDef -> UniqueDef -> Bool # (>) :: UniqueDef -> UniqueDef -> Bool # (>=) :: UniqueDef -> UniqueDef -> Bool # max :: UniqueDef -> UniqueDef -> UniqueDef # min :: UniqueDef -> UniqueDef -> UniqueDef #
Read UniqueDef # |
Methods readsPrec :: Int -> ReadS UniqueDef # readList :: ReadS [UniqueDef] # readPrec :: ReadPrec UniqueDef # readListPrec :: ReadPrec [UniqueDef] #
Show UniqueDef # |
Methods showsPrec :: Int -> UniqueDef -> ShowS # show :: UniqueDef -> String # showList :: [UniqueDef] -> ShowS #

data CompositeDef #

Constructors

CompositeDef |
Fields compositeFields :: ![FieldDef] compositeAttrs :: ![Attr]

Instances

Eq CompositeDef # |
Methods (==) :: CompositeDef -> CompositeDef -> Bool # (/=) :: CompositeDef -> CompositeDef -> Bool #
Ord CompositeDef # |
Methods compare :: CompositeDef -> CompositeDef -> Ordering # (<) :: CompositeDef -> CompositeDef -> Bool # (<=) :: CompositeDef -> CompositeDef -> Bool # (>) :: CompositeDef -> CompositeDef -> Bool # (>=) :: CompositeDef -> CompositeDef -> Bool # max :: CompositeDef -> CompositeDef -> CompositeDef # min :: CompositeDef -> CompositeDef -> CompositeDef #
Read CompositeDef # |
Methods readsPrec :: Int -> ReadS CompositeDef # readList :: ReadS [CompositeDef] # readPrec :: ReadPrec CompositeDef # readListPrec :: ReadPrec [CompositeDef] #
Show CompositeDef # |
Methods showsPrec :: Int -> CompositeDef -> ShowS # show :: CompositeDef -> String # showList :: [CompositeDef] -> ShowS #

type ForeignFieldDef = (HaskellName, DBName) #

Used instead of FieldDef to generate a smaller amount of code

data ForeignDef #

Constructors

ForeignDef |
Fields foreignRefTableHaskell :: !HaskellName foreignRefTableDBName :: !DBName foreignConstraintNameHaskell :: !HaskellName foreignConstraintNameDBName :: !DBName foreignFields :: ![(ForeignFieldDef, ForeignFieldDef)] foreignAttrs :: ![Attr] foreignNullable :: Bool

Instances

Eq ForeignDef # |
Methods (==) :: ForeignDef -> ForeignDef -> Bool # (/=) :: ForeignDef -> ForeignDef -> Bool #
Ord ForeignDef # |
Methods compare :: ForeignDef -> ForeignDef -> Ordering # (<) :: ForeignDef -> ForeignDef -> Bool # (<=) :: ForeignDef -> ForeignDef -> Bool # (>) :: ForeignDef -> ForeignDef -> Bool # (>=) :: ForeignDef -> ForeignDef -> Bool # max :: ForeignDef -> ForeignDef -> ForeignDef # min :: ForeignDef -> ForeignDef -> ForeignDef #
Read ForeignDef # |
Methods readsPrec :: Int -> ReadS ForeignDef # readList :: ReadS [ForeignDef] # readPrec :: ReadPrec ForeignDef # readListPrec :: ReadPrec [ForeignDef] #
Show ForeignDef # |
Methods showsPrec :: Int -> ForeignDef -> ShowS # show :: ForeignDef -> String # showList :: [ForeignDef] -> ShowS #

data PersistException #

Constructors

PersistError Text | Generic Exception
PersistMarshalError Text |
PersistInvalidField Text |
PersistForeignConstraintUnmet Text |
PersistMongoDBError Text |
PersistMongoDBUnsupported Text |

Instances

Show PersistException # |
Methods showsPrec :: Int -> PersistException -> ShowS # show :: PersistException -> String # showList :: [PersistException] -> ShowS #
Exception PersistException # |
Methods toException :: PersistException -> SomeException # fromException :: SomeException -> Maybe PersistException # displayException :: PersistException -> String #
Error PersistException # |
Methods noMsg :: PersistException # strMsg :: String -> PersistException #

data PersistValue #

A raw value which can be stored in any backend and can be marshalled to and from a `PersistField`.

Constructors

PersistText Text |
PersistByteString ByteString |
PersistInt64 Int64 |
PersistDouble Double |
PersistRational Rational |
PersistBool Bool |
PersistDay Day |
PersistTimeOfDay TimeOfDay |
PersistUTCTime UTCTime |
PersistNull |
PersistList [PersistValue] |
PersistMap [(Text, PersistValue)] |
PersistObjectId ByteString | Intended especially for MongoDB backend
PersistDbSpecific ByteString | Using `PersistDbSpecific` allows you to use types specific to a particular backend For example, below is a simple example of the PostGIS geography type:
    data Geo = Geo ByteString

    instance PersistField Geo where
      toPersistValue (Geo t) = PersistDbSpecific t

      fromPersistValue (PersistDbSpecific t) = Right $ Geo $ Data.ByteString.concat ["'", t, "'"]
      fromPersistValue _ = Left "Geo values must be converted from PersistDbSpecific"

    instance PersistFieldSql Geo where
      sqlType _ = SqlOther "GEOGRAPHY(POINT,4326)"

    toPoint :: Double -> Double -> Geo
    toPoint lat lon = Geo $ Data.ByteString.concat ["'POINT(", ps $ lon, " ", ps $ lat, ")'"]
      where ps = Data.Text.pack . show
If Foo has a geography field, we can then perform insertions like the following:
    insert $ Foo (toPoint 44 44)

Instances

Eq PersistValue # |
Methods (==) :: PersistValue -> PersistValue -> Bool # (/=) :: PersistValue -> PersistValue -> Bool #
Ord PersistValue # |
Methods compare :: PersistValue -> PersistValue -> Ordering # (<) :: PersistValue -> PersistValue -> Bool # (<=) :: PersistValue -> PersistValue -> Bool # (>) :: PersistValue -> PersistValue -> Bool # (>=) :: PersistValue -> PersistValue -> Bool # max :: PersistValue -> PersistValue -> PersistValue # min :: PersistValue -> PersistValue -> PersistValue #
Read PersistValue # |
Methods readsPrec :: Int -> ReadS PersistValue # readList :: ReadS [PersistValue] # readPrec :: ReadPrec PersistValue # readListPrec :: ReadPrec [PersistValue] #
Show PersistValue # |
Methods showsPrec :: Int -> PersistValue -> ShowS # show :: PersistValue -> String # showList :: [PersistValue] -> ShowS #
FromJSON PersistValue # |
Methods parseJSON :: Value -> Parser PersistValue # parseJSONList :: Value -> Parser [PersistValue] #
ToJSON PersistValue # |
Methods toJSON :: PersistValue -> Value # toEncoding :: PersistValue -> Encoding # toJSONList :: [PersistValue] -> Value # toEncodingList :: [PersistValue] -> Encoding #
ToHttpApiData PersistValue # |
Methods toUrlPiece :: PersistValue -> Text # toEncodedUrlPiece :: PersistValue -> Builder # toHeader :: PersistValue -> ByteString # toQueryParam :: PersistValue -> Text #
FromHttpApiData PersistValue # |
Methods parseUrlPiece :: Text -> Either Text PersistValue # parseHeader :: ByteString -> Either Text PersistValue # parseQueryParam :: Text -> Either Text PersistValue #
PathPiece PersistValue # |
Methods fromPathPiece :: Text -> Maybe PersistValue # toPathPiece :: PersistValue -> Text #
PersistField PersistValue # |
Methods toPersistValue :: PersistValue -> PersistValue # fromPersistValue :: PersistValue -> Either Text PersistValue #
PersistFieldSql PersistValue # |
Methods sqlType :: Proxy * PersistValue -> SqlType #

fromPersistValueText :: PersistValue -> Either Text Text #

data SqlType #

A SQL data type. Naming attempts to reflect the underlying Haskell datatypes, eg SqlString instead of SqlVarchar. Different SQL databases may have different translations for these types.

Constructors

SqlString |
SqlInt32 |
SqlInt64 |
SqlReal |
SqlNumeric Word32 Word32 |
SqlBool |
SqlDay |
SqlTime |
SqlDayTime | Always uses UTC timezone
SqlBlob |
SqlOther Text | a backend-specific name

Instances

Eq SqlType # |
Methods (==) :: SqlType -> SqlType -> Bool # (/=) :: SqlType -> SqlType -> Bool #
Ord SqlType # |
Methods compare :: SqlType -> SqlType -> Ordering # (<) :: SqlType -> SqlType -> Bool # (<=) :: SqlType -> SqlType -> Bool # (>) :: SqlType -> SqlType -> Bool # (>=) :: SqlType -> SqlType -> Bool # max :: SqlType -> SqlType -> SqlType # min :: SqlType -> SqlType -> SqlType #
Read SqlType # |
Methods readsPrec :: Int -> ReadS SqlType # readList :: ReadS [SqlType] # readPrec :: ReadPrec SqlType # readListPrec :: ReadPrec [SqlType] #
Show SqlType # |
Methods showsPrec :: Int -> SqlType -> ShowS # show :: SqlType -> String # showList :: [SqlType] -> ShowS #

data PersistFilter #

Constructors

Eq |
Ne |
Gt |
Lt |
Ge |
Le |
In |
NotIn |
BackendSpecificFilter Text |

Instances

Read PersistFilter # |
Methods readsPrec :: Int -> ReadS PersistFilter # readList :: ReadS [PersistFilter] # readPrec :: ReadPrec PersistFilter # readListPrec :: ReadPrec [PersistFilter] #
Show PersistFilter # |
Methods showsPrec :: Int -> PersistFilter -> ShowS # show :: PersistFilter -> String # showList :: [PersistFilter] -> ShowS #

data UpdateException #

Constructors

KeyNotFound String |
UpsertError String |

Instances

Show UpdateException # |
Methods showsPrec :: Int -> UpdateException -> ShowS # show :: UpdateException -> String # showList :: [UpdateException] -> ShowS #
Exception UpdateException # |
Methods toException :: UpdateException -> SomeException # fromException :: SomeException -> Maybe UpdateException # displayException :: UpdateException -> String #

data OnlyUniqueException #

Constructors

OnlyUniqueException String |

Instances

Show OnlyUniqueException # |
Methods showsPrec :: Int -> OnlyUniqueException -> ShowS # show :: OnlyUniqueException -> String # showList :: [OnlyUniqueException] -> ShowS #
Exception OnlyUniqueException # |
Methods toException :: OnlyUniqueException -> SomeException # fromException :: SomeException -> Maybe OnlyUniqueException # displayException :: OnlyUniqueException -> String #

data PersistUpdate #

Constructors

Assign |
Add |
Subtract |
Multiply |
Divide |
BackendSpecificUpdate Text |

Instances

Read PersistUpdate # |
Methods readsPrec :: Int -> ReadS PersistUpdate # readList :: ReadS [PersistUpdate] # readPrec :: ReadPrec PersistUpdate # readListPrec :: ReadPrec [PersistUpdate] #
Show PersistUpdate # |
Methods showsPrec :: Int -> PersistUpdate -> ShowS # show :: PersistUpdate -> String # showList :: [PersistUpdate] -> ShowS #

data SomePersistField #

Constructors

PersistField a => SomePersistField a |

Instances

PersistField SomePersistField # |
Methods toPersistValue :: SomePersistField -> PersistValue # fromPersistValue :: PersistValue -> Either Text SomePersistField #

data Update record #

Updating a database entity.

Persistent users use combinators to create these.

Constructors

PersistField typ => Update |
Fields updateField :: EntityField record typ updateValue :: typ updateUpdate :: PersistUpdate
BackendUpdate (BackendSpecificUpdate (PersistEntityBackend record) record) |

type family BackendSpecificUpdate backend record #

data SelectOpt record #

Query options.

Persistent users use these directly.

Constructors

Asc (EntityField record typ) |
Desc (EntityField record typ) |
OffsetBy Int |
LimitTo Int |

data Filter record #

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.

Persistent users use combinators to create these.

Constructors

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

type family BackendSpecificFilter backend record #

data Entity record #

Datatype that represents an entity, with both its `Key` and its Haskell record representation.

When using a SQL-based backend (such as SQLite or PostgreSQL), an `Entity` may take any number of columns depending on how many fields it has. In order to reconstruct your entity on the Haskell side, `persistent` needs all of your entity columns and in the right order. Note that you don't need to worry about this when using `persistent`'s API since everything is handled correctly behind the scenes.

However, if you want to issue a raw SQL command that returns an `Entity`, then you have to be careful with the column order. While you could use `SELECT Entity.* WHERE ...` and that would work most of the time, there are times when the order of the columns on your database is different from the order that `persistent` expects (for example, if you add a new field in the middle of you entity definition and then use the migration code -- `persistent` will expect the column to be in the middle, but your DBMS will put it as the last column). So, instead of using a query like the one above, you may use `rawSql` (from the Database.Persist.GenericSql module) with its /entity selection placeholder/ (a double question mark `??`). Using `rawSql` the query above must be written as `SELECT ?? WHERE ..`. Then `rawSql` will replace `??` with the list of all columns that we need from your entity in the right order. If your query returns two entities (i.e. `(Entity backend a, Entity backend b)`), then you must you use `SELECT ??, ?? WHERE ...`, and so on.

Constructors

PersistEntity record => Entity |
Fields entityKey :: Key record entityVal :: record

Instances

(PersistEntity record, Eq (Key record), Eq record) => Eq (Entity record) # |
Methods (==) :: Entity record -> Entity record -> Bool # (/=) :: Entity record -> Entity record -> Bool #
(PersistEntity record, Ord (Key record), Ord record) => Ord (Entity record) # |
Methods compare :: Entity record -> Entity record -> Ordering # (<) :: Entity record -> Entity record -> Bool # (<=) :: Entity record -> Entity record -> Bool # (>) :: Entity record -> Entity record -> Bool # (>=) :: Entity record -> Entity record -> Bool # max :: Entity record -> Entity record -> Entity record # min :: Entity record -> Entity record -> Entity record #
(PersistEntity record, Read (Key record), Read record) => Read (Entity record) # |
Methods readsPrec :: Int -> ReadS (Entity record) # readList :: ReadS [Entity record] # readPrec :: ReadPrec (Entity record) # readListPrec :: ReadPrec [Entity record] #
(PersistEntity record, Show (Key record), Show record) => Show (Entity record) # |
Methods showsPrec :: Int -> Entity record -> ShowS # show :: Entity record -> String # showList :: [Entity record] -> ShowS #
(PersistEntity record, PersistField record, PersistField (Key record)) => PersistField (Entity record) # |
Methods toPersistValue :: Entity record -> PersistValue # fromPersistValue :: PersistValue -> Either Text (Entity record) #
(PersistField record, PersistEntity record) => PersistFieldSql (Entity record) # |
Methods sqlType :: Proxy * (Entity record) -> SqlType #
(PersistEntity record, (~) * (PersistEntityBackend record) backend, IsPersistBackend backend) => RawSql (Entity record) # |
Methods rawSqlCols :: (DBName -> Text) -> Entity record -> (Int, [Text]) # rawSqlColCountReason :: Entity record -> String # rawSqlProcessRow :: [PersistValue] -> Either Text (Entity record) #