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

Orville.PostgreSQL.Marshall.SyntheticField

Description

Since: 1.0.0.0

Synopsis

Documentation

data SyntheticField a Source #

A SyntheticField can be used to evaluate a SQL expression based on the columns of a table when records are selected from the database. Synthetic fields are inherently read-only.

Since: 1.0.0.0

syntheticFieldExpression :: SyntheticField a -> ValueExpression Source #

Returns the SQL expression that should be used in select statements to calculate the synthetic field.

Since: 1.0.0.0

syntheticFieldAlias :: SyntheticField a -> FieldName Source #

Returns the alias that should be used in select statements to name the synthetic field.

Since: 1.0.0.0

syntheticFieldValueFromSqlValue :: SyntheticField a -> SqlValue -> Either String a Source #

Decodes a calculated value selected from the database to its expected Haskell type. Returns a Left with an error message if the decoding fails.

Since: 1.0.0.0

syntheticField Source #

Arguments

:: ValueExpression

The SQL expression to be selected.

-> String

The alias to be used to name the calculation in SQL expressions.

-> (SqlValue -> Either String a)

A function to decode the expression result from a SqlValue.

-> SyntheticField a 

Constructs a SyntheticField that will select a SQL expression using the given alias.

Since: 1.0.0.0

nullableSyntheticField :: SyntheticField a -> SyntheticField (Maybe a) Source #

Modifies a SyntheticField to allow it to decode NULL values.

Since: 1.0.0.0

prefixSyntheticField :: String -> SyntheticField a -> SyntheticField a Source #

Adds a prefix, followed by an underscore, to the alias used to name the synthetic field.

Since: 1.0.0.0