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

Safe Haskell | None
Language | Haskell2010

Database.Persist.FieldDef

Contents

- The `FieldDef` type
  - Setters
  - Helpers
- `FieldCascade`

Description

Since: 2.13.0.0

Synopsis

- data FieldDef
- setFieldAttrs :: [FieldAttr] -> FieldDef -> FieldDef
- overFieldAttrs :: ([FieldAttr] -> [FieldAttr]) -> FieldDef -> FieldDef
- addFieldAttr :: FieldAttr -> FieldDef -> FieldDef
- isFieldNullable :: FieldDef -> IsNullable
- isFieldMaybe :: FieldDef -> Bool
- isFieldNotGenerated :: FieldDef -> Bool
- isHaskellField :: FieldDef -> Bool
- data FieldCascade = FieldCascade {
  - fcOnUpdate :: !(Maybe CascadeAction)
  - fcOnDelete :: !(Maybe CascadeAction)
  }
- renderFieldCascade :: FieldCascade -> Text
- renderCascadeAction :: CascadeAction -> Text
- noCascade :: FieldCascade
- data CascadeAction
  - = Cascade
  - | Restrict
  - | SetNull
  - | SetDefault

# The `FieldDef` type

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.

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

## Setters

setFieldAttrs :: [FieldAttr] -> FieldDef -> FieldDef Source #

Replace the `FieldDef` `FieldAttr` with the new list.

Since: 2.13.0.0

overFieldAttrs :: ([FieldAttr] -> [FieldAttr]) -> FieldDef -> FieldDef Source #

Modify the list of field attributes.

Since: 2.13.0.0

addFieldAttr :: FieldAttr -> FieldDef -> FieldDef Source #

Add an attribute to the list of field attributes.

Since: 2.13.0.0

## Helpers

isFieldNullable :: FieldDef -> IsNullable Source #

Check if the field definition is nullable

Since: 2.13.0.0

isFieldMaybe :: FieldDef -> Bool Source #

Check if the field is `Maybe a`

Since: 2.13.0.0

isFieldNotGenerated :: FieldDef -> Bool Source #

isHaskellField :: FieldDef -> Bool Source #

Returns `True` if the `FieldDef` does not have a `MigrationOnly` or `SafeToRemove` flag from the QuasiQuoter.

Since: 2.13.0.0

# `FieldCascade`

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 #

renderFieldCascade :: FieldCascade -> Text Source #

Renders a `FieldCascade` value such that it can be used in SQL migrations.

Since: 2.11.0

renderCascadeAction :: CascadeAction -> Text Source #

Render a `CascadeAction` to `Text` such that it can be used in a SQL command.

Since: 2.11.0

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 #