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

Safe Haskell | None
Language | Haskell2010

Database.Persist.Types

Contents

- Various Types of Names
- Database Definitions
  - Entity/Table Definitions
  - Field definitions
- Intermediate Values
- Other Useful Stuff
- The rest of the types

Description

This module exports many types and functions for operating on `persistent`'s database representation. It's a bit of a kitchen sink. In the future, this module will be reorganized, and many of the dependent modules will be viewable on their own for easier documentation and organization.

Synopsis

- module Database.Persist.Names
- module Database.Persist.EntityDef
- module Database.Persist.FieldDef
- module Database.Persist.PersistValue
- 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 :: FilterValue typ
    - filterFilter :: PersistFilter
    }
  - | FilterAnd [Filter record]
  - | FilterOr [Filter record]
  - | BackendFilter (BackendSpecificFilter (PersistEntityBackend record) record)
- data FilterValue typ where
  - FilterValue :: forall typ. typ -> FilterValue typ
  - FilterValues :: forall typ. [typ] -> FilterValue typ
  - UnsafeValue :: forall a typ. PersistField a => a -> FilterValue typ
- type family BackendSpecificFilter backend record
- data family Key record
- data Entity record = Entity {
  - entityKey :: Key record
  - entityVal :: record
  }
- newtype OverflowNatural = OverflowNatural {
  - unOverflowNatural :: Natural
  }
- data PersistFilter
  - = Eq
  - | Ne
  - | Gt
  - | Lt
  - | Ge
  - | Le
  - | In
  - | NotIn
  - | BackendSpecificFilter Text
- data PersistUpdate
  - = Assign
  - | Add
  - | Subtract
  - | Multiply
  - | Divide
  - | BackendSpecificUpdate Text
- keyAndEntityFields :: EntityDef -> NonEmpty FieldDef
- keyAndEntityFieldsDatabase :: EntityDef -> NonEmpty FieldDef
- data FieldDef = FieldDef {
  - fieldHaskell :: !FieldNameHS
  - fieldDB :: !FieldNameDB
  - fieldType :: !FieldType
  - fieldSqlType :: !SqlType
  - fieldAttrs :: ![FieldAttr]
  - fieldStrict :: !Bool
  - fieldReference :: !ReferenceDef
  - fieldCascade :: !FieldCascade
  - fieldComments :: !(Maybe Text)
  - fieldGenerated :: !(Maybe Text)
  - fieldIsImplicitIdColumn :: !Bool
  }
- data ForeignDef = ForeignDef {
  - foreignRefTableHaskell :: !EntityNameHS
  - foreignRefTableDBName :: !EntityNameDB
  - foreignConstraintNameHaskell :: !ConstraintNameHS
  - foreignConstraintNameDBName :: !ConstraintNameDB
  - foreignFieldCascade :: !FieldCascade
  - foreignFields :: ![(ForeignFieldDef, ForeignFieldDef)]
  - foreignAttrs :: ![Attr]
  - foreignNullable :: Bool
  - foreignToPrimary :: Bool
  }
- data UniqueDef = UniqueDef {
  - uniqueHaskell :: !ConstraintNameHS
  - uniqueDBName :: !ConstraintNameDB
  - uniqueFields :: !(NonEmpty (FieldNameHS, FieldNameDB))
  - uniqueAttrs :: ![Attr]
  }
- data FieldCascade = FieldCascade {
  - fcOnUpdate :: !(Maybe CascadeAction)
  - fcOnDelete :: !(Maybe CascadeAction)
  }
- noCascade :: FieldCascade
- data CascadeAction
  - = Cascade
  - | Restrict
  - | SetNull
  - | SetDefault
- data FieldAttr
  - = FieldAttrMaybe
  - | FieldAttrNullable
  - | FieldAttrMigrationOnly
  - | FieldAttrSafeToRemove
  - | FieldAttrNoreference
  - | FieldAttrReference Text
  - | FieldAttrConstraint Text
  - | FieldAttrDefault Text
  - | FieldAttrSqltype Text
  - | FieldAttrMaxlen Integer
  - | FieldAttrSql Text
  - | FieldAttrOther Text
- data FieldType
  - = FTTypeCon (Maybe Text) Text
  - | FTLit FieldTypeLit
  - | FTTypePromoted Text
  - | FTApp FieldType FieldType
  - | FTList FieldType
- data IsNullable
  - = Nullable !WhyNullable
  - | NotNullable
- fieldAttrsContainsNullable :: [FieldAttr] -> IsNullable
- data SqlType
  - = SqlString
  - | SqlInt32
  - | SqlInt64
  - | SqlReal
  - | SqlNumeric Word32 Word32
  - | SqlBool
  - | SqlDay
  - | SqlTime
  - | SqlDayTime
  - | SqlBlob
  - | SqlOther Text
- data PersistValue where
  - 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
  - PersistArray [PersistValue]
  - PersistLiteral_ LiteralType ByteString
  - pattern PersistLiteral :: ByteString -> PersistValue
  - pattern PersistLiteralEscaped :: ByteString -> PersistValue
  - pattern PersistDbSpecific :: ByteString -> PersistValue
- data LiteralType
  - = Escaped
  - | Unescaped
  - | DbSpecific
- data CompositeDef = CompositeDef {
  - compositeFields :: !(NonEmpty FieldDef)
  - compositeAttrs :: ![Attr]
  }
- type Attr = Text
- data Checkmark
  - = Active
  - | Inactive
- data EmbedEntityDef = EmbedEntityDef {
  - embeddedHaskell :: EntityNameHS
  - embeddedFields :: [EmbedFieldDef]
  }
- data EmbedFieldDef = EmbedFieldDef {
  - emFieldDB :: FieldNameDB
  - emFieldEmbed :: Maybe (Either SelfEmbed EntityNameHS)
  }
- type ExtraLine = [Text]
- type ForeignFieldDef = (FieldNameHS, FieldNameDB)
- data PersistException
  - = PersistError Text
  - | PersistMarshalError Text
  - | PersistInvalidField Text
  - | PersistForeignConstraintUnmet Text
  - | PersistMongoDBError Text
  - | PersistMongoDBUnsupported Text
- data ReferenceDef
  - = NoReference
  - | ForeignRef !EntityNameHS
  - | EmbedRef EntityNameHS
  - | SelfReference
- data UpdateException
  - = KeyNotFound String
  - | UpsertError String
- data WhyNullable
  - = ByMaybeAttr
  - | ByNullableAttr
- parseFieldAttrs :: [Text] -> [FieldAttr]

# Various Types of Names

There are so many kinds of names. `persistent` defines newtype wrappers for `Text` so you don't confuse what a name is and what it is supposed to be used for

module Database.Persist.Names

# Database Definitions

## Entity/Table Definitions

The `EntityDef` type is used by `persistent` to generate Haskell code, generate database migrations, and maintain metadata about entities. These are generated in the call to `mkPersist`.

module Database.Persist.EntityDef

## Field definitions

The `FieldDef` type is used to describe how a field should be represented at the Haskell and database layers.

module Database.Persist.FieldDef

# Intermediate Values

The `PersistValue` type is used as an intermediate layer between database and Haskell types.

module Database.Persist.PersistValue

# Other Useful Stuff

data Update record Source #

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

data SelectOpt record Source #

Query options.

Persistent users use these directly.

Constructors

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

data Filter record Source #

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.

Note that it's important to be careful about the `PersistFilter` that you are using, if you use this directly. For example, using the `In` `PersistFilter` requires that you have an array- or list-shaped `EntityField`. It is possible to construct values using this that will create malformed runtime values.

Constructors

PersistField typ => Filter |

Fields

- filterField :: EntityField record typ
- filterValue :: FilterValue typ
- filterFilter :: PersistFilter

FilterAnd [Filter record] | convenient for internal use, not needed for the API
FilterOr [Filter record] |
BackendFilter (BackendSpecificFilter (PersistEntityBackend record) record) |

data FilterValue typ where Source #

Value to filter with. Highly dependant on the type of filter used.

Since: 2.10.0

Constructors

FilterValue :: forall typ. typ -> FilterValue typ |
FilterValues :: forall typ. [typ] -> FilterValue typ |
UnsafeValue :: forall a typ. PersistField a => a -> FilterValue typ |

type family BackendSpecificFilter backend record Source #

data family Key record Source #

By default, a backend will automatically generate the key Instead you can specify a Primary key made up of unique values.

#### Instances

Instances details

(PersistEntity a, PersistEntityBackend a ~ backend, IsPersistBackend backend) => RawSql (Key a) Source # |
Instance details Defined in Database.Persist.Sql.Class Methods rawSqlCols :: (Text -> Text) -> Key a -> (Int, [Text]) Source # rawSqlColCountReason :: Key a -> String Source # rawSqlProcessRow :: [PersistValue] -> Either Text (Key a) Source #

data Entity record Source #

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.Sql 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

Entity |

Fields

- entityKey :: Key record
- entityVal :: record

#### Instances

Instances details

(Generic (Key record), Generic record) => Generic (Entity record) Source # |

Instance details

Defined in Database.Persist.Class.PersistEntity

Associated Types

type Rep (Entity record) |

Instance details

Defined in Database.Persist.Class.PersistEntity

type Rep (Entity record) = D1 ('MetaData "Entity" "Database.Persist.Class.PersistEntity" "persistent-2.17.1.0-EQFFjlejpWP10lX0h8hkWO" 'False) (C1 ('MetaCons "Entity" 'PrefixI 'True) (S1 ('MetaSel ('Just "entityKey") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Key record)) :*: S1 ('MetaSel ('Just "entityVal") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 record)))

Methods

from :: Entity record -> Rep (Entity record) x Source #

to :: Rep (Entity record) x -> Entity record Source #

(Read (Key record), Read record) => Read (Entity record) Source # |
Instance details Defined in Database.Persist.Class.PersistEntity Methods readsPrec :: Int -> ReadS (Entity record) Source # readList :: ReadS [Entity record] Source # readPrec :: ReadPrec (Entity record) Source # readListPrec :: ReadPrec [Entity record] Source #
(Show (Key record), Show record) => Show (Entity record) Source # |
Instance details Defined in Database.Persist.Class.PersistEntity Methods showsPrec :: Int -> Entity record -> ShowS Source # show :: Entity record -> String Source # showList :: [Entity record] -> ShowS Source #
(Eq (Key record), Eq record) => Eq (Entity record) Source # |
Instance details Defined in Database.Persist.Class.PersistEntity Methods (==) :: Entity record -> Entity record -> Bool Source # (/=) :: Entity record -> Entity record -> Bool Source #
(Ord (Key record), Ord record) => Ord (Entity record) Source # |

Instance details

Defined in Database.Persist.Class.PersistEntity

Methods

compare :: Entity record -> Entity record -> Ordering Source #

(<) :: Entity record -> Entity record -> Bool Source #

(<=) :: Entity record -> Entity record -> Bool Source #

(>) :: Entity record -> Entity record -> Bool Source #

(>=) :: Entity record -> Entity record -> Bool Source #

max :: Entity record -> Entity record -> Entity record Source #

min :: Entity record -> Entity record -> Entity record Source #

(TypeError (EntityErrorMessage a) :: Constraint) => SafeToInsert (Entity a) Source # |
Instance details Defined in Database.Persist.Class.PersistEntity
(PersistEntity record, PersistField record, PersistField (Key record)) => PersistField (Entity record) Source # |
Instance details Defined in Database.Persist.Class.PersistEntity Methods toPersistValue :: Entity record -> PersistValue Source # fromPersistValue :: PersistValue -> Either Text (Entity record) Source #
(PersistField record, PersistEntity record) => PersistFieldSql (Entity record) Source # |
Instance details Defined in Database.Persist.Sql.Class Methods sqlType :: Proxy (Entity record) -> SqlType Source #
(PersistEntity record, PersistEntityBackend record ~ backend, IsPersistBackend backend) => RawSql (Entity record) Source # |
Instance details Defined in Database.Persist.Sql.Class Methods rawSqlCols :: (Text -> Text) -> Entity record -> (Int, [Text]) Source # rawSqlColCountReason :: Entity record -> String Source # rawSqlProcessRow :: [PersistValue] -> Either Text (Entity record) Source #
type Rep (Entity record) Source # |

Instance details

Defined in Database.Persist.Class.PersistEntity

type Rep (Entity record) = D1 ('MetaData "Entity" "Database.Persist.Class.PersistEntity" "persistent-2.17.1.0-EQFFjlejpWP10lX0h8hkWO" 'False) (C1 ('MetaCons "Entity" 'PrefixI 'True) (S1 ('MetaSel ('Just "entityKey") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Key record)) :*: S1 ('MetaSel ('Just "entityVal") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 record)))

newtype OverflowNatural Source #

Prior to `persistent-2.11.0`, we provided an instance of `PersistField` for the `Natural` type. This was in error, because `Natural` represents an infinite value, and databases don't have reasonable types for this.

The instance for `Natural` used the `Int64` underlying type, which will cause underflow and overflow errors. This type has the exact same code in the instances, and will work seamlessly.

A more appropriate type for this is the `Word` series of types from Data.Word. These have a bounded size, are guaranteed to be non-negative, and are quite efficient for the database to store.

Since: 2.11.0

Constructors

OverflowNatural |

Fields

- unOverflowNatural :: Natural

#### Instances

Instances details

Num OverflowNatural Source # |

Instance details

Defined in Database.Persist.Class.PersistField

Methods

(+) :: OverflowNatural -> OverflowNatural -> OverflowNatural Source #

(-) :: OverflowNatural -> OverflowNatural -> OverflowNatural Source #

(*) :: OverflowNatural -> OverflowNatural -> OverflowNatural Source #

negate :: OverflowNatural -> OverflowNatural Source #

abs :: OverflowNatural -> OverflowNatural Source #

signum :: OverflowNatural -> OverflowNatural Source #

fromInteger :: Integer -> OverflowNatural Source #

Show OverflowNatural Source # |
Instance details Defined in Database.Persist.Class.PersistField Methods showsPrec :: Int -> OverflowNatural -> ShowS Source # show :: OverflowNatural -> String Source # showList :: [OverflowNatural] -> ShowS Source #
Eq OverflowNatural Source # |
Instance details Defined in Database.Persist.Class.PersistField Methods (==) :: OverflowNatural -> OverflowNatural -> Bool Source # (/=) :: OverflowNatural -> OverflowNatural -> Bool Source #
Ord OverflowNatural Source # |

Instance details

Defined in Database.Persist.Class.PersistField

Methods

compare :: OverflowNatural -> OverflowNatural -> Ordering Source #

(<) :: OverflowNatural -> OverflowNatural -> Bool Source #

(<=) :: OverflowNatural -> OverflowNatural -> Bool Source #

(>) :: OverflowNatural -> OverflowNatural -> Bool Source #

(>=) :: OverflowNatural -> OverflowNatural -> Bool Source #

max :: OverflowNatural -> OverflowNatural -> OverflowNatural Source #

min :: OverflowNatural -> OverflowNatural -> OverflowNatural Source #

PersistField OverflowNatural Source # |
Instance details Defined in Database.Persist.Class.PersistField Methods toPersistValue :: OverflowNatural -> PersistValue Source # fromPersistValue :: PersistValue -> Either Text OverflowNatural Source #
PersistFieldSql OverflowNatural Source # | This type uses the `SqlInt64` version, which will exhibit overflow and underflow behavior. Additionally, it permits negative values in the database, which isn't ideal. Since: 2.11.0
Instance details Defined in Database.Persist.Sql.Class Methods sqlType :: Proxy OverflowNatural -> SqlType Source #

# The rest of the types

data PersistFilter Source #

Constructors

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

#### Instances

Instances details

Read PersistFilter Source # |
Instance details Defined in Database.Persist.Types.Base Methods readsPrec :: Int -> ReadS PersistFilter Source # readList :: ReadS [PersistFilter] Source # readPrec :: ReadPrec PersistFilter Source # readListPrec :: ReadPrec [PersistFilter] Source #
Show PersistFilter Source # |
Instance details Defined in Database.Persist.Types.Base Methods showsPrec :: Int -> PersistFilter -> ShowS Source # show :: PersistFilter -> String Source # showList :: [PersistFilter] -> ShowS Source #
Lift PersistFilter Source # |
Instance details Defined in Database.Persist.Types.Base Methods lift :: Quote m => PersistFilter -> m Exp Source # liftTyped :: forall (m :: Type -> Type). Quote m => PersistFilter -> Code m PersistFilter Source #

data PersistUpdate Source #

Constructors

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

#### Instances

Instances details

Read PersistUpdate Source # |
Instance details Defined in Database.Persist.Types.Base Methods readsPrec :: Int -> ReadS PersistUpdate Source # readList :: ReadS [PersistUpdate] Source # readPrec :: ReadPrec PersistUpdate Source # readListPrec :: ReadPrec [PersistUpdate] Source #
Show PersistUpdate Source # |
Instance details Defined in Database.Persist.Types.Base Methods showsPrec :: Int -> PersistUpdate -> ShowS Source # show :: PersistUpdate -> String Source # showList :: [PersistUpdate] -> ShowS Source #
Lift PersistUpdate Source # |
Instance details Defined in Database.Persist.Types.Base Methods lift :: Quote m => PersistUpdate -> m Exp Source # liftTyped :: forall (m :: Type -> Type). Quote m => PersistUpdate -> Code m PersistUpdate Source #

keyAndEntityFields :: EntityDef -> NonEmpty FieldDef Source #

Returns a `NonEmpty` list of `FieldDef` that correspond with the key columns for an `EntityDef`.

keyAndEntityFieldsDatabase :: EntityDef -> NonEmpty FieldDef Source #

Returns a `NonEmpty` list of `FieldDef` that correspond with the key columns for an `EntityDef` including those fields that are marked as `MigrationOnly` (and therefore only present in the database) or `SafeToRemove` (and a migration will drop the column if it exists in the database).

For fields on the Haskell type use `keyAndEntityFieldsDatabase`

Since: 2.15.1.0

data FieldDef Source #

A `FieldDef` represents the inormation that `persistent` knows about a field of a datatype. This includes information used to parse the field out of the database and what the field corresponds to.

Constructors

FieldDef |

Fields

- fieldHaskell :: !FieldNameHS

  The name of the field. Note that this does not corresponds to the record labels generated for the particular entity - record labels are generated with the type name prefixed to the field, so a `FieldDef` that contains a ``FieldNameHS` "name"` for a type `User` will have a record field `userName`.

- fieldDB :: !FieldNameDB

  The name of the field in the database. For SQL databases, this corresponds to the column name.

- fieldType :: !FieldType

  The type of the field in Haskell.

- fieldSqlType :: !SqlType

  The type of the field in a SQL database.

- fieldAttrs :: ![FieldAttr]

  User annotations for a field. These are provided with the `!` operator.

- fieldStrict :: !Bool

  If this is `True`, then the Haskell datatype will have a strict record field. The default value for this is `True`.

- fieldReference :: !ReferenceDef
- fieldCascade :: !FieldCascade

  Defines how operations on the field cascade on to the referenced tables. This doesn't have any meaning if the `fieldReference` is set to `NoReference` or `SelfReference`. The cascade option here should be the same as the one obtained in the `fieldReference`.

  Since: 2.11.0

- fieldComments :: !(Maybe Text)

  Optional comments for a `Field`.

  Since: 2.10.0

- fieldGenerated :: !(Maybe Text)

  Whether or not the field is a `GENERATED` column, and additionally the expression to use for generation.

  Since: 2.11.0.0

- fieldIsImplicitIdColumn :: !Bool

  `True` if the field is an implicit ID column. `False` otherwise.

  Since: 2.13.0.0

#### Instances

Instances details

Read FieldDef Source # |
Instance details Defined in Database.Persist.Types.Base Methods readsPrec :: Int -> ReadS FieldDef Source # readList :: ReadS [FieldDef] Source # readPrec :: ReadPrec FieldDef Source # readListPrec :: ReadPrec [FieldDef] Source #
Show FieldDef Source # |
Instance details Defined in Database.Persist.Types.Base Methods showsPrec :: Int -> FieldDef -> ShowS Source # show :: FieldDef -> String Source # showList :: [FieldDef] -> ShowS Source #
Eq FieldDef Source # |
Instance details Defined in Database.Persist.Types.Base Methods (==) :: FieldDef -> FieldDef -> Bool Source # (/=) :: FieldDef -> FieldDef -> Bool Source #
Ord FieldDef Source # |
Instance details Defined in Database.Persist.Types.Base Methods compare :: FieldDef -> FieldDef -> Ordering Source # (<) :: FieldDef -> FieldDef -> Bool Source # (<=) :: FieldDef -> FieldDef -> Bool Source # (>) :: FieldDef -> FieldDef -> Bool Source # (>=) :: FieldDef -> FieldDef -> Bool Source # max :: FieldDef -> FieldDef -> FieldDef Source # min :: FieldDef -> FieldDef -> FieldDef Source #
Lift FieldDef Source # |
Instance details Defined in Database.Persist.Types.Base Methods lift :: Quote m => FieldDef -> m Exp Source # liftTyped :: forall (m :: Type -> Type). Quote m => FieldDef -> Code m FieldDef Source #

data ForeignDef Source #

Constructors

ForeignDef |

Fields

- foreignRefTableHaskell :: !EntityNameHS
- foreignRefTableDBName :: !EntityNameDB
- foreignConstraintNameHaskell :: !ConstraintNameHS
- foreignConstraintNameDBName :: !ConstraintNameDB
- foreignFieldCascade :: !FieldCascade

  Determine how the field will cascade on updates and deletions.

  Since: 2.11.0

- foreignFields :: ![(ForeignFieldDef, ForeignFieldDef)]
- foreignAttrs :: ![Attr]
- foreignNullable :: Bool
- foreignToPrimary :: Bool

  Determines if the reference is towards a Primary Key or not.

  Since: 2.11.0

#### Instances

Instances details

Read ForeignDef Source # |
Instance details Defined in Database.Persist.Types.Base Methods readsPrec :: Int -> ReadS ForeignDef Source # readList :: ReadS [ForeignDef] Source # readPrec :: ReadPrec ForeignDef Source # readListPrec :: ReadPrec [ForeignDef] Source #
Show ForeignDef Source # |
Instance details Defined in Database.Persist.Types.Base Methods showsPrec :: Int -> ForeignDef -> ShowS Source # show :: ForeignDef -> String Source # showList :: [ForeignDef] -> ShowS Source #
Eq ForeignDef Source # |
Instance details Defined in Database.Persist.Types.Base Methods (==) :: ForeignDef -> ForeignDef -> Bool Source # (/=) :: ForeignDef -> ForeignDef -> Bool Source #
Ord ForeignDef Source # |

Instance details

Defined in Database.Persist.Types.Base

Methods

compare :: ForeignDef -> ForeignDef -> Ordering Source #

(<) :: ForeignDef -> ForeignDef -> Bool Source #

(<=) :: ForeignDef -> ForeignDef -> Bool Source #

(>) :: ForeignDef -> ForeignDef -> Bool Source #

(>=) :: ForeignDef -> ForeignDef -> Bool Source #

max :: ForeignDef -> ForeignDef -> ForeignDef Source #

min :: ForeignDef -> ForeignDef -> ForeignDef Source #

Lift ForeignDef Source # |
Instance details Defined in Database.Persist.Types.Base Methods lift :: Quote m => ForeignDef -> m Exp Source # liftTyped :: forall (m :: Type -> Type). Quote m => ForeignDef -> Code m ForeignDef Source #

data UniqueDef Source #

Type for storing the Uniqueness constraint in the Schema. Assume you have the following schema with a uniqueness constraint:

    Person
      name String
      age Int
      UniqueAge age

This will be represented as:

    UniqueDef
        { uniqueHaskell = ConstraintNameHS (packPTH UniqueAge)
        , uniqueDBName = ConstraintNameDB (packPTH "unique_age")
        , uniqueFields = [(FieldNameHS (packPTH "age"), FieldNameDB (packPTH "age"))]
        , uniqueAttrs = []
        }

Constructors

UniqueDef |

Fields

- uniqueHaskell :: !ConstraintNameHS
- uniqueDBName :: !ConstraintNameDB
- uniqueFields :: !(NonEmpty (FieldNameHS, FieldNameDB))
- uniqueAttrs :: ![Attr]

#### Instances

Instances details

Read UniqueDef Source # |
Instance details Defined in Database.Persist.Types.Base Methods readsPrec :: Int -> ReadS UniqueDef Source # readList :: ReadS [UniqueDef] Source # readPrec :: ReadPrec UniqueDef Source # readListPrec :: ReadPrec [UniqueDef] Source #
Show UniqueDef Source # |
Instance details Defined in Database.Persist.Types.Base Methods showsPrec :: Int -> UniqueDef -> ShowS Source # show :: UniqueDef -> String Source # showList :: [UniqueDef] -> ShowS Source #
Eq UniqueDef Source # |
Instance details Defined in Database.Persist.Types.Base Methods (==) :: UniqueDef -> UniqueDef -> Bool Source # (/=) :: UniqueDef -> UniqueDef -> Bool Source #
Ord UniqueDef Source # |

Instance details

Defined in Database.Persist.Types.Base

Methods

compare :: UniqueDef -> UniqueDef -> Ordering Source #

(<) :: UniqueDef -> UniqueDef -> Bool Source #

(<=) :: UniqueDef -> UniqueDef -> Bool Source #

(>) :: UniqueDef -> UniqueDef -> Bool Source #

(>=) :: UniqueDef -> UniqueDef -> Bool Source #

max :: UniqueDef -> UniqueDef -> UniqueDef Source #

min :: UniqueDef -> UniqueDef -> UniqueDef Source #

Lift UniqueDef Source # |
Instance details Defined in Database.Persist.Types.Base Methods lift :: Quote m => UniqueDef -> m Exp Source # liftTyped :: forall (m :: Type -> Type). Quote m => UniqueDef -> Code m UniqueDef Source #

data FieldCascade Source #

This datatype describes how a foreign reference field cascades deletes or updates.

This type is used in both parsing the model definitions and performing migrations. A `Nothing` in either of the field values means that the user has not specified a `CascadeAction`. An unspecified `CascadeAction` is defaulted to `Restrict` when doing migrations.

Since: 2.11.0

Constructors

FieldCascade |

Fields

- fcOnUpdate :: !(Maybe CascadeAction)
- fcOnDelete :: !(Maybe CascadeAction)

#### Instances

Instances details

Read FieldCascade Source # |
Instance details Defined in Database.Persist.Types.Base Methods readsPrec :: Int -> ReadS FieldCascade Source # readList :: ReadS [FieldCascade] Source # readPrec :: ReadPrec FieldCascade Source # readListPrec :: ReadPrec [FieldCascade] Source #
Show FieldCascade Source # |
Instance details Defined in Database.Persist.Types.Base Methods showsPrec :: Int -> FieldCascade -> ShowS Source # show :: FieldCascade -> String Source # showList :: [FieldCascade] -> ShowS Source #
Eq FieldCascade Source # |
Instance details Defined in Database.Persist.Types.Base Methods (==) :: FieldCascade -> FieldCascade -> Bool Source # (/=) :: FieldCascade -> FieldCascade -> Bool Source #
Ord FieldCascade Source # |

Instance details

Defined in Database.Persist.Types.Base

Methods

compare :: FieldCascade -> FieldCascade -> Ordering Source #

(<) :: FieldCascade -> FieldCascade -> Bool Source #

(<=) :: FieldCascade -> FieldCascade -> Bool Source #

(>) :: FieldCascade -> FieldCascade -> Bool Source #

(>=) :: FieldCascade -> FieldCascade -> Bool Source #

max :: FieldCascade -> FieldCascade -> FieldCascade Source #

min :: FieldCascade -> FieldCascade -> FieldCascade Source #

Lift FieldCascade Source # |
Instance details Defined in Database.Persist.Types.Base Methods lift :: Quote m => FieldCascade -> m Exp Source # liftTyped :: forall (m :: Type -> Type). Quote m => FieldCascade -> Code m FieldCascade Source #

noCascade :: FieldCascade Source #

A `FieldCascade` that does nothing.

Since: 2.11.0

data CascadeAction Source #

An action that might happen on a deletion or update on a foreign key change.

Since: 2.11.0

Constructors

Cascade |
Restrict |
SetNull |
SetDefault |

#### Instances

Instances details

Read CascadeAction Source # |
Instance details Defined in Database.Persist.Types.Base Methods readsPrec :: Int -> ReadS CascadeAction Source # readList :: ReadS [CascadeAction] Source # readPrec :: ReadPrec CascadeAction Source # readListPrec :: ReadPrec [CascadeAction] Source #
Show CascadeAction Source # |
Instance details Defined in Database.Persist.Types.Base Methods showsPrec :: Int -> CascadeAction -> ShowS Source # show :: CascadeAction -> String Source # showList :: [CascadeAction] -> ShowS Source #
Eq CascadeAction Source # |
Instance details Defined in Database.Persist.Types.Base Methods (==) :: CascadeAction -> CascadeAction -> Bool Source # (/=) :: CascadeAction -> CascadeAction -> Bool Source #
Ord CascadeAction Source # |

Instance details

Defined in Database.Persist.Types.Base

Methods

compare :: CascadeAction -> CascadeAction -> Ordering Source #

(<) :: CascadeAction -> CascadeAction -> Bool Source #

(<=) :: CascadeAction -> CascadeAction -> Bool Source #

(>) :: CascadeAction -> CascadeAction -> Bool Source #

(>=) :: CascadeAction -> CascadeAction -> Bool Source #

max :: CascadeAction -> CascadeAction -> CascadeAction Source #

min :: CascadeAction -> CascadeAction -> CascadeAction Source #

Lift CascadeAction Source # |
Instance details Defined in Database.Persist.Types.Base Methods lift :: Quote m => CascadeAction -> m Exp Source # liftTyped :: forall (m :: Type -> Type). Quote m => CascadeAction -> Code m CascadeAction Source #

data FieldAttr Source #

Attributes that may be attached to fields that can affect migrations and serialization in backend-specific ways.

While we endeavor to, we can't forsee all use cases for all backends, and so `FieldAttr` is extensible through its constructor `FieldAttrOther`.

Since: 2.11.0.0

Constructors

FieldAttrMaybe

The `Maybe` keyword goes after the type. This indicates that the column is nullable, and the generated Haskell code will have a ``Maybe`` type for it.

Example:

    User
        name Text Maybe

FieldAttrNullable

This indicates that the column is nullable, but should not have a `Maybe` type. For this to work out, you need to ensure that the `PersistField` instance for the type in question can support a `PersistNull` value.

    data What = NoWhat | Hello Text

    instance PersistField What where
        fromPersistValue PersistNull =
            pure NoWhat
        fromPersistValue pv =
            Hello $ fromPersistValue pv

    instance PersistFieldSql What where
        sqlType _ = SqlString

    User
        what What nullable

FieldAttrMigrationOnly

This tag means that the column will not be present on the Haskell code, but will not be removed from the database. Useful to deprecate fields in phases.

You should set the column to be nullable in the database. Otherwise, inserts won't have values.

    User
        oldName Text MigrationOnly
        newName Text

FieldAttrSafeToRemove

A `SafeToRemove` attribute is not present on the Haskell datatype, and the backend migrations should attempt to drop the column without triggering any unsafe migration warnings.

Useful after you've used `MigrationOnly` to remove a column from the database in phases.

    User
        oldName Text SafeToRemove
        newName Text

FieldAttrNoreference

This attribute indicates that we should not create a foreign key reference from a column. By default, `persistent` will try and create a foreign key reference for a column if it can determine that the type of the column is a ``Key` entity` or an `EntityId` and the `Entity`'s name was present in `mkPersist`.

This is useful if you want to use the explicit foreign key syntax.

    Post
        title    Text

    Comment
        postId   PostId      noreference
        Foreign Post fk_comment_post postId

FieldAttrReference Text

This is set to specify precisely the database table the column refers to.

    Post
        title    Text

    Comment
        postId   PostId references="post"

You should not need this - `persistent` should be capable of correctly determining the target table's name. If you do need this, please file an issue describing why.

FieldAttrConstraint Text

Specify a name for the constraint on the foreign key reference for this table.

    Post
        title    Text

    Comment
        postId   PostId constraint="my_cool_constraint_name"

FieldAttrDefault Text

Specify the default value for a column.

    User
        createdAt    UTCTime     default="NOW()"

Note that a `default=` attribute does not mean you can omit the value while inserting.

FieldAttrSqltype Text

Specify a custom SQL type for the column. Generally, you should define a custom datatype with a custom `PersistFieldSql` instance instead of using this.

    User
        uuid     Text    sqltype=UUID

FieldAttrMaxlen Integer

Set a maximum length for a column. Useful for VARCHAR and indexes.

    User
        name     Text    maxlen=200

        UniqueName name

FieldAttrSql Text

Specify the database name of the column.

    User
        blarghle     Int     sql="b_l_a_r_g_h_l_e"

Useful for performing phased migrations, where one column is renamed to another column over time.

FieldAttrOther Text | A grab bag of random attributes that were unrecognized by the parser.

#### Instances

Instances details

Read FieldAttr Source # |
Instance details Defined in Database.Persist.Types.Base Methods readsPrec :: Int -> ReadS FieldAttr Source # readList :: ReadS [FieldAttr] Source # readPrec :: ReadPrec FieldAttr Source # readListPrec :: ReadPrec [FieldAttr] Source #
Show FieldAttr Source # |
Instance details Defined in Database.Persist.Types.Base Methods showsPrec :: Int -> FieldAttr -> ShowS Source # show :: FieldAttr -> String Source # showList :: [FieldAttr] -> ShowS Source #
Eq FieldAttr Source # |
Instance details Defined in Database.Persist.Types.Base Methods (==) :: FieldAttr -> FieldAttr -> Bool Source # (/=) :: FieldAttr -> FieldAttr -> Bool Source #
Ord FieldAttr Source # |

Instance details

Defined in Database.Persist.Types.Base

Methods

compare :: FieldAttr -> FieldAttr -> Ordering Source #

(<) :: FieldAttr -> FieldAttr -> Bool Source #

(<=) :: FieldAttr -> FieldAttr -> Bool Source #

(>) :: FieldAttr -> FieldAttr -> Bool Source #

(>=) :: FieldAttr -> FieldAttr -> Bool Source #

max :: FieldAttr -> FieldAttr -> FieldAttr Source #

min :: FieldAttr -> FieldAttr -> FieldAttr Source #

Lift FieldAttr Source # |
Instance details Defined in Database.Persist.Types.Base Methods lift :: Quote m => FieldAttr -> m Exp Source # liftTyped :: forall (m :: Type -> Type). Quote m => FieldAttr -> Code m FieldAttr Source #

data FieldType Source #

A `FieldType` describes a field parsed from the QuasiQuoter and is used to determine the Haskell type in the generated code.

`name Text` parses into `FTTypeCon Nothing Text`

`name T.Text` parses into `FTTypeCon (Just T Text)`

`name (Jsonb User)` parses into:

    FTApp (FTTypeCon Nothing Jsonb) (FTTypeCon Nothing User)

Constructors

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

#### Instances

Instances details

Read FieldType Source # |
Instance details Defined in Database.Persist.Types.Base Methods readsPrec :: Int -> ReadS FieldType Source # readList :: ReadS [FieldType] Source # readPrec :: ReadPrec FieldType Source # readListPrec :: ReadPrec [FieldType] Source #
Show FieldType Source # |
Instance details Defined in Database.Persist.Types.Base Methods showsPrec :: Int -> FieldType -> ShowS Source # show :: FieldType -> String Source # showList :: [FieldType] -> ShowS Source #
Eq FieldType Source # |
Instance details Defined in Database.Persist.Types.Base Methods (==) :: FieldType -> FieldType -> Bool Source # (/=) :: FieldType -> FieldType -> Bool Source #
Ord FieldType Source # |

Instance details

Defined in Database.Persist.Types.Base

Methods

compare :: FieldType -> FieldType -> Ordering Source #

(<) :: FieldType -> FieldType -> Bool Source #

(<=) :: FieldType -> FieldType -> Bool Source #

(>) :: FieldType -> FieldType -> Bool Source #

(>=) :: FieldType -> FieldType -> Bool Source #

max :: FieldType -> FieldType -> FieldType Source #

min :: FieldType -> FieldType -> FieldType Source #

Lift FieldType Source # |
Instance details Defined in Database.Persist.Types.Base Methods lift :: Quote m => FieldType -> m Exp Source # liftTyped :: forall (m :: Type -> Type). Quote m => FieldType -> Code m FieldType Source #

data IsNullable Source #

Constructors

Nullable !WhyNullable |
NotNullable |

#### Instances

Instances details

Show IsNullable Source # |
Instance details Defined in Database.Persist.Types.Base Methods showsPrec :: Int -> IsNullable -> ShowS Source # show :: IsNullable -> String Source # showList :: [IsNullable] -> ShowS Source #
Eq IsNullable Source # |
Instance details Defined in Database.Persist.Types.Base Methods (==) :: IsNullable -> IsNullable -> Bool Source # (/=) :: IsNullable -> IsNullable -> Bool Source #

fieldAttrsContainsNullable :: [FieldAttr] -> IsNullable Source #

data SqlType Source #

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

Instances details

Read SqlType Source # |
Instance details Defined in Database.Persist.Types.Base Methods readsPrec :: Int -> ReadS SqlType Source # readList :: ReadS [SqlType] Source # readPrec :: ReadPrec SqlType Source # readListPrec :: ReadPrec [SqlType] Source #
Show SqlType Source # |
Instance details Defined in Database.Persist.Types.Base Methods showsPrec :: Int -> SqlType -> ShowS Source # show :: SqlType -> String Source # showList :: [SqlType] -> ShowS Source #
Eq SqlType Source # |
Instance details Defined in Database.Persist.Types.Base Methods (==) :: SqlType -> SqlType -> Bool Source # (/=) :: SqlType -> SqlType -> Bool Source #
Ord SqlType Source # |
Instance details Defined in Database.Persist.Types.Base Methods compare :: SqlType -> SqlType -> Ordering Source # (<) :: SqlType -> SqlType -> Bool Source # (<=) :: SqlType -> SqlType -> Bool Source # (>) :: SqlType -> SqlType -> Bool Source # (>=) :: SqlType -> SqlType -> Bool Source # max :: SqlType -> SqlType -> SqlType Source # min :: SqlType -> SqlType -> SqlType Source #
Lift SqlType Source # |
Instance details Defined in Database.Persist.Types.Base Methods lift :: Quote m => SqlType -> m Exp Source # liftTyped :: forall (m :: Type -> Type). Quote m => SqlType -> Code m SqlType Source #

data PersistValue Source #

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
PersistArray [PersistValue] | Intended especially for PostgreSQL backend for text arrays
PersistLiteral_ LiteralType ByteString | This constructor is used to specify some raw literal value for the backend. The `LiteralType` value specifies how the value should be escaped. This can be used to make special, custom types avaialable in the back end. Since: 2.12.0.0

Bundled Patterns

pattern PersistLiteral :: ByteString -> PersistValue | This pattern synonym used to be a data constructor on `PersistValue`, but was changed into a catch-all pattern synonym to allow backwards compatiblity with database types. See the documentation on `PersistDbSpecific` for more details. Since: 2.12.0.0
pattern PersistLiteralEscaped :: ByteString -> PersistValue | This pattern synonym used to be a data constructor on `PersistValue`, but was changed into a catch-all pattern synonym to allow backwards compatiblity with database types. See the documentation on `PersistDbSpecific` for more details. Since: 2.12.0.0

pattern PersistDbSpecific :: ByteString -> PersistValue

Deprecated: Deprecated since 2.11 because of inconsistent escaping behavior across backends. The Postgres backend escapes these values, while the MySQL backend does not. If you are using this, please switch to `PersistLiteral_` and provide a relevant `LiteralType` for your conversion.

This pattern synonym used to be a data constructor for the `PersistValue` type. It was changed to be a pattern so that JSON-encoded database values could be parsed into their corresponding values. You should not use this, and instead prefer to pattern match on `PersistLiteral_` directly.

If you use this, it will overlap a patern match on the 'PersistLiteral_, `PersistLiteral`, and `PersistLiteralEscaped` patterns. If you need to disambiguate between these constructors, pattern match on `PersistLiteral_` directly.

Since: 2.12.0.0

#### Instances

Instances details

FromJSON PersistValue Source # |
Instance details Defined in Database.Persist.PersistValue Methods parseJSON :: Value -> Parser PersistValue Source # parseJSONList :: Value -> Parser [PersistValue] Source # omittedField :: Maybe PersistValue Source #
ToJSON PersistValue Source # |
Instance details Defined in Database.Persist.PersistValue Methods toJSON :: PersistValue -> Value Source # toEncoding :: PersistValue -> Encoding Source # toJSONList :: [PersistValue] -> Value Source # toEncodingList :: [PersistValue] -> Encoding Source # omitField :: PersistValue -> Bool Source #
NFData PersistValue Source # | Since: 2.14.4.0
Instance details Defined in Database.Persist.PersistValue Methods rnf :: PersistValue -> () Source #
Read PersistValue Source # |
Instance details Defined in Database.Persist.PersistValue Methods readsPrec :: Int -> ReadS PersistValue Source # readList :: ReadS [PersistValue] Source # readPrec :: ReadPrec PersistValue Source # readListPrec :: ReadPrec [PersistValue] Source #
Show PersistValue Source # |
Instance details Defined in Database.Persist.PersistValue Methods showsPrec :: Int -> PersistValue -> ShowS Source # show :: PersistValue -> String Source # showList :: [PersistValue] -> ShowS Source #
Eq PersistValue Source # |
Instance details Defined in Database.Persist.PersistValue Methods (==) :: PersistValue -> PersistValue -> Bool Source # (/=) :: PersistValue -> PersistValue -> Bool Source #
Ord PersistValue Source # |

Instance details

Defined in Database.Persist.PersistValue

Methods

compare :: PersistValue -> PersistValue -> Ordering Source #

(<) :: PersistValue -> PersistValue -> Bool Source #

(<=) :: PersistValue -> PersistValue -> Bool Source #

(>) :: PersistValue -> PersistValue -> Bool Source #

(>=) :: PersistValue -> PersistValue -> Bool Source #

max :: PersistValue -> PersistValue -> PersistValue Source #

min :: PersistValue -> PersistValue -> PersistValue Source #

FromHttpApiData PersistValue Source # |
Instance details Defined in Database.Persist.PersistValue Methods parseUrlPiece :: Text -> Either Text PersistValue Source # parseHeader :: ByteString -> Either Text PersistValue Source # parseQueryParam :: Text -> Either Text PersistValue Source #
ToHttpApiData PersistValue Source # |
Instance details Defined in Database.Persist.PersistValue Methods toUrlPiece :: PersistValue -> Text Source # toEncodedUrlPiece :: PersistValue -> Builder Source # toHeader :: PersistValue -> ByteString Source # toQueryParam :: PersistValue -> Text Source # toEncodedQueryParam :: PersistValue -> Builder Source #
PathPiece PersistValue Source # |
Instance details Defined in Database.Persist.PersistValue Methods fromPathPiece :: Text -> Maybe PersistValue Source # toPathPiece :: PersistValue -> Text Source #
PersistField PersistValue Source # |
Instance details Defined in Database.Persist.Class.PersistField Methods toPersistValue :: PersistValue -> PersistValue Source # fromPersistValue :: PersistValue -> Either Text PersistValue Source #
PersistFieldSql PersistValue Source # |
Instance details Defined in Database.Persist.Sql.Class Methods sqlType :: Proxy PersistValue -> SqlType Source #

data LiteralType Source #

A type that determines how a backend should handle the literal.

Since: 2.12.0.0

Constructors

Escaped | The accompanying value will be escaped before inserting into the database. This is the correct default choice to use. Since: 2.12.0.0
Unescaped | The accompanying value will not be escaped when inserting into the database. This is potentially dangerous - use this with care. Since: 2.12.0.0
DbSpecific | The `DbSpecific` constructor corresponds to the legacy `PersistDbSpecific` constructor. We need to keep this around because old databases may have serialized JSON representations that reference this. We don't want to break the ability of a database to load rows. Since: 2.12.0.0

#### Instances

Instances details

Read LiteralType Source # |
Instance details Defined in Database.Persist.PersistValue Methods readsPrec :: Int -> ReadS LiteralType Source # readList :: ReadS [LiteralType] Source # readPrec :: ReadPrec LiteralType Source # readListPrec :: ReadPrec [LiteralType] Source #
Show LiteralType Source # |
Instance details Defined in Database.Persist.PersistValue Methods showsPrec :: Int -> LiteralType -> ShowS Source # show :: LiteralType -> String Source # showList :: [LiteralType] -> ShowS Source #
Eq LiteralType Source # |
Instance details Defined in Database.Persist.PersistValue Methods (==) :: LiteralType -> LiteralType -> Bool Source # (/=) :: LiteralType -> LiteralType -> Bool Source #
Ord LiteralType Source # |

Instance details

Defined in Database.Persist.PersistValue

Methods

compare :: LiteralType -> LiteralType -> Ordering Source #

(<) :: LiteralType -> LiteralType -> Bool Source #

(<=) :: LiteralType -> LiteralType -> Bool Source #

(>) :: LiteralType -> LiteralType -> Bool Source #

(>=) :: LiteralType -> LiteralType -> Bool Source #

max :: LiteralType -> LiteralType -> LiteralType Source #

min :: LiteralType -> LiteralType -> LiteralType Source #

data CompositeDef Source #

Constructors

CompositeDef |

Fields

- compositeFields :: !(NonEmpty FieldDef)
- compositeAttrs :: ![Attr]

#### Instances

Instances details

Read CompositeDef Source # |
Instance details Defined in Database.Persist.Types.Base Methods readsPrec :: Int -> ReadS CompositeDef Source # readList :: ReadS [CompositeDef] Source # readPrec :: ReadPrec CompositeDef Source # readListPrec :: ReadPrec [CompositeDef] Source #
Show CompositeDef Source # |
Instance details Defined in Database.Persist.Types.Base Methods showsPrec :: Int -> CompositeDef -> ShowS Source # show :: CompositeDef -> String Source # showList :: [CompositeDef] -> ShowS Source #
Eq CompositeDef Source # |
Instance details Defined in Database.Persist.Types.Base Methods (==) :: CompositeDef -> CompositeDef -> Bool Source # (/=) :: CompositeDef -> CompositeDef -> Bool Source #
Ord CompositeDef Source # |

Instance details

Defined in Database.Persist.Types.Base

Methods

compare :: CompositeDef -> CompositeDef -> Ordering Source #

(<) :: CompositeDef -> CompositeDef -> Bool Source #

(<=) :: CompositeDef -> CompositeDef -> Bool Source #

(>) :: CompositeDef -> CompositeDef -> Bool Source #

(>=) :: CompositeDef -> CompositeDef -> Bool Source #

max :: CompositeDef -> CompositeDef -> CompositeDef Source #

min :: CompositeDef -> CompositeDef -> CompositeDef Source #

Lift CompositeDef Source # |
Instance details Defined in Database.Persist.Types.Base Methods lift :: Quote m => CompositeDef -> m Exp Source # liftTyped :: forall (m :: Type -> Type). Quote m => CompositeDef -> Code m CompositeDef Source #

type Attr = Text Source #

data Checkmark Source #

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

Instances details

Bounded Checkmark Source # |
Instance details Defined in Database.Persist.Types.Base Methods minBound :: Checkmark Source # maxBound :: Checkmark Source #
Enum Checkmark Source # |

Instance details

Defined in Database.Persist.Types.Base

Methods

succ :: Checkmark -> Checkmark Source #

pred :: Checkmark -> Checkmark Source #

toEnum :: Int -> Checkmark Source #

fromEnum :: Checkmark -> Int Source #

enumFrom :: Checkmark -> [Checkmark] Source #

enumFromThen :: Checkmark -> Checkmark -> [Checkmark] Source #

enumFromTo :: Checkmark -> Checkmark -> [Checkmark] Source #

enumFromThenTo :: Checkmark -> Checkmark -> Checkmark -> [Checkmark] Source #

Read Checkmark Source # |
Instance details Defined in Database.Persist.Types.Base Methods readsPrec :: Int -> ReadS Checkmark Source # readList :: ReadS [Checkmark] Source # readPrec :: ReadPrec Checkmark Source # readListPrec :: ReadPrec [Checkmark] Source #
Show Checkmark Source # |
Instance details Defined in Database.Persist.Types.Base Methods showsPrec :: Int -> Checkmark -> ShowS Source # show :: Checkmark -> String Source # showList :: [Checkmark] -> ShowS Source #
Eq Checkmark Source # |
Instance details Defined in Database.Persist.Types.Base Methods (==) :: Checkmark -> Checkmark -> Bool Source # (/=) :: Checkmark -> Checkmark -> Bool Source #
Ord Checkmark Source # |

Instance details

Defined in Database.Persist.Types.Base

Methods

compare :: Checkmark -> Checkmark -> Ordering Source #

(<) :: Checkmark -> Checkmark -> Bool Source #

(<=) :: Checkmark -> Checkmark -> Bool Source #

(>) :: Checkmark -> Checkmark -> Bool Source #

(>=) :: Checkmark -> Checkmark -> Bool Source #

max :: Checkmark -> Checkmark -> Checkmark Source #

min :: Checkmark -> Checkmark -> Checkmark Source #

FromHttpApiData Checkmark Source # |
Instance details Defined in Database.Persist.Types.Base Methods parseUrlPiece :: Text -> Either Text Checkmark Source # parseHeader :: ByteString -> Either Text Checkmark Source # parseQueryParam :: Text -> Either Text Checkmark Source #
ToHttpApiData Checkmark Source # |
Instance details Defined in Database.Persist.Types.Base Methods toUrlPiece :: Checkmark -> Text Source # toEncodedUrlPiece :: Checkmark -> Builder Source # toHeader :: Checkmark -> ByteString Source # toQueryParam :: Checkmark -> Text Source # toEncodedQueryParam :: Checkmark -> Builder Source #
PathPiece Checkmark Source # |
Instance details Defined in Database.Persist.Types.Base Methods fromPathPiece :: Text -> Maybe Checkmark Source # toPathPiece :: Checkmark -> Text Source #
PersistField Checkmark Source # |
Instance details Defined in Database.Persist.Class.PersistField Methods toPersistValue :: Checkmark -> PersistValue Source # fromPersistValue :: PersistValue -> Either Text Checkmark Source #
PersistFieldSql Checkmark Source # |
Instance details Defined in Database.Persist.Sql.Class Methods sqlType :: Proxy Checkmark -> SqlType Source #

data EmbedEntityDef Source #

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 :: EntityNameHS
- embeddedFields :: [EmbedFieldDef]

#### Instances

Instances details

Read EmbedEntityDef Source # |
Instance details Defined in Database.Persist.Types.Base Methods readsPrec :: Int -> ReadS EmbedEntityDef Source # readList :: ReadS [EmbedEntityDef] Source # readPrec :: ReadPrec EmbedEntityDef Source # readListPrec :: ReadPrec [EmbedEntityDef] Source #
Show EmbedEntityDef Source # |
Instance details Defined in Database.Persist.Types.Base Methods showsPrec :: Int -> EmbedEntityDef -> ShowS Source # show :: EmbedEntityDef -> String Source # showList :: [EmbedEntityDef] -> ShowS Source #
Eq EmbedEntityDef Source # |
Instance details Defined in Database.Persist.Types.Base Methods (==) :: EmbedEntityDef -> EmbedEntityDef -> Bool Source # (/=) :: EmbedEntityDef -> EmbedEntityDef -> Bool Source #
Ord EmbedEntityDef Source # |

Instance details

Defined in Database.Persist.Types.Base

Methods

compare :: EmbedEntityDef -> EmbedEntityDef -> Ordering Source #

(<) :: EmbedEntityDef -> EmbedEntityDef -> Bool Source #

(<=) :: EmbedEntityDef -> EmbedEntityDef -> Bool Source #

(>) :: EmbedEntityDef -> EmbedEntityDef -> Bool Source #

(>=) :: EmbedEntityDef -> EmbedEntityDef -> Bool Source #

max :: EmbedEntityDef -> EmbedEntityDef -> EmbedEntityDef Source #

min :: EmbedEntityDef -> EmbedEntityDef -> EmbedEntityDef Source #

Lift EmbedEntityDef Source # |
Instance details Defined in Database.Persist.Types.Base Methods lift :: Quote m => EmbedEntityDef -> m Exp Source # liftTyped :: forall (m :: Type -> Type). Quote m => EmbedEntityDef -> Code m EmbedEntityDef Source #

data EmbedFieldDef Source #

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 :: FieldNameDB
- emFieldEmbed :: Maybe (Either SelfEmbed EntityNameHS)

#### Instances

Instances details

Read EmbedFieldDef Source # |
Instance details Defined in Database.Persist.Types.Base Methods readsPrec :: Int -> ReadS EmbedFieldDef Source # readList :: ReadS [EmbedFieldDef] Source # readPrec :: ReadPrec EmbedFieldDef Source # readListPrec :: ReadPrec [EmbedFieldDef] Source #
Show EmbedFieldDef Source # |
Instance details Defined in Database.Persist.Types.Base Methods showsPrec :: Int -> EmbedFieldDef -> ShowS Source # show :: EmbedFieldDef -> String Source # showList :: [EmbedFieldDef] -> ShowS Source #
Eq EmbedFieldDef Source # |
Instance details Defined in Database.Persist.Types.Base Methods (==) :: EmbedFieldDef -> EmbedFieldDef -> Bool Source # (/=) :: EmbedFieldDef -> EmbedFieldDef -> Bool Source #
Ord EmbedFieldDef Source # |

Instance details

Defined in Database.Persist.Types.Base

Methods

compare :: EmbedFieldDef -> EmbedFieldDef -> Ordering Source #

(<) :: EmbedFieldDef -> EmbedFieldDef -> Bool Source #

(<=) :: EmbedFieldDef -> EmbedFieldDef -> Bool Source #

(>) :: EmbedFieldDef -> EmbedFieldDef -> Bool Source #

(>=) :: EmbedFieldDef -> EmbedFieldDef -> Bool Source #

max :: EmbedFieldDef -> EmbedFieldDef -> EmbedFieldDef Source #

min :: EmbedFieldDef -> EmbedFieldDef -> EmbedFieldDef Source #

Lift EmbedFieldDef Source # |
Instance details Defined in Database.Persist.Types.Base Methods lift :: Quote m => EmbedFieldDef -> m Exp Source # liftTyped :: forall (m :: Type -> Type). Quote m => EmbedFieldDef -> Code m EmbedFieldDef Source #

type ExtraLine = [Text] Source #

type ForeignFieldDef = (FieldNameHS, FieldNameDB) Source #

Used instead of FieldDef to generate a smaller amount of code

data PersistException Source #

Constructors

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

#### Instances

Instances details

Exception PersistException Source # |
Instance details Defined in Database.Persist.Types.Base Methods toException :: PersistException -> SomeException Source # fromException :: SomeException -> Maybe PersistException Source # displayException :: PersistException -> String Source # backtraceDesired :: PersistException -> Bool Source #
Show PersistException Source # |
Instance details Defined in Database.Persist.Types.Base Methods showsPrec :: Int -> PersistException -> ShowS Source # show :: PersistException -> String Source # showList :: [PersistException] -> ShowS Source #

data ReferenceDef Source #

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

Constructors

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

#### Instances

Instances details

Read ReferenceDef Source # |
Instance details Defined in Database.Persist.Types.Base Methods readsPrec :: Int -> ReadS ReferenceDef Source # readList :: ReadS [ReferenceDef] Source # readPrec :: ReadPrec ReferenceDef Source # readListPrec :: ReadPrec [ReferenceDef] Source #
Show ReferenceDef Source # |
Instance details Defined in Database.Persist.Types.Base Methods showsPrec :: Int -> ReferenceDef -> ShowS Source # show :: ReferenceDef -> String Source # showList :: [ReferenceDef] -> ShowS Source #
Eq ReferenceDef Source # |
Instance details Defined in Database.Persist.Types.Base Methods (==) :: ReferenceDef -> ReferenceDef -> Bool Source # (/=) :: ReferenceDef -> ReferenceDef -> Bool Source #
Ord ReferenceDef Source # |

Instance details

Defined in Database.Persist.Types.Base

Methods

compare :: ReferenceDef -> ReferenceDef -> Ordering Source #

(<) :: ReferenceDef -> ReferenceDef -> Bool Source #

(<=) :: ReferenceDef -> ReferenceDef -> Bool Source #

(>) :: ReferenceDef -> ReferenceDef -> Bool Source #

(>=) :: ReferenceDef -> ReferenceDef -> Bool Source #

max :: ReferenceDef -> ReferenceDef -> ReferenceDef Source #

min :: ReferenceDef -> ReferenceDef -> ReferenceDef Source #

Lift ReferenceDef Source # |
Instance details Defined in Database.Persist.Types.Base Methods lift :: Quote m => ReferenceDef -> m Exp Source # liftTyped :: forall (m :: Type -> Type). Quote m => ReferenceDef -> Code m ReferenceDef Source #

data UpdateException Source #

Constructors

KeyNotFound String |
UpsertError String |

#### Instances

Instances details

Exception UpdateException Source # |
Instance details Defined in Database.Persist.Types.Base Methods toException :: UpdateException -> SomeException Source # fromException :: SomeException -> Maybe UpdateException Source # displayException :: UpdateException -> String Source # backtraceDesired :: UpdateException -> Bool Source #
Show UpdateException Source # |
Instance details Defined in Database.Persist.Types.Base Methods showsPrec :: Int -> UpdateException -> ShowS Source # show :: UpdateException -> String Source # showList :: [UpdateException] -> ShowS Source #

data WhyNullable Source #

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

Instances details

Show WhyNullable Source # |
Instance details Defined in Database.Persist.Types.Base Methods showsPrec :: Int -> WhyNullable -> ShowS Source # show :: WhyNullable -> String Source # showList :: [WhyNullable] -> ShowS Source #
Eq WhyNullable Source # |
Instance details Defined in Database.Persist.Types.Base Methods (==) :: WhyNullable -> WhyNullable -> Bool Source # (/=) :: WhyNullable -> WhyNullable -> Bool Source #

parseFieldAttrs :: [Text] -> [FieldAttr] Source #

Parse raw field attributes into structured form. Any unrecognized attributes will be preserved, identically as they are encountered, as `FieldAttrOther` values.

Since: 2.11.0.0