Copyright | Flipstone Technology Partners 2023 |
---|---|
License | MIT |
Stability | Stable |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
This module provides functions and types for describing a single-column data
type that exists in PostgreSQL so that Orville can determine how to serialize
Haskell values to and from the SQL type. If you need to use a SQL type that
Orville does not provide support for here, you can construct your own SqlType
value and use fieldOfType
to build the required
FieldDefinition
.
Since: 1.0.0.0
Synopsis
- data SqlType a = SqlType {}
- integer :: SqlType Int32
- serial :: SqlType Int32
- bigInteger :: SqlType Int64
- bigSerial :: SqlType Int64
- smallInteger :: SqlType Int16
- double :: SqlType Double
- boolean :: SqlType Bool
- unboundedText :: SqlType Text
- fixedText :: Int32 -> SqlType Text
- boundedText :: Int32 -> SqlType Text
- textSearchVector :: SqlType Text
- uuid :: SqlType UUID
- date :: SqlType Day
- timestamp :: SqlType UTCTime
- timestampWithoutZone :: SqlType LocalTime
- jsonb :: SqlType Text
- oid :: SqlType Oid
- foreignRefType :: SqlType a -> SqlType a
- convertSqlType :: (b -> a) -> (a -> b) -> SqlType a -> SqlType b
- tryConvertSqlType :: (b -> a) -> (a -> Either String b) -> SqlType a -> SqlType b
Documentation
SqlType defines the mapping of a Haskell type (a
) to a SQL column type in the
database. This includes both how to convert the type to and from the raw values
read from the database as well as the schema information required to create
and migrate columns using the type.
Since: 1.0.0.0
SqlType | |
|
bigInteger :: SqlType Int64 Source #
bigInteger
defines a 64-bit integer type. This corresponds to the BIGINT
type in SQL.
Since: 1.0.0.0
smallInteger :: SqlType Int16 Source #
smallInteger
defines a 16-bit integer type. This corresponds to the SMALLINT type in SQL.
Since: 1.0.0.0
double :: SqlType Double Source #
double
defines a floating point numeric type. This corresponds to the
"DOUBLE PRECISION" type in SQL.
Since: 1.0.0.0
unboundedText :: SqlType Text Source #
unboundedText
defines an unbounded length text field type. This corresponds to a
TEXT type in PostgreSQL.
Since: 1.0.0.0
fixedText :: Int32 -> SqlType Text Source #
fixedText
defines a fixed length text field type. This corresponds to a
"CHAR(len)" type in PostgreSQL.
Since: 1.0.0.0
boundedText :: Int32 -> SqlType Text Source #
boundedText
defines a variable length text field type. This corresponds to a
"VARCHAR(len)" type in PostgreSQL.
Since: 1.0.0.0
textSearchVector :: SqlType Text Source #
textSearchVector
defines a type for indexed text searching. It corresponds to the
TSVECTOR type in PostgreSQL.
Since: 1.0.0.0
timestamp :: SqlType UTCTime Source #
timestamp
defines a type representing a particular point in time without time zone information,
but can be constructed with a time zone offset.
It corresponds to the "TIMESTAMP with time zone" type in SQL.
Note: This is NOT a typo. The "TIMESTAMP with time zone" type in SQL does not include any actual time zone information. For an excellent explanation of the complexities involving this type, please see Chris Clark's blog post about it: http://blog.untrod.com/2016/08/actually-understanding-timezones-in-postgresql.html
Since: 1.0.0.0
timestampWithoutZone :: SqlType LocalTime Source #
timestampWithoutZone
defines a type representing a particular point in time (without time zone).
It corresponds to the "TIMESTAMP without time zone" type in SQL.
http://blog.untrod.com/2016/08/actually-understanding-timezones-in-postgresql.html
Since: 1.0.0.0
oid
corresponds to the type used in PostgreSQL for identifying system
objects.
Since: 1.0.0.0
foreignRefType :: SqlType a -> SqlType a Source #
foreignRefType
creates a SqlType
suitable for columns that will be
foreign keys referencing a column of the given SqlType
. For most types, the
underlying SQL type will be identical, but for special types (such as
auto-incrementing primary keys), the type constructed by foreignRefType
will
have a regular underlying SQL type. Each SqlType
definition must specify any
special handling required when creating foreign reference types by setting
the sqlTypeReferenceExpr
field to an appropriate value.
Since: 1.0.0.0
convertSqlType :: (b -> a) -> (a -> b) -> SqlType a -> SqlType b Source #
convertSqlType
changes the Haskell type used by a SqlType
in the same manner
as tryConvertSqlType
in cases where an a
can always be converted to a b
.
Since: 1.0.0.0
tryConvertSqlType :: (b -> a) -> (a -> Either String b) -> SqlType a -> SqlType b Source #
tryConvertSqlType
changes the Haskell type used by a SqlType
which
changes the column type that will be used in the database schema. The
functions given will be used to convert the now Haskell type to and from the
original type when reading and writing values from the database. When reading
an a
value from the database, the conversion function should produce Left
with an error message if the value cannot be successfully converted to a b
.
Since: 1.0.0.0