-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Type-safe, non-relational, multi-backend persistence. -- -- This library provides just the general interface and helper functions. -- You must use a specific backend in order to make this useful. @package persistent @version 0.2.1 module Database.Persist.Pool createPool :: (MonadCatchIO m) => IO a -> (a -> IO ()) -> Int -> (Pool a -> m b) -> m b withPool :: (MonadCatchIO m) => Pool a -> (a -> m b) -> m (Maybe b) withPool' :: (MonadCatchIO m) => Pool a -> (a -> m b) -> m b data Pool a instance Typeable PoolExhaustedException instance Show PoolExhaustedException instance Exception PoolExhaustedException -- | This defines the API for performing database actions. There are two -- levels to this API: dealing with fields, and dealing with entities. In -- SQL, a field corresponds to a column, and should be a single, -- non-composite value. An entity corresponds to a SQL table. In other -- words: An entity is a collection of fields. module Database.Persist.Base -- | A raw value which can be stored in any backend and can be marshalled -- to and from a PersistField. data PersistValue PersistString :: String -> PersistValue PersistByteString :: ByteString -> PersistValue PersistInt64 :: Int64 -> PersistValue PersistDouble :: Double -> PersistValue PersistBool :: Bool -> PersistValue PersistDay :: Day -> PersistValue PersistTimeOfDay :: TimeOfDay -> PersistValue PersistUTCTime :: UTCTime -> PersistValue PersistNull :: PersistValue -- | 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. data SqlType SqlString :: SqlType SqlInt32 :: SqlType -- | 8-byte integer; should be renamed SqlInt64 SqlInteger :: SqlType SqlReal :: SqlType SqlBool :: SqlType SqlDay :: SqlType SqlTime :: SqlType SqlDayTime :: SqlType SqlBlob :: SqlType -- | A value which can be marshalled to and from a PersistValue. class PersistField a toPersistValue :: (PersistField a) => a -> PersistValue fromPersistValue :: (PersistField a) => PersistValue -> Either String a sqlType :: (PersistField a) => a -> SqlType isNullable :: (PersistField a) => a -> Bool -- | A single database entity. For example, if writing a blog application, -- a blog entry would be an entry, containing fields such as title and -- content. class PersistEntity val where { data family Key val; data family Update val; data family Filter val; data family Order val; data family Unique val; } entityDef :: (PersistEntity val) => val -> EntityDef toPersistFields :: (PersistEntity val) => val -> [SomePersistField] fromPersistValues :: (PersistEntity val) => [PersistValue] -> Either String val halfDefined :: (PersistEntity val) => val toPersistKey :: (PersistEntity val) => Int64 -> Key val fromPersistKey :: (PersistEntity val) => Key val -> Int64 showPersistKey :: (PersistEntity val) => Key val -> String persistFilterToFieldName :: (PersistEntity val) => Filter val -> String persistFilterToFilter :: (PersistEntity val) => Filter val -> PersistFilter persistFilterToValue :: (PersistEntity val) => Filter val -> Either PersistValue [PersistValue] persistOrderToFieldName :: (PersistEntity val) => Order val -> String persistOrderToOrder :: (PersistEntity val) => Order val -> PersistOrder persistUpdateToFieldName :: (PersistEntity val) => Update val -> String persistUpdateToValue :: (PersistEntity val) => Update val -> PersistValue persistUniqueToFieldNames :: (PersistEntity val) => Unique val -> [String] persistUniqueToValues :: (PersistEntity val) => Unique val -> [PersistValue] persistUniqueKeys :: (PersistEntity val) => val -> [Unique val] data EntityDef EntityDef :: String -> [String] -> [(String, String, [String])] -> [(String, [String])] -> [String] -> EntityDef entityName :: EntityDef -> String entityAttribs :: EntityDef -> [String] -- | name, type, attribs entityColumns :: EntityDef -> [(String, String, [String])] -- | name, columns entityUniques :: EntityDef -> [(String, [String])] entityDerives :: EntityDef -> [String] class (Monad m) => PersistBackend m insert :: (PersistBackend m, PersistEntity val) => val -> m (Key val) replace :: (PersistBackend m, PersistEntity val) => Key val -> val -> m () update :: (PersistBackend m, PersistEntity val) => Key val -> [Update val] -> m () updateWhere :: (PersistBackend m, PersistEntity val) => [Filter val] -> [Update val] -> m () delete :: (PersistBackend m, PersistEntity val) => Key val -> m () deleteBy :: (PersistBackend m, PersistEntity val) => Unique val -> m () deleteWhere :: (PersistBackend m, PersistEntity val) => [Filter val] -> m () get :: (PersistBackend m, PersistEntity val) => Key val -> m (Maybe val) getBy :: (PersistBackend m, PersistEntity val) => Unique val -> m (Maybe (Key val, val)) select :: (PersistBackend m, PersistEntity val) => [Filter val] -> [Order val] -> Int -> Int -> Enumerator (Key val, val) m a selectKeys :: (PersistBackend m, PersistEntity val) => [Filter val] -> Enumerator (Key val) m a count :: (PersistBackend m, PersistEntity val) => [Filter val] -> m Int data PersistFilter Eq :: PersistFilter Ne :: PersistFilter Gt :: PersistFilter Lt :: PersistFilter Ge :: PersistFilter Le :: PersistFilter In :: PersistFilter NotIn :: PersistFilter data PersistOrder Asc :: PersistOrder Desc :: PersistOrder data SomePersistField SomePersistField :: a -> SomePersistField -- | Call select but return the result as a list. selectList :: (PersistEntity val, PersistBackend m, Monad m) => [Filter val] -> [Order val] -> Int -> Int -> m [(Key val, val)] -- | Try to insert the given entity; if another entity exists with the same -- unique key, return that entity; otherwise, return the newly created -- entity. insertBy :: (PersistEntity val, PersistBackend m) => val -> m (Key val, val) -- | Check whether there are any conflicts for unique keys with this entity -- and existing entities in the database. -- -- Returns True if the entity would be unique, and could thus -- safely be inserted; returns False on a conflict. checkUnique :: (PersistEntity val, PersistBackend m) => val -> m Bool class (PersistEntity a) => DeleteCascade a deleteCascade :: (DeleteCascade a, PersistBackend m) => Key a -> m () deleteCascadeWhere :: (DeleteCascade a, PersistBackend m) => [Filter a] -> m () data PersistException PersistMarshalException :: String -> PersistException instance Typeable PersistException instance Typeable SqlType instance Typeable PersistValue instance Show PersistException instance Read PersistOrder instance Show PersistOrder instance Read PersistFilter instance Show PersistFilter instance Show EntityDef instance Show SqlType instance Read SqlType instance Eq SqlType instance Show PersistValue instance Read PersistValue instance Eq PersistValue instance Exception PersistException instance Lift PersistOrder instance Lift PersistFilter instance Lift EntityDef instance PersistField SomePersistField instance (PersistField a) => PersistField (Maybe a) instance PersistField UTCTime instance PersistField TimeOfDay instance PersistField Day instance PersistField Bool instance PersistField Double instance PersistField Word64 instance PersistField Word32 instance PersistField Word16 instance PersistField Word8 instance PersistField Int64 instance PersistField Int32 instance PersistField Int16 instance PersistField Int8 instance PersistField Int instance PersistField Html instance PersistField Text instance PersistField ByteString instance PersistField String -- | This module provides utilities for creating backends. Regular users do -- not need to use this module. module Database.Persist.TH -- | Create data types and appropriate PersistEntity instances for -- the given EntityDefs. Works well with the persist quasi-quoter. mkPersist :: [EntityDef] -> Q [Dec] share2 :: ([EntityDef] -> Q [Dec]) -> ([EntityDef] -> Q [Dec]) -> [EntityDef] -> Q [Dec] mkSave :: String -> [EntityDef] -> Q [Dec] mkDeleteCascade :: [EntityDef] -> Q [Dec] module Database.Persist.Quasi -- | Converts a quasi-quoted syntax into a list of entity definitions, to -- be used as input to the template haskell generation code (mkPersist). persist :: QuasiQuoter -- | Code that is only needed for writing GenericSql backends. module Database.Persist.GenericSql.Internal data Connection Connection :: (String -> IO Statement) -> (RawName -> [RawName] -> Either String (String, String)) -> IORef (Map String Statement) -> IO () -> (forall v. (PersistEntity v) => (String -> IO Statement) -> v -> IO (Either [String] [(Bool, String)])) -> ((String -> IO Statement) -> IO ()) -> ((String -> IO Statement) -> IO ()) -> ((String -> IO Statement) -> IO ()) -> (RawName -> String) -> String -> Connection prepare :: Connection -> String -> IO Statement insertSql :: Connection -> RawName -> [RawName] -> Either String (String, String) stmtMap :: Connection -> IORef (Map String Statement) close :: Connection -> IO () migrateSql :: Connection -> forall v. (PersistEntity v) => (String -> IO Statement) -> v -> IO (Either [String] [(Bool, String)]) begin :: Connection -> (String -> IO Statement) -> IO () commit :: Connection -> (String -> IO Statement) -> IO () rollback :: Connection -> (String -> IO Statement) -> IO () escapeName :: Connection -> RawName -> String noLimit :: Connection -> String data Statement Statement :: IO () -> IO () -> ([PersistValue] -> IO ()) -> (forall a m. (MonadCatchIO m) => [PersistValue] -> (RowPopper m -> m a) -> m a) -> Statement finalize :: Statement -> IO () reset :: Statement -> IO () execute :: Statement -> [PersistValue] -> IO () withStmt :: Statement -> forall a m. (MonadCatchIO m) => [PersistValue] -> (RowPopper m -> m a) -> m a withSqlConn :: (MonadCatchIO m) => IO Connection -> (Connection -> m a) -> m a withSqlPool :: (MonadCatchIO m) => IO Connection -> Int -> (Pool Connection -> m a) -> m a type RowPopper m = m (Maybe [PersistValue]) -- | Create the list of columns for the given entity. mkColumns :: (PersistEntity val) => val -> ([Column], [UniqueDef]) data Column Column :: RawName -> Bool -> SqlType -> Maybe String -> (Maybe (RawName, RawName)) -> Column cName :: Column -> RawName cNull :: Column -> Bool cType :: Column -> SqlType cDefault :: Column -> Maybe String cReference :: Column -> (Maybe (RawName, RawName)) type UniqueDef = (RawName, [RawName]) refName :: RawName -> RawName -> RawName tableColumns :: EntityDef -> [(RawName, String, [String])] rawFieldName :: (String, String, [String]) -> RawName rawTableName :: EntityDef -> RawName newtype RawName RawName :: String -> RawName unRawName :: RawName -> String instance Eq RawName instance Ord RawName module Database.Persist.GenericSql.Raw withStmt :: (MonadCatchIO m) => String -> [PersistValue] -> (RowPopper (SqlPersist m) -> SqlPersist m a) -> SqlPersist m a execute :: (MonadIO m) => String -> [PersistValue] -> SqlPersist m () newtype SqlPersist m a SqlPersist :: (ReaderT Connection m a) -> SqlPersist m a getStmt' :: Connection -> String -> IO Statement getStmt :: (MonadIO m) => String -> SqlPersist m Statement instance (Monad m) => Monad (SqlPersist m) instance (MonadIO m) => MonadIO (SqlPersist m) instance (MonadCatchIO m) => MonadCatchIO (SqlPersist m) instance MonadTrans SqlPersist instance (Functor m) => Functor (SqlPersist m) instance (Applicative m) => Applicative (SqlPersist m) -- | This is a helper module for creating SQL backends. Regular users do -- not need to use this module. module Database.Persist.GenericSql newtype SqlPersist m a SqlPersist :: (ReaderT Connection m a) -> SqlPersist m a data Connection type ConnectionPool = Pool Connection data Statement runSqlConn :: (MonadCatchIO m) => SqlPersist m a -> Connection -> m a runSqlPool :: (MonadCatchIO m) => SqlPersist m a -> Pool Connection -> m a type Migration m = WriterT [String] (WriterT CautiousMigration m) () parseMigration :: (Monad m) => Migration m -> m (Either [String] CautiousMigration) parseMigration' :: (Monad m) => Migration m -> m (CautiousMigration) printMigration :: (MonadCatchIO m) => Migration (SqlPersist m) -> SqlPersist m () getMigration :: (MonadCatchIO m) => Migration (SqlPersist m) -> SqlPersist m [Sql] runMigration :: (MonadCatchIO m) => Migration (SqlPersist m) -> SqlPersist m () runMigrationUnsafe :: (MonadCatchIO m) => Migration (SqlPersist m) -> SqlPersist m () migrate :: (MonadCatchIO m, PersistEntity val) => val -> Migration (SqlPersist m) instance (MonadCatchIO m) => PersistBackend (SqlPersist m) module Database.Persist -- | A value which can be marshalled to and from a PersistValue. class PersistField a toPersistValue :: (PersistField a) => a -> PersistValue fromPersistValue :: (PersistField a) => PersistValue -> Either String a sqlType :: (PersistField a) => a -> SqlType isNullable :: (PersistField a) => a -> Bool -- | A single database entity. For example, if writing a blog application, -- a blog entry would be an entry, containing fields such as title and -- content. class PersistEntity val where { data family Key val; data family Update val; data family Filter val; data family Order val; data family Unique val; } entityDef :: (PersistEntity val) => val -> EntityDef toPersistFields :: (PersistEntity val) => val -> [SomePersistField] fromPersistValues :: (PersistEntity val) => [PersistValue] -> Either String val halfDefined :: (PersistEntity val) => val toPersistKey :: (PersistEntity val) => Int64 -> Key val fromPersistKey :: (PersistEntity val) => Key val -> Int64 showPersistKey :: (PersistEntity val) => Key val -> String persistFilterToFieldName :: (PersistEntity val) => Filter val -> String persistFilterToFilter :: (PersistEntity val) => Filter val -> PersistFilter persistFilterToValue :: (PersistEntity val) => Filter val -> Either PersistValue [PersistValue] persistOrderToFieldName :: (PersistEntity val) => Order val -> String persistOrderToOrder :: (PersistEntity val) => Order val -> PersistOrder persistUpdateToFieldName :: (PersistEntity val) => Update val -> String persistUpdateToValue :: (PersistEntity val) => Update val -> PersistValue persistUniqueToFieldNames :: (PersistEntity val) => Unique val -> [String] persistUniqueToValues :: (PersistEntity val) => Unique val -> [PersistValue] persistUniqueKeys :: (PersistEntity val) => val -> [Unique val] class (Monad m) => PersistBackend m insert :: (PersistBackend m, PersistEntity val) => val -> m (Key val) replace :: (PersistBackend m, PersistEntity val) => Key val -> val -> m () update :: (PersistBackend m, PersistEntity val) => Key val -> [Update val] -> m () updateWhere :: (PersistBackend m, PersistEntity val) => [Filter val] -> [Update val] -> m () delete :: (PersistBackend m, PersistEntity val) => Key val -> m () deleteBy :: (PersistBackend m, PersistEntity val) => Unique val -> m () deleteWhere :: (PersistBackend m, PersistEntity val) => [Filter val] -> m () get :: (PersistBackend m, PersistEntity val) => Key val -> m (Maybe val) getBy :: (PersistBackend m, PersistEntity val) => Unique val -> m (Maybe (Key val, val)) select :: (PersistBackend m, PersistEntity val) => [Filter val] -> [Order val] -> Int -> Int -> Enumerator (Key val, val) m a selectKeys :: (PersistBackend m, PersistEntity val) => [Filter val] -> Enumerator (Key val) m a count :: (PersistBackend m, PersistEntity val) => [Filter val] -> m Int -- | Create data types and appropriate PersistEntity instances for -- the given EntityDefs. Works well with the persist quasi-quoter. mkPersist :: [EntityDef] -> Q [Dec] -- | Converts a quasi-quoted syntax into a list of entity definitions, to -- be used as input to the template haskell generation code (mkPersist). persist :: QuasiQuoter -- | Call select but return the result as a list. selectList :: (PersistEntity val, PersistBackend m, Monad m) => [Filter val] -> [Order val] -> Int -> Int -> m [(Key val, val)] -- | Try to insert the given entity; if another entity exists with the same -- unique key, return that entity; otherwise, return the newly created -- entity. insertBy :: (PersistEntity val, PersistBackend m) => val -> m (Key val, val) -- | Check whether there are any conflicts for unique keys with this entity -- and existing entities in the database. -- -- Returns True if the entity would be unique, and could thus -- safely be inserted; returns False on a conflict. checkUnique :: (PersistEntity val, PersistBackend m) => val -> m Bool