orville-postgresql-1.0.0.0: A Haskell library for PostgreSQL
CopyrightFlipstone Technology Partners 2023
LicenseMIT
StabilityStable
Safe HaskellSafe-Inferred
LanguageHaskell2010

Orville.PostgreSQL.Marshall.SqlType

Description

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

Documentation

data SqlType a Source #

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

Constructors

SqlType 

Fields

  • sqlTypeExpr :: DataType

    The SQL data type expression to use when creating/migrating columns of this type.

  • sqlTypeReferenceExpr :: Maybe DataType

    The SQL data type expression to use when creating/migrating columns with foreign keys to this type. This is used by foreignRefType to build a new SqlType when making foreign key fields.

  • sqlTypeOid :: Oid

    The Oid for the type in PostgreSQL. This will be used during migrations to determine whether the column type needs to be altered.

  • sqlTypeMaximumLength :: Maybe Int32

    The maximum length for types that take a type parameter (such as char and varchar). This will be used during migration to determine whether the column type needs to be altered.

  • sqlTypeToSql :: a -> SqlValue

    A function for converting Haskell values of this type into values to be stored in the database.

  • sqlTypeFromSql :: SqlValue -> Either String a

    A function for converting values of this type stored in the database into Haskell values. This function should return Left to indicate an error if the conversion is impossible. Otherwise it should return a Right of the corresponding a value.

  • sqlTypeDontDropImplicitDefaultDuringMigrate :: Bool

    The SERIAL and BIGSERIAL PostgreSQL types are really pseudo-types that create an implicit default value. This flag tells Orville's auto-migration logic to ignore the default value rather than drop it as it normally would.

integer :: SqlType Int32 Source #

integer defines a 32-bit integer type. This corresponds to the INTEGER type in SQL.

Since: 1.0.0.0

serial :: SqlType Int32 Source #

serial defines a 32-bit auto-incrementing column type. This corresponds to the SERIAL type in PostgreSQL.

Since: 1.0.0.0

bigInteger :: SqlType Int64 Source #

bigInteger defines a 64-bit integer type. This corresponds to the BIGINT type in SQL.

Since: 1.0.0.0

bigSerial :: SqlType Int64 Source #

bigSerial defines a 64-bit auto-incrementing column type. This corresponds to the BIGSERIAL type in PostgresSQL.

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

boolean :: SqlType Bool Source #

boolean defines a True/False boolean type. This corresponds to the BOOLEAN 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

uuid :: SqlType UUID Source #

uuid defines a UUID type. It corresponds to the UUID type in PostgreSQL.

Since: 1.0.0.0

date :: SqlType Day Source #

date defines a type representing a calendar date (without time zone). It corresponds to the DATE type in SQL.

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

jsonb :: SqlType Text Source #

jsonb represents any type that can be converted To and From JSON. This corresponds to the JSONB type in PostgreSQL.

Since: 1.0.0.0

oid :: SqlType Oid Source #

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