Hoogle Search

Within LTS Haskell 24.6 (ghc-9.10.2)

Note that Stackage only displays results for the latest LTS and Nightly snapshot. Learn more.

  1. data PersistException

    persistent-redis Database.Persist.Redis

    No documentation available.

  2. class PersistField a

    persistent-redis Database.Persist.Redis

    This class teaches Persistent how to take a custom type and marshal it to and from a PersistValue, allowing it to be stored in a database.

    Examples

    Simple Newtype
    You can use newtype to add more type safety/readability to a basis type like ByteString. In these cases, just derive PersistField and PersistFieldSql:
    {-# LANGUAGE GeneralizedNewtypeDeriving #-}
    
    newtype HashedPassword = HashedPassword ByteString
    deriving (Eq, Show, PersistField, PersistFieldSql)
    
    Smart Constructor Newtype
    In this example, we create a PersistField instance for a newtype following the "Smart Constructor" pattern.
    {-# LANGUAGE GeneralizedNewtypeDeriving #-}
    import qualified Data.Text as T
    import qualified Data.Char as C
    
    -- | An American Social Security Number
    newtype SSN = SSN Text
    deriving (Eq, Show, PersistFieldSql)
    
    mkSSN :: Text -> Either Text SSN
    mkSSN t = if (T.length t == 9) && (T.all C.isDigit t)
    then Right $ SSN t
    else Left $ "Invalid SSN: " <> t
    
    instance PersistField SSN where
    toPersistValue (SSN t) = PersistText t
    fromPersistValue (PersistText t) = mkSSN t
    -- Handle cases where the database does not give us PersistText
    fromPersistValue x = Left $ "File.hs: When trying to deserialize an SSN: expected PersistText, received: " <> T.pack (show x)
    
    Tips:
    • This file contain dozens of PersistField instances you can look at for examples.
    • Typically custom PersistField instances will only accept a single PersistValue constructor in fromPersistValue.
    • Internal PersistField instances accept a wide variety of PersistValues to accomodate e.g. storing booleans as integers, booleans or strings.
    • If you're making a custom instance and using a SQL database, you'll also need PersistFieldSql to specify the type of the database column.

  3. data PersistFilter

    persistent-redis Database.Persist.Redis

    No documentation available.

  4. PersistForeignConstraintUnmet :: Text -> PersistException

    persistent-redis Database.Persist.Redis

    No documentation available.

  5. PersistInt64 :: Int64 -> PersistValue

    persistent-redis Database.Persist.Redis

    No documentation available.

  6. PersistInvalidField :: Text -> PersistException

    persistent-redis Database.Persist.Redis

    No documentation available.

  7. PersistList :: [PersistValue] -> PersistValue

    persistent-redis Database.Persist.Redis

    No documentation available.

  8. pattern PersistLiteral :: ByteString -> PersistValue

    persistent-redis Database.Persist.Redis

    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.

  9. pattern PersistLiteralEscaped :: ByteString -> PersistValue

    persistent-redis Database.Persist.Redis

    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.

  10. PersistLiteral_ :: LiteralType -> ByteString -> PersistValue

    persistent-redis Database.Persist.Redis

    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.

Page 32 of many | Previous | Next