-- 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 1.0.1.2
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
type Attr = Text
data EntityDef
EntityDef :: HaskellName -> DBName -> DBName -> [Attr] -> [FieldDef] -> [UniqueDef] -> [Text] -> Map Text [ExtraLine] -> Bool -> 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]
entitySum :: EntityDef -> Bool
data FieldDef
FieldDef :: HaskellName -> DBName -> FieldType -> [Attr] -> FieldDef
fieldHaskell :: FieldDef -> HaskellName
fieldDB :: FieldDef -> DBName
fieldType :: FieldDef -> FieldType
fieldAttrs :: FieldDef -> [Attr]
data FieldType
-- | optional module, name
FTTypeCon :: (Maybe Text) -> Text -> FieldType
FTApp :: FieldType -> FieldType -> FieldType
FTList :: FieldType -> FieldType
data UniqueDef
UniqueDef :: HaskellName -> DBName -> [(HaskellName, DBName)] -> UniqueDef
uniqueHaskell :: UniqueDef -> HaskellName
uniqueDBName :: UniqueDef -> DBName
uniqueFields :: UniqueDef -> [(HaskellName, DBName)]
type ExtraLine = [Text]
stripId :: FieldType -> Maybe 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
instance Show Token
instance Eq Token
-- | 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
PersistZonedTime :: ZT -> 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
SqlInt64 :: SqlType
SqlReal :: SqlType
SqlBool :: SqlType
SqlDay :: SqlType
SqlTime :: SqlType
SqlDayTime :: SqlType
SqlDayTimeZoned :: SqlType
SqlBlob :: SqlType
-- | a backend-specific name
SqlOther :: Text -> SqlType
-- | A value which can be marshalled to and from a PersistValue.
class PersistField a where isNullable _ = False
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 (MonadBaseControl IO m, MonadBaseControl IO (backend m)) => PersistStore backend m
insert :: (PersistStore backend m, PersistEntity val) => val -> backend m (Key backend val)
insertKey :: (PersistStore backend m, PersistEntity val) => Key backend val -> val -> backend m ()
repsert :: (PersistStore backend m, PersistEntity val) => Key backend val -> val -> backend m ()
replace :: (PersistStore backend m, PersistEntity val) => Key backend val -> val -> backend m ()
delete :: (PersistStore backend m, PersistEntity val) => Key backend val -> backend m ()
get :: (PersistStore backend m, PersistEntity val) => Key backend val -> backend m (Maybe val)
class PersistStore backend m => PersistUnique backend m where insertUnique datum = do { isUnique <- checkUnique datum; if isUnique then Just `liftM` insert datum else return Nothing }
getBy :: (PersistUnique backend m, PersistEntityBackend val ~ backend, PersistEntity val) => Unique val backend -> backend m (Maybe (Entity val))
deleteBy :: (PersistUnique backend m, PersistEntity val) => Unique val backend -> backend m ()
insertUnique :: (PersistUnique backend m, backend ~ PersistEntityBackend val, PersistEntity val) => val -> backend m (Maybe (Key backend 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
-- | Avoid orphan instances.
newtype ZT
ZT :: ZonedTime -> ZT
-- | 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 backend m, PersistUnique backend m, backend ~ PersistEntityBackend v) => v -> backend m (Either (Entity v) (Key backend 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 backend m, PersistEntityBackend v ~ backend) => v -> backend m (Maybe (Entity 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 backend m, PersistEntity val, Show (Key backend val)) => Key backend val -> backend m val
belongsTo :: (PersistStore backend m, PersistEntity ent1, PersistEntity ent2) => (ent1 -> Maybe (Key backend ent2)) -> ent1 -> backend m (Maybe ent2)
-- | same as belongsTo, but uses getJust and therefore is
-- similarly unsafe
belongsToJust :: (PersistStore backend m, PersistEntity ent1, PersistEntity ent2) => (ent1 -> Key backend ent2) -> ent1 -> backend 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 :: (PersistEntityBackend val ~ backend, PersistEntity val, PersistUnique backend m) => val -> backend m Bool
class PersistEntity a => DeleteCascade a backend m
deleteCascade :: DeleteCascade a backend m => Key backend a -> backend 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 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 entity
Entity :: Key (PersistEntityBackend entity) entity -> entity -> Entity entity
entityKey :: Entity entity -> Key (PersistEntityBackend entity) entity
entityVal :: Entity entity -> entity
getPersistMap :: PersistValue -> Either Text [(Text, PersistValue)]
listToJSON :: [PersistValue] -> Text
mapToJSON :: [(Text, PersistValue)] -> Text
-- | 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, MonadBaseControl IO m, MonadIO m) => c -> PersistConfigBackend c m a -> PersistConfigPool c -> m a
instance [overlap ok] Typeable PersistException
instance [overlap ok] Typeable ZT
instance [overlap ok] Typeable PersistValue
instance [overlap ok] Typeable SqlType
instance [overlap ok] Show PersistException
instance [overlap ok] Show ZT
instance [overlap ok] Read ZT
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] Ord 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 entity)
instance [overlap ok] Ord entity => Ord (Entity entity)
instance [overlap ok] Show entity => Show (Entity entity)
instance [overlap ok] Read entity => Read (Entity entity)
instance [overlap ok] Read PersistFilter
instance [overlap ok] Show PersistFilter
instance [overlap ok] PersistField PersistValue
instance [overlap ok] FromJSON (Key backend entity)
instance [overlap ok] ToJSON (Key backend entity)
instance [overlap ok] PersistField SomePersistField
instance [overlap ok] PersistField v => PersistField (Map Text v)
instance [overlap ok] (PersistField a, PersistField b) => PersistField (a, b)
instance [overlap ok] (Ord a, PersistField a) => PersistField (Set a)
instance [overlap ok] PersistField a => PersistField [a]
instance [overlap ok] PersistField a => PersistField (Maybe a)
instance [overlap ok] PersistField ZonedTime
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] FromJSON PersistValue
instance [overlap ok] ToJSON PersistValue
instance [overlap ok] PathPiece PersistValue
instance [overlap ok] Ord ZT
instance [overlap ok] Eq ZT
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. MonadResource m => [PersistValue] -> Source m [PersistValue]) -> Statement
finalize :: Statement -> IO ()
reset :: Statement -> IO ()
execute :: Statement -> [PersistValue] -> IO ()
withStmt :: Statement -> forall m. MonadResource m => [PersistValue] -> Source m [PersistValue]
withSqlConn :: (MonadIO m, MonadBaseControl IO 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 Integer -> (Maybe (DBName, DBName)) -> Column
cName :: Column -> DBName
cNull :: Column -> Bool
cType :: Column -> SqlType
cDefault :: Column -> Maybe Text
cMaxLen :: Column -> Maybe Integer
cReference :: Column -> (Maybe (DBName, DBName))
logSQL :: Q Exp
instance Eq Column
instance Ord Column
instance Show Column
module Database.Persist.GenericSql.Raw
withStmt :: (MonadSqlPersist m, MonadResource m) => Text -> [PersistValue] -> Source m [PersistValue]
execute :: MonadSqlPersist m => Text -> [PersistValue] -> 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 :: MonadSqlPersist m => Text -> 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 MonadLogger m => MonadLogger (SqlPersist m)
instance MonadSqlPersist m => MonadSqlPersist (ResourceT m)
instance (MonadIO m, MonadLogger m) => MonadSqlPersist (SqlPersist m)
instance MonadResource m => MonadResource (SqlPersist m)
instance MonadTransControl SqlPersist
instance MonadBaseControl backend m => MonadBaseControl backend (SqlPersist m)
instance MonadBase backend m => MonadBase backend (SqlPersist m)
instance MonadThrow m => MonadThrow (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, MonadLogger 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, MonadLogger m) => Migration (SqlPersist m) -> SqlPersist m [Text]
runMigrationUnsafe :: (MonadBaseControl IO m, MonadIO m, MonadLogger 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, MonadUnsafeIO m, MonadThrow m, MonadIO m, MonadBaseControl IO m, MonadLogger 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 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 entity
Entity :: Key (PersistEntityBackend entity) entity -> entity -> Entity entity
entityKey :: Entity entity -> Key (PersistEntityBackend entity) entity
entityVal :: Entity 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
-- | Class for data types that may be retrived from a rawSql query.
class RawSql 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, MonadLogger 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, MonadLogger m) => Migration (SqlPersist m) -> SqlPersist m [Text]
runMigrationUnsafe :: (MonadBaseControl IO m, MonadIO m, MonadLogger 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 RawSql a => RawSql (Maybe a)
instance PersistEntity a => RawSql (Entity a)
instance PersistField a => RawSql (Single a)
instance (MonadBaseControl IO m, MonadUnsafeIO m, MonadIO m, MonadThrow m, MonadLogger m) => PersistUnique SqlPersist m
instance (MonadBaseControl IO m, MonadIO m, MonadThrow m, MonadUnsafeIO m, MonadLogger m) => PersistStore SqlPersist m
instance PathPiece (Key SqlPersist entity)
module Database.Persist.Query.Internal
class PersistStore backend m => PersistQuery backend m where updateGet key ups = do { update key ups; get key >>= maybe (liftBase $ throwIO $ KeyNotFound $ show key) return } selectFirst filts opts = runResourceT $ selectSource filts ((LimitTo 1) : opts) $$ head
update :: (PersistQuery backend m, PersistEntity val) => Key backend val -> [Update val] -> backend m ()
updateGet :: (PersistQuery backend m, PersistEntity val) => Key backend val -> [Update val] -> backend m val
updateWhere :: (PersistQuery backend m, PersistEntity val) => [Filter val] -> [Update val] -> backend m ()
deleteWhere :: (PersistQuery backend m, PersistEntity val) => [Filter val] -> backend m ()
selectSource :: (PersistQuery backend m, PersistEntity val, PersistEntityBackend val ~ backend) => [Filter val] -> [SelectOpt val] -> Source (ResourceT (backend m)) (Entity val)
selectFirst :: (PersistQuery backend m, PersistEntity val, PersistEntityBackend val ~ backend) => [Filter val] -> [SelectOpt val] -> backend m (Maybe (Entity val))
selectKeys :: (PersistQuery backend m, PersistEntity val) => [Filter val] -> [SelectOpt val] -> Source (ResourceT (backend m)) (Key backend val)
count :: (PersistQuery backend m, PersistEntity val) => [Filter val] -> backend m Int
-- | Call selectSource but return the result as a list.
selectList :: (PersistEntity val, PersistQuery backend m, PersistEntityBackend val ~ backend) => [Filter val] -> [SelectOpt val] -> backend m [Entity val]
-- | Call selectKeys but return the result as a list.
selectKeysList :: (PersistEntity val, PersistQuery b m, PersistEntityBackend val ~ b) => [Filter val] -> [SelectOpt val] -> b m [Key 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 backend m, PersistQuery backend m) => [Filter a] -> backend m ()
data UpdateGetException
KeyNotFound :: String -> UpdateGetException
instance Typeable UpdateGetException
instance Read PersistUpdate
instance Show PersistUpdate
instance Enum PersistUpdate
instance Bounded PersistUpdate
instance Exception UpdateGetException
instance Show UpdateGetException
module Database.Persist.Query.GenericSql
class PersistStore backend m => PersistQuery backend m where updateGet key ups = do { update key ups; get key >>= maybe (liftBase $ throwIO $ KeyNotFound $ show key) return } selectFirst filts opts = runResourceT $ selectSource filts ((LimitTo 1) : opts) $$ head
update :: (PersistQuery backend m, PersistEntity val) => Key backend val -> [Update val] -> backend m ()
updateGet :: (PersistQuery backend m, PersistEntity val) => Key backend val -> [Update val] -> backend m val
updateWhere :: (PersistQuery backend m, PersistEntity val) => [Filter val] -> [Update val] -> backend m ()
deleteWhere :: (PersistQuery backend m, PersistEntity val) => [Filter val] -> backend m ()
selectSource :: (PersistQuery backend m, PersistEntity val, PersistEntityBackend val ~ backend) => [Filter val] -> [SelectOpt val] -> Source (ResourceT (backend m)) (Entity val)
selectFirst :: (PersistQuery backend m, PersistEntity val, PersistEntityBackend val ~ backend) => [Filter val] -> [SelectOpt val] -> backend m (Maybe (Entity val))
selectKeys :: (PersistQuery backend m, PersistEntity val) => [Filter val] -> [SelectOpt val] -> Source (ResourceT (backend m)) (Key backend val)
count :: (PersistQuery backend m, PersistEntity val) => [Filter val] -> backend 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
filterClauseNoWhereOrNull :: 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 :: (PersistEntity val, SqlPersist ~ PersistEntityBackend val, MonadThrow m, MonadUnsafeIO m, MonadIO m, MonadBaseControl IO m, MonadLogger m) => Connection -> [Filter val] -> [SelectOpt val] -> Source (ResourceT m) (Entity val)
dummyFromFilts :: [Filter v] -> v
orderClause :: PersistEntity val => Bool -> Connection -> SelectOpt val -> Text
instance (MonadThrow m, MonadIO m, MonadUnsafeIO m, MonadBaseControl IO m, MonadLogger m) => PersistQuery SqlPersist m
module Database.Persist.Query
class PersistStore backend m => PersistQuery backend m where updateGet key ups = do { update key ups; get key >>= maybe (liftBase $ throwIO $ KeyNotFound $ show key) return } selectFirst filts opts = runResourceT $ selectSource filts ((LimitTo 1) : opts) $$ head
update :: (PersistQuery backend m, PersistEntity val) => Key backend val -> [Update val] -> backend m ()
updateGet :: (PersistQuery backend m, PersistEntity val) => Key backend val -> [Update val] -> backend m val
updateWhere :: (PersistQuery backend m, PersistEntity val) => [Filter val] -> [Update val] -> backend m ()
deleteWhere :: (PersistQuery backend m, PersistEntity val) => [Filter val] -> backend m ()
selectSource :: (PersistQuery backend m, PersistEntity val, PersistEntityBackend val ~ backend) => [Filter val] -> [SelectOpt val] -> Source (ResourceT (backend m)) (Entity val)
selectFirst :: (PersistQuery backend m, PersistEntity val, PersistEntityBackend val ~ backend) => [Filter val] -> [SelectOpt val] -> backend m (Maybe (Entity val))
selectKeys :: (PersistQuery backend m, PersistEntity val) => [Filter val] -> [SelectOpt val] -> Source (ResourceT (backend m)) (Key backend val)
count :: (PersistQuery backend m, PersistEntity val) => [Filter val] -> backend m Int
-- | Call selectSource but return the result as a list.
selectList :: (PersistEntity val, PersistQuery backend m, PersistEntityBackend val ~ backend) => [Filter val] -> [SelectOpt val] -> backend m [Entity val]
-- | Call selectKeys but return the result as a list.
selectKeysList :: (PersistEntity val, PersistQuery b m, PersistEntityBackend val ~ b) => [Filter val] -> [SelectOpt val] -> b m [Key b val]
deleteCascadeWhere :: (DeleteCascade a backend m, PersistQuery backend m) => [Filter a] -> backend 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
-- | assign a field a value
(=.) :: PersistField typ => EntityField v typ -> typ -> Update v
-- | assign a field by addition (+=)
(+=.) :: PersistField typ => EntityField v typ -> typ -> Update v
-- | assign a field by subtraction (-=)
(-=.) :: PersistField typ => EntityField v typ -> typ -> Update v
-- | assign a field by multiplication (*=)
(*=.) :: PersistField typ => EntityField v typ -> typ -> Update v
-- | assign a field by division (/=)
(/=.) :: PersistField typ => EntityField v typ -> typ -> Update v
(==.) :: PersistField typ => EntityField v typ -> typ -> Filter v
(!=.) :: PersistField typ => EntityField v typ -> typ -> Filter v
(<.) :: PersistField typ => EntityField v typ -> typ -> Filter v
(>.) :: PersistField typ => EntityField v typ -> typ -> Filter v
(<=.) :: PersistField typ => EntityField v typ -> typ -> Filter v
(>=.) :: PersistField typ => EntityField v typ -> typ -> Filter v
-- | In
(<-.) :: PersistField typ => EntityField v typ -> [typ] -> Filter v
-- | NotIn
(/<-.) :: PersistField typ => EntityField v typ -> [typ] -> Filter v
-- | the OR of two lists of filters
(||.) :: [Filter v] -> [Filter v] -> [Filter v]
module Database.Persist.Query.Join
class PersistQuery backend m => RunJoin a backend m where type family Result a
runJoin :: RunJoin a backend m => a -> backend 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, backend ~ PersistEntityBackend one, backend ~ PersistEntityBackend many) => RunJoin (SelectOneMany backend one many) backend monad
module Database.Persist.Query.Join.Sql
class RunJoin a
runJoin :: (RunJoin a, MonadThrow m, MonadUnsafeIO m, MonadIO m, MonadBaseControl IO m, MonadLogger 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 where isNullable _ = False
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 (MonadBaseControl IO m, MonadBaseControl IO (backend m)) => PersistStore backend m
insert :: (PersistStore backend m, PersistEntity val) => val -> backend m (Key backend val)
insertKey :: (PersistStore backend m, PersistEntity val) => Key backend val -> val -> backend m ()
repsert :: (PersistStore backend m, PersistEntity val) => Key backend val -> val -> backend m ()
replace :: (PersistStore backend m, PersistEntity val) => Key backend val -> val -> backend m ()
delete :: (PersistStore backend m, PersistEntity val) => Key backend val -> backend m ()
get :: (PersistStore backend m, PersistEntity val) => Key backend val -> backend m (Maybe val)
class PersistStore backend m => PersistUnique backend m where insertUnique datum = do { isUnique <- checkUnique datum; if isUnique then Just `liftM` insert datum else return Nothing }
getBy :: (PersistUnique backend m, PersistEntityBackend val ~ backend, PersistEntity val) => Unique val backend -> backend m (Maybe (Entity val))
deleteBy :: (PersistUnique backend m, PersistEntity val) => Unique val backend -> backend m ()
insertUnique :: (PersistUnique backend m, backend ~ PersistEntityBackend val, PersistEntity val) => val -> backend m (Maybe (Key backend val))
class PersistStore backend m => PersistQuery backend m where updateGet key ups = do { update key ups; get key >>= maybe (liftBase $ throwIO $ KeyNotFound $ show key) return } selectFirst filts opts = runResourceT $ selectSource filts ((LimitTo 1) : opts) $$ head
update :: (PersistQuery backend m, PersistEntity val) => Key backend val -> [Update val] -> backend m ()
updateGet :: (PersistQuery backend m, PersistEntity val) => Key backend val -> [Update val] -> backend m val
updateWhere :: (PersistQuery backend m, PersistEntity val) => [Filter val] -> [Update val] -> backend m ()
deleteWhere :: (PersistQuery backend m, PersistEntity val) => [Filter val] -> backend m ()
selectSource :: (PersistQuery backend m, PersistEntity val, PersistEntityBackend val ~ backend) => [Filter val] -> [SelectOpt val] -> Source (ResourceT (backend m)) (Entity val)
selectFirst :: (PersistQuery backend m, PersistEntity val, PersistEntityBackend val ~ backend) => [Filter val] -> [SelectOpt val] -> backend m (Maybe (Entity val))
selectKeys :: (PersistQuery backend m, PersistEntity val) => [Filter val] -> [SelectOpt val] -> Source (ResourceT (backend m)) (Key backend val)
count :: (PersistQuery backend m, PersistEntity val) => [Filter val] -> backend 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 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 entity
Entity :: Key (PersistEntityBackend entity) entity -> entity -> Entity entity
entityKey :: Entity entity -> Key (PersistEntityBackend entity) entity
entityVal :: Entity 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 backend m, PersistUnique backend m, backend ~ PersistEntityBackend v) => v -> backend m (Either (Entity v) (Key backend 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 backend m, PersistEntity val, Show (Key backend val)) => Key backend val -> backend m val
belongsTo :: (PersistStore backend m, PersistEntity ent1, PersistEntity ent2) => (ent1 -> Maybe (Key backend ent2)) -> ent1 -> backend m (Maybe ent2)
-- | same as belongsTo, but uses getJust and therefore is
-- similarly unsafe
belongsToJust :: (PersistStore backend m, PersistEntity ent1, PersistEntity ent2) => (ent1 -> Key backend ent2) -> ent1 -> backend 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 backend m, PersistEntityBackend v ~ backend) => v -> backend m (Maybe (Entity 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 :: (PersistEntityBackend val ~ backend, PersistEntity val, PersistUnique backend m) => val -> backend m Bool
-- | Call selectSource but return the result as a list.
selectList :: (PersistEntity val, PersistQuery backend m, PersistEntityBackend val ~ backend) => [Filter val] -> [SelectOpt val] -> backend m [Entity val]
deleteCascadeWhere :: (DeleteCascade a backend m, PersistQuery backend m) => [Filter a] -> backend 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
-- | assign a field a value
(=.) :: PersistField typ => EntityField v typ -> typ -> Update v
-- | assign a field by addition (+=)
(+=.) :: PersistField typ => EntityField v typ -> typ -> Update v
-- | assign a field by subtraction (-=)
(-=.) :: PersistField typ => EntityField v typ -> typ -> Update v
-- | assign a field by multiplication (*=)
(*=.) :: PersistField typ => EntityField v typ -> typ -> Update v
-- | assign a field by division (/=)
(/=.) :: PersistField typ => EntityField v typ -> typ -> Update v
(==.) :: PersistField typ => EntityField v typ -> typ -> Filter v
(!=.) :: PersistField typ => EntityField v typ -> typ -> Filter v
(<.) :: PersistField typ => EntityField v typ -> typ -> Filter v
(>.) :: PersistField typ => EntityField v typ -> typ -> Filter v
(<=.) :: PersistField typ => EntityField v typ -> typ -> Filter v
(>=.) :: PersistField typ => EntityField v typ -> typ -> Filter v
-- | In
(<-.) :: PersistField typ => EntityField v typ -> [typ] -> Filter v
-- | NotIn
(/<-.) :: PersistField typ => EntityField v typ -> [typ] -> Filter v
-- | the OR of two lists of filters
(||.) :: [Filter v] -> [Filter v] -> [Filter v]