-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Type-safe, multi-backend data serialization. -- -- Type-safe, data serialization. You must use a specific backend in -- order to make this useful. @package persistent @version 0.7.0.1 module Database.Persist.Util nullable :: [Text] -> Bool deprecate :: String -> a -> a module Database.Persist.TH.Library apE :: Either x (y -> z) -> Either x y -> Either x z module Database.Persist.EntityDef newtype HaskellName HaskellName :: Text -> HaskellName unHaskellName :: HaskellName -> Text newtype DBName DBName :: Text -> DBName unDBName :: DBName -> Text newtype FieldType FieldType :: Text -> FieldType unFieldType :: FieldType -> Text type Attr = Text data EntityDef EntityDef :: HaskellName -> DBName -> DBName -> [Attr] -> [FieldDef] -> [UniqueDef] -> [Text] -> Map Text [ExtraLine] -> EntityDef entityHaskell :: EntityDef -> HaskellName entityDB :: EntityDef -> DBName entityID :: EntityDef -> DBName entityAttrs :: EntityDef -> [Attr] entityFields :: EntityDef -> [FieldDef] entityUniques :: EntityDef -> [UniqueDef] entityDerives :: EntityDef -> [Text] entityExtra :: EntityDef -> Map Text [ExtraLine] data FieldDef FieldDef :: HaskellName -> DBName -> FieldType -> [Attr] -> FieldDef fieldHaskell :: FieldDef -> HaskellName fieldDB :: FieldDef -> DBName fieldType :: FieldDef -> FieldType fieldAttrs :: FieldDef -> [Attr] data UniqueDef UniqueDef :: HaskellName -> DBName -> [(HaskellName, DBName)] -> UniqueDef uniqueHaskell :: UniqueDef -> HaskellName uniqueDBName :: UniqueDef -> DBName uniqueFields :: UniqueDef -> [(HaskellName, DBName)] type ExtraLine = [Text] instance Show HaskellName instance Eq HaskellName instance Read HaskellName instance Ord HaskellName instance Show DBName instance Eq DBName instance Read DBName instance Ord DBName instance Show FieldType instance Eq FieldType instance Read FieldType instance Ord FieldType instance Show FieldDef instance Eq FieldDef instance Read FieldDef instance Ord FieldDef instance Show UniqueDef instance Eq UniqueDef instance Read UniqueDef instance Ord UniqueDef instance Show EntityDef instance Eq EntityDef instance Read EntityDef instance Ord EntityDef module Database.Persist.Quasi -- | Parses a quasi-quoted syntax into a list of entity definitions. parse :: PersistSettings -> Text -> [EntityDef] data PersistSettings PersistSettings :: (Text -> Text) -> PersistSettings psToDBName :: PersistSettings -> Text -> Text upperCaseSettings :: PersistSettings lowerCaseSettings :: PersistSettings -- | API for database actions. The API deals with fields and entities. In -- SQL, a field corresponds to a column, and should be a single -- non-composite value. An entity corresponds to a SQL table, so an -- entity is a collection of fields. module Database.Persist.Store -- | 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 PersistObjectId :: 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 Text 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 EntityField val :: * -> *; type family PersistEntityBackend val :: (* -> *) -> * -> *; data family Unique val :: ((* -> *) -> * -> *) -> *; } persistFieldDef :: PersistEntity val => EntityField val typ -> FieldDef entityDef :: PersistEntity val => val -> EntityDef toPersistFields :: PersistEntity val => val -> [SomePersistField] fromPersistValues :: PersistEntity val => [PersistValue] -> Either Text val halfDefined :: PersistEntity val => val persistUniqueToFieldNames :: PersistEntity val => Unique val backend -> [(HaskellName, DBName)] persistUniqueToValues :: PersistEntity val => Unique val backend -> [PersistValue] persistUniqueKeys :: PersistEntity val => val -> [Unique val backend] persistIdField :: PersistEntity val => EntityField val (Key (PersistEntityBackend val) val) class (ResourceIO m, ResourceIO (b m)) => PersistStore b m insert :: (PersistStore b m, PersistEntity val) => val -> b m (Key b val) insertKey :: (PersistStore b m, PersistEntity val) => Key b val -> val -> b m () repsert :: (PersistStore b m, PersistEntity val) => Key b val -> val -> b m () replace :: (PersistStore b m, PersistEntity val) => Key b val -> val -> b m () delete :: (PersistStore b m, PersistEntity val) => Key b val -> b m () get :: (PersistStore b m, PersistEntity val) => Key b val -> b m (Maybe val) class PersistStore b m => PersistUnique b m getBy :: (PersistUnique b m, PersistEntity val) => Unique val b -> b m (Maybe (Entity b val)) deleteBy :: (PersistUnique b m, PersistEntity val) => Unique val b -> b m () insertUnique :: (PersistUnique b m, PersistEntity val) => val -> b m (Maybe (Key b val)) data PersistFilter Eq :: PersistFilter Ne :: PersistFilter Gt :: PersistFilter Lt :: PersistFilter Ge :: PersistFilter Le :: PersistFilter In :: PersistFilter NotIn :: PersistFilter BackendSpecificFilter :: Text -> PersistFilter data SomePersistField SomePersistField :: a -> SomePersistField -- | 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, PersistStore b m, PersistUnique b m) => v -> b m (Either (Entity b v) (Key b 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, PersistUnique b m) => v -> b m (Maybe (Entity b v)) -- | Same as get, but for a non-null (not Maybe) foreign key Unsafe unless -- your database is enforcing that the foreign key is valid getJust :: (PersistStore b m, PersistEntity val, Show (Key b val)) => Key b val -> b m val belongsTo :: (PersistStore b m, PersistEntity ent1, PersistEntity ent2) => (ent1 -> Maybe (Key b ent2)) -> ent1 -> b m (Maybe ent2) -- | same as belongsTo, but uses getJust and therefore is -- similarly unsafe belongsToJust :: (PersistStore b m, PersistEntity ent1, PersistEntity ent2) => (ent1 -> Key b ent2) -> ent1 -> b m ent2 -- | 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, PersistUnique b m) => val -> b m Bool class PersistEntity a => DeleteCascade a b m deleteCascade :: DeleteCascade a b m => Key b a -> b m () data PersistException -- | Generic Exception PersistError :: Text -> PersistException PersistMarshalError :: Text -> PersistException PersistInvalidField :: Text -> PersistException PersistForeignConstraintUnmet :: Text -> PersistException PersistMongoDBError :: Text -> PersistException PersistMongoDBUnsupported :: Text -> PersistException newtype Key backend :: ((* -> *) -> * -> *) entity Key :: PersistValue -> Key entity unKey :: Key entity -> PersistValue -- | Datatype that represents an entity, with both its key and its Haskell -- representation. -- -- When using the an SQL-based backend (such as SQLite or PostgreSQL), an -- Entity may take any number of columns depending on how many -- fields it has. In order to reconstruct your entity on the Haskell -- side, persistent needs all of your entity columns and in the -- right order. Note that you don't need to worry about this when using -- persistent's API since everything is handled correctly behind -- the scenes. -- -- However, if you want to issue a raw SQL command that returns an -- Entity, then you have to be careful with the column order. -- While you could use SELECT Entity.* WHERE ... and that would -- work most of the time, there are times when the order of the columns -- on your database is different from the order that persistent -- expects (for example, if you add a new field in the middle of you -- entity definition and then use the migration code -- -- persistent will expect the column to be in the middle, but -- your DBMS will put it as the last column). So, instead of using a -- query like the one above, you may use -- Database.Persist.GenericSql.rawSql (from the -- Database.Persist.GenericSql module) with its /entity selection -- placeholder/ (a double question mark ??). Using -- rawSql the query above must be written as SELECT ?? WHERE -- ... Then rawSql will replace ?? with the list -- of all columns that we need from your entity in the right order. If -- your query returns two entities (i.e. (Entity backend a, Entity -- backend b)), then you must you use SELECT ??, ?? WHERE -- ..., and so on. data Entity backend entity Entity :: Key backend entity -> entity -> Entity backend entity entityKey :: Entity backend entity -> Key backend entity entityVal :: Entity backend entity -> entity -- | Represents a value containing all the configuration options for a -- specific backend. This abstraction makes it easier to write code that -- can easily swap backends. class PersistConfig c where { type family PersistConfigBackend c :: (* -> *) -> * -> *; type family PersistConfigPool c; { applyEnv = return } } loadConfig :: PersistConfig c => Value -> Parser c applyEnv :: PersistConfig c => c -> IO c createPoolConfig :: PersistConfig c => c -> IO (PersistConfigPool c) runPool :: (PersistConfig c, ResourceIO m) => c -> PersistConfigBackend c m a -> PersistConfigPool c -> m a instance [overlap ok] Typeable PersistException instance [overlap ok] Typeable PersistValue instance [overlap ok] Typeable SqlType instance [overlap ok] Show PersistException instance [overlap ok] Show PersistValue instance [overlap ok] Read PersistValue instance [overlap ok] Eq PersistValue instance [overlap ok] Ord PersistValue instance [overlap ok] Show SqlType instance [overlap ok] Read SqlType instance [overlap ok] Eq SqlType instance [overlap ok] Show (Key backend entity) instance [overlap ok] Read (Key backend entity) instance [overlap ok] Eq (Key backend entity) instance [overlap ok] Ord (Key backend entity) instance [overlap ok] PersistField (Key backend entity) instance [overlap ok] Eq entity => Eq (Entity backend entity) instance [overlap ok] Ord entity => Ord (Entity backend entity) instance [overlap ok] Show entity => Show (Entity backend entity) instance [overlap ok] Read entity => Read (Entity backend entity) instance [overlap ok] Read PersistFilter instance [overlap ok] Show PersistFilter instance [overlap ok] PersistField PersistValue instance [overlap ok] PersistField SomePersistField instance [overlap ok] PersistField a => PersistField (Maybe a) instance [overlap ok] PersistField UTCTime instance [overlap ok] PersistField TimeOfDay instance [overlap ok] PersistField Day instance [overlap ok] PersistField Bool instance [overlap ok] PersistField Double instance [overlap ok] PersistField Word64 instance [overlap ok] PersistField Word32 instance [overlap ok] PersistField Word16 instance [overlap ok] PersistField Word8 instance [overlap ok] PersistField Int64 instance [overlap ok] PersistField Int32 instance [overlap ok] PersistField Int16 instance [overlap ok] PersistField Int8 instance [overlap ok] PersistField Int instance [overlap ok] PersistField Html instance [overlap ok] PersistField Text instance [overlap ok] PersistField ByteString instance [overlap ok] PersistField String instance [overlap ok] PathPiece PersistValue instance [overlap ok] Error PersistException instance [overlap ok] Exception PersistException -- | Code that is only needed for writing GenericSql backends. module Database.Persist.GenericSql.Internal data Connection Connection :: (Text -> IO Statement) -> (DBName -> [DBName] -> Either Text (Text, Text)) -> IORef (Map Text Statement) -> IO () -> (forall v. PersistEntity v => [EntityDef] -> (Text -> IO Statement) -> v -> IO (Either [Text] [(Bool, Text)])) -> ((Text -> IO Statement) -> IO ()) -> ((Text -> IO Statement) -> IO ()) -> ((Text -> IO Statement) -> IO ()) -> (DBName -> Text) -> Text -> Connection -- | table name, column names, either 1 or 2 statements to run prepare :: Connection -> Text -> IO Statement insertSql :: Connection -> DBName -> [DBName] -> Either Text (Text, Text) stmtMap :: Connection -> IORef (Map Text Statement) close :: Connection -> IO () migrateSql :: Connection -> forall v. PersistEntity v => [EntityDef] -> (Text -> IO Statement) -> v -> IO (Either [Text] [(Bool, Text)]) begin :: Connection -> (Text -> IO Statement) -> IO () commitC :: Connection -> (Text -> IO Statement) -> IO () rollbackC :: Connection -> (Text -> IO Statement) -> IO () escapeName :: Connection -> DBName -> Text noLimit :: Connection -> Text data Statement Statement :: IO () -> IO () -> ([PersistValue] -> IO ()) -> (forall m. ResourceIO m => [PersistValue] -> Source m [PersistValue]) -> Statement finalize :: Statement -> IO () reset :: Statement -> IO () execute :: Statement -> [PersistValue] -> IO () withStmt :: Statement -> forall m. ResourceIO m => [PersistValue] -> Source m [PersistValue] withSqlConn :: ResourceIO m => IO Connection -> (Connection -> m a) -> m a withSqlPool :: MonadIO m => IO Connection -> Int -> (Pool Connection -> m a) -> m a createSqlPool :: MonadIO m => IO Connection -> Int -> m (Pool Connection) -- | Create the list of columns for the given entity. mkColumns :: PersistEntity val => [EntityDef] -> val -> ([Column], [UniqueDef]) data Column Column :: DBName -> Bool -> SqlType -> Maybe Text -> (Maybe (DBName, DBName)) -> Column cName :: Column -> DBName cNull :: Column -> Bool cType :: Column -> SqlType cDefault :: Column -> Maybe Text cReference :: Column -> (Maybe (DBName, DBName)) module Database.Persist.GenericSql.Raw withStmt :: ResourceIO m => Text -> [PersistValue] -> Source (SqlPersist m) [PersistValue] 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 MonadPlus m => MonadPlus (SqlPersist m) instance MonadTransControl SqlPersist instance MonadBaseControl b m => MonadBaseControl b (SqlPersist m) instance MonadBase b m => MonadBase b (SqlPersist m) instance ResourceThrow m => ResourceThrow (SqlPersist m) module Database.Persist.GenericSql.Migration 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 :: (MonadBaseControl IO m, MonadIO m) => Migration (SqlPersist m) -> SqlPersist m () getMigration :: (MonadBaseControl IO m, MonadIO m) => Migration (SqlPersist m) -> SqlPersist m [Sql] runMigration :: (MonadIO m, MonadBaseControl IO 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 :: (MonadBaseControl IO m, MonadIO m) => Migration (SqlPersist m) -> SqlPersist m [Text] runMigrationUnsafe :: (MonadBaseControl IO m, MonadIO m) => Migration (SqlPersist m) -> SqlPersist m () migrate :: (MonadIO m, MonadBaseControl IO m, PersistEntity val) => [EntityDef] -> val -> Migration (SqlPersist m) -- | Perform a database commit. commit :: MonadIO m => SqlPersist m () -- | Perform a database rollback. rollback :: MonadIO m => 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 :: (MonadBaseControl IO m, MonadIO m) => SqlPersist m a -> Connection -> m a -- | Get a connection from the pool, run the given action, and then return -- the connection to the pool. runSqlPool :: (MonadBaseControl IO m, MonadIO m) => SqlPersist m a -> Pool Connection -> m a newtype Key backend :: ((* -> *) -> * -> *) entity Key :: PersistValue -> Key entity unKey :: Key entity -> PersistValue -- | Execute a raw SQL statement and return its results as a list. -- -- If you're using Entitys (which is quite likely), then -- you must use entity selection placeholders (double question -- mark, ??). These ?? placeholders are then replaced -- for the names of the columns that we need for your entities. You'll -- receive an error if you don't use the placeholders. Please see the -- Entitys documentation for more details. -- -- You may put value placeholders (question marks, ?) in your -- SQL query. These placeholders are then replaced by the values you pass -- on the second parameter, already correctly escaped. You may want to -- use toPersistValue to help you constructing the placeholder -- values. -- -- Since you're giving a raw SQL statement, you don't get any guarantees -- regarding safety. If rawSql is not able to parse the results of -- your query back, then an exception is raised. However, most common -- problems are mitigated by using the entity selection placeholder -- ??, and you shouldn't see any error at all if you're not -- using Single. rawSql :: (RawSql a, ResourceIO m) => Text -> [PersistValue] -> SqlPersist m [a] -- | Datatype that represents an entity, with both its key and its Haskell -- representation. -- -- When using the an SQL-based backend (such as SQLite or PostgreSQL), an -- Entity may take any number of columns depending on how many -- fields it has. In order to reconstruct your entity on the Haskell -- side, persistent needs all of your entity columns and in the -- right order. Note that you don't need to worry about this when using -- persistent's API since everything is handled correctly behind -- the scenes. -- -- However, if you want to issue a raw SQL command that returns an -- Entity, then you have to be careful with the column order. -- While you could use SELECT Entity.* WHERE ... and that would -- work most of the time, there are times when the order of the columns -- on your database is different from the order that persistent -- expects (for example, if you add a new field in the middle of you -- entity definition and then use the migration code -- -- persistent will expect the column to be in the middle, but -- your DBMS will put it as the last column). So, instead of using a -- query like the one above, you may use -- Database.Persist.GenericSql.rawSql (from the -- Database.Persist.GenericSql module) with its /entity selection -- placeholder/ (a double question mark ??). Using -- rawSql the query above must be written as SELECT ?? WHERE -- ... Then rawSql will replace ?? with the list -- of all columns that we need from your entity in the right order. If -- your query returns two entities (i.e. (Entity backend a, Entity -- backend b)), then you must you use SELECT ??, ?? WHERE -- ..., and so on. data Entity backend entity Entity :: Key backend entity -> entity -> Entity backend entity entityKey :: Entity backend entity -> Key backend entity entityVal :: Entity backend entity -> entity -- | A single column (see rawSql). Any PersistField may be -- used here, including PersistValue (which does not do any -- processing). newtype Single a Single :: a -> Single a unSingle :: Single a -> 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 :: (MonadBaseControl IO m, MonadIO m) => Migration (SqlPersist m) -> SqlPersist m () getMigration :: (MonadBaseControl IO m, MonadIO m) => Migration (SqlPersist m) -> SqlPersist m [Sql] runMigration :: (MonadIO m, MonadBaseControl IO 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 :: (MonadBaseControl IO m, MonadIO m) => Migration (SqlPersist m) -> SqlPersist m [Text] runMigrationUnsafe :: (MonadBaseControl IO m, MonadIO m) => Migration (SqlPersist m) -> SqlPersist m () migrate :: (MonadIO m, MonadBaseControl IO m, PersistEntity val) => [EntityDef] -> val -> Migration (SqlPersist m) -- | Perform a database commit. commit :: MonadIO m => SqlPersist m () -- | Perform a database rollback. rollback :: MonadIO m => SqlPersist m () instance Eq a => Eq (Single a) instance Ord a => Ord (Single a) instance Show a => Show (Single a) instance Read a => Read (Single a) instance (RawSql a, RawSql b, RawSql c, RawSql d, RawSql e, RawSql f, RawSql g, RawSql h) => RawSql (a, b, c, d, e, f, g, h) instance (RawSql a, RawSql b, RawSql c, RawSql d, RawSql e, RawSql f, RawSql g) => RawSql (a, b, c, d, e, f, g) instance (RawSql a, RawSql b, RawSql c, RawSql d, RawSql e, RawSql f) => RawSql (a, b, c, d, e, f) instance (RawSql a, RawSql b, RawSql c, RawSql d, RawSql e) => RawSql (a, b, c, d, e) instance (RawSql a, RawSql b, RawSql c, RawSql d) => RawSql (a, b, c, d) instance (RawSql a, RawSql b, RawSql c) => RawSql (a, b, c) instance (RawSql a, RawSql b) => RawSql (a, b) instance PersistEntity a => RawSql (Entity backend a) instance PersistField a => RawSql (Single a) instance ResourceIO m => PersistUnique SqlPersist m instance ResourceIO m => PersistStore SqlPersist m instance PathPiece (Key SqlPersist entity) module Database.Persist.Query.Internal class PersistStore b m => PersistQuery b m update :: (PersistQuery b m, PersistEntity val) => Key b val -> [Update val] -> b m () updateWhere :: (PersistQuery b m, PersistEntity val) => [Filter val] -> [Update val] -> b m () deleteWhere :: (PersistQuery b m, PersistEntity val) => [Filter val] -> b m () selectSource :: (PersistQuery b m, PersistEntity val) => [Filter val] -> [SelectOpt val] -> Source (b m) (Entity b val) selectFirst :: (PersistQuery b m, PersistEntity val) => [Filter val] -> [SelectOpt val] -> b m (Maybe (Entity b val)) selectKeys :: (PersistQuery b m, PersistEntity val) => [Filter val] -> Source (b m) (Key b val) count :: (PersistQuery b m, PersistEntity val) => [Filter val] -> b m Int -- | Call select but return the result as a list. selectList :: (PersistEntity val, PersistQuery b m) => [Filter val] -> [SelectOpt val] -> b m [Entity b val] data SelectOpt v Asc :: (EntityField v typ) -> SelectOpt v Desc :: (EntityField v typ) -> SelectOpt v OffsetBy :: Int -> SelectOpt v LimitTo :: Int -> SelectOpt v limitOffsetOrder :: PersistEntity val => [SelectOpt val] -> (Int, Int, [SelectOpt val]) -- | Filters which are available for select, updateWhere -- and deleteWhere. Each filter constructor specifies the field -- being filtered on, the type of comparison applied (equals, not equals, -- etc) and the argument for the comparison. data Filter v Filter :: EntityField v typ -> Either typ [typ] -> PersistFilter -> Filter v filterField :: Filter v -> EntityField v typ filterValue :: Filter v -> Either typ [typ] filterFilter :: Filter v -> PersistFilter -- | convenient for internal use, not needed for the API FilterAnd :: [Filter v] -> Filter v FilterOr :: [Filter v] -> Filter v data PersistUpdate Assign :: PersistUpdate Add :: PersistUpdate Subtract :: PersistUpdate Multiply :: PersistUpdate Divide :: PersistUpdate data Update v Update :: EntityField v typ -> typ -> PersistUpdate -> Update v updateField :: Update v -> EntityField v typ updateValue :: Update v -> typ updateUpdate :: Update v -> PersistUpdate updateFieldDef :: PersistEntity v => Update v -> FieldDef deleteCascadeWhere :: (DeleteCascade a b m, PersistQuery b m) => [Filter a] -> b m () instance Read PersistUpdate instance Show PersistUpdate instance Enum PersistUpdate instance Bounded PersistUpdate module Database.Persist.Query.GenericSql class PersistStore b m => PersistQuery b m update :: (PersistQuery b m, PersistEntity val) => Key b val -> [Update val] -> b m () updateWhere :: (PersistQuery b m, PersistEntity val) => [Filter val] -> [Update val] -> b m () deleteWhere :: (PersistQuery b m, PersistEntity val) => [Filter val] -> b m () selectSource :: (PersistQuery b m, PersistEntity val) => [Filter val] -> [SelectOpt val] -> Source (b m) (Entity b val) selectFirst :: (PersistQuery b m, PersistEntity val) => [Filter val] -> [SelectOpt val] -> b m (Maybe (Entity b val)) selectKeys :: (PersistQuery b m, PersistEntity val) => [Filter val] -> Source (b m) (Key b val) count :: (PersistQuery b m, PersistEntity val) => [Filter val] -> b m Int newtype SqlPersist m a SqlPersist :: ReaderT Connection m a -> SqlPersist m a unSqlPersist :: SqlPersist m a -> ReaderT Connection m a filterClauseNoWhere :: PersistEntity val => Bool -> Connection -> [Filter val] -> Text getFiltsValues :: PersistEntity val => Connection -> [Filter val] -> [PersistValue] -- | Equivalent to selectSource, but instead of getting the -- connection from the environment inside a SqlPersist monad, -- provide an explicit Connection. This can allow you to use the -- returned Source in an arbitrary monad. selectSourceConn :: (ResourceIO m, PersistEntity val) => Connection -> [Filter val] -> [SelectOpt val] -> Source m (Entity SqlPersist val) dummyFromFilts :: [Filter v] -> v orderClause :: PersistEntity val => Bool -> Connection -> SelectOpt val -> Text instance ResourceIO m => PersistQuery SqlPersist m module Database.Persist.Query class PersistStore b m => PersistQuery b m update :: (PersistQuery b m, PersistEntity val) => Key b val -> [Update val] -> b m () updateWhere :: (PersistQuery b m, PersistEntity val) => [Filter val] -> [Update val] -> b m () deleteWhere :: (PersistQuery b m, PersistEntity val) => [Filter val] -> b m () selectSource :: (PersistQuery b m, PersistEntity val) => [Filter val] -> [SelectOpt val] -> Source (b m) (Entity b val) selectFirst :: (PersistQuery b m, PersistEntity val) => [Filter val] -> [SelectOpt val] -> b m (Maybe (Entity b val)) selectKeys :: (PersistQuery b m, PersistEntity val) => [Filter val] -> Source (b m) (Key b val) count :: (PersistQuery b m, PersistEntity val) => [Filter val] -> b m Int -- | Call select but return the result as a list. selectList :: (PersistEntity val, PersistQuery b m) => [Filter val] -> [SelectOpt val] -> b m [Entity b val] deleteCascadeWhere :: (DeleteCascade a b m, PersistQuery b m) => [Filter a] -> b m () data SelectOpt v Asc :: (EntityField v typ) -> SelectOpt v Desc :: (EntityField v typ) -> SelectOpt v OffsetBy :: Int -> SelectOpt v LimitTo :: Int -> SelectOpt v -- | Filters which are available for select, updateWhere -- and deleteWhere. Each filter constructor specifies the field -- being filtered on, the type of comparison applied (equals, not equals, -- etc) and the argument for the comparison. data Filter v Filter :: EntityField v typ -> Either typ [typ] -> PersistFilter -> Filter v filterField :: Filter v -> EntityField v typ filterValue :: Filter v -> Either typ [typ] filterFilter :: Filter v -> PersistFilter -- | convenient for internal use, not needed for the API FilterAnd :: [Filter v] -> Filter v FilterOr :: [Filter v] -> Filter v (=., /=., *=., -=., +=.) :: PersistField typ => EntityField v typ -> typ -> Update v -- | assign a field a value -- -- assign a field by addition (+=) -- -- assign a field by subtraction (-=) -- -- assign a field by multiplication (*=) -- -- assign a field by division (/=) (==., >=., >., <=., <., !=.) :: PersistField typ => EntityField v typ -> typ -> Filter v (<-., /<-.) :: PersistField typ => EntityField v typ -> [typ] -> Filter v -- | In -- -- NotIn (||.) :: [Filter v] -> [Filter v] -> [Filter v] module Database.Persist.Query.Join class PersistQuery b m => RunJoin a b m where { type family Result a; } runJoin :: RunJoin a b m => a -> b m (Result a) data SelectOneMany backend one many SelectOneMany :: [Filter one] -> [SelectOpt one] -> [Filter many] -> [SelectOpt many] -> ([Key backend one] -> Filter many) -> (many -> Key backend one) -> Bool -> SelectOneMany backend one many somFilterOne :: SelectOneMany backend one many -> [Filter one] somOrderOne :: SelectOneMany backend one many -> [SelectOpt one] somFilterMany :: SelectOneMany backend one many -> [Filter many] somOrderMany :: SelectOneMany backend one many -> [SelectOpt many] somFilterKeys :: SelectOneMany backend one many -> [Key backend one] -> Filter many somGetKey :: SelectOneMany backend one many -> many -> Key backend one somIncludeNoMatch :: SelectOneMany backend one many -> Bool selectOneMany :: ([Key backend one] -> Filter many) -> (many -> Key backend one) -> SelectOneMany backend one many instance (PersistEntity one, PersistEntity many, Ord (Key backend one), PersistQuery backend monad) => RunJoin (SelectOneMany backend one many) backend monad module Database.Persist.Query.Join.Sql class RunJoin a runJoin :: (RunJoin a, ResourceIO m) => a -> SqlPersist m (Result a) instance (PersistEntity one, PersistEntity many, Eq (Key SqlPersist one)) => RunJoin (SelectOneMany SqlPersist 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 Text 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 EntityField val :: * -> *; type family PersistEntityBackend val :: (* -> *) -> * -> *; data family Unique val :: ((* -> *) -> * -> *) -> *; } persistFieldDef :: PersistEntity val => EntityField val typ -> FieldDef entityDef :: PersistEntity val => val -> EntityDef toPersistFields :: PersistEntity val => val -> [SomePersistField] fromPersistValues :: PersistEntity val => [PersistValue] -> Either Text val halfDefined :: PersistEntity val => val persistUniqueToFieldNames :: PersistEntity val => Unique val backend -> [(HaskellName, DBName)] persistUniqueToValues :: PersistEntity val => Unique val backend -> [PersistValue] persistUniqueKeys :: PersistEntity val => val -> [Unique val backend] persistIdField :: PersistEntity val => EntityField val (Key (PersistEntityBackend val) val) class (ResourceIO m, ResourceIO (b m)) => PersistStore b m insert :: (PersistStore b m, PersistEntity val) => val -> b m (Key b val) insertKey :: (PersistStore b m, PersistEntity val) => Key b val -> val -> b m () repsert :: (PersistStore b m, PersistEntity val) => Key b val -> val -> b m () replace :: (PersistStore b m, PersistEntity val) => Key b val -> val -> b m () delete :: (PersistStore b m, PersistEntity val) => Key b val -> b m () get :: (PersistStore b m, PersistEntity val) => Key b val -> b m (Maybe val) class PersistStore b m => PersistUnique b m getBy :: (PersistUnique b m, PersistEntity val) => Unique val b -> b m (Maybe (Entity b val)) deleteBy :: (PersistUnique b m, PersistEntity val) => Unique val b -> b m () insertUnique :: (PersistUnique b m, PersistEntity val) => val -> b m (Maybe (Key b val)) class PersistStore b m => PersistQuery b m update :: (PersistQuery b m, PersistEntity val) => Key b val -> [Update val] -> b m () updateWhere :: (PersistQuery b m, PersistEntity val) => [Filter val] -> [Update val] -> b m () deleteWhere :: (PersistQuery b m, PersistEntity val) => [Filter val] -> b m () selectSource :: (PersistQuery b m, PersistEntity val) => [Filter val] -> [SelectOpt val] -> Source (b m) (Entity b val) selectFirst :: (PersistQuery b m, PersistEntity val) => [Filter val] -> [SelectOpt val] -> b m (Maybe (Entity b val)) selectKeys :: (PersistQuery b m, PersistEntity val) => [Filter val] -> Source (b m) (Key b val) count :: (PersistQuery b m, PersistEntity val) => [Filter val] -> b m Int newtype Key backend :: ((* -> *) -> * -> *) entity Key :: PersistValue -> Key entity unKey :: Key entity -> PersistValue -- | Datatype that represents an entity, with both its key and its Haskell -- representation. -- -- When using the an SQL-based backend (such as SQLite or PostgreSQL), an -- Entity may take any number of columns depending on how many -- fields it has. In order to reconstruct your entity on the Haskell -- side, persistent needs all of your entity columns and in the -- right order. Note that you don't need to worry about this when using -- persistent's API since everything is handled correctly behind -- the scenes. -- -- However, if you want to issue a raw SQL command that returns an -- Entity, then you have to be careful with the column order. -- While you could use SELECT Entity.* WHERE ... and that would -- work most of the time, there are times when the order of the columns -- on your database is different from the order that persistent -- expects (for example, if you add a new field in the middle of you -- entity definition and then use the migration code -- -- persistent will expect the column to be in the middle, but -- your DBMS will put it as the last column). So, instead of using a -- query like the one above, you may use -- Database.Persist.GenericSql.rawSql (from the -- Database.Persist.GenericSql module) with its /entity selection -- placeholder/ (a double question mark ??). Using -- rawSql the query above must be written as SELECT ?? WHERE -- ... Then rawSql will replace ?? with the list -- of all columns that we need from your entity in the right order. If -- your query returns two entities (i.e. (Entity backend a, Entity -- backend b)), then you must you use SELECT ??, ?? WHERE -- ..., and so on. data Entity backend entity Entity :: Key backend entity -> entity -> Entity backend entity entityKey :: Entity backend entity -> Key backend entity entityVal :: Entity backend entity -> entity -- | 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, PersistStore b m, PersistUnique b m) => v -> b m (Either (Entity b v) (Key b v)) -- | Same as get, but for a non-null (not Maybe) foreign key Unsafe unless -- your database is enforcing that the foreign key is valid getJust :: (PersistStore b m, PersistEntity val, Show (Key b val)) => Key b val -> b m val belongsTo :: (PersistStore b m, PersistEntity ent1, PersistEntity ent2) => (ent1 -> Maybe (Key b ent2)) -> ent1 -> b m (Maybe ent2) -- | same as belongsTo, but uses getJust and therefore is -- similarly unsafe belongsToJust :: (PersistStore b m, PersistEntity ent1, PersistEntity ent2) => (ent1 -> Key b ent2) -> ent1 -> b m ent2 -- | 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, PersistUnique b m) => v -> b m (Maybe (Entity b 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, PersistUnique b m) => val -> b m Bool -- | Call select but return the result as a list. selectList :: (PersistEntity val, PersistQuery b m) => [Filter val] -> [SelectOpt val] -> b m [Entity b val] deleteCascadeWhere :: (DeleteCascade a b m, PersistQuery b m) => [Filter a] -> b m () data SelectOpt v Asc :: (EntityField v typ) -> SelectOpt v Desc :: (EntityField v typ) -> SelectOpt v OffsetBy :: Int -> SelectOpt v LimitTo :: Int -> SelectOpt v -- | Filters which are available for select, updateWhere -- and deleteWhere. Each filter constructor specifies the field -- being filtered on, the type of comparison applied (equals, not equals, -- etc) and the argument for the comparison. data Filter v Filter :: EntityField v typ -> Either typ [typ] -> PersistFilter -> Filter v filterField :: Filter v -> EntityField v typ filterValue :: Filter v -> Either typ [typ] filterFilter :: Filter v -> PersistFilter -- | convenient for internal use, not needed for the API FilterAnd :: [Filter v] -> Filter v FilterOr :: [Filter v] -> Filter v (=., /=., *=., -=., +=.) :: PersistField typ => EntityField v typ -> typ -> Update v -- | assign a field a value -- -- assign a field by addition (+=) -- -- assign a field by subtraction (-=) -- -- assign a field by multiplication (*=) -- -- assign a field by division (/=) (==., >=., >., <=., <., !=.) :: PersistField typ => EntityField v typ -> typ -> Filter v (<-., /<-.) :: PersistField typ => EntityField v typ -> [typ] -> Filter v -- | In -- -- NotIn (||.) :: [Filter v] -> [Filter v] -> [Filter v]