persistent-0.4.0.1: Type-safe, non-relational, multi-backend persistence.

Database.Persist.Base

Description

This defines the API for performing database actions. There are two levels to this API: dealing with fields, and dealing with entities. In SQL, a field corresponds to a column, and should be a single, non-composite value. An entity corresponds to a SQL table. In other words: An entity is a collection of fields.

Synopsis

Documentation

data SqlType Source

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.

Constructors

SqlString 
SqlInt32 
SqlInteger

8-byte integer; should be renamed SqlInt64

SqlReal 
SqlBool 
SqlDay 
SqlTime 
SqlDayTime 
SqlBlob 

class PersistEntity val whereSource

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.

Associated Types

data Key val Source

The unique identifier associated with this entity. In general, backends also define a type synonym for this, such that "type MyEntityId = Key MyEntity".

data Update val Source

Fields which can be updated using the update and updateWhere functions.

data Filter val Source

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 Order val Source

How you can sort the results of a select.

data Unique val Source

Unique keys in existence on this entity.

data EntityDef Source

Constructors

EntityDef 

Fields

entityName :: String
 
entityAttribs :: [String]
 
entityColumns :: [(String, String, [String])]

name, type, attribs

entityUniques :: [(String, [String])]

name, columns

entityDerives :: [String]
 

class Monad m => PersistBackend m whereSource

Methods

insert :: PersistEntity val => val -> m (Key val)Source

Create a new record in the database, returning the newly created identifier.

replace :: PersistEntity val => Key val -> val -> m ()Source

Replace the record in the database with the given key. Result is undefined if such a record does not exist.

update :: PersistEntity val => Key val -> [Update val] -> m ()Source

Update individual fields on a specific record.

updateWhere :: PersistEntity val => [Filter val] -> [Update val] -> m ()Source

Update individual fields on any record matching the given criterion.

delete :: PersistEntity val => Key val -> m ()Source

Delete a specific record by identifier. Does nothing if record does not exist.

deleteBy :: PersistEntity val => Unique val -> m ()Source

Delete a specific record by unique key. Does nothing if no record matches.

deleteWhere :: PersistEntity val => [Filter val] -> m ()Source

Delete all records matching the given criterion.

get :: PersistEntity val => Key val -> m (Maybe val)Source

Get a record by identifier, if available.

getBy :: PersistEntity val => Unique val -> m (Maybe (Key val, val))Source

Get a record by unique key, if available. Returns also the identifier.

selectSource

Arguments

:: PersistEntity val 
=> [Filter val] 
-> [Order val] 
-> Int

limit

-> Int

offset

-> Enumerator (Key val, val) m a 

Get all records matching the given criterion in the specified order. Returns also the identifiers.

selectKeys :: PersistEntity val => [Filter val] -> Enumerator (Key val) m aSource

Get the Keys of all records matching the given criterion.

count :: PersistEntity val => [Filter val] -> m IntSource

The total number of records fulfilling the given criterion.

selectListSource

Arguments

:: (PersistEntity val, PersistBackend m, Monad m) 
=> [Filter val] 
-> [Order val] 
-> Int

limit

-> Int

offset

-> m [(Key val, val)] 

Call select but return the result as a list.

insertBy :: (PersistEntity v, PersistBackend m) => v -> m (Either (Key v, v) (Key v))Source

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.

checkUnique :: (PersistEntity val, PersistBackend m) => val -> m BoolSource

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.