-- 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.5.1 module Database.Persist.TH.Library apE :: Either x (y -> z) -> Either x y -> Either x z module Database.Persist.Util nullable :: [String] -> Bool deprecate :: String -> a -> a -- | 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 PersistText :: Text -> PersistValue PersistByteString :: ByteString -> PersistValue PersistInt64 :: Int64 -> PersistValue PersistDouble :: Double -> PersistValue PersistBool :: Bool -> PersistValue PersistDay :: Day -> PersistValue PersistTimeOfDay :: TimeOfDay -> PersistValue PersistUTCTime :: UTCTime -> PersistValue PersistNull :: PersistValue PersistList :: [PersistValue] -> PersistValue PersistMap :: [(Text, PersistValue)] -> PersistValue -- | intended especially for MongoDB backend. FIXME: rename to -- PersistObjectId PersistForeignKey :: ByteString -> 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 -- | FIXME 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 Show (Key val) => 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 => PersistValue -> Key val fromPersistKey :: PersistEntity val => Key val -> PersistValue 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 persistUpdateToUpdate :: PersistEntity val => Update val -> PersistUpdate 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)) selectEnum :: (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 PersistUpdate Update :: PersistUpdate Add :: PersistUpdate Subtract :: PersistUpdate Multiply :: PersistUpdate Divide :: PersistUpdate 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)] -- | Insert a value, checking for conflicts with any unique constraints. If -- a duplicate exists in the database, it is returned as Left. -- Otherwise, the new Key is returned as Right. insertBy :: (PersistEntity v, PersistBackend m) => v -> m (Either (Key v, v) (Key v)) -- | A modification of getBy, which takes the PersistEntity -- itself instead of a Unique value. Returns a value matching -- one of the unique keys. This function makes the most sense on -- entities with a single Unique constructor. getByValue :: (PersistEntity v, PersistBackend m) => v -> m (Maybe (Key v, v)) -- | 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 PersistValue instance Typeable SqlType instance Typeable PersistException instance Show PersistValue instance Read PersistValue instance Eq PersistValue instance Ord PersistValue instance Show SqlType instance Read SqlType instance Eq SqlType instance Show EntityDef instance Read PersistFilter instance Show PersistFilter instance Read PersistOrder instance Show PersistOrder instance Show PersistException instance Read PersistUpdate instance Show PersistUpdate instance PersistField PersistValue instance Exception PersistException 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 module Database.Persist.Quasi -- | Parses a quasi-quoted syntax into a list of entity definitions. parse :: String -> [EntityDef] -- | Code that is only needed for writing GenericSql backends. module Database.Persist.GenericSql.Internal data Connection Connection :: (Text -> IO Statement) -> (RawName -> [RawName] -> Either Text (Text, Text)) -> IORef (Map Text Statement) -> IO () -> (forall v. PersistEntity v => (Text -> IO Statement) -> v -> IO (Either [Text] [(Bool, Text)])) -> ((Text -> IO Statement) -> IO ()) -> ((Text -> IO Statement) -> IO ()) -> ((Text -> IO Statement) -> IO ()) -> (RawName -> String) -> String -> Connection prepare :: Connection -> Text -> IO Statement insertSql :: Connection -> RawName -> [RawName] -> Either Text (Text, Text) stmtMap :: Connection -> IORef (Map Text Statement) close :: Connection -> IO () migrateSql :: Connection -> forall v. PersistEntity v => (Text -> IO Statement) -> v -> IO (Either [Text] [(Bool, Text)]) begin :: Connection -> (Text -> IO Statement) -> IO () commit :: Connection -> (Text -> IO Statement) -> IO () rollback :: Connection -> (Text -> IO Statement) -> IO () escapeName :: Connection -> RawName -> String noLimit :: Connection -> String data Statement Statement :: IO () -> IO () -> ([PersistValue] -> IO ()) -> (forall a m. MonadControlIO m => [PersistValue] -> (RowPopper m -> m a) -> m a) -> Statement finalize :: Statement -> IO () reset :: Statement -> IO () execute :: Statement -> [PersistValue] -> IO () withStmt :: Statement -> forall a m. MonadControlIO m => [PersistValue] -> (RowPopper m -> m a) -> m a withSqlConn :: MonadControlIO m => IO Connection -> (Connection -> m a) -> m a withSqlPool :: MonadControlIO 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 filterClause :: PersistEntity val => Bool -> Connection -> Filter val -> String getFieldName :: EntityDef -> String -> RawName dummyFromFilts :: [Filter v] -> v getFiltsValues :: PersistEntity val => [Filter val] -> [PersistValue] orderClause :: PersistEntity val => Bool -> Connection -> Order val -> String instance Eq RawName instance Ord RawName module Database.Persist.GenericSql.Raw withStmt :: MonadControlIO m => Text -> [PersistValue] -> (RowPopper (SqlPersist m) -> SqlPersist m a) -> SqlPersist m a execute :: MonadIO m => Text -> [PersistValue] -> SqlPersist m () newtype SqlPersist m a SqlPersist :: ReaderT Connection m a -> SqlPersist m a unSqlPersist :: SqlPersist m a -> ReaderT Connection m a getStmt' :: Connection -> Text -> IO Statement getStmt :: MonadIO m => Text -> SqlPersist m Statement instance Monad m => Monad (SqlPersist m) instance MonadIO m => MonadIO (SqlPersist m) instance MonadTrans SqlPersist instance Functor m => Functor (SqlPersist m) instance Applicative m => Applicative (SqlPersist m) instance MonadControlIO m => MonadControlIO (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 unSqlPersist :: SqlPersist m a -> ReaderT Connection m a data Connection type ConnectionPool = Pool Connection data Statement runSqlConn :: MonadControlIO m => SqlPersist m a -> Connection -> m a runSqlPool :: MonadControlIO m => SqlPersist m a -> Pool Connection -> m a type Migration m = WriterT [Text] (WriterT CautiousMigration m) () parseMigration :: Monad m => Migration m -> m (Either [Text] CautiousMigration) parseMigration' :: Monad m => Migration m -> m (CautiousMigration) printMigration :: MonadControlIO m => Migration (SqlPersist m) -> SqlPersist m () getMigration :: MonadControlIO m => Migration (SqlPersist m) -> SqlPersist m [Sql] runMigration :: MonadControlIO m => Migration (SqlPersist m) -> SqlPersist m () -- | Same as runMigration, but returns a list of the SQL commands -- executed instead of printing them to stderr. runMigrationSilent :: MonadControlIO m => Migration (SqlPersist m) -> SqlPersist m [Text] runMigrationUnsafe :: MonadControlIO m => Migration (SqlPersist m) -> SqlPersist m () migrate :: (MonadControlIO m, PersistEntity val) => val -> Migration (SqlPersist m) instance MonadControlIO m => PersistBackend (SqlPersist m) module Database.Persist.Join class RunJoin a where { type family Result a; } runJoin :: (RunJoin a, PersistBackend m) => a -> m (Result a) data SelectOneMany one many SelectOneMany :: [Filter one] -> [Order one] -> [Filter many] -> [Order many] -> ([Key one] -> Filter many) -> (many -> Key one) -> Bool -> SelectOneMany one many somFilterOne :: SelectOneMany one many -> [Filter one] somOrderOne :: SelectOneMany one many -> [Order one] somFilterMany :: SelectOneMany one many -> [Filter many] somOrderMany :: SelectOneMany one many -> [Order many] somFilterKeys :: SelectOneMany one many -> [Key one] -> Filter many somGetKey :: SelectOneMany one many -> many -> Key one somIncludeNoMatch :: SelectOneMany one many -> Bool selectOneMany :: ([Key one] -> Filter many) -> (many -> Key one) -> SelectOneMany one many instance (PersistEntity one, PersistEntity many, Ord (Key one)) => RunJoin (SelectOneMany one many) module Database.Persist.Join.Sql class RunJoin a runJoin :: (RunJoin a, MonadControlIO m) => a -> SqlPersist m (Result a) instance (PersistEntity one, PersistEntity many, Eq (Key one)) => RunJoin (SelectOneMany one many) 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 Show (Key val) => 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 => PersistValue -> Key val fromPersistKey :: PersistEntity val => Key val -> PersistValue 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 persistUpdateToUpdate :: PersistEntity val => Update val -> PersistUpdate 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)) selectEnum :: (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 -- | 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)] -- | Insert a value, checking for conflicts with any unique constraints. If -- a duplicate exists in the database, it is returned as Left. -- Otherwise, the new Key is returned as Right. insertBy :: (PersistEntity v, PersistBackend m) => v -> m (Either (Key v, v) (Key v)) -- | A modification of getBy, which takes the PersistEntity -- itself instead of a Unique value. Returns a value matching -- one of the unique keys. This function makes the most sense on -- entities with a single Unique constructor. getByValue :: (PersistEntity v, PersistBackend m) => v -> m (Maybe (Key v, v)) -- | 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