opaleye-0.6.7003.1: 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 SqlInt4 (for example) is created with required and gives rise to a

TableFields (Column SqlInt4) (Column SqlInt4)

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

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

TableFields (Column (Nullable SqlInt4)) (Column (Nullable SqlInt4))

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

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

TableFields (Maybe (Column SqlInt4)) (Column SqlInt4)

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 SqlInt4). 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 SqlInt4.

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

TableFields (Maybe (Column (Nullable SqlInt4))) (Column (Nullable SqlInt4))

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 SqlInt4)). If you provide Nothing then the default value will be used. Otherwise you have to provide a Just containing a Column (Nullable SqlInt4) (which can be null).

Synopsis

Creating tables

table Source #

Arguments

:: String

Table name

-> TableFields writeFields viewFields 
-> Table writeFields viewFields 

Create a table with unqualified names.

tableWithSchema Source #

Arguments

:: String

Schema name

-> String

Table name

-> TableFields writeFields viewFields 
-> Table writeFields viewFields 

Create a table.

data Table writerColumns viewColumns Source #

Instances
Profunctor Table Source # 
Instance details

Defined in Opaleye.Internal.Table

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 => q b c -> Table a b -> Table a c #

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

Functor (Table a) Source # 
Instance details

Defined in Opaleye.Internal.Table

Methods

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

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

tableColumn :: TableColumn writeType sqlType => String -> TableFields writeType (Column sqlType) Source #

Infer either a required or optional column depending on the write type. It's generally more convenient to use this than required or optional but you do have to provide a type signature instead.

tableField :: TableColumn writeType sqlType => String -> TableFields writeType (Column sqlType) Source #

optional :: String -> TableFields (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 -> TableFields (Column a) (Column a) Source #

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

Querying tables

selectTable Source #

Arguments

:: Default Unpackspec fields fields 
=> Table a fields 
-> Select fields 

Example type specialization:

selectTable :: Table w (Column a, Column b)
            -> Select (Column a, Column b)

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

selectTable :: Table w (Foo (Column a) (Column b) (Column c))
            -> Select (Foo (Column a) (Column b) (Column c))

Other

type TableColumns = TableProperties Source #

Use TableFields instead. TableColumns will be deprecated in version 0.7.

type TableFields = TableProperties Source #

The new name for TableColumns and TableProperties which will replace them 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
Profunctor Writer Source # 
Instance details

Defined in Opaleye.Internal.Table

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 => q b c -> Writer a b -> Writer a c #

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

ProductProfunctor Writer Source # 
Instance details

Defined in Opaleye.Internal.Table

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') #

Functor (Writer a) Source # 
Instance details

Defined in Opaleye.Internal.Table

Methods

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

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

Applicative (Writer a) Source # 
Instance details

Defined in Opaleye.Internal.Table

Methods

pure :: a0 -> Writer a a0 #

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

liftA2 :: (a0 -> b -> c) -> Writer a a0 -> Writer a b -> Writer a c #

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

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

data Table writerColumns viewColumns Source #

Constructors

Table String (TableFields 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 (TableFields 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 # 
Instance details

Defined in Opaleye.Internal.Table

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 => q b c -> Table a b -> Table a c #

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

Functor (Table a) Source # 
Instance details

Defined in Opaleye.Internal.Table

Methods

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

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

Module reexport

selectTable Source #

Arguments

:: Default Unpackspec fields fields 
=> Table a fields 
-> Select fields 

Example type specialization:

selectTable :: Table w (Column a, Column b)
            -> Select (Column a, Column b)

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

selectTable :: Table w (Foo (Column a) (Column b) (Column c))
            -> Select (Foo (Column a) (Column b) (Column c))

table Source #

Arguments

:: String

Table name

-> TableFields writeFields viewFields 
-> Table writeFields viewFields 

Create a table with unqualified names.

tableWithSchema Source #

Arguments

:: String

Schema name

-> String

Table name

-> TableFields writeFields viewFields 
-> Table writeFields viewFields 

Create a table.

selectTableExplicit Source #

Arguments

:: Unpackspec tablefields fields 
-> Table a tablefields 
-> Select fields 

queryTable :: Default Unpackspec fields fields => Table a fields -> Select fields Source #

Use selectTable instead. Will be deprecated in version 0.7.

queryTableExplicit :: Unpackspec tablefields fields -> Table a tablefields -> Select fields Source #

Use selectTableExplicit instead. Will be deprecated in version 0.7.