úÎ!éÿà      !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~€‚ƒ„…†‡ˆ‰Š‹ŒŽ‘’“”•–—˜™š›œžŸ ¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ      !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~€‚ƒ„…†‡ˆ‰Š‹ŒŽ‘’“”•–—˜™š›œžŸ ¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂNone<FTô persistent£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. persistent Load the config settings from a Ã-, most likely taken from a YAML config file. persistent:Modify the config settings based on environment variables. persistent@Create a new connection pool based on the given config settings. persistent;Run a database action by taking a connection from the pool. None1` persistent¼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.& persistentAlways uses UTC timezone( persistenta backend-specific name) persistentTA raw value which can be stored in any backend and can be marshalled to and from a  PersistField.6 persistent'Intended especially for MongoDB backend7 persistentUsing 7€ allows you to use types specific to a particular backend For example, below is a simple example of the PostGIS geography type: ÿdata Geo = Geo ByteString instance PersistField Geo where toPersistValue (Geo t) = PersistDbSpecific t fromPersistValue (PersistDbSpecific t) = Right $ Geo $ Data.ByteString.concat ["'", t, "'"] fromPersistValue _ = Left "Geo values must be converted from PersistDbSpecific" instance PersistFieldSql Geo where sqlType _ = SqlOther "GEOGRAPHY(POINT,4326)" toPoint :: Double -> Double -> Geo toPoint lat lon = Geo $ Data.ByteString.concat ["'POINT(", ps $ lon, " ", ps $ lat, ")'"] where ps = Data.Text.pack . show PIf Foo has a geography field, we can then perform insertions like the following: insert $ Foo (toPoint 44 44) 9 persistentGeneric ExceptionH persistent>Used instead of FieldDef to generate a smaller amount of codeS persistent|An EmbedFieldDef is the same as a FieldDef But it is only used for embeddedFields so it only has data needed for embeddingW persistentV< can create a cycle (issue #311) when a cycle is detected, V will be Nothing and W will be JustX persistentAn EmbedEntityDef is the same as an EntityDef But it is only used for fieldReference so it only has data needed for embedding\ persistentpThere are 3 kinds of references 1) composite (to fields that exist in the record) 2) single field 3) embedded^ persistent“A ForeignRef has a late binding to the EntityDef it references via HaskellName and has the Haskell type of the foreign key in the form of FieldTypea persistentcA SelfReference stops an immediate cycle which causes non-termination at compile-time (issue #311).d persistentname of the fieldh persistentuser annotations for a fieldi persistent.a strict field in the data type. Default: truel persistentOptional module and name.ƒ persistentThe reason why a field is nullable< is very important. A field that is nullable because of a Maybe& tag will have its type changed from A to Maybe A0. OTOH, a field that is nullable because of a nullable% tag will remain with the same type.‰ persistentA ‰Æ should be used as a field type whenever a uniqueness constraint should guarantee that a certain kind of record may appear at most once, but other kinds of records may appear any number of times.NOTE: You need to mark any  Checkmark fields as nullable (see the following example).For example, suppose there's a Location0 entity that represents where a user has lived: mLocation user UserId name Text current Checkmark nullable UniqueLocation user current The UniqueLocation" constraint allows any number of ‹ Locations to be current&. However, there may be at most one current Location/ per user (i.e., either zero or one per user).9This data type works because of the way that SQL treats NULLHable fields within uniqueness constraints. The SQL standard says that NULL9 values should be considered different, so we represent ‹ as SQL NULL, thus allowing any number of ‹, records. On the other hand, we represent Š as TRUE<, so the uniqueness constraint will disallow more than one Š record.Note:I There may be DBMSs that do not respect the SQL standard's treatment of NULL_ values on uniqueness constraints, please check if this data type works before relying on it.The SQL BOOLEANV type is used because it's the smallest data type available. Note that we never use FALSE, just TRUE and NULL. Provides the same behavior Maybe () would if () was a valid  PersistField.Š persistent@When used on a uniqueness constraint, there may be at most one Š record.‹ persistentBWhen used on a uniqueness constraint, there may be any number of ‹ records.Š  ('&%$#"! )76543210/.-,+*8>=<;:9?@GFEDCBAHIJLKMNRQPOSTWVUXY[Z\a_^]`bcihgfjdeknmlopqrstuvwx‚€~|zy}{ƒ…„†ˆ‡‰‹ŠŒŽ None;=COV…ß“ persistentUThis class teaches Persistent how to take a custom type and marshal it to and from a )), allowing it to be stored in a database.ExamplesSimple Newtype You can use newtype: to add more type safety/readability to a basis type like Ä. In these cases, just derive “ and PersistFieldSql: U{-# LANGUAGE GeneralizedNewtypeDeriving #-} newtype HashedPassword = HashedPassword Ä deriving (Eq, Show, “, PersistFieldSql) Smart Constructor NewtypeIn this example, we create a “B instance for a newtype following the "Smart Constructor" pattern. ={-# LANGUAGE GeneralizedNewtypeDeriving #-} import qualified  Data.Text as T import qualified  Data.CharA as C -- | An American Social Security Number newtype SSN = SSN Å1 deriving (Eq, Show, PersistFieldSql) mkSSN :: Å -> Æ ÅA SSN mkSSN t = if (T.length t == 9) && (T.all C.isDigit t) then Ç $ SSN t else È" $ "Invalid SSN: " <> t instance “ SSN where ” (SSN t) = * t • (*R t) = mkSSN t -- Handle cases where the database does not give us PersistText • x = Èe $ "File.hs: When trying to deserialize an SSN: expected PersistText, received: " <> T.pack (show x) Tips:This file contain dozens of “( instances you can look at for examples.Typically custom “% instances will only accept a single ) constructor in •.  Internal “$ instances accept a wide variety of )Gs to accomodate e.g. storing booleans as integers, booleans or strings.NIf you're making a custom instance and using a SQL database, you'll also need PersistFieldSql, to specify the type of the database column.– persistent FIXME Add documentation to that.É persistent Haskell type persistentOriginal bytestring persistentInteger result persistentExtra bytestring persistent Error messageÊ persistent Haskell type persistentOriginal bytestring persistent Error messageË persistent6Haskell type, should match Haskell name exactly, e.g. Int64 persistentODatabase type(s), should appear different from Haskell name, e.g. "integer" or INT, not Int. persistentIncorrect value persistent Error messageÌ persistent6Haskell type, should match Haskell name exactly, e.g. Int64 persistentReceived value persistent Error message‘’“”•– None016<CFQTVèq— persistent2Datatype that represents an entity, with both its ²( and its Haskell record representation.CWhen using a SQL-based backend (such as SQLite or PostgreSQL), an —€ may take any number of columns depending on how many fields it has. In order to reconstruct your entity on the Haskell side,  persistentu 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.AHowever, if you want to issue a raw SQL command that returns an —K, 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  persistentz 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   (from the Database.Persist.GenericSqlJ 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.› persistent 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.1Persistent users use combinators to create these. persistent3convenient for internal use, not needed for the API¤ persistentQuery options.$Persistent users use these directly.© persistentUpdating a database entity.1Persistent users use combinators to create these.° persistentCPersistent serialized Haskell records to the database. A Database —> (A row in SQL, a document in MongoDB, etc) corresponds to a ² plus a Haskell record.OFor every Haskell record type stored in the database there is a corresponding °½ instance. An instance of PersistEntity contains meta-data for the record. PersistEntity also helps abstract over different record types. That way the same query interface can return a °@, with each query returning different types of Haskell records.¬Some advanced type system capabilities are used to make this process type-safe. Persistent users usually don't need to understand the class associated data and functions.± persistent:Persistent allows multiple different backends (databases).² persistentzBy default, a backend will automatically generate the key Instead you can specify a Primary key made up of unique values.³ persistentAn ³] is parameterised by the Haskell record it belongs to and the additional type of that field.´ persistentUnique keys besides the ².µ persistentA lower-level key operation.¶ persistentA lower-level key operation.· persistent!A meta-operation to retrieve the ² ³.¸ persistent Retrieve the w meta-data for the record.¹ persistentReturn meta-data for a given ³.º persistent8A meta-operation to get the database fields of a record.» persistentLA lower-level operation to convert from database values to a Haskell record.¼ persistent%A meta operation to retrieve all the ´ keys.½ persistentA lower level operation.¾ persistentA lower level operation.¿ persistentUse a “ as a lens.À persistent1Get list of values corresponding to given entity.Á persistent Predefined toJSON!. The resulting JSON looks like "{"key": 1, "value": {"name": ...}}.The typical usage is: Finstance ToJSON (Entity User) where toJSON = keyValueEntityToJSON  persistent Predefined  parseJSON. The input JSON looks like "{"key": 1, "value": {"name": ...}}.The typical usage is: Minstance FromJSON (Entity User) where parseJSON = keyValueEntityFromJSON à persistent Predefined toJSON!. The resulting JSON looks like {"id": 1, "name": ...}.The typical usage is: @instance ToJSON (Entity User) where toJSON = entityIdToJSON Ä persistent Predefined  parseJSON. The input JSON looks like {"id": 1, "name": ...}.The typical usage is: Ginstance FromJSON (Entity User) where parseJSON = entityIdFromJSON Í persistentYRealistically this is only going to be used for MongoDB, so lets use MongoDB conventionsÅ persistent(Convenience function for getting a free “+ instance from a type with JSON instances."Example usage in combination with Æ: sinstance PersistField MyData where fromPersistValue = fromPersistValueJSON toPersistValue = toPersistValueJSON Æ persistent(Convenience function for getting a free “É instance from a type with JSON instances. The JSON parser used will accept JSON values other that object and arrays. So, if your instance serializes the data to a JSON string, this will still work."Example usage in combination with Å: sinstance PersistField MyData where fromPersistValue = fromPersistValueJSON toPersistValue = toPersistValueJSON Î persistent(Convenience function for getting a free “ instance from a type with an Ï instance. The function derivePersistFieldn from the persistent-template package should generally be preferred. However, if you want to ensure that an ORDER BYf clause that uses your field will order rows by the data constructor order, this is a better choice."Example usage in combination with Ð: Édata SeverityLevel = Low | Medium | Critical | High deriving (Enum, Bounded) instance PersistField SeverityLevel where fromPersistValue = fromPersistValueEnum toPersistValue = toPersistValueEnum Ð persistent(Convenience function for getting a free “ instance from a type with an Ï* instance. This function also requires a Ñ- instance to improve the reporting of errors."Example usage in combination with Î: Édata SeverityLevel = Low | Medium | Critical | High deriving (Enum, Bounded) instance PersistField SeverityLevel where fromPersistValue = fromPersistValueEnum toPersistValue = toPersistValueEnum 2—˜™š›œžŸ ¡¢£¤¥¦§¨©ª«¬­®¯°²´³±¶»¹µ·¸º¼½¾¿ÀÁÂÃÄÅÆÎÐNoneCFTVé ¦   !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\`]^_abcedjfghiklmnopqrstuvwx{}yz|~€‚ƒ„…†‡ˆ‰Š‹ŒŽ‘’—˜™š›œžŸ ¡¢£¤¥¦§¨©ª«¬­®¯²¦‰‹Š†ˆ‡ƒ…„wx‚€~|zy}{ŒŽvstupqroknmlbcihgfjde\a_^]`XY[ZSTWVUMNRQPOIJLKH?@GFEDCBA8>=<;:9)76543210/.-,+*('&%$#"!   ‘’©ª«¬­®¯¤¥¦§¨›œžŸ ¡¢£²—˜™šNone%O) Ò persistentfields in other entityÓ persistentvA line. We don't care about spaces in the middle of the line. Also, we don't care about the ammount of indentation.Ô persistentA token used by the parser.Õ persistentSpaces n are n consecutive spaces.Ö persistent Token tok is token tok already unquoted.Ê persistent5Whether fields are by default strict. Default value: True.Ë persistent*The name of the id column. Default value: idF The name of the id column can also be changed on a per-model basis Dhttps://github.com/yesodweb/persistent/wiki/Persistent-entity-syntaxÎ persistent?Parses a quasi-quoted syntax into a list of entity definitions.× persistentTokenize a string.Ø persistentVA string of tokens is empty when it has only spaces. There can't be two consecutive Õ, so this takes O(1) time.Ù persistentERemove leading spaces and remove spaces in the middle of the tokens.Ú persistent5Divide lines into blocks and make entity definitions.Û persistentConstruct an entity definition.Û persistentname persistententity attributes persistentindented lines ÇÈÉÊËÌÍÎÏ ÎÇÈÉÊËÌÍÏNone +<>?AFTëÔ persistentkCreate a new record in the database, returning an automatically created key (in SQL an auto-increment id). Example usageUsing  #schema-persist-store-1schema-1 and  #dataset-persist-store-1 dataset-1, let's insert a new user John. _insertJohn :: MonadIO m => ReaderT SqlBackend m (Key User) insertJohn = insert $ User "John" 30 johnId <- insertJohn The above query when applied on  #dataset-persist-store-1 dataset-1, will produce this: ¼+-----+------+-----+ |id |name |age | +-----+------+-----+ |1 |SPJ |40 | +-----+------+-----+ |2 |Simon |41 | +-----+------+-----+ |3 |John |30 | +-----+------+-----+Õ persistentSame as Ô, but doesn't return a Key. Example usagewith  #schema-persist-store-1schema-1 and  #dataset-persist-store-1 dataset-1, `insertJohn :: MonadIO m => ReaderT SqlBackend m (Key User) insertJohn = insert_ $ User "John" 30 The above query when applied on  #dataset-persist-store-1 dataset-1, will produce this: ¼+-----+------+-----+ |id |name |age | +-----+------+-----+ |1 |SPJ |40 | +-----+------+-----+ |2 |Simon |41 | +-----+------+-----+ |3 |John |30 | +-----+------+-----+Ö persistent9Create multiple records in the database and return their ²s.If you don't need the inserted ²s, use ×.fThe MongoDB and PostgreSQL backends insert all records and retrieve their keys in one database query.GThe SQLite and MySQL backends use the slow, default implementation of  mapM insert. Example usagewith  #schema-persist-store-1schema-1 and  #dataset-persist-store-1 dataset-1, …insertUsers :: MonadIO m => ReaderT SqlBackend m [Key User] insertUsers = insertMany [User "John" 30, User "Nick" 32, User "Jane" 20] userIds <- insertUsers The above query when applied on  #dataset-persist-store-1 dataset-1, will produce this: ÿ+-----+------+-----+ |id |name |age | +-----+------+-----+ |1 |SPJ |40 | +-----+------+-----+ |2 |Simon |41 | +-----+------+-----+ |3 |John |30 | +-----+------+-----+ |4 |Nick |32 | +-----+------+-----+ |5 |Jane |20 | +-----+------+-----+× persistentSame as Ö, but doesn't return any ²s.]The MongoDB, PostgreSQL, SQLite and MySQL backends insert all records in one database query. Example usageWith  #schema-persist-store-1schema-1 and  #dataset-persist-store-1 dataset-1, €insertUsers_ :: MonadIO m => ReaderT SqlBackend m () insertUsers_ = insertMany_ [User "John" 30, User "Nick" 32, User "Jane" 20] The above query when applied on  #dataset-persist-store-1 dataset-1, will produce this: ÿ+-----+------+-----+ |id |name |age | +-----+------+-----+ |1 |SPJ |40 | +-----+------+-----+ |2 |Simon |41 | +-----+------+-----+ |3 |John |30 | +-----+------+-----+ |4 |Nick |32 | +-----+------+-----+ |5 |Jane |20 | +-----+------+-----+Ø persistentSame as ×, but takes an — instead of just a record.PUseful when migrating data from one entity to another and want to preserve ids.]The MongoDB, PostgreSQL, SQLite and MySQL backends insert all records in one database query. Example usageWith  #schema-persist-store-1schema-1 and  #dataset-persist-store-1 dataset-1, }insertUserEntityMany :: MonadIO m => ReaderT SqlBackend m () insertUserEntityMany = insertEntityMany [SnakeEntity, EvaEntity] The above query when applied on  #dataset-persist-store-1 dataset-1, will produce this: æ+-----+------+-----+ |id |name |age | +-----+------+-----+ |1 |SPJ |40 | +-----+------+-----+ |2 |Simon |41 | +-----+------+-----+ |3 |Snake |38 | +-----+------+-----+ |4 |Eva |38 | +-----+------+-----+Ù persistent8Create a new record in the database using the given key. Example usageWith  #schema-persist-store-1schema-1 and  #dataset-persist-store-1 dataset-1, winsertAliceKey :: MonadIO m => Key User -> ReaderT SqlBackend m () insertAliceKey key = insertKey key $ User "Alice" 20 JinsertAliceKey $ UserKey {unUserKey = SqlBackendKey {unSqlBackendKey = 3}} The above query when applied on  #dataset-persist-store-1 dataset-1, will produce this: ¼+-----+------+-----+ |id |name |age | +-----+------+-----+ |1 |SPJ |40 | +-----+------+-----+ |2 |Simon |41 | +-----+------+-----+ |3 |Alice |20 | +-----+------+-----+Ú persistent;Put the record in the database with the given key. Unlike ÜT, if a record with the given key does not exist then a new record will be inserted. Example usageWe try to explain upsertBy using  #schema-persist-store-1schema-1 and  #dataset-persist-store-1 dataset-1.First, we insert Philip to  #dataset-persist-store-1 dataset-1. einsertPhilip :: MonadIO m => ReaderT SqlBackend m (Key User) insertPhilip = insert $ User "Philip" 42 philipId <- insertPhilipThis query will produce: ¼+-----+------+-----+ |id |name |age | +-----+------+-----+ |1 |SPJ |40 | +-----+------+-----+ |2 |Simon |41 | +-----+------+-----+ |3 |Philip|42 | +-----+------+-----+ wrepsertHaskell :: MonadIO m => Key record -> ReaderT SqlBackend m () repsertHaskell id = repsert id $ User "Haskell" 81 repsertHaskell philipId;This query will replace Philip's record with Haskell's one: ÿ:+-----+-----------------+--------+ |id |name |age | +-----+-----------------+--------+ |1 |SPJ |40 | +-----+-----------------+--------+ |2 |Simon |41 | +-----+-----------------+--------+ |3 |Philip -> Haskell|42 -> 81| +-----+-----------------+--------+Ú3 inserts the given record if the key doesn't exist. nrepsertXToUnknown :: MonadIO m => ReaderT SqlBackend m () repsertXToUnknown = repsert unknownId $ User "X" 999)For example, applying the above query to  #dataset-persist-store-1 dataset-1 will produce this: ¼+-----+------+-----+ |id |name |age | +-----+------+-----+ |1 |SPJ |40 | +-----+------+-----+ |2 |Simon |41 | +-----+------+-----+ |3 |X |999 | +-----+------+-----+Û persistent$Put many entities into the database.Batch version of Ú for SQL backends.PUseful when migrating data from one entity to another and want to preserve ids. Example usageWith  #schema-persist-store-1schema-1 and  #dataset-persist-store-1 dataset-1, –repsertManyUsers :: MonadIO m =>ReaderT SqlBackend m () repsertManyusers = repsertMany [(simonId, User "Philip" 20), (unknownId999, User "Mr. X" 999)] The above query when applied on  #dataset-persist-store-1 dataset-1, will produce this: ÿ:+-----+----------------+---------+ |id |name |age | +-----+----------------+---------+ |1 |SPJ |40 | +-----+----------------+---------+ |2 |Simon -> Philip |41 -> 20 | +-----+----------------+---------+ |999 |Mr. X |999 | +-----+----------------+---------+Ü persistentŠReplace the record in the database with the given key. Note that the result is undefined if such record does not exist, so you must use Ù or Ú in these cases. Example usageWith  #schema-persist-store-1schema-1 schama-1 and  #dataset-persist-store-1 dataset-1, creplaceSpj :: MonadIO m => User -> ReaderT SqlBackend m () replaceSpj record = replace spjId record The above query when applied on  #dataset-persist-store-1 dataset-1, will produce this: ’+-----+------+-----+ |id |name |age | +-----+------+-----+ |1 |Mike |45 | +-----+------+-----+ |2 |Simon |41 | +-----+------+-----+Ý persistentODelete a specific record by identifier. Does nothing if record does not exist. Example usageWith  #schema-persist-store-1schema-1 and  #dataset-persist-store-1 dataset-1, JdeleteSpj :: MonadIO m => ReaderT SqlBackend m () deleteSpj = delete spjId The above query when applied on  #dataset-persist-store-1 dataset-1, will produce this: h+-----+------+-----+ |id |name |age | +-----+------+-----+ |2 |Simon |41 | +-----+------+-----+Þ persistent.Update individual fields on a specific record. Example usageWith  #schema-persist-store-1schema-1 and  #dataset-persist-store-1 dataset-1, kupdateSpj :: MonadIO m => [Update User] -> ReaderT SqlBackend m () updateSpj updates = update spjId updates updateSpj [UserAge +=. 100] The above query when applied on  #dataset-persist-store-1 dataset-1, will produce this: ’+-----+------+-----+ |id |name |age | +-----+------+-----+ |1 |SPJ |140 | +-----+------+-----+ |2 |Simon |41 | +-----+------+-----+ß persistentaUpdate individual fields on a specific record, and retrieve the updated value from the database._Note that this function will throw an exception if the given key is not found in the database. Example usageWith  #schema-persist-store-1schema-1 and  #dataset-persist-store-1 dataset-1, vupdateGetSpj :: MonadIO m => [Update User] -> ReaderT SqlBackend m User updateGetSpj updates = updateGet spjId updates %spj <- updateGetSpj [UserAge +=. 100] The above query when applied on  #dataset-persist-store-1 dataset-1, will produce this: ’+-----+------+-----+ |id |name |age | +-----+------+-----+ |1 |SPJ |140 | +-----+------+-----+ |2 |Simon |41 | +-----+------+-----+á persistent)Get a record by identifier, if available. Example usageWith  #schema-persist-store-1schema-1 and  #dataset-persist-store-1 dataset-1, KgetSpj :: MonadIO m => ReaderT SqlBackend m (Maybe User) getSpj = get spjId mspj <- getSpj The above query when applied on  #dataset-persist-store-1 dataset-1, will get this: J+------+-----+ | name | age | +------+-----+ | SPJ | 40 | +------+-----+â persistent?Get many records by their respective identifiers, if available. Example usageWith  #schema-persist-store-1schema-1 and  #dataset-persist-store-1 dataset-1: ^getUsers :: MonadIO m => ReaderT SqlBackend m (Map (Key User) User) getUsers = getMany allkeys musers <- getUsers The above query when applied on  #dataset-persist-store-1 dataset-1, will get these records: ’+----+-------+-----+ | id | name | age | +----+-------+-----+ | 1 | SPJ | 40 | +----+-------+-----+ | 2 | Simon | 41 | +----+-------+-----+å persistentå converts a ° ² into a ä8 This can be used by each backend to convert between a ²7 and a plain Haskell type. For Sql, that is done with toSqlKey and  fromSqlKey.By default, a ° uses the default ä0 for its Key and is an instance of ToBackendKeyA ²= that instead uses a custom type will not be an instance of å.è persistent-A convenient alias for common type signaturesé persistentYThis class witnesses that two backend are compatible, and that you can convert from the sub backend into the sup" backend. This is similar to the í and ëH classes, but where you don't want to fix the type associated with the ± of a record.)Generally speaking, where you might have:  foo :: ( ° record , PeristEntityBackend record ~ î backend ,  IsSqlBackend backend ) this can be replaced with:  foo :: ( ° record, , ± record ~ backend , é  SqlBackend backend ) This works for SqlReadBackend because of the  instance é  SqlBackend SqlReadBackend$, without needing to go through the î type family.8Likewise, functions that are currently hardcoded to use  SqlBackend can be generalized: -- before: asdf :: Ü  SqlBackend) m () asdf = pure () -- after: asdf' :: é@ SqlBackend backend => ReaderT backend m () asdf' = withReaderT ê asdf ë persistentClass which witnesses that backend is essentially the same as BaseBackend backend#. That is, they're isomorphic and backend is just some wrapper over BaseBackend backend.ì persistent¦This function is how we actually construct and tag a backend as having read or write capabilities. It should be used carefully and only when actually constructing a backendY. Careless use allows us to accidentally run a write query against a read-only database.í persistent%Class which allows the plucking of a BaseBackend backend' from some larger type. For example, œ instance HasPersistBackend (SqlReadBackend, Int) where type BaseBackend (SqlReadBackend, Int) = SqlBackend persistBackend = unSqlReadBackend . fst ñ persistentSame as áv, but for a non-null (not Maybe) foreign key. Unsafe unless your database is enforcing that the foreign key is valid. Example usageWith  #schema-persist-store-1schema-1 and  #dataset-persist-store-1 dataset-1, OgetJustSpj :: MonadIO m => ReaderT SqlBackend m User getJustSpj = getJust spjId spj <- getJust spjId The above query when applied on  #dataset-persist-store-1 dataset-1, will get this record: c+----+------+-----+ | id | name | age | +----+------+-----+ | 1 | SPJ | 40 | +----+------+-----+ [getJustUnknown :: MonadIO m => ReaderT SqlBackend m User getJustUnknown = getJust unknownIdmrx <- getJustUnknownThis just throws an error.ò persistentSame as ñ, but returns an — instead of just the record. Example usageWith  #schema-persist-store-1schema-1 and  #dataset-persist-store-1 dataset-1, jgetJustEntitySpj :: MonadIO m => ReaderT SqlBackend m (Entity User) getJustEntitySpj = getJustEntity spjId spjEnt <- getJustEntitySpj The above query when applied on  #dataset-persist-store-1 dataset-1, will get this entity: c+----+------+-----+ | id | name | age | +----+------+-----+ | 1 | SPJ | 40 | +----+------+-----+ó persistentICurry this to make a convenience function that loads an associated model. foreign = belongsTo foreignIdô persistentSame as ó , but uses getJust# and therefore is similarly unsafe.õ persistentLike insert, but returns the complete Entity. Example usageWith  #schema-persist-store-1schema-1 and  #dataset-persist-store-1 dataset-1, }insertHaskellEntity :: MonadIO m => ReaderT SqlBackend m (Entity User) insertHaskellEntity = insertEntity $ User "Haskell" 81 !haskellEnt <- insertHaskellEntity The above query when applied on  #dataset-persist-store-1 dataset-1, will produce this: Î+----+---------+-----+ | id | name | age | +----+---------+-----+ | 1 | SPJ | 40 | +----+---------+-----+ | 2 | Simon | 41 | +----+---------+-----+ | 3 | Haskell | 81 | +----+---------+-----+ö persistentLike get, but returns the complete Entity. Example usageWith  #schema-persist-store-1schema-1 and  #dataset-persist-store-1 dataset-1, fgetSpjEntity :: MonadIO m => ReaderT SqlBackend m (Maybe (Entity User)) getSpjEntity = getEntity spjId mSpjEnt <- getSpjEntity The above query when applied on  #dataset-persist-store-1 dataset-1, will get this entity: c+----+------+-----+ | id | name | age | +----+------+-----+ | 1 | SPJ | 40 | +----+------+-----+÷ persistentLike õ( but just returns the record instead of —. Example usageWith  #schema-persist-store-1schema-1 and  #dataset-persist-store-1 dataset-1, kinsertDaveRecord :: MonadIO m => ReaderT SqlBackend m User insertDaveRecord = insertRecord $ User "Dave" 50 dave <- insertDaveRecord The above query when applied on  #dataset-persist-store-1 dataset-1, will produce this: ¼+-----+------+-----+ |id |name |age | +-----+------+-----+ |1 |SPJ |40 | +-----+------+-----+ |2 |Simon |41 | +-----+------+-----+ |3 |Dave |50 | +-----+------+-----+%ÓÝÔÞÜÕÖרÙÚÛßàáâãäåæçèéêëìíîïðñòóôõö÷None+<FT‘µø persistentSome functions in this module (ú, , and ƒ) first query the unique indexes to check for conflicts. You could instead optimistically attempt to perform the operation (e.g. Ü instead of  ). However,gthere is some fragility to trying to catch the correct exception and determing the column of failure;Ban exception will automatically abort the current SQL transaction.ù persistentKDelete a specific record by unique key. Does nothing if no record matches. Example usageWith  #schema-persist-unique-1schema-1 and  #dataset-persist-unique-1 dataset-1, gdeleteBySpjName :: MonadIO m => ReaderT SqlBackend m () deleteBySpjName = deleteBy UniqueUserName "SPJ" The above query when applied on  #dataset-persist-unique-1 dataset-1, will produce this: h+-----+------+-----+ |id |name |age | +-----+------+-----+ |2 |Simon |41 | +-----+------+-----+ú persistentLike Ô, but returns ÝJ when the record couldn't be inserted because of a uniqueness constraint. Example usageWith  #schema-persist-unique-1schema-1 and  #dataset-persist-unique-1 dataset-1-, we try to insert the following two records: QlinusId <- insertUnique $ User "Linus" 48 spjId <- insertUnique $ User "SPJ" 90 ¼+-----+------+-----+ |id |name |age | +-----+------+-----+ |1 |SPJ |40 | +-----+------+-----+ |2 |Simon |41 | +-----+------+-----+ |3 |Linus |48 | +-----+------+-----+Linus's record was inserted to  #dataset-persist-unique-1 dataset-11, while SPJ wasn't because SPJ already exists in  #dataset-persist-unique-1 dataset-1.û persistent2Update based on a uniqueness constraint or insert:+insert the new record if it does not exist;žIf the record exists (matched via it's uniqueness constraint), then update the existing record with the parameters which is passed on as list to the function.BThrows an exception if there is more than 1 uniqueness constraint. Example usageFirst, we try to explain û using  #schema-persist-unique-1schema-1 and  #dataset-persist-unique-1 dataset-1. ‰upsertSpj :: MonadIO m => [Update User] -> ReaderT SqlBackend m (Maybe (Entity User)) upsertSpj updates = upsert (User "SPJ" 999) upadtes %mSpjEnt <- upsertSpj [UserAge +=. 15] The above query when applied on  #dataset-persist-unique-1 dataset-1, will produce this:  +-----+-----+--------+ |id |name |age | +-----+-----+--------+ |1 |SPJ |40 -> 55| +-----+-----+--------+ |2 |Simon|41 | +-----+-----+--------+ ƒupsertX :: MonadIO m => [Update User] -> ReaderT SqlBackend m (Maybe (Entity User)) upsertX updates = upsert (User "X" 999) upadtes !mXEnt <- upsertX [UserAge +=. 15] The above query when applied on  #dataset-persist-unique-1 dataset-1, will produce this: Î+-----+-----+--------+ |id |name |age | +-----+-----+--------+ |1 |SPJ |40 | +-----+-----+--------+ |2 |Simon|41 | +-----+-----+--------+ |3 |X |999 | +-----+-----+--------+SNext, what if the schema has two uniqueness constraints? Let's check it out using  #schema-persist-unique-2schema-2: %mSpjEnt <- upsertSpj [UserAge +=. 15]SThen, it throws an error message something like "Expected only one unique key, got"ü persistent8Update based on a given uniqueness constraint or insert:+insert the new record if it does not exist;Hupdate the existing record that matches the given uniqueness constraint. Example usageWe try to explain ü using  #schema-persist-unique-2schema-2 and  #dataset-persist-unique-1 dataset-1. «upsertBySpjName :: MonadIO m => User -> [Update User] -> ReaderT SqlBackend m (Entity User) upsertBySpjName record updates = upsertBy (UniqueUserName "SPJ") record updates >mSpjEnt <- upsertBySpjName (Person "X" 999) [PersonAge += .15]The above query will alter  #dataset-persist-unique-1 dataset-1 to:  +-----+-----+--------+ |id |name |age | +-----+-----+--------+ |1 |SPJ |40 -> 55| +-----+-----+--------+ |2 |Simon|41 | +-----+-----+--------+ ­upsertBySimonAge :: MonadIO m => User -> [Update User] -> ReaderT SqlBackend m (Entity User) upsertBySimonAge record updates = upsertBy (UniqueUserName "SPJ") record updates DmPhilipEnt <- upsertBySimonAge (User "X" 999) [UserName =. "Philip"]The above query will alter  #dataset-persist-unique-1 dataset-1 to: Ø+----+-----------------+-----+ | id | name | age | +----+-----------------+-----+ | 1 | SPJ | 40 | +----+-----------------+-----+ | 2 | Simon -> Philip | 41 | +----+-----------------+-----+ ·upsertByUnknownName :: MonadIO m => User -> [Update User] -> ReaderT SqlBackend m (Entity User) upsertByUnknownName record updates = upsertBy (UniqueUserName "Unknown") record updates <mXEnt <- upsertByUnknownName (User "X" 999) [UserAge +=. 15]This query will alter  #dataset-persist-unique-1 dataset-1 to: ³+-----+-----+-----+ |id |name |age | +-----+-----+-----+ |1 |SPJ |40 | +-----+-----+-----+ |2 |Simon|41 | +-----+-----+-----+ |3 |X |999 | +-----+-----+-----+ý persistentPut many records into dbHinsert new records that do not exist (or violate any unique constraints)Greplace existing records (matching any unique constraint) @since 2.8.1þ persistentQueries against ´ keys (other than the id ²).IPlease read the general Persistent documentation to learn how to create ´ keys.qUsing this with an Entity without a Unique key leads to undefined behavior. A few of these functions require a single ´$, so using an Entity with multiple ´”s is also undefined. In these cases persistent's goal is to throw an exception as soon as possible, but persistent is still transitioning to that.žSQL backends automatically create uniqueness constraints, but for MongoDB you must manually place a unique index on a field to have a uniqueness constraint.ÿ persistentFGet a record by unique key, if available. Returns also the identifier. Example usageWith  #schema-persist-unique-1schema-1 and  #dataset-persist-unique-1 dataset-1: tgetBySpjName :: MonadIO m => ReaderT SqlBackend m (Maybe (Entity User)) getBySpjName = getBy $ UniqueUserName "SPJ" mSpjEnt <- getBySpjName The above query when applied on  #dataset-persist-unique-1 dataset-1, will get this entity: c+----+------+-----+ | id | name | age | +----+------+-----+ | 1 | SPJ | 40 | +----+------+-----+ persistentInsert a value, checking for conflicts with any unique constraints. If a duplicate exists in the database, it is returned as È*. Otherwise, the new 'Key is returned as Ç. Example usageWith  #schema-persist-unique-2schema-2 and  #dataset-persist-unique-1 dataset-1", we have following lines of code: |l1 <- insertBy $ User "SPJ" 20 l2 <- insertBy $ User "XXX" 41 l3 <- insertBy $ User "SPJ" 40 r1 <- insertBy $ User "XXX" 100First three lines return Èp because there're duplicates in given record's uniqueness constraints. While the last line returns a new key as Ç.Þ persistent³Insert a value, checking for conflicts with any unique constraints. If a duplicate exists in the database, it is left untouched. The key of the existing or new entry is returned persistentLike õ, but returns ÝJ when the record couldn't be inserted because of a uniqueness constraint. Example usageWe use  #schema-persist-unique-2schema-2 and  #dataset-persist-unique-1 dataset-1 here. ‹insertUniqueSpjEntity :: MonadIO m => ReaderT SqlBackend m (Maybe (Entity User)) insertUniqueSpjEntity = insertUniqueEntity $ User "SPJ" 50  mSpjEnt <- insertUniqueSpjEntityThe above query results Ý as SPJ already exists. insertUniqueAlexaEntity :: MonadIO m => ReaderT SqlBackend m (Maybe (Entity User)) insertUniqueAlexaEntity = insertUniqueEntity $ User "Alexa" 3 "mAlexaEnt <- insertUniqueSpjEntity]Because there's no such unique keywords of the given record, the above query when applied on  #dataset-persist-unique-1 dataset-1, will produce this: ¼+----+-------+-----+ | id | name | age | +----+-------+-----+ | 1 | SPJ | 40 | +----+-------+-----+ | 2 | Simon | 41 | +----+-------+-----+ | 3 | Alexa | 3 | +----+-------+-----+ persistent*Return the single unique key for a record. Example usageWe use shcema-1 and  #dataset-persist-unique-1 dataset-1 here. ponlySimonConst :: MonadIO m => ReaderT SqlBackend m (Unique User) onlySimonConst = onlyUnique $ User "Simon" 999 mSimonConst <- onlySimonConst mSimonConst3 would be Simon's uniqueness constraint. Note that  onlyUnique4 doesn't work if there're more than two constraints. persistentA modification of ÿ, which takes the ° itself instead of a ´# record. Returns a record matching oneS of the unique keys. This function makes the most sense on entities with a single ´ constructor. Example usageWith  #schema-persist-unique-1schema-1 and  #dataset-persist-unique-1 dataset-1,lgetBySpjValue :: MonadIO m => ReaderT SqlBackend m (Maybe (Entity User)) getBySpjValue = getByValue $ User SPJ 999 mSpjEnt <- getBySpjValue The above query when applied on  #dataset-persist-unique-1 dataset-1, will get this record: c+----+------+-----+ | id | name | age | +----+------+-----+ | 1 | SPJ | 40 | +----+------+-----+ persistent¨Attempt to replace the record of the given key with the given new record. First query the unique fields to make sure the replacement maintains uniqueness constraints.Return ÝC if the replacement was made. If uniqueness is violated, return a ß with the ´ violation persistentnCheck whether there are any conflicts for unique keys with this entity and existing entities in the database.Returns Ým if the entity would be unique, and could thus safely be inserted. on a conflict returns the conflicting key Example usageWe use  #schema-persist-unique-1schema-1 and  #dataset-persist-unique-1 dataset-1 here.This would be Ý: *mAlanConst <- checkUnique $ User "Alan" 70While this would be ß because SPJ already exists: (mSpjConst <- checkUnique $ User "SPJ" 60à persistentThe slow but generic ý implemetation for any þB. * Lookup corresponding entities (if any) for each record using & * For pre-existing records, issue a ÜB for each old key and new record * For new records, issue a bulk ×á persistentiThe _essence_ of a unique record. useful for comaparing records in haskell land for uniqueness equality.û persistentnew record to insert persistent/updates to perform if the record already exists persistent.the record in the database after the operationü persistent uniqueness constraint to find by persistentnew record to insert persistent/updates to perform if the record already exists persistent.the record in the database after the operationý persistent4A list of the records you want to insert or replace.øùüúûýþÿàáNone+<FTŸÄ  persistent0Backends supporting conditional write operations persistentDUpdate individual fields on any record matching the given criterion. persistent0Delete all records matching the given criterion.  persistent0Backends supporting conditional read operations.  persistentcGet all records matching the given criterion in the specified order. Returns also the identifiers.  persistent,Get just the first record for the criterion.  persistentGet the ².s of all records matching the given criterion.  persistent;The total number of records fulfilling the given criterion. persistentcGet all records matching the given criterion in the specified order. Returns also the identifiers. persistentGet the ².s of all records matching the given criterion. persistentCall ! but return the result as a list. persistentCall ! but return the result as a list.      None>?FT¥a persistent´For combinations of backends and entities that support cascade-deletion. Cascade-deletion  means that entries that depend on other entries to be deleted will be deleted as well. persistent3Perform cascade-deletion of single database entry. persistent5Cascade-deletion of entries satisfying given filters.None+¯6 persistent¿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. persistent¿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. persistent¿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.e“”•°²´³±¶»¹µ·¸º¼½¾¿ÀÁÂÃÄÅÆÓÝÔÞÜÕÖרÙÚÛßàáâãäåæçèéêëíîïðñòóôõö÷øùüúûýþÿ     eåæçãäàáâÓÝÔÞÜÕÖרÙÚÛßèñòöóôõ÷þÿøùüúûý     °²´³±¶»¹µ·¸º¼½¾¿“”•ÀíîïëðéêÁÂÃÄÅÆNone +1<>?FQTVÚ¾ persistent$A backend which is a wrapper around  SqlBackend. persistentLike  SqlPersistTM but compatible with any SQL backend which can handle read and write queries. persistentLike  SqlPersistTC but compatible with any SQL backend which can handle read queries. persistent^A constraint synonym which witnesses that a backend is SQL and can run read and write queries. persistentTA constraint synonym which witnesses that a backend is SQL and can run read queries. persistent5An SQL backend which can handle read or write queries persistent1An SQL backend which can only handle read queries$ persistentBtable name, column names, id name, either 1 or 2 statements to run% persistentpSQL for inserting many rows and returning their primary keys, for backends that support this functioanlity. If Ý-, rows will be inserted one-at-a-time using $.& persistentOSome databases support performing UPSERT _and_ RETURN entity in a single call.This field when set will be used to generate the UPSERT+RETURN sql given * an entity definition * updates to be run on unique key(s) collision When left as ݲ, we find the unique key from entity def before * trying to fetch an entity by said key * perform an update when result found, else issue an insert * return new entity from db' persistentoSome databases support performing bulk UPSERT, specifically "insert or replace many records" in a single call.“This field when set, given * an entity definition * number of records to be inserted should produce a PUT MANY sql with placeholders for records When left as Ý, we default to using defaultPutMany.3 persistentsSome databases (probably only Sqlite) have a limit on how many question-mark parameters may be used in a statement4  persistent‚Some databases support performing bulk an atomic+bulk INSERT where constraint conflicting entities can replace existing entities.ŸThis field when set, given * an entity definition * number of records to be inserted should produce a INSERT sql with placeholders for primary+record fields When left as Ý, we default to using defaultRepsertMany.5 persistent„Please refer to the documentation for the database in question for a full overview of the semantics of the varying isloation levelsF persistentWUseful for running a write query against an untagged backend with unknown capabilities.G persistentSUseful for running a read query against a backend with read and write capabilities.H persistentLUseful for running a read query against a backend with unknown capabilities.6ëìíîï !".#$%&'()*+,-/0123456789:;<=>?@ABCDEFGH6íîïëì HGFD@ABC:;<=>?56789E!".#$%&'()*+,-/01234None+1;<=>?EFKQTVßþT persistentA single column (see rawSql). Any  PersistField may be used here, including )% (which does not do any processing).j persistentDeprecated synonym for  SqlBackend.B !".#$%&'()*+,-/01234:;<=>?@ABCDFGHTUVWXYZ[\]^_`abcdefghijNoneOâ?l persistent0Create the list of columns for the given entity.klNone<CFTVH:m persistentAssign a field a value. Example usage pupdateAge :: MonadIO m => ReaderT SqlBackend m () updateAge = updateWhere [UserName ==. "SPJ" ] [UserAge =. 45]  Similar to W which is shown in the above example you can use other functions present in the module Database.Persist.Class#. Note that the first parameter of  is [› val] and second parameter is [©* val]. By comparing this with the type of r and m4, you can see that they match up in the above usage. The above query when applied on  #dataset dataset-1, will produce this:  +-----+-----+--------+ |id |name |age | +-----+-----+--------+ |1 |SPJ |40 -> 45| +-----+-----+--------+ |2 |Simon|41 | +-----+-----+--------+n persistentAssign a field by addition (+=). Example usage jaddAge :: MonadIO m => ReaderT SqlBackend m () addAge = updateWhere [UserName ==. "SPJ" ] [UserAge +=. 1]  The above query when applied on  #dataset dataset-1, will produce this: §+-----+-----+---------+ |id |name |age | +-----+-----+---------+ |1 |SPJ |40 -> 41 | +-----+-----+---------+ |2 |Simon|41 | +-----+-----+---------+o persistentAssign a field by subtraction (-=). Example usage tsubtractAge :: MonadIO m => ReaderT SqlBackend m () subtractAge = updateWhere [UserName ==. "SPJ" ] [UserAge -=. 1]  The above query when applied on  #dataset dataset-1, will produce this: §+-----+-----+---------+ |id |name |age | +-----+-----+---------+ |1 |SPJ |40 -> 39 | +-----+-----+---------+ |2 |Simon|41 | +-----+-----+---------+p persistent"Assign a field by multiplication (*=). Example usage tmultiplyAge :: MonadIO m => ReaderT SqlBackend m () multiplyAge = updateWhere [UserName ==. "SPJ" ] [UserAge *=. 2]  The above query when applied on  #dataset dataset-1, will produce this:  +-----+-----+--------+ |id |name |age | +-----+-----+--------+ |1 |SPJ |40 -> 80| +-----+-----+--------+ |2 |Simon|41 | +-----+-----+--------+q persistentAssign a field by division (/=). Example usage pdivideAge :: MonadIO m => ReaderT SqlBackend m () divideAge = updateWhere [UserName ==. "SPJ" ] [UserAge /=. 2]  The above query when applied on  #dataset dataset-1, will produce this: §+-----+-----+---------+ |id |name |age | +-----+-----+---------+ |1 |SPJ |40 -> 20 | +-----+-----+---------+ |2 |Simon|41 | +-----+-----+---------+r persistentCheck for equality. Example usage mselectSPJ :: MonadIO m => ReaderT SqlBackend m [Entity User] selectSPJ = selectList [UserName ==. "SPJ" ] []  The above query when applied on  #dataset dataset-1, will produce this: c+-----+-----+-----+ |id |name |age | +-----+-----+-----+ |1 |SPJ |40 | +-----+-----+-----+s persistentNon-equality check. Example usage qselectSimon :: MonadIO m => ReaderT SqlBackend m [Entity User] selectSimon = selectList [UserName !=. "SPJ" ] []  The above query when applied on  #dataset dataset-1, will produce this: c+-----+-----+-----+ |id |name |age | +-----+-----+-----+ |2 |Simon|41 | +-----+-----+-----+t persistentLess-than check. Example usage pselectLessAge :: MonadIO m => ReaderT SqlBackend m [Entity User] selectLessAge = selectList [UserAge <. 41 ] []  The above query when applied on  #dataset dataset-1, will produce this: c+-----+-----+-----+ |id |name |age | +-----+-----+-----+ |1 |SPJ |40 | +-----+-----+-----+u persistentLess-than or equal check. Example usage {selectLessEqualAge :: MonadIO m => ReaderT SqlBackend m [Entity User] selectLessEqualAge = selectList [UserAge <=. 40 ] []  The above query when applied on  #dataset dataset-1, will produce this: c+-----+-----+-----+ |id |name |age | +-----+-----+-----+ |1 |SPJ |40 | +-----+-----+-----+v persistentGreater-than check. Example usage vselectGreaterAge :: MonadIO m => ReaderT SqlBackend m [Entity User] selectGreaterAge = selectList [UserAge >. 40 ] []  The above query when applied on  #dataset dataset-1, will produce this: c+-----+-----+-----+ |id |name |age | +-----+-----+-----+ |2 |Simon|41 | +-----+-----+-----+w persistentGreater-than or equal check. Example usage selectGreaterEqualAge :: MonadIO m => ReaderT SqlBackend m [Entity User] selectGreaterEqualAge = selectList [UserAge >=. 41 ] []  The above query when applied on  #dataset dataset-1, will produce this: c+-----+-----+-----+ |id |name |age | +-----+-----+-----+ |2 |Simon|41 | +-----+-----+-----+x persistent Check if value is in given list. Example usage rselectUsers :: MonadIO m => ReaderT SqlBackend m [Entity User] selectUsers = selectList [UserAge <-. [40, 41]] []  The above query when applied on  #dataset dataset-1, will produce this: ‹+-----+-----+-----+ |id |name |age | +-----+-----+-----+ |1 |SPJ |40 | +-----+-----+-----+ |2 |Simon|41 | +-----+-----+-----+ jselectSPJ :: MonadIO m => ReaderT SqlBackend m [Entity User] selectSPJ = selectList [UserAge <-. [40]] []  The above query when applied on  #dataset dataset-1, will produce this: c+-----+-----+-----+ |id |name |age | +-----+-----+-----+ |1 |SPJ |40 | +-----+-----+-----+y persistent$Check if value is not in given list. Example usage oselectSimon :: MonadIO m => ReaderT SqlBackend m [Entity User] selectSimon = selectList [UserAge /<-. [40]] []  The above query when applied on  #dataset dataset-1, will produce this: c+-----+-----+-----+ |id |name |age | +-----+-----+-----+ |2 |Simon|41 | +-----+-----+-----+z persistent,The OR of two lists of filters. For example: ‚selectList ([ PersonAge >. 25 , PersonAge <. 30 ] ||. [ PersonIncome >. 15000 , PersonIncome <. 25000 ]) []>will filter records where a person's age is between 25 and 30 or1 a person's income is between (15000 and 25000).If you are looking for an (&&.) operator to do (A AND B AND (C OR D)) you can use the (++)! operator instead as there is no (&&.). For example: ‚selectList ([ PersonAge >. 25 , PersonAge <. 30 ] ++ ([PersonCategory ==. 1] ||. [PersonCategory ==. 5])) []>will filter records where a person's age is between 25 and 30 and' (person's category is either 1 or 5).{ persistentConvert list of )Vs into textual representation of JSON object. This is a type-constrained synonym for }.| persistentqConvert map (list of tuples) into textual representation of JSON object. This is a type-constrained synonym for }.} persistent+A more general way to convert instances of â type class to strict text Å.~ persistentFIXME What's this exactly?ÿ   !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\`]^_abcedjfghiklmnopqrstuvwx{}yz|~€‚ƒ„…†‡ˆ‰Š‹ŒŽ‘’“”•–—˜™š›œžŸ ¡¢£¤¥¦§¨©ª«¬­®¯°²´³±¶»¹µ·¸º¼½¾¿ÀÁÂÃÄÅÆÓÝÔÞÜÕÖרÙÚÛßàáâãäåæçèéêëíîïðñòóôõö÷øùüúûýþÿ     mnopqrstuvwxyz{|}~mnopqrstvuwxyz{|}–~m3n3o3p3q3r4s4t4u4v4w4x4y4z3NoneNÒˆ persistent Gets the b for an ©.€‚ƒ„…†‡ˆ‰Š‹Œ†€‡‚ƒ„…ˆ‰‹ŒŠNone7;<=FOTVnÙŽ persistentRTells Persistent what database column type should be used to store a Haskell type.ExamplesSimple Boolean Alternative 7data Switch = On | Off deriving (Show, Eq) instance “ Switch where ” s = case s of On -> / True Off -> / False • (/ b) = if b then Ç On else Ç Off •z x = Left $ "File.hs: When trying to deserialize a Switch: expected PersistBool, received: " <> T.pack (show x) instance Ž Switch where  _ = # Non-Standard Database Types@If your database supports non-standard types, such as Postgres' uuid, you can use ( to use them: ,import qualified Data.UUID as UUID instance “ UUID where ” = 7 . toASCIIBytes • (7/ uuid) = case fromASCIIBytes uuid of Ý -> È` $ "Model/CustomTypes.hs: Failed to deserialize a UUID; received: " <> T.pack (show uuid) ß uuid' -> Ç uuid' •ƒ x = Left $ "File.hs: When trying to deserialize a UUID: expected PersistDbSpecific, received: "-- > <> T.pack (show x) instance Ž UUID where  _ = ( "uuid" User Created Database TypesHSimilarly, some databases support creating custom types, e.g. Postgres'  Dhttps://www.postgresql.org/docs/current/static/sql-createdomain.htmlDOMAIN and  Ahttps://www.postgresql.org/docs/current/static/datatype-enum.htmlENUM features. You can use ( to specify a custom type: >CREATE DOMAIN ssn AS text CHECK ( value ~ '^[0-9]{9}$');  instance PersistFieldSQL SSN where  _ = ( "ssn"  cCREATE TYPE rainbow_color AS ENUM ('red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet');  instance PersistFieldSQL RainbowColor where  _ = ( "rainbow_color"  persistent1Class for data types that may be retrived from a rawSql query.‘ persistentONumber of columns that this data type needs and the list of substitutions for SELECT placeholders ??.’ persistent>A string telling the user why the column count is what it is.“ persistent1Transform a row of the result into the data type.ã persistentŽ‘’“None+<FTªr– persistentExecute a raw SQL statement— persistentKExecute a raw SQL statement and return the number of rows it has modified.™ persistent>Execute a raw SQL statement and return its results as a list.If you're using —s$ (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 —s documentation for more details.0You 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 ”2 to help you constructing the placeholder values.]Since you're giving a raw SQL statement, you don't get any guarantees regarding safety. If ™¬ 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 T.Some example of ™ based on this schema: Éshare [mkPersist sqlSettings, mkMigrate "migrateAll"] [persistLowerCase| Person name String age Int Maybe deriving Show BlogPost title String authorId PersonId deriving Show |] #Examples based on the above schema: ÿ„getPerson :: MonadIO m => ReaderT SqlBackend m [Entity Person] getPerson = rawSql "select ?? from person where name=?" [PersistText "john"] getAge :: MonadIO m => ReaderT SqlBackend m [Single Int] getAge = rawSql "select person.age from person where name=?" [PersistText "john"] getAgeName :: MonadIO m => ReaderT SqlBackend m [(Single Int, Single Text)] getAgeName = rawSql "select person.age, person.name from person where name=?" [PersistText "john"] getPersonBlog :: MonadIO m => ReaderT SqlBackend m [(Entity Person, Entity BlogPost)] getPersonBlog = rawSql "select ??,?? from person,blog_post where person.id = blog_post.author_id" [] KMinimal working program for PostgreSQL backend based on the above concepts: ÿ-{-# LANGUAGE EmptyDataDecls #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE GADTs #-} {-# LANGUAGE GeneralizedNewtypeDeriving #-} {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE QuasiQuotes #-} {-# LANGUAGE TemplateHaskell #-} {-# LANGUAGE TypeFamilies #-} import Control.Monad.IO.Class (liftIO) import Control.Monad.Logger (runStderrLoggingT) import Database.Persist import Control.Monad.Reader import Data.Text import Database.Persist.Sql import Database.Persist.Postgresql import Database.Persist.TH share [mkPersist sqlSettings, mkMigrate "migrateAll"] [persistLowerCase| Person name String age Int Maybe deriving Show |] conn = "host=localhost dbname=new_db user=postgres password=postgres port=5432" getPerson :: MonadIO m => ReaderT SqlBackend m [Entity Person] getPerson = rawSql "select ?? from person where name=?" [PersistText "sibi"] liftSqlPersistMPool y x = liftIO (runSqlPersistMPool y x) main :: IO () main = runStderrLoggingT $ withPostgresqlPool conn 10 $ liftSqlPersistMPool $ do runMigration migrateAll xs <- getPerson liftIO (print xs) – persistent*SQL statement, possibly with placeholders. persistent Values to fill the placeholders.— persistent*SQL statement, possibly with placeholders. persistent Values to fill the placeholders.™ persistent*SQL statement, possibly with placeholders. persistent Values to fill the placeholders.”•–—䘙None+<FTVµ“š persistentbGet a connection from the pool, run the given action, and then return the connection to the pool.´Note: This function previously timed out after 2 seconds, but this behavior was buggy and caused more problems than it solved. Since version 2.1.2, it performs no timeout checks.›  persistentLike š-, but supports specifying an isolation level.å persistentLike æh, but times out the operation if resource allocation does not complete within the given timeout period.  persistentLike œ-, but supports specifying an isolation level.å persistentTimeout period in microseconds¡ persistentcreate a new connection persistentconnection count š›åœžŸ ¡¢£¤¥None+;<=>?FKQTV¿¯ persistent[get the SQL string for the table that a PeristEntity represents Useful for raw SQL queries`Your backend may provide a more convenient tableName function which does not operate in a Monad° persistent>useful for a backend to implement tableName by adding escaping± persistent[get the SQL string for the field that an EntityField represents Useful for raw SQL queries`Your backend may provide a more convenient fieldName function which does not operate in a Monad² persistent>useful for a backend to implement fieldName by adding escaping䪨¦«©§¬­®¯°±²None<FT¿¥None+FQTVų persistentSame as *, but returns the number of rows affected.´ persistentSame as *, but returns the number of rows affected.µ persistentBGenerates sql for limit and offset for postgres, sqlite and mysql.ç persistentinclude table name? persistentinclude WHERE?è persistentinclude table name?é persistentinclude the table name³´µNone<Úº ¶ persistentGiven a Xr, this parses it and returns either a list of errors associated with the migration or a list of migrations to do.· persistentLike ¶,, but instead of returning the value in an Æ value, it calls ê on the error values.¸ persistentPrints a migration.¹ persistent Convert a X to a list of Å values corresponding to their Z statements.º persistentReturn all of the Z4 values associated with the given migration. Calls ê+ if there's a parse error on any migration.» persistentkRuns a migration. If the migration fails to parse or if any of the migrations are unsafe, then this calls ê to halt the program.¼ persistentSame as »V, but returns a list of the SQL commands executed instead of printing them to stderr.ë persistentÏRun the given migration against the database. If the migration fails to parse, or there are any unsafe migrations, then this will error at runtime. This returns a list of the migrations that were executed.½ persistentLike »P, but this will perform the unsafe database migrations instead of erroring out.ì persistentQSort the alter DB statements so tables are created before constraints are added.¾ persistent1Given a list of old entity definitions and a new w in val, this creates a X9 to update the old list of definitions with the new one.ë persistent is silent? ¶·¸¹º»¼½¾Noneà¡¿ persistent3Commit the current transaction and begin a new one.À  persistentVCommit the current transaction and begin a new one with the specified isolation level.Á persistent6Roll back the current transaction and begin a new one.  persistentYRoll back the current transaction and begin a new one with the specified isolation level.ÿ›   !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\`]^_abcedjfghiklmnopqrstuvwx{}yz|~€‚ƒ„…†‡ˆ‰Š‹ŒŽ‘’“”•–—˜™š›œžŸ ¡¢£¤¥¦§¨©ª«¬­®¯°²´³±¶»¹µ·¸º¼½¾¿ÀÁÂÃÄÅÆÓÝÔÞÜÕÖרÙÚÛßàáâã䪨¦«©§åæçèéêëíîïðñòóôõö÷øùüúûýþÿ      !".#$%&'()*+,-/0123456789:;<=>?@ABCDFGHTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~Ž‘’“”•–—˜™š›œžŸ ¡¢£¤¥¬­®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂTUVWXYZ[\]^_`abcdefghij!".#$%&'()*+,-/01234 :;<=>?D@ABCHGF‘’“Žš›œžŸ ¡¢£¤¥¶·¸¹º»¼½¾¬äª¨¦«©§­®±¯°²”•–—™³´¿ÀÁÂ56789˜lkµí ! " # $ % & ' ( ) ) * + , - . / 0 1 2 3 4 5 6 7 8 9 : ; < = > ? @ A B C D E F G H I J K L M N O P Q R S T U V W X Y Y Z [ \ ] ^ _ ` a b b c d e e f g h i j j k l m n n o p q r s t u v w w x y z { | } ~  €  ‚ ƒ „ „ … † † ‡ ˆ ‰ ‰ Š ‹ Œ Ž ‘ ’ “ ” • – — ˜ ™ š › œ ž Ÿ   ¡ ¢ ¢ £ ¤ ¥ ¦ § § ¨ © ª ª « ¬ ­ ® ¯ ° 6 ± ² ³ ´ µ ¶ ¶ · ¸ ¹ º ( » ¼ ½ ¾ ¿ À Á Â Ã Ä Å Æ Ç È É Ê Ë Ì Í Î Ï Ð ÑÒÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ      !"#$%&'()*++,-./0123456789:;<=>?@ABCCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghhijklmnopqrstuvwxyz{|}~€‚ƒ„…†‡ˆ‰Š‹ŒŽ‘’“”•–—˜™š›œž Ÿ ¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÑÒÔÑÒÕ Ö × Ø Ù Ú ÛÑÜÝ ÞÑÜßàáâãâäåæçèéêëÑìíîÑìïðñÈòóôõö÷øùúûüÑýþÿ'persistent-2.9.0-IG71hmdjKut6Bg7wMGN6MCDatabase.Persist.ClassDatabase.Persist.TypesDatabase.PersistDatabase.Persist.Quasi#Database.Persist.Sql.Types.InternalDatabase.Persist.SqlDatabase.Persist.Sql.Util$Database.Persist.Class.PersistConfigDatabase.Persist.Types.Base#Database.Persist.Class.PersistField$Database.Persist.Class.PersistEntityDatabase.Persist.GenericSqlrawSql#Database.Persist.Class.PersistStore$Database.Persist.Class.PersistUnique#Database.Persist.Class.PersistQuery$Database.Persist.Class.DeleteCascadeDatabase.Persist.Sql.TypesDatabase.Persist.Sql.InternalDatabase.Persist.Sql.ClassDatabase.Persist.Sql.RawDatabase.Persist.Sql.Run(Database.Persist.Sql.Orphan.PersistStore)Database.Persist.Sql.Orphan.PersistUnique(Database.Persist.Sql.Orphan.PersistQueryDatabase.Persist.Sql.Migration PersistConfigPersistConfigBackendPersistConfigPool loadConfigapplyEnvcreatePoolConfigrunPool PersistUpdateAssignAddSubtractMultiplyDivideBackendSpecificUpdateOnlyUniqueExceptionUpdateException KeyNotFound UpsertError PersistFilterEqNeGtLtGeLeInNotInBackendSpecificFilterSqlType SqlStringSqlInt32SqlInt64SqlReal SqlNumericSqlBoolSqlDaySqlTime SqlDayTimeSqlBlobSqlOther PersistValue PersistTextPersistByteString PersistInt64 PersistDoublePersistRational PersistBool PersistDayPersistTimeOfDayPersistUTCTime PersistNull PersistList PersistMapPersistObjectIdPersistDbSpecificPersistException PersistErrorPersistMarshalErrorPersistInvalidFieldPersistForeignConstraintUnmetPersistMongoDBErrorPersistMongoDBUnsupported ForeignDefforeignRefTableHaskellforeignRefTableDBNameforeignConstraintNameHaskellforeignConstraintNameDBName foreignFields foreignAttrsforeignNullableForeignFieldDef CompositeDefcompositeFieldscompositeAttrs UniqueDef uniqueHaskell uniqueDBName uniqueFields uniqueAttrs EmbedFieldDef emFieldDB emFieldEmbed emFieldCycleEmbedEntityDefembeddedHaskellembeddedFields ReferenceDef NoReference ForeignRefEmbedRef CompositeRef SelfReferenceFieldDef fieldHaskellfieldDB fieldType fieldSqlType fieldAttrs fieldStrictfieldReference FieldType FTTypeConFTAppFTListAttrDBNameunDBName HaskellName unHaskellName ExtraLine EntityDef entityHaskellentityDBentityId entityAttrs entityFields entityUniquesentityForeigns entityDerives entityExtra entitySum WhyNullable ByMaybeAttrByNullableAttr IsNullableNullable NotNullable CheckmarkActiveInactive entityPrimaryentityKeyFieldskeyAndEntityFieldstoEmbedEntityDeffromPersistValueTextSomePersistField PersistFieldtoPersistValuefromPersistValue getPersistMapEntity entityKey entityValFilter FilterAndFilterOr BackendFilter filterField filterValue filterFilter SelectOptAscDescOffsetByLimitToUpdate BackendUpdate updateField updateValue updateUpdate PersistEntityPersistEntityBackendKey EntityFieldUnique keyToValues keyFromValuespersistIdField entityDefpersistFieldDeftoPersistFieldsfromPersistValuespersistUniqueKeyspersistUniqueToFieldNamespersistUniqueToValues fieldLens entityValueskeyValueEntityToJSONkeyValueEntityFromJSONentityIdToJSONentityIdFromJSONtoPersistValueJSONfromPersistValueJSONPersistSettings psToDBNamepsStrictFieldspsIdNameupperCaseSettingslowerCaseSettingsparsenullable$fShowParseState $fShowToken $fEqTokenPersistStoreWriteinsertinsert_ insertMany insertMany_insertEntityMany insertKeyrepsert repsertManyreplacedeleteupdate updateGetPersistStoreReadgetgetMany PersistCore BackendKey ToBackendKey toBackendKeyfromBackendKeyPersistRecordBackendBackendCompatibleprojectBackendIsPersistBackendmkPersistBackendHasPersistBackend BaseBackendpersistBackend liftPersistgetJust getJustEntity belongsTo belongsToJust insertEntity getEntity insertRecordPersistUniqueWritedeleteBy insertUniqueupsertupsertByputManyPersistUniqueReadgetByinsertByinsertUniqueEntity onlyUnique getByValue replaceUnique checkUniquePersistQueryWrite updateWhere deleteWherePersistQueryReadselectSourceRes selectFirst selectKeysRescount selectSource selectKeys selectListselectKeysList DeleteCascade deleteCascadedeleteCascadeWhere PersistStore PersistQuery PersistUnique IsSqlBackend SqlWriteTSqlReadTSqlBackendCanWriteSqlBackendCanReadSqlWriteBackendunSqlWriteBackendSqlReadBackendunSqlReadBackend SqlBackend connPrepare connInsertSqlconnInsertManySql connUpsertSqlconnPutManySql connStmtMap connCloseconnMigrateSql connBegin connCommit connRollbackconnEscapeName connNoLimit connRDBMSconnLimitOffset connLogFunc connMaxParamsconnRepsertManySqlIsolationLevelReadUncommitted ReadCommittedRepeatableRead Serializable Statement stmtFinalize stmtReset stmtExecute stmtQueryInsertSqlResult ISRSingle ISRInsertGet ISRManyKeysLogFuncmakeIsolationLevelStatementwriteToUnknown readToWrite readToUnknown$fIsPersistBackendSqlBackend$fHasPersistBackendSqlBackend $fIsPersistBackendSqlReadBackend!$fHasPersistBackendSqlReadBackend!$fIsPersistBackendSqlWriteBackend"$fHasPersistBackendSqlWriteBackend$fShowIsolationLevel$fEqIsolationLevel$fEnumIsolationLevel$fOrdIsolationLevel$fBoundedIsolationLevelSingleunSingleConnectionPool MigrationCautiousMigrationSql SqlPersistM SqlPersist SqlPersistTPersistentSqlExceptionStatementAlreadyFinalizedCouldn'tGetSQLConnectionColumncNamecNullcSqlTypecDefaultcDefaultConstraintNamecMaxLen cReference ConnectiondefaultAttribute mkColumns=.+=.-=.*=./=.==.!=.<.<=.>.>=.<-./<-.||. listToJSON mapToJSON toJsonTextlimitOffsetOrderentityColumnNameskeyAndEntityColumnNamesentityColumnCounthasCompositeKey dbIdColumnsdbIdColumnsEsc dbColumnsparseEntityValues isIdFieldupdateFieldDefupdatePersistValuecommaSeparated mkUpdateText mkUpdateText' parenWrappedPersistFieldSqlsqlTypeRawSql rawSqlColsrawSqlColCountReasonrawSqlProcessRowrawQuery rawQueryRes rawExecuterawExecuteCount getStmtConn runSqlPoolrunSqlPoolWithIsolation runSqlConnrunSqlConnWithIsolationrunSqlPersistMrunSqlPersistMPoolliftSqlPersistMPool withSqlPool createSqlPool askLogFunc withSqlConnclose'SqlWriteBackendKeyunSqlWriteBackendKeySqlReadBackendKeyunSqlReadBackendKey SqlBackendKeyunSqlBackendKey withRawQuerytoSqlKey fromSqlKey getTableName tableDBName getFieldName fieldDBNamedeleteWhereCountupdateWhereCountdecorateSQLWithLimitOffsetparseMigrationparseMigration'printMigration showMigration getMigration runMigrationrunMigrationSilentrunMigrationUnsafemigratetransactionSavetransactionSaveWithIsolationtransactionUndotransactionUndoWithIsolation$aeson-1.4.1.0-JaiCPnIg80cGqC9EfqkML4Data.Aeson.Types.InternalValuebytestring-0.10.8.2Data.ByteString.Internal ByteString text-1.2.3.0Data.Text.InternalTextbase Data.EitherEitherRightLeftextraInputError intParseErrorfromPersistValueErrorfromPersistValueParseErroridFieldtoPersistValueEnumGHC.EnumEnumfromPersistValueEnumBounded_unboundFieldsLineTokenSpacestokenizeempty removeSpaces parseLines mkEntityDeftransformers-0.5.5.0Control.Monad.Trans.ReaderReaderTGHC.BaseNothing _insertOrGetJustdefaultPutManypersistUniqueKeyValuesData.Aeson.Types.ToJSONToJSON $fRawSqlMaybegetStmtwithResourceTimeout,resource-pool-0.2.3.2-64aL1uw9r6qI8STNDTLTWE Data.Pool withResourcefilterClauseHelper filterClause orderClauseGHC.Errerror runMigration'sortMigrations