| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Opaleye.Table
Description
Fields can be required or optional and, independently, nullable or non-nullable.
A required non-nullable SqlInt4 (for example) is defined with
required and gives rise to a
TableFields (Field SqlInt4) (Field SqlInt4)
The leftmost argument is the type of writes. When you insert or
update into this column you must give it a Field SqlInt4 (which you
can define with sqlInt4 :: Int -> Field SqlInt4).
A required nullable SqlInt4 is defined with required and gives rise
to a
TableFields (FieldNullable SqlInt4) (FieldNullable SqlInt4)
When you insert or update into this column you must give it a
FieldNullable SqlInt4, which you can define either with sqlInt4 and
toNullable :: Field a -> FieldNullable a, or with null ::
FieldNullable a.
An optional non-nullable SqlInt4 is defined with optional and gives
rise to a
TableFields (Maybe (Field SqlInt4)) (Field 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
(Field 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 Field SqlInt4.
An optional nullable SqlInt4 is defined with optional and gives
rise to a
TableFields (Maybe (FieldNullable SqlInt4)) (FieldNullable 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
(FieldNullable SqlInt4). If you provide Nothing then the default
value will be used. Otherwise you have to provide a Just containing
a FieldNullable SqlInt4 (which can be null).
Synopsis
- table :: String -> TableFields writeFields viewFields -> Table writeFields viewFields
- tableWithSchema :: String -> String -> TableFields writeFields viewFields -> Table writeFields viewFields
- data Table writeFields viewFields
- tableField :: TableColumn writeType sqlType => String -> TableFields writeType (Column sqlType)
- optional :: String -> TableFields (Maybe (Column a)) (Column a)
- readOnly :: String -> TableFields () (Column a)
- required :: String -> TableFields (Column a) (Column a)
- selectTable :: Default Unpackspec fields fields => Table a fields -> Select fields
- type TableColumns = TableProperties
- type TableFields = TableProperties
- tableColumn :: TableColumn writeType sqlType => String -> TableFields writeType (Column sqlType)
- data View columns
- data Writer columns dummy
- data Table writeFields viewFields
- = Table String (TableFields writeFields viewFields)
- | TableWithSchema String String (TableFields writeFields viewFields)
- selectTable :: Default Unpackspec fields fields => Table a fields -> Select fields
- table :: String -> TableFields writeFields viewFields -> Table writeFields viewFields
- tableWithSchema :: String -> String -> TableFields writeFields viewFields -> Table writeFields viewFields
- selectTableExplicit :: Unpackspec tablefields fields -> Table a tablefields -> Select fields
- queryTable :: Default Unpackspec fields fields => Table a fields -> Select fields
- queryTableExplicit :: Unpackspec tablefields fields -> Table a tablefields -> Select fields
Defining tables
Arguments
| :: String | Table name |
| -> TableFields writeFields viewFields | |
| -> Table writeFields viewFields |
Define a table with an unqualified name.
Arguments
| :: String | Schema name |
| -> String | Table name |
| -> TableFields writeFields viewFields | |
| -> Table writeFields viewFields |
Define a table with a qualified name.
data Table writeFields viewFields Source #
Instances
| Profunctor Table Source # | |
Defined in Opaleye.Internal.Table | |
| Functor (Table a) Source # | |
tableField :: TableColumn writeType sqlType => String -> TableFields writeType (Column sqlType) Source #
optional :: String -> TableFields (Maybe (Column a)) (Column a) Source #
optional is for fields that you can omit on writes, such as
columns which have defaults or which are SERIAL.
readOnly :: String -> TableFields () (Column a) Source #
readOnly is for fields that you must omit on writes, such as
SERIAL columns intended to auto-increment only.
Querying tables
Arguments
| :: Default Unpackspec fields fields | |
| => Table a fields | |
| -> Select fields |
Example type specialization:
selectTable :: Table w (Field a, Field b)
-> Select (Field a, Field b)
Assuming the makeAdaptorAndInstance splice has been run for the
product type Foo:
selectTable :: Table w (Foo (Field a) (Field b) (Field c))
-> Select (Foo (Field a) (Field b) (Field 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
tableColumn :: TableColumn writeType sqlType => String -> TableFields writeType (Column sqlType) Source #
Do not use. Use tableField instead. Will be deprecated in
0.7.
data Writer columns dummy Source #
Internal only. Do not use. Writer will be deprecated in
version 0.7.
Instances
| Profunctor Writer Source # | |
Defined in Opaleye.Internal.Table | |
| ProductProfunctor Writer Source # | |
| Functor (Writer a) Source # | |
| Applicative (Writer a) Source # | |
data Table writeFields viewFields Source #
Constructors
| Table String (TableFields writeFields viewFields) | For unqualified table names. Do not use the constructor. It is internal and will be deprecated in version 0.7. |
| TableWithSchema String String (TableFields writeFields viewFields) | 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 # | |
Defined in Opaleye.Internal.Table | |
| Functor (Table a) Source # | |
Module reexport
Arguments
| :: Default Unpackspec fields fields | |
| => Table a fields | |
| -> Select fields |
Example type specialization:
selectTable :: Table w (Field a, Field b)
-> Select (Field a, Field b)
Assuming the makeAdaptorAndInstance splice has been run for the
product type Foo:
selectTable :: Table w (Foo (Field a) (Field b) (Field c))
-> Select (Foo (Field a) (Field b) (Field c))
Arguments
| :: String | Table name |
| -> TableFields writeFields viewFields | |
| -> Table writeFields viewFields |
Define a table with an unqualified name.
Arguments
| :: String | Schema name |
| -> String | Table name |
| -> TableFields writeFields viewFields | |
| -> Table writeFields viewFields |
Define a table with a qualified name.
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.