1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182
|
{-# LANGUAGE ConstraintKinds #-}
-- | This module exports all of the type classes in @persistent@ for operating
-- on the database backends.
--
-- @persistent@ offers methods that are abstract in the specific @backend@ type.
-- For SQL databases, this wil be 'Database.Persist.SqlBackend.SqlBackend'.
-- Other database backends will define their own types.
--
-- Methods and functions in this module have examples documented under an
-- "Example Usage" thing, that you need to click on to expand.
--
module Database.Persist.Class
(
-- * PersistStore
-- | The 'PersistStore', 'PersistStoreRead', and 'PersistStoreWrite' type
-- classes are used to define basic operations on the database. A database
-- that implements these classes is capable of being used as a simple
-- key-value store.
--
-- All the examples present here will be explained based on these schemas, datasets and functions:
--
-- = schema-1
--
-- #schema-persist-store-1#
--
-- > share [mkPersist sqlSettings, mkMigrate "migrateAll"] [persistLowerCase|
-- > User
-- > name String
-- > age Int
-- > deriving Show
-- > |]
--
-- = dataset-1
--
-- #dataset-persist-store-1#
--
-- > +----+-------+-----+
-- > | id | name | age |
-- > +----+-------+-----+
-- > | 1 | SPJ | 40 |
-- > +----+-------+-----+
-- > | 2 | Simon | 41 |
-- > +----+-------+-----+
PersistStore
, PersistStoreRead (..)
, PersistStoreWrite (..)
, PersistRecordBackend
, getJust
, getJustEntity
, getEntity
, belongsTo
, belongsToJust
, SafeToInsert
, insertEntity
, insertRecord
-- * PersistUnique
-- | The 'PersistUnique' type class is relevant for database backends that
-- offer uniqueness keys. Uniquenes keys allow us to perform operations like
-- 'getBy', 'deleteBy', as well as 'upsert' and 'putMany'.
--
-- All the examples present here will be explained based on these two schemas and the dataset:
--
-- = schema-1
-- This schema has single unique constraint.
--
-- #schema-persist-unique-1#
--
-- > share [mkPersist sqlSettings, mkMigrate "migrateAll"] [persistLowerCase|
-- > User
-- > name String
-- > age Int
-- > UniqueUserName name
-- > deriving Show
-- > |]
--
-- = schema-2
-- This schema has two unique constraints.
--
-- #schema-persist-unique-2#
--
-- > share [mkPersist sqlSettings, mkMigrate "migrateAll"] [persistLowerCase|
-- > User
-- > name String
-- > age Int
-- > UniqueUserName name
-- > UniqueUserAge age
-- > deriving Show
-- > |]
--
-- = dataset-1
--
-- #dataset-persist-unique-1#
--
-- > +-----+-----+-----+
-- > |id |name |age |
-- > +-----+-----+-----+
-- > |1 |SPJ |40 |
-- > +-----+-----+-----+
-- > |2 |Simon|41 |
-- > +-----+-----+-----+
, PersistUnique
, PersistUniqueRead (..)
, PersistUniqueWrite (..)
, OnlyOneUniqueKey (..)
, AtLeastOneUniqueKey (..)
, onlyOneUniqueDef
, NoUniqueKeysError
, MultipleUniqueKeysError
, getByValue
, insertBy
, insertUniqueEntity
, replaceUnique
, checkUnique
, checkUniqueUpdateable
, onlyUnique
-- * PersistQuery
-- | The 'PersistQuery' type class allows us to select lists and filter
-- database models. 'selectList' is the canonical read operation, and we
-- can write 'updateWhere' and 'deleteWhere' to modify based on filters.
, selectList
, selectKeys
, PersistQuery
, PersistQueryRead (..)
, PersistQueryWrite (..)
, selectSource
, selectKeysList
-- * PersistEntity
, PersistEntity (..)
, tabulateEntity
, SymbolToField (..)
-- * PersistField
, PersistField (..)
-- * PersistConfig
, PersistConfig (..)
, entityValues
-- * Lifting
, HasPersistBackend (..)
, withBaseBackend
, IsPersistBackend ()
, liftPersist
, BackendCompatible (..)
, withCompatibleBackend
-- * PersistCore
-- | 'PersistCore' is a type class that defines a default database
-- 'BackendKey' type. For SQL databases, this is currently an
-- auto-incrementing inteer primary key. For MongoDB, it is the default
-- ObjectID.
, PersistCore (..)
, ToBackendKey (..)
-- * JSON utilities
, keyValueEntityToJSON, keyValueEntityFromJSON
, entityIdToJSON, entityIdFromJSON
, toPersistValueJSON, fromPersistValueJSON
) where
import Database.Persist.Class.PersistConfig
import Database.Persist.Class.PersistEntity
import Database.Persist.Class.PersistField
import Database.Persist.Class.PersistQuery
import Database.Persist.Class.PersistStore
import Database.Persist.Class.PersistUnique
-- | A backwards-compatible alias for those that don't care about distinguishing between read and write queries.
-- It signifies the assumption that, by default, a backend can write as well as read.
type PersistUnique a = PersistUniqueWrite a
-- | A backwards-compatible alias for those that don't care about distinguishing between read and write queries.
-- It signifies the assumption that, by default, a backend can write as well as read.
type PersistQuery a = PersistQueryWrite a
-- | A backwards-compatible alias for those that don't care about distinguishing between read and write queries.
-- It signifies the assumption that, by default, a backend can write as well as read.
type PersistStore a = PersistStoreWrite a
|