persistent-2.14.6.3: 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 #

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 # |
Instance details Defined in Database.Persist.PersistValue Methods parseJSON :: Value -> Parser PersistValue # parseJSONList :: Value -> Parser [PersistValue] # omittedField :: Maybe PersistValue #
ToJSON PersistValue # |
Instance details Defined in Database.Persist.PersistValue Methods toJSON :: PersistValue -> Value # toEncoding :: PersistValue -> Encoding # toJSONList :: [PersistValue] -> Value # toEncodingList :: [PersistValue] -> Encoding # omitField :: PersistValue -> Bool #
NFData PersistValue # | Since: 2.14.4.0
Instance details Defined in Database.Persist.PersistValue Methods rnf :: PersistValue -> () #
Read PersistValue # |
Instance details Defined in Database.Persist.PersistValue Methods readsPrec :: Int -> ReadS PersistValue # readList :: ReadS [PersistValue] # readPrec :: ReadPrec PersistValue # readListPrec :: ReadPrec [PersistValue] #
Show PersistValue # |
Instance details Defined in Database.Persist.PersistValue Methods showsPrec :: Int -> PersistValue -> ShowS # show :: PersistValue -> String # showList :: [PersistValue] -> ShowS #
Eq PersistValue # |
Instance details Defined in Database.Persist.PersistValue Methods (==) :: PersistValue -> PersistValue -> Bool # (/=) :: PersistValue -> PersistValue -> Bool #
Ord PersistValue # |
Instance details Defined in Database.Persist.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 #
FromHttpApiData PersistValue # |
Instance details Defined in Database.Persist.PersistValue Methods parseUrlPiece :: Text -> Either Text PersistValue # parseHeader :: ByteString -> Either Text PersistValue # parseQueryParam :: Text -> Either Text PersistValue #
ToHttpApiData PersistValue # |
Instance details Defined in Database.Persist.PersistValue Methods toUrlPiece :: PersistValue -> Text # toEncodedUrlPiece :: PersistValue -> Builder # toHeader :: PersistValue -> ByteString # toQueryParam :: PersistValue -> Text # toEncodedQueryParam :: PersistValue -> Builder #
PathPiece PersistValue # |
Instance details Defined in Database.Persist.PersistValue Methods fromPathPiece :: Text -> Maybe PersistValue # toPathPiece :: PersistValue -> Text #
PersistField PersistValue # |
Instance details Defined in Database.Persist.Class.PersistField Methods toPersistValue :: PersistValue -> PersistValue # fromPersistValue :: PersistValue -> Either Text PersistValue #
PersistFieldSql PersistValue # |
Instance details Defined in Database.Persist.Sql.Class Methods sqlType :: Proxy PersistValue -> SqlType #

fromPersistValueText :: PersistValue -> Either Text Text #

data LiteralType #

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 # |
Instance details Defined in Database.Persist.PersistValue Methods readsPrec :: Int -> ReadS LiteralType # readList :: ReadS [LiteralType] # readPrec :: ReadPrec LiteralType # readListPrec :: ReadPrec [LiteralType] #
Show LiteralType # |
Instance details Defined in Database.Persist.PersistValue Methods showsPrec :: Int -> LiteralType -> ShowS # show :: LiteralType -> String # showList :: [LiteralType] -> ShowS #
Eq LiteralType # |
Instance details Defined in Database.Persist.PersistValue Methods (==) :: LiteralType -> LiteralType -> Bool # (/=) :: LiteralType -> LiteralType -> Bool #
Ord LiteralType # |
Instance details Defined in Database.Persist.PersistValue Methods compare :: LiteralType -> LiteralType -> Ordering # (<) :: LiteralType -> LiteralType -> Bool # (<=) :: LiteralType -> LiteralType -> Bool # (>) :: LiteralType -> LiteralType -> Bool # (>=) :: LiteralType -> LiteralType -> Bool # max :: LiteralType -> LiteralType -> LiteralType # min :: LiteralType -> LiteralType -> LiteralType #