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

Safe Haskell | None
Language | Haskell2010

Database.Persist.PersistValue

Description

This module contains an intermediate representation of values before the backends serialize them into explicit database types.

Since: 2.13.0.0

Synopsis

- 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
- fromPersistValueText :: PersistValue -> Either Text Text
- data LiteralType
  - = Escaped
  - | Unescaped
  - | DbSpecific

# Documentation

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 #

fromPersistValueText :: PersistValue -> Either Text Text 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 #