simple-0.4.0: A minimalist web framework for the WAI server interface

Safe HaskellNone



Type classes for PostgreSQL-backed data models.



class FromParams p whereSource


fromParams :: [Param] -> Maybe pSource

Converts an HTML form into a type


(FromParams a, FromParams b) => FromParams (a, b) 

type Param = (ByteString, ByteString)

Post parameter name and value.

class (FromRow p, ToRow p, ToField (PrimaryKey p), FromField (PrimaryKey p)) => PostgreSQLModel p whereSource

Basis type for PostgreSQL-backed data-models. Instances must, at minimum, implement primaryKey, tableName and columns. /Note: the column ordering must match that used in the type's implementation of FromRow and ToRow/

Associated Types

type PrimaryKey p :: *Source


primaryKey :: p -> Maybe (PrimaryKey p)Source

Given a model, returns the value of it's primary key. In many cases, this will simply be an alias to a record accessor.

tableName :: p -> TableName pSource

Returns the TableName of the model. Instances should have a top-level value for the TableName that is always returned. For example:

 employees :: TableName Employee
 employees = TableName "employees"

 instance PostgreSQLModel Employee where
   tableName _ = employess

columns :: TableName p -> [String]Source

Column names excluding primary key. Column order must match the ordering used in ToRow and FromRow.

primaryKeyName :: TableName p -> StringSource

Name of primary key column (default: "id").

columns_ :: TableName p -> [String]Source

Column names with primary-key name prepended.

orderBy :: TableName p -> Maybe StringSource

insert :: p -> Connection -> IO (PrimaryKey p)Source

Inserts the model into the database. It relies on the primary key being autogenerated by the database.

upsert :: p -> Connection -> IO (PrimaryKey p)Source

Create or update the model (uses the primary key to determine if the model already exists in the database)

destroy :: p -> Connection -> IO BoolSource

find :: TableName p -> PrimaryKey p -> Connection -> IO (Maybe p)Source

Retrieves the single model corresponding to the given primary key



:: ToField f 
=> TableName p 
-> String

Search column name

-> f

Search value

-> Connection 
-> IO (Maybe p) 

Finds the first model in the database based on the column-value contstraint.

findAll :: TableName p -> Connection -> IO [p]Source

Retrieves all models in the table



:: ToField f 
=> TableName p 
-> String

Search column name

-> f

Search value

-> Connection 
-> IO [p] 

Retrieves all models in the table subject to the column-value constraint.

class (PostgreSQLModel parent, PostgreSQLModel child) => HasMany parent child whereSource

Defines a "has-many" relationship between two models, where the parent model may be associated with zero or more of the child model. Specifically, the child table has a foreign key column pointing to the parent model.


foreignKey :: TableName parent -> TableName child -> StringSource

childrenOf :: parent -> TableName child -> Connection -> IO [child]Source

childOf :: parent -> TableName child -> PrimaryKey child -> Connection -> IO (Maybe child)Source

childOfBy :: ToField v => parent -> TableName child -> String -> v -> Connection -> IO (Maybe child)Source

childrenOfBy :: ToField f => parent -> TableName child -> String -> f -> Connection -> IO [child]Source

insertFor :: parent -> child -> Connection -> IO (PrimaryKey child)Source

newtype TableName p Source

Wrapper type representing PostgreSQL table names


TableName String 


class IsString a where

Class for string-like datastructures; used by the overloaded string extension (-foverloaded-strings in GHC).


fromString :: String -> a