opaleye-0.6.0.0: An SQL-generating DSL targeting PostgreSQL

Safe HaskellNone
LanguageHaskell2010

Opaleye.Table

Contents

Description

Columns can be required or optional and, independently, nullable or non-nullable.

A required non-nullable PGInt4 (for example) is created with required and gives rise to a

TableColumns (Column PGInt4) (Column PGInt4)

The leftmost argument is the type of writes. When you insert or update into this column you must give it a Column PGInt4 (which you can create with pgInt4 :: Int -> Column PGInt4).

A required nullable PGInt4 is created with required and gives rise to a

TableColumns (Column (Nullable PGInt4)) (Column (Nullable PGInt4))

When you insert or update into this column you must give it a Column (Nullable PGInt4), which you can create either with pgInt4 and toNullable :: Column a -> Column (Nullable a), or with null :: Column (Nullable a).

An optional non-nullable PGInt4 is created with optional and gives rise to a

TableColumns (Maybe (Column PGInt4)) (Column PGInt4)

Optional columns are those that can be omitted on writes, such as those that have DEFAULTs or those that are SERIAL. When you insert or update into this column you must give it a Maybe (Column PGInt4). If you provide Nothing then the column will be omitted from the query and the default value will be used. Otherwise you have to provide a Just containing a Column PGInt4.

An optional nullable PGInt4 is created with optional and gives rise to a

TableColumns (Maybe (Column (Nullable PGInt4))) (Column (Nullable PGInt4))

Optional columns are those that can be omitted on writes, such as those that have DEFAULTs or those that are SERIAL. When you insert or update into this column you must give it a Maybe (Column (Nullable PGInt4)). If you provide Nothing then the default value will be used. Otherwise you have to provide a Just containing a Column (Nullable PGInt4) (which can be null).

Synopsis

Creating tables

table Source #

Arguments

:: String

Table name

-> TableColumns writeColumns viewColumns 
-> Table writeColumns viewColumns 

Create a table with unqualified names.

tableWithSchema Source #

Arguments

:: String

Schema name

-> String

Table name

-> TableColumns writeColumns viewColumns 
-> Table writeColumns viewColumns 

Create a table.

data Table writerColumns viewColumns Source #

Constructors

Table String (TableColumns writerColumns viewColumns)

For unqualified table names. Do not use the constructor. It is internal and will be deprecated in version 0.7.

TableWithSchema String String (TableColumns writerColumns viewColumns)

Schema name, table name, table properties. Do not use the constructor. It is internal and will be deprecated in version 0.7.

Instances

Profunctor Table Source # 

Methods

dimap :: (a -> b) -> (c -> d) -> Table b c -> Table a d #

lmap :: (a -> b) -> Table b c -> Table a c #

rmap :: (b -> c) -> Table a b -> Table a c #

(#.) :: Coercible * c b => (b -> c) -> Table a b -> Table a c #

(.#) :: Coercible * b a => Table b c -> (a -> b) -> Table a c #

Functor (Table a) Source # 

Methods

fmap :: (a -> b) -> Table a a -> Table a b #

(<$) :: a -> Table a b -> Table a a #

tableColumn :: TableColumn a b => String -> TableColumns a (Column b) Source #

Create either a required or optional column depending on the write type. It's generally more convenient to use this than required or optional.

optional :: String -> TableColumns (Maybe (Column a)) (Column a) Source #

optional is for columns that you can omit on writes, such as columns which have defaults or which are SERIAL.

required :: String -> TableColumns (Column a) (Column a) Source #

required is for columns which are not optional. You must provide them on writes.

Querying tables

queryTable :: Default Unpackspec columns columns => Table a columns -> Query columns Source #

Example type specialization:

queryTable :: Table w (Column a, Column b)
           -> Query (Column a, Column b)

Assuming the makeAdaptorAndInstance splice has been run for the product type Foo:

queryTable :: Table w (Foo (Column a) (Column b) (Column c))
           -> Query (Foo (Column a) (Column b) (Column c))

Other

type TableColumns = TableProperties Source #

The new name for TableColumns which will replace TableColumn in version 0.7.

Deprecated

data View columns Source #

Internal only. Do not use. View will be deprecated in version 0.7.

data Writer columns dummy Source #

Internal only. Do not use. Writer will be deprecated in version 0.7.

Instances

ProductProfunctor Writer Source # 

Methods

purePP :: b -> Writer a b #

(****) :: Writer a (b -> c) -> Writer a b -> Writer a c #

empty :: Writer () () #

(***!) :: Writer a b -> Writer a' b' -> Writer (a, a') (b, b') #

Profunctor Writer Source # 

Methods

dimap :: (a -> b) -> (c -> d) -> Writer b c -> Writer a d #

lmap :: (a -> b) -> Writer b c -> Writer a c #

rmap :: (b -> c) -> Writer a b -> Writer a c #

(#.) :: Coercible * c b => (b -> c) -> Writer a b -> Writer a c #

(.#) :: Coercible * b a => Writer b c -> (a -> b) -> Writer a c #

Functor (Writer a) Source # 

Methods

fmap :: (a -> b) -> Writer a a -> Writer a b #

(<$) :: a -> Writer a b -> Writer a a #

Applicative (Writer a) Source # 

Methods

pure :: a -> Writer a a #

(<*>) :: Writer a (a -> b) -> Writer a a -> Writer a b #

(*>) :: Writer a a -> Writer a b -> Writer a b #

(<*) :: Writer a a -> Writer a b -> Writer a a #

data Table writerColumns viewColumns Source #

Constructors

Table String (TableColumns writerColumns viewColumns)

For unqualified table names. Do not use the constructor. It is internal and will be deprecated in version 0.7.

TableWithSchema String String (TableColumns writerColumns viewColumns)

Schema name, table name, table properties. Do not use the constructor. It is internal and will be deprecated in version 0.7.

Instances

Profunctor Table Source # 

Methods

dimap :: (a -> b) -> (c -> d) -> Table b c -> Table a d #

lmap :: (a -> b) -> Table b c -> Table a c #

rmap :: (b -> c) -> Table a b -> Table a c #

(#.) :: Coercible * c b => (b -> c) -> Table a b -> Table a c #

(.#) :: Coercible * b a => Table b c -> (a -> b) -> Table a c #

Functor (Table a) Source # 

Methods

fmap :: (a -> b) -> Table a a -> Table a b #

(<$) :: a -> Table a b -> Table a a #

Module reexport

queryTable :: Default Unpackspec columns columns => Table a columns -> Query columns Source #

Example type specialization:

queryTable :: Table w (Column a, Column b)
           -> Query (Column a, Column b)

Assuming the makeAdaptorAndInstance splice has been run for the product type Foo:

queryTable :: Table w (Foo (Column a) (Column b) (Column c))
           -> Query (Foo (Column a) (Column b) (Column c))

table Source #

Arguments

:: String

Table name

-> TableColumns writeColumns viewColumns 
-> Table writeColumns viewColumns 

Create a table with unqualified names.

tableWithSchema Source #

Arguments

:: String

Schema name

-> String

Table name

-> TableColumns writeColumns viewColumns 
-> Table writeColumns viewColumns 

Create a table.

Explicit versions

queryTableExplicit :: Unpackspec tablecolumns columns -> Table a tablecolumns -> Query columns Source #