rel8-1.3.1.0: Hey! Hey! Can u rel8?
Safe HaskellNone
LanguageHaskell2010

Rel8

Synopsis

Database types

DBType

class NotNull a => DBType a where Source #

Haskell types that can be represented as expressions in a database. There should be an instance of DBType for all column types in your database schema (e.g., int, timestamptz, etc).

Rel8 comes with stock instances for most default types in PostgreSQL, so you should only need to derive instances of this class for custom database types, such as types defined in PostgreSQL extensions, or custom domain types.

Instances

Instances details
DBType Bool Source #

Corresponds to bool

Instance details

Defined in Rel8.Type

DBType Char Source #

Corresponds to char

Instance details

Defined in Rel8.Type

DBType Double Source #

Corresponds to float8

Instance details

Defined in Rel8.Type

DBType Float Source #

Corresponds to float4

Instance details

Defined in Rel8.Type

DBType Int16 Source #

Corresponds to int2

Instance details

Defined in Rel8.Type

DBType Int32 Source #

Corresponds to int4

Instance details

Defined in Rel8.Type

DBType Int64 Source #

Corresponds to int8

Instance details

Defined in Rel8.Type

DBType ByteString Source #

Corresponds to bytea

Instance details

Defined in Rel8.Type

DBType ByteString Source #

Corresponds to bytea

Instance details

Defined in Rel8.Type

DBType Scientific Source #

Corresponds to numeric

Instance details

Defined in Rel8.Type

DBType UTCTime Source #

Corresponds to timestamptz

Instance details

Defined in Rel8.Type

DBType Text Source #

Corresponds to text

Instance details

Defined in Rel8.Type

DBType Value Source #

Corresponds to jsonb

Instance details

Defined in Rel8.Type

DBType Text Source #

Corresponds to text

Instance details

Defined in Rel8.Type

DBType UUID Source #

Corresponds to uuid

Instance details

Defined in Rel8.Type

DBType CalendarDiffTime Source #

Corresponds to interval

Instance details

Defined in Rel8.Type

DBType Day Source #

Corresponds to date

Instance details

Defined in Rel8.Type

DBType TimeOfDay Source #

Corresponds to time

Instance details

Defined in Rel8.Type

DBType LocalTime Source #

Corresponds to timestamp

Instance details

Defined in Rel8.Type

Sql DBType a => DBType [a] Source # 
Instance details

Defined in Rel8.Type

Sql DBType a => DBType (NonEmpty a) Source # 
Instance details

Defined in Rel8.Type

DBType (CI Text) Source #

Corresponds to citext

Instance details

Defined in Rel8.Type

DBType (CI Text) Source #

Corresponds to citext

Instance details

Defined in Rel8.Type

(FromJSON a, ToJSON a) => DBType (JSONBEncoded a) Source # 
Instance details

Defined in Rel8.Type.JSONBEncoded

(FromJSON a, ToJSON a) => DBType (JSONEncoded a) Source # 
Instance details

Defined in Rel8.Type.JSONEncoded

DBEnum a => DBType (Enum a) Source # 
Instance details

Defined in Rel8.Type.Enum

(Read a, Show a, Typeable a) => DBType (ReadShow a) Source # 
Instance details

Defined in Rel8.Type.ReadShow

DBComposite a => DBType (Composite a) Source # 
Instance details

Defined in Rel8.Type.Composite

Deriving-via helpers

JSONEncoded

newtype JSONEncoded a Source #

A deriving-via helper type for column types that store a Haskell value using a JSON encoding described by aeson's ToJSON and FromJSON type classes.

Constructors

JSONEncoded 

Fields

Instances

Instances details
(FromJSON a, ToJSON a) => DBType (JSONEncoded a) Source # 
Instance details

Defined in Rel8.Type.JSONEncoded

newtype JSONBEncoded a Source #

Like JSONEncoded, but works for jsonb columns.

Constructors

JSONBEncoded 

Fields

Instances

Instances details
(FromJSON a, ToJSON a) => DBType (JSONBEncoded a) Source # 
Instance details

Defined in Rel8.Type.JSONBEncoded

ReadShow

newtype ReadShow a Source #

A deriving-via helper type for column types that store a Haskell value using a Haskell's Read and Show type classes.

Constructors

ReadShow 

Fields

Instances

Instances details
(Read a, Show a, Typeable a) => DBType (ReadShow a) Source # 
Instance details

Defined in Rel8.Type.ReadShow

Generic

newtype Composite a Source #

A deriving-via helper type for column types that store a Haskell product type in a single Postgres column using a Postgres composite type.

Note that this must map to a specific extant type in your database's schema (created with CREATE TYPE). Use DBComposite to specify the name of this Postgres type and the names of the individual fields (for projecting with decompose).

Constructors

Composite a 

Instances

Instances details
DBComposite a => DBType (Composite a) Source # 
Instance details

Defined in Rel8.Type.Composite

(DBComposite a, EqTable (HKD a Expr)) => DBEq (Composite a) Source # 
Instance details

Defined in Rel8.Type.Composite

(DBComposite a, OrdTable (HKD a Expr)) => DBMin (Composite a) Source # 
Instance details

Defined in Rel8.Type.Composite

(DBComposite a, OrdTable (HKD a Expr)) => DBMax (Composite a) Source # 
Instance details

Defined in Rel8.Type.Composite

(DBComposite a, OrdTable (HKD a Expr)) => DBOrd (Composite a) Source # 
Instance details

Defined in Rel8.Type.Composite

class (DBType a, HKDable a) => DBComposite a where Source #

DBComposite is used to associate composite type metadata with a Haskell type.

Methods

compositeFields :: HKD a Name Source #

The names of all fields in the composite type that a maps to.

compositeTypeName :: String Source #

The name of the composite type that a maps to.

compose :: DBComposite a => HKD a Expr -> Expr a Source #

Collapse a HKD into a PostgreSQL composite type.

HKD values are represented in queries by having a column for each field in the corresponding Haskell type. compose collapses these columns into a single column expression, by combining them into a PostgreSQL composite type.

decompose :: forall a. DBComposite a => Expr a -> HKD a Expr Source #

Expand a composite type into a HKD.

decompose is the inverse of compose.

newtype Enum a Source #

A deriving-via helper type for column types that store an "enum" type (in Haskell terms, a sum type where all constructors are nullary) using a Postgres enum type.

Note that this should map to a specific type in your database's schema (explicitly created with CREATE TYPE ... AS ENUM). Use DBEnum to specify the name of this Postgres type and the names of the individual values. If left unspecified, the names of the values of the Postgres enum are assumed to match exactly exactly the names of the constructors of the Haskell type (up to and including case sensitivity).

Constructors

Enum a 

Instances

Instances details
DBEnum a => DBType (Enum a) Source # 
Instance details

Defined in Rel8.Type.Enum

DBEnum a => DBEq (Enum a) Source # 
Instance details

Defined in Rel8.Type.Enum

DBEnum a => DBMin (Enum a) Source # 
Instance details

Defined in Rel8.Type.Enum

DBEnum a => DBMax (Enum a) Source # 
Instance details

Defined in Rel8.Type.Enum

DBEnum a => DBOrd (Enum a) Source # 
Instance details

Defined in Rel8.Type.Enum

class (DBType a, Enumable a) => DBEnum a where Source #

DBEnum contains the necessary metadata to describe a PostgreSQL enum type.

Minimal complete definition

enumTypeName

Methods

enumValue :: a -> String Source #

Map Haskell values to the corresponding element of the enum type. The default implementation of this method will use the exact name of the Haskell constructors.

enumTypeName :: String Source #

The name of the PostgreSQL enum type that a maps to.

class (Generic a, GEnumable (Rep a)) => Enumable a Source #

Types that are sum types, where each constructor is unary (that is, has no fields).

Instances

Instances details
(Generic a, GEnumable (Rep a)) => Enumable a Source # 
Instance details

Defined in Rel8.Type.Enum

TypeInformation

data TypeInformation a Source #

TypeInformation describes how to encode and decode a Haskell type to and from database queries. The typeName is the name of the type in the database, which is used to accurately type literals.

Constructors

TypeInformation 

Fields

mapTypeInformation :: (a -> b) -> (b -> a) -> TypeInformation a -> TypeInformation b Source #

Simultaneously map over how a type is both encoded and decoded, while retaining the name of the type. This operation is useful if you want to essentially newtype another DBType.

The mapping is required to be total. If you have a partial mapping, see parseTypeInformation.

parseTypeInformation :: (a -> Either String b) -> (b -> a) -> TypeInformation a -> TypeInformation b Source #

Apply a parser to TypeInformation.

This can be used if the data stored in the database should only be subset of a given TypeInformation. The parser is applied when deserializing rows returned - the encoder assumes that the input data is already in the appropriate form.

The DBType hierarchy

class DBType a => DBSemigroup a where Source #

The class of DBTypes that form a semigroup. This class is purely a Rel8 concept, and exists to mirror the Semigroup class.

Methods

(<>.) :: Expr a -> Expr a -> Expr a infixr 6 Source #

An associative operation.

Instances

Instances details
DBSemigroup ByteString Source # 
Instance details

Defined in Rel8.Type.Semigroup

DBSemigroup ByteString Source # 
Instance details

Defined in Rel8.Type.Semigroup

DBSemigroup Text Source # 
Instance details

Defined in Rel8.Type.Semigroup

Methods

(<>.) :: Expr Text -> Expr Text -> Expr Text Source #

DBSemigroup Text Source # 
Instance details

Defined in Rel8.Type.Semigroup

Methods

(<>.) :: Expr Text -> Expr Text -> Expr Text Source #

DBSemigroup CalendarDiffTime Source # 
Instance details

Defined in Rel8.Type.Semigroup

Sql DBType a => DBSemigroup [a] Source # 
Instance details

Defined in Rel8.Type.Semigroup

Methods

(<>.) :: Expr [a] -> Expr [a] -> Expr [a] Source #

Sql DBType a => DBSemigroup (NonEmpty a) Source # 
Instance details

Defined in Rel8.Type.Semigroup

Methods

(<>.) :: Expr (NonEmpty a) -> Expr (NonEmpty a) -> Expr (NonEmpty a) Source #

DBSemigroup (CI Text) Source # 
Instance details

Defined in Rel8.Type.Semigroup

Methods

(<>.) :: Expr (CI Text) -> Expr (CI Text) -> Expr (CI Text) Source #

DBSemigroup (CI Text) Source # 
Instance details

Defined in Rel8.Type.Semigroup

Methods

(<>.) :: Expr (CI Text) -> Expr (CI Text) -> Expr (CI Text) Source #

class DBSemigroup a => DBMonoid a where Source #

The class of DBTypes that form a semigroup. This class is purely a Rel8 concept, and exists to mirror the Monoid class.

Methods

memptyExpr :: Expr a Source #

Instances

Instances details
DBMonoid ByteString Source # 
Instance details

Defined in Rel8.Type.Monoid

DBMonoid ByteString Source # 
Instance details

Defined in Rel8.Type.Monoid

DBMonoid Text Source # 
Instance details

Defined in Rel8.Type.Monoid

DBMonoid Text Source # 
Instance details

Defined in Rel8.Type.Monoid

DBMonoid CalendarDiffTime Source # 
Instance details

Defined in Rel8.Type.Monoid

Sql DBType a => DBMonoid [a] Source # 
Instance details

Defined in Rel8.Type.Monoid

Methods

memptyExpr :: Expr [a] Source #

DBMonoid (CI Text) Source # 
Instance details

Defined in Rel8.Type.Monoid

DBMonoid (CI Text) Source # 
Instance details

Defined in Rel8.Type.Monoid

class DBType a => DBNum a Source #

The class of database types that support the +, *, - operators, and the abs, negate, sign functions.

Instances

Instances details
DBNum Double Source # 
Instance details

Defined in Rel8.Type.Num

DBNum Float Source # 
Instance details

Defined in Rel8.Type.Num

DBNum Int16 Source # 
Instance details

Defined in Rel8.Type.Num

DBNum Int32 Source # 
Instance details

Defined in Rel8.Type.Num

DBNum Int64 Source # 
Instance details

Defined in Rel8.Type.Num

DBNum Scientific Source # 
Instance details

Defined in Rel8.Type.Num

class (DBNum a, DBOrd a) => DBIntegral a Source #

The class of database types that can be coerced to from integral expressions. This is a Rel8 concept, and allows us to provide fromIntegral.

Instances

Instances details
DBIntegral Int16 Source # 
Instance details

Defined in Rel8.Type.Num

DBIntegral Int32 Source # 
Instance details

Defined in Rel8.Type.Num

DBIntegral Int64 Source # 
Instance details

Defined in Rel8.Type.Num

class DBNum a => DBFractional a Source #

The class of database types that support the / operator.

Instances

Instances details
DBFractional Double Source # 
Instance details

Defined in Rel8.Type.Num

DBFractional Float Source # 
Instance details

Defined in Rel8.Type.Num

DBFractional Scientific Source # 
Instance details

Defined in Rel8.Type.Num

class DBFractional a => DBFloating a Source #

The class of database types that support the / operator.

Instances

Instances details
DBFloating Double Source # 
Instance details

Defined in Rel8.Type.Num

DBFloating Float Source # 
Instance details

Defined in Rel8.Type.Num

Tables and higher-kinded tables

class HTable (GColumns t) => Rel8able t Source #

This type class allows you to define custom Tables using higher-kinded data types. Higher-kinded data types are data types of the pattern:

data MyType f =
  MyType { field1 :: Column f T1 OR HK1 f
         , field2 :: Column f T2 OR HK2 f
         , ...
         , fieldN :: Column f Tn OR HKn f
         }

where Tn is any Haskell type, and HKn is any higher-kinded type.

That is, higher-kinded data are records where all fields in the record are all either of the type Column f T (for any T), or are themselves higher-kinded data:

Nested
data Nested f =
  Nested { nested1 :: MyType f
         , nested2 :: MyType f
         }

The Rel8able type class is used to give us a special mapping operation that lets us change the type parameter f.

Supplying Rel8able instances

This type class should be derived generically for all table types in your project. To do this, enable the DeriveAnyType and DeriveGeneric language extensions:

{-# LANGUAGE DeriveAnyClass, DeriveGeneric #-}

data MyType f = MyType { fieldA :: Column f T }
  deriving ( GHC.Generics.Generic, Rel8able )

Instances

Instances details
HKDable a => Rel8able (HKD a) Source # 
Instance details

Defined in Rel8.Table.HKD

Associated Types

type GColumns (HKD a) :: HTable

type GFromExprs (HKD a)

Methods

gfromColumns :: forall (context :: Context). SContext context -> GColumns (HKD a) context -> HKD a context

gtoColumns :: forall (context :: Context). SContext context -> HKD a context -> GColumns (HKD a) context

gfromResult :: GColumns (HKD a) Result -> GFromExprs (HKD a)

gtoResult :: GFromExprs (HKD a) -> GColumns (HKD a) Result

ADTable t => Rel8able (ADT t) Source # 
Instance details

Defined in Rel8.Table.ADT

Associated Types

type GColumns (ADT t) :: HTable

type GFromExprs (ADT t)

Methods

gfromColumns :: forall (context :: Context). SContext context -> GColumns (ADT t) context -> ADT t context

gtoColumns :: forall (context :: Context). SContext context -> ADT t context -> GColumns (ADT t) context

gfromResult :: GColumns (ADT t) Result -> GFromExprs (ADT t)

gtoResult :: GFromExprs (ADT t) -> GColumns (ADT t) Result

type KRel8able = Rel8able Source #

The kind of Rel8able types

type family Column context a where ... Source #

This type family is used to specify columns in Rel8ables. In Column f a, f is the context of the column (which should be left polymorphic in Rel8able definitions), and a is the type of the column.

Equations

Column Result a = a 
Column context a = context a 

type family HADT context t where ... Source #

Equations

HADT Result t = t Result 
HADT context t = ADT t context 

type family HEither context = either | either -> context where ... Source #

Nest an Either value within a Rel8able. HEither f a b will produce a EitherTable a b in the Expr context, and a Either a b in the Result context.

Equations

HEither Result = Either 
HEither context = EitherTable context 

type family HMaybe context = maybe | maybe -> context where ... Source #

Nest a Maybe value within a Rel8able. HMaybe f a will produce a MaybeTable a in the Expr context, and a Maybe a in the Result context.

Equations

HMaybe Result = Maybe 
HMaybe context = MaybeTable context 

type family HList context = list | list -> context where ... Source #

Nest a list within a Rel8able. HList f a will produce a ListTable a in the Expr context, and a [a] in the Result context.

Equations

HList Result = [] 
HList context = ListTable context 

type family HNonEmpty context = nonEmpty | nonEmpty -> context where ... Source #

Nest a NonEmpty list within a Rel8able. HNonEmpty f a will produce a NonEmptyTable a in the Expr context, and a NonEmpty a in the Result context.

Equations

HNonEmpty Result = NonEmpty 
HNonEmpty context = NonEmptyTable context 

type family HThese context = these | these -> context where ... Source #

Nest an These value within a Rel8able. HThese f a b will produce a TheseTable a b in the Expr context, and a These a b in the Result context.

Equations

HThese Result = These 
HThese context = TheseTable context 

type family Lift context a where ... Source #

Equations

Lift Result a = a 
Lift context a = HKD a context 

class (HTable (Columns a), context ~ Context a, a ~ Transpose context a) => Table context a | a -> context where Source #

Tables are one of the foundational elements of Rel8, and describe data types that have a finite number of columns. Each of these columns contains data under a shared context, and contexts describe how to interpret the metadata about a column to a particular Haskell type. In Rel8, we have contexts for expressions (the Expr context), aggregations (the Aggregate context), insert values (the Insert contex), among others.

In typical usage of Rel8 you don't need to derive instances of Table yourself, as anything that's an instance of Rel8able is always a Table.

Minimal complete definition

Nothing

Associated Types

type Columns a :: HTable Source #

The HTable functor that describes the schema of this table.

type Columns a = GColumns TColumns (Rep (Record a))

type Context a :: Context Source #

The common context that all columns use as an interpretation.

type Context a = GContext TContext (Rep (Record a))

type FromExprs a :: Type Source #

The FromExprs type family maps a type in the Expr context to the corresponding Haskell type.

type FromExprs a = Map TFromExprs a

type Transpose (context' :: Context) a :: Type Source #

type Transpose context a = Map (TTranspose context) a

Methods

toColumns :: a -> Columns a context Source #

default toColumns :: (Generic (Record a), GTable (TTable context) TColumns (Rep (Record a)), Columns a ~ GColumns TColumns (Rep (Record a))) => a -> Columns a context Source #

fromColumns :: Columns a context -> a Source #

default fromColumns :: (Generic (Record a), GTable (TTable context) TColumns (Rep (Record a)), Columns a ~ GColumns TColumns (Rep (Record a))) => Columns a context -> a Source #

fromResult :: Columns a Result -> FromExprs a Source #

default fromResult :: (Generic (Record (FromExprs a)), GSerialize TSerialize TColumns (Rep (Record a)) (Rep (Record (FromExprs a))), Columns a ~ GColumns TColumns (Rep (Record a))) => Columns a Result -> FromExprs a Source #

toResult :: FromExprs a -> Columns a Result Source #

default toResult :: (Generic (Record (FromExprs a)), GSerialize TSerialize TColumns (Rep (Record a)) (Rep (Record (FromExprs a))), Columns a ~ GColumns TColumns (Rep (Record a))) => FromExprs a -> Columns a Result Source #

Instances

Instances details
(Rel8able t, Reifiable context, context ~ context') => Table context' (t context) Source # 
Instance details

Defined in Rel8.Table.Rel8able

Associated Types

type Columns (t context) :: HTable Source #

type Context (t context) :: Context Source #

type FromExprs (t context) Source #

type Transpose context' (t context) Source #

Methods

toColumns :: t context -> Columns (t context) context' Source #

fromColumns :: Columns (t context) context' -> t context Source #

fromResult :: Columns (t context) Result -> FromExprs (t context) Source #

toResult :: FromExprs (t context) -> Columns (t context) Result Source #

Sql DBType a => Table Expr (Expr a) Source # 
Instance details

Defined in Rel8.Expr

Associated Types

type Columns (Expr a) :: HTable Source #

type Context (Expr a) :: Context Source #

type FromExprs (Expr a) Source #

type Transpose context' (Expr a) Source #

Sql DBType a => Table Result (Identity a) Source # 
Instance details

Defined in Rel8.Table

Associated Types

type Columns (Identity a) :: HTable Source #

type Context (Identity a) :: Context Source #

type FromExprs (Identity a) Source #

type Transpose context' (Identity a) Source #

Sql DBType a => Table Name (Name a) Source # 
Instance details

Defined in Rel8.Schema.Name

Associated Types

type Columns (Name a) :: HTable Source #

type Context (Name a) :: Context Source #

type FromExprs (Name a) Source #

type Transpose context' (Name a) Source #

Sql DBType a => Table Aggregate (Aggregate a) Source # 
Instance details

Defined in Rel8.Aggregate

Associated Types

type Columns (Aggregate a) :: HTable Source #

type Context (Aggregate a) :: Context Source #

type FromExprs (Aggregate a) Source #

type Transpose context' (Aggregate a) Source #

(Table context a, Table context b) => Table context (a, b) Source # 
Instance details

Defined in Rel8.Table

Associated Types

type Columns (a, b) :: HTable Source #

type Context (a, b) :: Context Source #

type FromExprs (a, b) Source #

type Transpose context' (a, b) Source #

Methods

toColumns :: (a, b) -> Columns (a, b) context Source #

fromColumns :: Columns (a, b) context -> (a, b) Source #

fromResult :: Columns (a, b) Result -> FromExprs (a, b) Source #

toResult :: FromExprs (a, b) -> Columns (a, b) Result Source #

(Table context a, context ~ context') => Table context' (NonEmptyTable context a) Source # 
Instance details

Defined in Rel8.Table.NonEmpty

Associated Types

type Columns (NonEmptyTable context a) :: HTable Source #

type Context (NonEmptyTable context a) :: Context Source #

type FromExprs (NonEmptyTable context a) Source #

type Transpose context' (NonEmptyTable context a) Source #

Methods

toColumns :: NonEmptyTable context a -> Columns (NonEmptyTable context a) context' Source #

fromColumns :: Columns (NonEmptyTable context a) context' -> NonEmptyTable context a Source #

fromResult :: Columns (NonEmptyTable context a) Result -> FromExprs (NonEmptyTable context a) Source #

toResult :: FromExprs (NonEmptyTable context a) -> Columns (NonEmptyTable context a) Result Source #

(Table context a, context ~ context') => Table context' (ListTable context a) Source # 
Instance details

Defined in Rel8.Table.List

Associated Types

type Columns (ListTable context a) :: HTable Source #

type Context (ListTable context a) :: Context Source #

type FromExprs (ListTable context a) Source #

type Transpose context' (ListTable context a) Source #

Methods

toColumns :: ListTable context a -> Columns (ListTable context a) context' Source #

fromColumns :: Columns (ListTable context a) context' -> ListTable context a Source #

fromResult :: Columns (ListTable context a) Result -> FromExprs (ListTable context a) Source #

toResult :: FromExprs (ListTable context a) -> Columns (ListTable context a) Result Source #

(Table context a, Reifiable context, context ~ context') => Table context' (MaybeTable context a) Source # 
Instance details

Defined in Rel8.Table.Maybe

Associated Types

type Columns (MaybeTable context a) :: HTable Source #

type Context (MaybeTable context a) :: Context Source #

type FromExprs (MaybeTable context a) Source #

type Transpose context' (MaybeTable context a) Source #

Methods

toColumns :: MaybeTable context a -> Columns (MaybeTable context a) context' Source #

fromColumns :: Columns (MaybeTable context a) context' -> MaybeTable context a Source #

fromResult :: Columns (MaybeTable context a) Result -> FromExprs (MaybeTable context a) Source #

toResult :: FromExprs (MaybeTable context a) -> Columns (MaybeTable context a) Result Source #

(Table context a, Table context b, Table context c) => Table context (a, b, c) Source # 
Instance details

Defined in Rel8.Table

Associated Types

type Columns (a, b, c) :: HTable Source #

type Context (a, b, c) :: Context Source #

type FromExprs (a, b, c) Source #

type Transpose context' (a, b, c) Source #

Methods

toColumns :: (a, b, c) -> Columns (a, b, c) context Source #

fromColumns :: Columns (a, b, c) context -> (a, b, c) Source #

fromResult :: Columns (a, b, c) Result -> FromExprs (a, b, c) Source #

toResult :: FromExprs (a, b, c) -> Columns (a, b, c) Result Source #

(Table context a, Table context b, Reifiable context, context ~ context') => Table context' (TheseTable context a b) Source # 
Instance details

Defined in Rel8.Table.These

Associated Types

type Columns (TheseTable context a b) :: HTable Source #

type Context (TheseTable context a b) :: Context Source #

type FromExprs (TheseTable context a b) Source #

type Transpose context' (TheseTable context a b) Source #

Methods

toColumns :: TheseTable context a b -> Columns (TheseTable context a b) context' Source #

fromColumns :: Columns (TheseTable context a b) context' -> TheseTable context a b Source #

fromResult :: Columns (TheseTable context a b) Result -> FromExprs (TheseTable context a b) Source #

toResult :: FromExprs (TheseTable context a b) -> Columns (TheseTable context a b) Result Source #

(Table context a, Table context b, Reifiable context, context ~ context') => Table context' (EitherTable context a b) Source # 
Instance details

Defined in Rel8.Table.Either

Associated Types

type Columns (EitherTable context a b) :: HTable Source #

type Context (EitherTable context a b) :: Context Source #

type FromExprs (EitherTable context a b) Source #

type Transpose context' (EitherTable context a b) Source #

Methods

toColumns :: EitherTable context a b -> Columns (EitherTable context a b) context' Source #

fromColumns :: Columns (EitherTable context a b) context' -> EitherTable context a b Source #

fromResult :: Columns (EitherTable context a b) Result -> FromExprs (EitherTable context a b) Source #

toResult :: FromExprs (EitherTable context a b) -> Columns (EitherTable context a b) Result Source #

(Table context a, Table context b, Table context c, Table context d) => Table context (a, b, c, d) Source # 
Instance details

Defined in Rel8.Table

Associated Types

type Columns (a, b, c, d) :: HTable Source #

type Context (a, b, c, d) :: Context Source #

type FromExprs (a, b, c, d) Source #

type Transpose context' (a, b, c, d) Source #

Methods

toColumns :: (a, b, c, d) -> Columns (a, b, c, d) context Source #

fromColumns :: Columns (a, b, c, d) context -> (a, b, c, d) Source #

fromResult :: Columns (a, b, c, d) Result -> FromExprs (a, b, c, d) Source #

toResult :: FromExprs (a, b, c, d) -> Columns (a, b, c, d) Result Source #

(Table context a, Table context b, Table context c, Table context d, Table context e) => Table context (a, b, c, d, e) Source # 
Instance details

Defined in Rel8.Table

Associated Types

type Columns (a, b, c, d, e) :: HTable Source #

type Context (a, b, c, d, e) :: Context Source #

type FromExprs (a, b, c, d, e) Source #

type Transpose context' (a, b, c, d, e) Source #

Methods

toColumns :: (a, b, c, d, e) -> Columns (a, b, c, d, e) context Source #

fromColumns :: Columns (a, b, c, d, e) context -> (a, b, c, d, e) Source #

fromResult :: Columns (a, b, c, d, e) Result -> FromExprs (a, b, c, d, e) Source #

toResult :: FromExprs (a, b, c, d, e) -> Columns (a, b, c, d, e) Result Source #

(Table context a, Table context b, Table context c, Table context d, Table context e, Table context f) => Table context (a, b, c, d, e, f) Source # 
Instance details

Defined in Rel8.Table

Associated Types

type Columns (a, b, c, d, e, f) :: HTable Source #

type Context (a, b, c, d, e, f) :: Context Source #

type FromExprs (a, b, c, d, e, f) Source #

type Transpose context' (a, b, c, d, e, f) Source #

Methods

toColumns :: (a, b, c, d, e, f) -> Columns (a, b, c, d, e, f) context Source #

fromColumns :: Columns (a, b, c, d, e, f) context -> (a, b, c, d, e, f) Source #

fromResult :: Columns (a, b, c, d, e, f) Result -> FromExprs (a, b, c, d, e, f) Source #

toResult :: FromExprs (a, b, c, d, e, f) -> Columns (a, b, c, d, e, f) Result Source #

(Table context a, Table context b, Table context c, Table context d, Table context e, Table context f, Table context g) => Table context (a, b, c, d, e, f, g) Source # 
Instance details

Defined in Rel8.Table

Associated Types

type Columns (a, b, c, d, e, f, g) :: HTable Source #

type Context (a, b, c, d, e, f, g) :: Context Source #

type FromExprs (a, b, c, d, e, f, g) Source #

type Transpose context' (a, b, c, d, e, f, g) Source #

Methods

toColumns :: (a, b, c, d, e, f, g) -> Columns (a, b, c, d, e, f, g) context Source #

fromColumns :: Columns (a, b, c, d, e, f, g) context -> (a, b, c, d, e, f, g) Source #

fromResult :: Columns (a, b, c, d, e, f, g) Result -> FromExprs (a, b, c, d, e, f, g) Source #

toResult :: FromExprs (a, b, c, d, e, f, g) -> Columns (a, b, c, d, e, f, g) Result Source #

Sql DBType a => Table (Field table) (Field table a) Source # 
Instance details

Defined in Rel8.Schema.Field

Associated Types

type Columns (Field table a) :: HTable Source #

type Context (Field table a) :: Context Source #

type FromExprs (Field table a) Source #

type Transpose context' (Field table a) Source #

Methods

toColumns :: Field table a -> Columns (Field table a) (Field table) Source #

fromColumns :: Columns (Field table a) (Field table) -> Field table a Source #

fromResult :: Columns (Field table a) Result -> FromExprs (Field table a) Source #

toResult :: FromExprs (Field table a) -> Columns (Field table a) Result Source #

class HTable t Source #

A HTable is a functor-indexed/higher-kinded data type that is representable (htabulate/hfield), constrainable (hdicts), and specified (hspecs).

This is an internal concept for Rel8, and you should not need to define instances yourself or specify this constraint.

class (Table from a, Table to b, Congruent a b, b ~ Transpose to a, a ~ Transpose from b) => Transposes from to a b | a -> from, b -> to, a to -> b, b from -> a Source #

Transposes from to a b means that a and b are Tables, in the from and to contexts respectively, which share the same underlying structure. In other words, b is a version of a transposed from the from context to the to context (and vice versa).

Instances

Instances details
(Table from a, Table to b, Congruent a b, b ~ Transpose to a, a ~ Transpose from b) => Transposes from to a b Source # 
Instance details

Defined in Rel8.Table.Transpose

class AltTable f where Source #

Like Alt in Haskell. This class is purely a Rel8 concept, and allows you to take a choice between two tables. See also AlternativeTable.

For example, using <|>: on MaybeTable allows you to combine two tables and to return the first one that is a "just" MaybeTable.

Methods

(<|>:) :: Table Expr a => f a -> f a -> f a infixl 3 Source #

An associative binary operation on Tables.

Instances

Instances details
AltTable Query Source #

<|>: = unionAll.

Instance details

Defined in Rel8.Query

Methods

(<|>:) :: Table Expr a => Query a -> Query a -> Query a Source #

context ~ Expr => AltTable (NonEmptyTable context) Source # 
Instance details

Defined in Rel8.Table.NonEmpty

Methods

(<|>:) :: Table Expr a => NonEmptyTable context a -> NonEmptyTable context a -> NonEmptyTable context a Source #

context ~ Expr => AltTable (ListTable context) Source # 
Instance details

Defined in Rel8.Table.List

Methods

(<|>:) :: Table Expr a => ListTable context a -> ListTable context a -> ListTable context a Source #

context ~ Expr => AltTable (MaybeTable context) Source # 
Instance details

Defined in Rel8.Table.Maybe

Methods

(<|>:) :: Table Expr a => MaybeTable context a -> MaybeTable context a -> MaybeTable context a Source #

EqTable k => AltTable (Tabulation k) Source #

If Tabulation k a is Map k (NonEmpty a), then (|:) is unionWith (<>).

Instance details

Defined in Rel8.Tabulate

Methods

(<|>:) :: Table Expr a => Tabulation k a -> Tabulation k a -> Tabulation k a Source #

class AltTable f => AlternativeTable f where Source #

Like Alternative in Haskell, some Tables form a monoid on applicative functors.

Methods

emptyTable :: Table Expr a => f a Source #

The identity of <|>:.

Instances

Instances details
AlternativeTable Query Source #

emptyTable = values [].

Instance details

Defined in Rel8.Query

Methods

emptyTable :: Table Expr a => Query a Source #

context ~ Expr => AlternativeTable (ListTable context) Source # 
Instance details

Defined in Rel8.Table.List

Methods

emptyTable :: Table Expr a => ListTable context a Source #

context ~ Expr => AlternativeTable (MaybeTable context) Source # 
Instance details

Defined in Rel8.Table.Maybe

Methods

emptyTable :: Table Expr a => MaybeTable context a Source #

EqTable k => AlternativeTable (Tabulation k) Source # 
Instance details

Defined in Rel8.Tabulate

Methods

emptyTable :: Table Expr a => Tabulation k a Source #

class Table Expr a => EqTable a where Source #

The class of Tables that can be compared for equality. Equality on tables is defined by equality of all columns all columns, so this class means "all columns in a Table have an instance of DBEq".

Minimal complete definition

Nothing

Methods

eqTable :: Columns a (Dict (Sql DBEq)) Source #

default eqTable :: (GTable TEqTable TColumns (Rep (Record a)), Columns a ~ GColumns TColumns (Rep (Record a))) => Columns a (Dict (Sql DBEq)) Source #

Instances

Instances details
(context ~ Expr, Rel8able t, HConstrainTable (Columns (t context)) (Sql DBEq)) => EqTable (t context) Source # 
Instance details

Defined in Rel8.Table.Rel8able

Methods

eqTable :: Columns (t context) (Dict (Sql DBEq)) Source #

Sql DBEq a => EqTable (Expr a) Source # 
Instance details

Defined in Rel8.Table.Eq

Methods

eqTable :: Columns (Expr a) (Dict (Sql DBEq)) Source #

(EqTable a, EqTable b) => EqTable (a, b) Source # 
Instance details

Defined in Rel8.Table.Eq

Methods

eqTable :: Columns (a, b) (Dict (Sql DBEq)) Source #

(EqTable a, context ~ Expr) => EqTable (NonEmptyTable context a) Source # 
Instance details

Defined in Rel8.Table.NonEmpty

Methods

eqTable :: Columns (NonEmptyTable context a) (Dict (Sql DBEq)) Source #

(EqTable a, context ~ Expr) => EqTable (ListTable context a) Source # 
Instance details

Defined in Rel8.Table.List

Methods

eqTable :: Columns (ListTable context a) (Dict (Sql DBEq)) Source #

(EqTable a, context ~ Expr) => EqTable (MaybeTable context a) Source # 
Instance details

Defined in Rel8.Table.Maybe

Methods

eqTable :: Columns (MaybeTable context a) (Dict (Sql DBEq)) Source #

(EqTable a, EqTable b, EqTable c) => EqTable (a, b, c) Source # 
Instance details

Defined in Rel8.Table.Eq

Methods

eqTable :: Columns (a, b, c) (Dict (Sql DBEq)) Source #

(EqTable a, EqTable b, context ~ Expr) => EqTable (TheseTable context a b) Source # 
Instance details

Defined in Rel8.Table.These

Methods

eqTable :: Columns (TheseTable context a b) (Dict (Sql DBEq)) Source #

(EqTable a, EqTable b, context ~ Expr) => EqTable (EitherTable context a b) Source # 
Instance details

Defined in Rel8.Table.Either

Methods

eqTable :: Columns (EitherTable context a b) (Dict (Sql DBEq)) Source #

(EqTable a, EqTable b, EqTable c, EqTable d) => EqTable (a, b, c, d) Source # 
Instance details

Defined in Rel8.Table.Eq

Methods

eqTable :: Columns (a, b, c, d) (Dict (Sql DBEq)) Source #

(EqTable a, EqTable b, EqTable c, EqTable d, EqTable e) => EqTable (a, b, c, d, e) Source # 
Instance details

Defined in Rel8.Table.Eq

Methods

eqTable :: Columns (a, b, c, d, e) (Dict (Sql DBEq)) Source #

(EqTable a, EqTable b, EqTable c, EqTable d, EqTable e, EqTable f) => EqTable (a, b, c, d, e, f) Source # 
Instance details

Defined in Rel8.Table.Eq

Methods

eqTable :: Columns (a, b, c, d, e, f) (Dict (Sql DBEq)) Source #

(EqTable a, EqTable b, EqTable c, EqTable d, EqTable e, EqTable f, EqTable g) => EqTable (a, b, c, d, e, f, g) Source # 
Instance details

Defined in Rel8.Table.Eq

Methods

eqTable :: Columns (a, b, c, d, e, f, g) (Dict (Sql DBEq)) Source #

(==:) :: forall a. EqTable a => a -> a -> Expr Bool infix 4 Source #

Compare two Tables for equality. This corresponds to comparing all columns inside each table for equality, and combining all comparisons with AND.

(/=:) :: forall a. EqTable a => a -> a -> Expr Bool infix 4 Source #

Test if two Tables are different. This corresponds to comparing all columns inside each table for inequality, and combining all comparisons with OR.

class EqTable a => OrdTable a where Source #

The class of Tables that can be ordered. Ordering on tables is defined by their lexicographic ordering of all columns, so this class means "all columns in a Table have an instance of DBOrd".

Minimal complete definition

Nothing

Methods

ordTable :: Columns a (Dict (Sql DBOrd)) Source #

default ordTable :: (GTable TOrdTable TColumns (Rep (Record a)), Columns a ~ GColumns TColumns (Rep (Record a))) => Columns a (Dict (Sql DBOrd)) Source #

Instances

Instances details
(context ~ Expr, Rel8able t, HConstrainTable (Columns (t context)) (Sql DBEq), HConstrainTable (Columns (t context)) (Sql DBOrd)) => OrdTable (t context) Source # 
Instance details

Defined in Rel8.Table.Rel8able

Methods

ordTable :: Columns (t context) (Dict (Sql DBOrd)) Source #

Sql DBOrd a => OrdTable (Expr a) Source # 
Instance details

Defined in Rel8.Table.Ord

Methods

ordTable :: Columns (Expr a) (Dict (Sql DBOrd)) Source #

(OrdTable a, OrdTable b) => OrdTable (a, b) Source # 
Instance details

Defined in Rel8.Table.Ord

Methods

ordTable :: Columns (a, b) (Dict (Sql DBOrd)) Source #

(OrdTable a, context ~ Expr) => OrdTable (NonEmptyTable context a) Source # 
Instance details

Defined in Rel8.Table.NonEmpty

Methods

ordTable :: Columns (NonEmptyTable context a) (Dict (Sql DBOrd)) Source #

(OrdTable a, context ~ Expr) => OrdTable (ListTable context a) Source # 
Instance details

Defined in Rel8.Table.List

Methods

ordTable :: Columns (ListTable context a) (Dict (Sql DBOrd)) Source #

(OrdTable a, context ~ Expr) => OrdTable (MaybeTable context a) Source # 
Instance details

Defined in Rel8.Table.Maybe

Methods

ordTable :: Columns (MaybeTable context a) (Dict (Sql DBOrd)) Source #

(OrdTable a, OrdTable b, OrdTable c) => OrdTable (a, b, c) Source # 
Instance details

Defined in Rel8.Table.Ord

Methods

ordTable :: Columns (a, b, c) (Dict (Sql DBOrd)) Source #

(OrdTable a, OrdTable b, context ~ Expr) => OrdTable (TheseTable context a b) Source # 
Instance details

Defined in Rel8.Table.These

Methods

ordTable :: Columns (TheseTable context a b) (Dict (Sql DBOrd)) Source #

(OrdTable a, OrdTable b, context ~ Expr) => OrdTable (EitherTable context a b) Source # 
Instance details

Defined in Rel8.Table.Either

Methods

ordTable :: Columns (EitherTable context a b) (Dict (Sql DBOrd)) Source #

(OrdTable a, OrdTable b, OrdTable c, OrdTable d) => OrdTable (a, b, c, d) Source # 
Instance details

Defined in Rel8.Table.Ord

Methods

ordTable :: Columns (a, b, c, d) (Dict (Sql DBOrd)) Source #

(OrdTable a, OrdTable b, OrdTable c, OrdTable d, OrdTable e) => OrdTable (a, b, c, d, e) Source # 
Instance details

Defined in Rel8.Table.Ord

Methods

ordTable :: Columns (a, b, c, d, e) (Dict (Sql DBOrd)) Source #

(OrdTable a, OrdTable b, OrdTable c, OrdTable d, OrdTable e, OrdTable f) => OrdTable (a, b, c, d, e, f) Source # 
Instance details

Defined in Rel8.Table.Ord

Methods

ordTable :: Columns (a, b, c, d, e, f) (Dict (Sql DBOrd)) Source #

(OrdTable a, OrdTable b, OrdTable c, OrdTable d, OrdTable e, OrdTable f, OrdTable g) => OrdTable (a, b, c, d, e, f, g) Source # 
Instance details

Defined in Rel8.Table.Ord

Methods

ordTable :: Columns (a, b, c, d, e, f, g) (Dict (Sql DBOrd)) Source #

(<:) :: forall a. OrdTable a => a -> a -> Expr Bool infix 4 Source #

Test if one Table sorts before another. Corresponds to comparing all columns with <.

(<=:) :: forall a. OrdTable a => a -> a -> Expr Bool infix 4 Source #

Test if one Table sorts before, or is equal to, another. Corresponds to comparing all columns with <=.

(>:) :: forall a. OrdTable a => a -> a -> Expr Bool infix 4 Source #

Test if one Table sorts after another. Corresponds to comparing all columns with >.

(>=:) :: forall a. OrdTable a => a -> a -> Expr Bool infix 4 Source #

Test if one Table sorts after another. Corresponds to comparing all columns with >=.

ascTable :: forall a. OrdTable a => Order a Source #

Construct an Order for a Table by sorting all columns into ascending orders (any nullable columns will be sorted with NULLS FIRST).

descTable :: forall a. OrdTable a => Order a Source #

Construct an Order for a Table by sorting all columns into descending orders (any nullable columns will be sorted with NULLS LAST).

greatest :: OrdTable a => a -> a -> a Source #

Given two Tables, return the table that sorts after the other.

least :: OrdTable a => a -> a -> a Source #

Given two Tables, return the table that sorts before the other.

lit :: forall exprs a. Serializable exprs a => a -> exprs Source #

Use lit to turn literal Haskell values into expressions. lit is capable of lifting single Exprs to full tables.

bool :: Table Expr a => a -> a -> Expr Bool -> a Source #

An if-then-else expression on tables.

bool x y p returns x if p is False, and returns y if p is True.

case_ :: Table Expr a => [(Expr Bool, a)] -> a -> a Source #

Produce a table expression from a list of alternatives. Returns the first table where the Expr Bool expression is True. If no alternatives are true, the given default is returned.

castTable :: Table Expr a => a -> a Source #

Transform a table by adding CAST to all columns. This is most useful for finalising a SELECT or RETURNING statement, guaranteed that the output matches what is encoded in each columns TypeInformation.

MaybeTable

data MaybeTable context a Source #

MaybeTable t is the table t, but as the result of an outer join. If the outer join fails to match any rows, this is essentialy Nothing, and if the outer join does match rows, this is like Just. Unfortunately, SQL makes it impossible to distinguish whether or not an outer join matched any rows based generally on the row contents - if you were to join a row entirely of nulls, you can't distinguish if you matched an all null row, or if the match failed. For this reason MaybeTable contains an extra field - a "nullTag" - to track whether or not the outer join produced any rows.

Instances

Instances details
(Table context a, Reifiable context, context ~ context') => Table context' (MaybeTable context a) Source # 
Instance details

Defined in Rel8.Table.Maybe

Associated Types

type Columns (MaybeTable context a) :: HTable Source #

type Context (MaybeTable context a) :: Context Source #

type FromExprs (MaybeTable context a) Source #

type Transpose context' (MaybeTable context a) Source #

Methods

toColumns :: MaybeTable context a -> Columns (MaybeTable context a) context' Source #

fromColumns :: Columns (MaybeTable context a) context' -> MaybeTable context a Source #

fromResult :: Columns (MaybeTable context a) Result -> FromExprs (MaybeTable context a) Source #

toResult :: FromExprs (MaybeTable context a) -> Columns (MaybeTable context a) Result Source #

context ~ Expr => Monad (MaybeTable context) Source #

Has the same behavior as the Monad instance for Maybe.

Instance details

Defined in Rel8.Table.Maybe

Methods

(>>=) :: MaybeTable context a -> (a -> MaybeTable context b) -> MaybeTable context b #

(>>) :: MaybeTable context a -> MaybeTable context b -> MaybeTable context b #

return :: a -> MaybeTable context a #

Nullifiable context => Functor (MaybeTable context) Source # 
Instance details

Defined in Rel8.Table.Maybe

Methods

fmap :: (a -> b) -> MaybeTable context a -> MaybeTable context b #

(<$) :: a -> MaybeTable context b -> MaybeTable context a #

context ~ Expr => Applicative (MaybeTable context) Source #

Has the same behavior as the Applicative instance for Maybe. See also: traverseMaybeTable.

Instance details

Defined in Rel8.Table.Maybe

Methods

pure :: a -> MaybeTable context a #

(<*>) :: MaybeTable context (a -> b) -> MaybeTable context a -> MaybeTable context b #

liftA2 :: (a -> b -> c) -> MaybeTable context a -> MaybeTable context b -> MaybeTable context c #

(*>) :: MaybeTable context a -> MaybeTable context b -> MaybeTable context b #

(<*) :: MaybeTable context a -> MaybeTable context b -> MaybeTable context a #

context ~ Expr => Apply (MaybeTable context) Source # 
Instance details

Defined in Rel8.Table.Maybe

Methods

(<.>) :: MaybeTable context (a -> b) -> MaybeTable context a -> MaybeTable context b #

(.>) :: MaybeTable context a -> MaybeTable context b -> MaybeTable context b #

(<.) :: MaybeTable context a -> MaybeTable context b -> MaybeTable context a #

liftF2 :: (a -> b -> c) -> MaybeTable context a -> MaybeTable context b -> MaybeTable context c #

context ~ Expr => Bind (MaybeTable context) Source # 
Instance details

Defined in Rel8.Table.Maybe

Methods

(>>-) :: MaybeTable context a -> (a -> MaybeTable context b) -> MaybeTable context b #

join :: MaybeTable context (MaybeTable context a) -> MaybeTable context a #

Projectable (MaybeTable context) Source # 
Instance details

Defined in Rel8.Table.Maybe

Methods

project :: Projecting a b => Projection a b -> MaybeTable context a -> MaybeTable context b Source #

context ~ Expr => AlternativeTable (MaybeTable context) Source # 
Instance details

Defined in Rel8.Table.Maybe

Methods

emptyTable :: Table Expr a => MaybeTable context a Source #

context ~ Expr => AltTable (MaybeTable context) Source # 
Instance details

Defined in Rel8.Table.Maybe

Methods

(<|>:) :: Table Expr a => MaybeTable context a -> MaybeTable context a -> MaybeTable context a Source #

(context ~ Expr, Table Expr a, Semigroup a) => Semigroup (MaybeTable context a) Source # 
Instance details

Defined in Rel8.Table.Maybe

Methods

(<>) :: MaybeTable context a -> MaybeTable context a -> MaybeTable context a #

sconcat :: NonEmpty (MaybeTable context a) -> MaybeTable context a #

stimes :: Integral b => b -> MaybeTable context a -> MaybeTable context a #

(context ~ Expr, Table Expr a, Semigroup a) => Monoid (MaybeTable context a) Source # 
Instance details

Defined in Rel8.Table.Maybe

Methods

mempty :: MaybeTable context a #

mappend :: MaybeTable context a -> MaybeTable context a -> MaybeTable context a #

mconcat :: [MaybeTable context a] -> MaybeTable context a #

(EqTable a, context ~ Expr) => EqTable (MaybeTable context a) Source # 
Instance details

Defined in Rel8.Table.Maybe

Methods

eqTable :: Columns (MaybeTable context a) (Dict (Sql DBEq)) Source #

(OrdTable a, context ~ Expr) => OrdTable (MaybeTable context a) Source # 
Instance details

Defined in Rel8.Table.Maybe

Methods

ordTable :: Columns (MaybeTable context a) (Dict (Sql DBOrd)) Source #

(ToExprs exprs a, context ~ Expr) => ToExprs (MaybeTable context exprs) (Maybe a) Source # 
Instance details

Defined in Rel8.Table.Maybe

type Transpose to (MaybeTable context a) Source # 
Instance details

Defined in Rel8.Table.Maybe

type Transpose to (MaybeTable context a) = MaybeTable to (Transpose to a)
type Columns (MaybeTable context a) Source # 
Instance details

Defined in Rel8.Table.Maybe

type Columns (MaybeTable context a)
type Context (MaybeTable context a) Source # 
Instance details

Defined in Rel8.Table.Maybe

type Context (MaybeTable context a) = Context a
type FromExprs (MaybeTable context a) Source # 
Instance details

Defined in Rel8.Table.Maybe

type FromExprs (MaybeTable context a) = Maybe (FromExprs a)

maybeTable :: Table Expr b => b -> (a -> b) -> MaybeTable Expr a -> b Source #

Perform case analysis on a MaybeTable. Like maybe.

($?) :: forall a b. Sql DBType b => (a -> Expr b) -> MaybeTable Expr a -> Expr (Nullify b) infixl 4 Source #

Project a single expression out of a MaybeTable. You can think of this operator like the $ operator, but it also has the ability to return null.

nothingTable :: Table Expr a => MaybeTable Expr a Source #

The null table. Like Nothing.

justTable :: a -> MaybeTable Expr a Source #

Lift any table into MaybeTable. Like Just. Note you can also use pure.

isNothingTable :: MaybeTable Expr a -> Expr Bool Source #

Check if a MaybeTable is absent of any row. Like isNothing.

isJustTable :: MaybeTable Expr a -> Expr Bool Source #

Check if a MaybeTable contains a row. Like isJust.

optional :: Query a -> Query (MaybeTable Expr a) Source #

Convert a query that might return zero rows to a query that always returns at least one row.

To speak in more concrete terms, optional is most useful to write LEFT JOINs.

catMaybeTable :: MaybeTable Expr a -> Query a Source #

Filter out MaybeTables, returning only the tables that are not-null.

This operation can be used to "undo" the effect of optional, which operationally is like turning a LEFT JOIN back into a full JOIN. You can think of this as analogous to catMaybes.

traverseMaybeTable :: (a -> Query b) -> MaybeTable Expr a -> Query (MaybeTable Expr b) Source #

Extend an optional query with another query. This is useful if you want to step through multiple LEFT JOINs.

Note that traverseMaybeTable takes a a -> Query b function, which means you also have the ability to "expand" one row into multiple rows. If the a -> Query b function returns no rows, then the resulting query will also have no rows. However, regardless of the given a -> Query b function, if the input is nothingTable, you will always get exactly one nothingTable back.

aggregateMaybeTable :: (exprs -> aggregates) -> MaybeTable Expr exprs -> MaybeTable Aggregate aggregates Source #

Lift an aggregating function to operate on a MaybeTable. nothingTables and justTables are grouped separately.

nameMaybeTable Source #

Arguments

:: Name (Maybe MaybeTag)

The name of the column to track whether a row is a justTable or nothingTable.

-> a

Names of the columns in a.

-> MaybeTable Name a 

Construct a MaybeTable in the Name context. This can be useful if you have a MaybeTable that you are storing in a table and need to construct a TableSchema.

EitherTable

data EitherTable context a b Source #

An EitherTable a b is a Rel8 table that contains either the table a or the table b. You can construct an EitherTable using leftTable and rightTable, and eliminate/pattern match using eitherTable.

An EitherTable is operationally the same as Haskell's Either type, but adapted to work with Rel8.

Instances

Instances details
(Table context a, Table context b, Reifiable context, context ~ context') => Table context' (EitherTable context a b) Source # 
Instance details

Defined in Rel8.Table.Either

Associated Types

type Columns (EitherTable context a b) :: HTable Source #

type Context (EitherTable context a b) :: Context Source #

type FromExprs (EitherTable context a b) Source #

type Transpose context' (EitherTable context a b) Source #

Methods

toColumns :: EitherTable context a b -> Columns (EitherTable context a b) context' Source #

fromColumns :: Columns (EitherTable context a b) context' -> EitherTable context a b Source #

fromResult :: Columns (EitherTable context a b) Result -> FromExprs (EitherTable context a b) Source #

toResult :: FromExprs (EitherTable context a b) -> Columns (EitherTable context a b) Result Source #

Nullifiable context => Bifunctor (EitherTable context) Source # 
Instance details

Defined in Rel8.Table.Either

Methods

bimap :: (a -> b) -> (c -> d) -> EitherTable context a c -> EitherTable context b d #

first :: (a -> b) -> EitherTable context a c -> EitherTable context b c #

second :: (b -> c) -> EitherTable context a b -> EitherTable context a c #

Biprojectable (EitherTable context) Source # 
Instance details

Defined in Rel8.Table.Either

Methods

biproject :: (Projecting a b, Projecting c d) => Projection a b -> Projection c d -> EitherTable context a c -> EitherTable context b d Source #

(context ~ Expr, Table Expr a) => Monad (EitherTable context a) Source # 
Instance details

Defined in Rel8.Table.Either

Methods

(>>=) :: EitherTable context a a0 -> (a0 -> EitherTable context a b) -> EitherTable context a b #

(>>) :: EitherTable context a a0 -> EitherTable context a b -> EitherTable context a b #

return :: a0 -> EitherTable context a a0 #

Nullifiable context => Functor (EitherTable context a) Source # 
Instance details

Defined in Rel8.Table.Either

Methods

fmap :: (a0 -> b) -> EitherTable context a a0 -> EitherTable context a b #

(<$) :: a0 -> EitherTable context a b -> EitherTable context a a0 #

(context ~ Expr, Table Expr a) => Applicative (EitherTable context a) Source # 
Instance details

Defined in Rel8.Table.Either

Methods

pure :: a0 -> EitherTable context a a0 #

(<*>) :: EitherTable context a (a0 -> b) -> EitherTable context a a0 -> EitherTable context a b #

liftA2 :: (a0 -> b -> c) -> EitherTable context a a0 -> EitherTable context a b -> EitherTable context a c #

(*>) :: EitherTable context a a0 -> EitherTable context a b -> EitherTable context a b #

(<*) :: EitherTable context a a0 -> EitherTable context a b -> EitherTable context a a0 #

(context ~ Expr, Table Expr a) => Apply (EitherTable context a) Source # 
Instance details

Defined in Rel8.Table.Either

Methods

(<.>) :: EitherTable context a (a0 -> b) -> EitherTable context a a0 -> EitherTable context a b #

(.>) :: EitherTable context a a0 -> EitherTable context a b -> EitherTable context a b #

(<.) :: EitherTable context a a0 -> EitherTable context a b -> EitherTable context a a0 #

liftF2 :: (a0 -> b -> c) -> EitherTable context a a0 -> EitherTable context a b -> EitherTable context a c #

(context ~ Expr, Table Expr a) => Bind (EitherTable context a) Source # 
Instance details

Defined in Rel8.Table.Either

Methods

(>>-) :: EitherTable context a a0 -> (a0 -> EitherTable context a b) -> EitherTable context a b #

join :: EitherTable context a (EitherTable context a a0) -> EitherTable context a a0 #

Projectable (EitherTable context a) Source # 
Instance details

Defined in Rel8.Table.Either

Methods

project :: Projecting a0 b => Projection a0 b -> EitherTable context a a0 -> EitherTable context a b Source #

(context ~ Expr, Table Expr a, Table Expr b) => Semigroup (EitherTable context a b) Source # 
Instance details

Defined in Rel8.Table.Either

Methods

(<>) :: EitherTable context a b -> EitherTable context a b -> EitherTable context a b #

sconcat :: NonEmpty (EitherTable context a b) -> EitherTable context a b #

stimes :: Integral b0 => b0 -> EitherTable context a b -> EitherTable context a b #

(EqTable a, EqTable b, context ~ Expr) => EqTable (EitherTable context a b) Source # 
Instance details

Defined in Rel8.Table.Either

Methods

eqTable :: Columns (EitherTable context a b) (Dict (Sql DBEq)) Source #

(OrdTable a, OrdTable b, context ~ Expr) => OrdTable (EitherTable context a b) Source # 
Instance details

Defined in Rel8.Table.Either

Methods

ordTable :: Columns (EitherTable context a b) (Dict (Sql DBOrd)) Source #

type Transpose to (EitherTable context a b) Source # 
Instance details

Defined in Rel8.Table.Either

type Transpose to (EitherTable context a b) = EitherTable to (Transpose to a) (Transpose to b)
type Columns (EitherTable context a b) Source # 
Instance details

Defined in Rel8.Table.Either

type Columns (EitherTable context a b)
type Context (EitherTable context a b) Source # 
Instance details

Defined in Rel8.Table.Either

type Context (EitherTable context a b) = Context a
type FromExprs (EitherTable context a b) Source # 
Instance details

Defined in Rel8.Table.Either

type FromExprs (EitherTable context a b) = Either (FromExprs a) (FromExprs b)

eitherTable :: Table Expr c => (a -> c) -> (b -> c) -> EitherTable Expr a b -> c Source #

Pattern match/eliminate an EitherTable, by providing mappings from a leftTable and rightTable.

leftTable :: Table Expr b => a -> EitherTable Expr a b Source #

Construct a left EitherTable. Like Left.

rightTable :: Table Expr a => b -> EitherTable Expr a b Source #

Construct a right EitherTable. Like Right.

keepLeftTable :: EitherTable Expr a b -> Query a Source #

Filter EitherTables, keeping only leftTables.

keepRightTable :: EitherTable Expr a b -> Query b Source #

Filter EitherTables, keeping only rightTables.

bitraverseEitherTable :: (a -> Query c) -> (b -> Query d) -> EitherTable Expr a b -> Query (EitherTable Expr c d) Source #

bitraverseEitherTable f g x will pass all leftTables through f and all rightTables through g. The results are then lifted back into leftTable and rightTable, respectively. This is similar to bitraverse for Either.

For example,

>>> :{
select do
  x <- values (map lit [ Left True, Right (42 :: Int32) ])
  bitraverseEitherTable (\y -> values [y, not_ y]) (\y -> pure (y * 100)) x
:}
[ Left True
, Left False
, Right 4200
]

aggregateEitherTable :: (exprs -> aggregates) -> (exprs' -> aggregates') -> EitherTable Expr exprs exprs' -> EitherTable Aggregate aggregates aggregates' Source #

Lift a pair of aggregating functions to operate on an EitherTable. leftTables and rightTables are grouped separately.

nameEitherTable Source #

Arguments

:: Name EitherTag

The name of the column to track whether a row is a leftTable or rightTable.

-> a

Names of the columns in the a table.

-> b

Names of the columns in the b table.

-> EitherTable Name a b 

Construct a EitherTable in the Name context. This can be useful if you have a EitherTable that you are storing in a table and need to construct a TableSchema.

TheseTable

data TheseTable context a b Source #

TheseTable a b is a Rel8 table that contains either the table a, the table b, or both tables a and b. You can construct TheseTables using thisTable, thatTable and thoseTable. TheseTables can be eliminated/pattern matched using theseTable.

TheseTable is operationally the same as Haskell's These type, but adapted to work with Rel8.

Instances

Instances details
(Table context a, Table context b, Reifiable context, context ~ context') => Table context' (TheseTable context a b) Source # 
Instance details

Defined in Rel8.Table.These

Associated Types

type Columns (TheseTable context a b) :: HTable Source #

type Context (TheseTable context a b) :: Context Source #

type FromExprs (TheseTable context a b) Source #

type Transpose context' (TheseTable context a b) Source #

Methods

toColumns :: TheseTable context a b -> Columns (TheseTable context a b) context' Source #

fromColumns :: Columns (TheseTable context a b) context' -> TheseTable context a b Source #

fromResult :: Columns (TheseTable context a b) Result -> FromExprs (TheseTable context a b) Source #

toResult :: FromExprs (TheseTable context a b) -> Columns (TheseTable context a b) Result Source #

Nullifiable context => Bifunctor (TheseTable context) Source # 
Instance details

Defined in Rel8.Table.These

Methods

bimap :: (a -> b) -> (c -> d) -> TheseTable context a c -> TheseTable context b d #

first :: (a -> b) -> TheseTable context a c -> TheseTable context b c #

second :: (b -> c) -> TheseTable context a b -> TheseTable context a c #

Biprojectable (TheseTable context) Source # 
Instance details

Defined in Rel8.Table.These

Methods

biproject :: (Projecting a b, Projecting c d) => Projection a b -> Projection c d -> TheseTable context a c -> TheseTable context b d Source #

(context ~ Expr, Table Expr a, Semigroup a) => Monad (TheseTable context a) Source # 
Instance details

Defined in Rel8.Table.These

Methods

(>>=) :: TheseTable context a a0 -> (a0 -> TheseTable context a b) -> TheseTable context a b #

(>>) :: TheseTable context a a0 -> TheseTable context a b -> TheseTable context a b #

return :: a0 -> TheseTable context a a0 #

Nullifiable context => Functor (TheseTable context a) Source # 
Instance details

Defined in Rel8.Table.These

Methods

fmap :: (a0 -> b) -> TheseTable context a a0 -> TheseTable context a b #

(<$) :: a0 -> TheseTable context a b -> TheseTable context a a0 #

(context ~ Expr, Table Expr a, Semigroup a) => Applicative (TheseTable context a) Source # 
Instance details

Defined in Rel8.Table.These

Methods

pure :: a0 -> TheseTable context a a0 #

(<*>) :: TheseTable context a (a0 -> b) -> TheseTable context a a0 -> TheseTable context a b #

liftA2 :: (a0 -> b -> c) -> TheseTable context a a0 -> TheseTable context a b -> TheseTable context a c #

(*>) :: TheseTable context a a0 -> TheseTable context a b -> TheseTable context a b #

(<*) :: TheseTable context a a0 -> TheseTable context a b -> TheseTable context a a0 #

(context ~ Expr, Table Expr a, Semigroup a) => Apply (TheseTable context a) Source # 
Instance details

Defined in Rel8.Table.These

Methods

(<.>) :: TheseTable context a (a0 -> b) -> TheseTable context a a0 -> TheseTable context a b #

(.>) :: TheseTable context a a0 -> TheseTable context a b -> TheseTable context a b #

(<.) :: TheseTable context a a0 -> TheseTable context a b -> TheseTable context a a0 #

liftF2 :: (a0 -> b -> c) -> TheseTable context a a0 -> TheseTable context a b -> TheseTable context a c #

(context ~ Expr, Table Expr a, Semigroup a) => Bind (TheseTable context a) Source # 
Instance details

Defined in Rel8.Table.These

Methods

(>>-) :: TheseTable context a a0 -> (a0 -> TheseTable context a b) -> TheseTable context a b #

join :: TheseTable context a (TheseTable context a a0) -> TheseTable context a a0 #

Projectable (TheseTable context a) Source # 
Instance details

Defined in Rel8.Table.These

Methods

project :: Projecting a0 b => Projection a0 b -> TheseTable context a a0 -> TheseTable context a b Source #

(context ~ Expr, Table Expr a, Table Expr b, Semigroup a, Semigroup b) => Semigroup (TheseTable context a b) Source # 
Instance details

Defined in Rel8.Table.These

Methods

(<>) :: TheseTable context a b -> TheseTable context a b -> TheseTable context a b #

sconcat :: NonEmpty (TheseTable context a b) -> TheseTable context a b #

stimes :: Integral b0 => b0 -> TheseTable context a b -> TheseTable context a b #

(EqTable a, EqTable b, context ~ Expr) => EqTable (TheseTable context a b) Source # 
Instance details

Defined in Rel8.Table.These

Methods

eqTable :: Columns (TheseTable context a b) (Dict (Sql DBEq)) Source #

(OrdTable a, OrdTable b, context ~ Expr) => OrdTable (TheseTable context a b) Source # 
Instance details

Defined in Rel8.Table.These

Methods

ordTable :: Columns (TheseTable context a b) (Dict (Sql DBOrd)) Source #

type Transpose to (TheseTable context a b) Source # 
Instance details

Defined in Rel8.Table.These

type Transpose to (TheseTable context a b) = TheseTable to (Transpose to a) (Transpose to b)
type Columns (TheseTable context a b) Source # 
Instance details

Defined in Rel8.Table.These

type Columns (TheseTable context a b)
type Context (TheseTable context a b) Source # 
Instance details

Defined in Rel8.Table.These

type Context (TheseTable context a b) = Context a
type FromExprs (TheseTable context a b) Source # 
Instance details

Defined in Rel8.Table.These

type FromExprs (TheseTable context a b) = These (FromExprs a) (FromExprs b)

theseTable :: Table Expr c => (a -> c) -> (b -> c) -> (a -> b -> c) -> TheseTable Expr a b -> c Source #

Pattern match on a TheseTable. Corresponds to these.

thisTable :: Table Expr b => a -> TheseTable Expr a b Source #

Construct a TheseTable. Corresponds to This.

thatTable :: Table Expr a => b -> TheseTable Expr a b Source #

Construct a TheseTable. Corresponds to That.

thoseTable :: a -> b -> TheseTable Expr a b Source #

Construct a TheseTable. Corresponds to These.

isThisTable :: TheseTable Expr a b -> Expr Bool Source #

Test if a TheseTable was constructed with thisTable.

Corresponds to isThis.

isThatTable :: TheseTable Expr a b -> Expr Bool Source #

Test if a TheseTable was constructed with thatTable.

Corresponds to isThat.

isThoseTable :: TheseTable Expr a b -> Expr Bool Source #

Test if a TheseTable was constructed with thoseTable.

Corresponds to isThese.

hasHereTable :: TheseTable Expr a b -> Expr Bool Source #

Test if the a side of TheseTable a b is present.

Corresponds to hasHere.

hasThereTable :: TheseTable Expr a b -> Expr Bool Source #

Test if the b table of TheseTable a b is present.

Corresponds to hasThere.

justHereTable :: TheseTable context a b -> MaybeTable context a Source #

Attempt to project out the a table of a TheseTable a b.

Corresponds to justHere.

justThereTable :: TheseTable context a b -> MaybeTable context b Source #

Attempt to project out the b table of a TheseTable a b.

Corresponds to justThere.

alignBy :: (a -> b -> Expr Bool) -> Query a -> Query b -> Query (TheseTable Expr a b) Source #

Corresponds to a FULL OUTER JOIN between two queries.

bitraverseTheseTable :: (a -> Query c) -> (b -> Query d) -> TheseTable Expr a b -> Query (TheseTable Expr c d) Source #

aggregateTheseTable :: (exprs -> aggregates) -> (exprs' -> aggregates') -> TheseTable Expr exprs exprs' -> TheseTable Aggregate aggregates aggregates' Source #

Lift a pair of aggregating functions to operate on an TheseTable. thisTables, thatTables and thoseTables are grouped separately.

nameTheseTable Source #

Arguments

:: Name (Maybe MaybeTag)

The name of the column to track the presence of the a table.

-> Name (Maybe MaybeTag)

The name of the column to track the presence of the b table.

-> a

Names of the columns in the a table.

-> b

Names of the columns in the b table.

-> TheseTable Name a b 

Construct a TheseTable in the Name context. This can be useful if you have a TheseTable that you are storing in a table and need to construct a TableSchema.

ListTable

data ListTable context a Source #

A ListTable value contains zero or more instances of a. You construct ListTables with many or listAgg.

Instances

Instances details
(Table context a, context ~ context') => Table context' (ListTable context a) Source # 
Instance details

Defined in Rel8.Table.List

Associated Types

type Columns (ListTable context a) :: HTable Source #

type Context (ListTable context a) :: Context Source #

type FromExprs (ListTable context a) Source #

type Transpose context' (ListTable context a) Source #

Methods

toColumns :: ListTable context a -> Columns (ListTable context a) context' Source #

fromColumns :: Columns (ListTable context a) context' -> ListTable context a Source #

fromResult :: Columns (ListTable context a) Result -> FromExprs (ListTable context a) Source #

toResult :: FromExprs (ListTable context a) -> Columns (ListTable context a) Result Source #

Projectable (ListTable context) Source # 
Instance details

Defined in Rel8.Table.List

Methods

project :: Projecting a b => Projection a b -> ListTable context a -> ListTable context b Source #

context ~ Expr => AlternativeTable (ListTable context) Source # 
Instance details

Defined in Rel8.Table.List

Methods

emptyTable :: Table Expr a => ListTable context a Source #

context ~ Expr => AltTable (ListTable context) Source # 
Instance details

Defined in Rel8.Table.List

Methods

(<|>:) :: Table Expr a => ListTable context a -> ListTable context a -> ListTable context a Source #

(context ~ Expr, Table Expr a) => Semigroup (ListTable context a) Source # 
Instance details

Defined in Rel8.Table.List

Methods

(<>) :: ListTable context a -> ListTable context a -> ListTable context a #

sconcat :: NonEmpty (ListTable context a) -> ListTable context a #

stimes :: Integral b => b -> ListTable context a -> ListTable context a #

(context ~ Expr, Table Expr a) => Monoid (ListTable context a) Source # 
Instance details

Defined in Rel8.Table.List

Methods

mempty :: ListTable context a #

mappend :: ListTable context a -> ListTable context a -> ListTable context a #

mconcat :: [ListTable context a] -> ListTable context a #

(EqTable a, context ~ Expr) => EqTable (ListTable context a) Source # 
Instance details

Defined in Rel8.Table.List

Methods

eqTable :: Columns (ListTable context a) (Dict (Sql DBEq)) Source #

(OrdTable a, context ~ Expr) => OrdTable (ListTable context a) Source # 
Instance details

Defined in Rel8.Table.List

Methods

ordTable :: Columns (ListTable context a) (Dict (Sql DBOrd)) Source #

(ToExprs exprs a, context ~ Expr) => ToExprs (ListTable context exprs) [a] Source # 
Instance details

Defined in Rel8.Table.List

type Transpose to (ListTable context a) Source # 
Instance details

Defined in Rel8.Table.List

type Transpose to (ListTable context a) = ListTable to (Transpose to a)
type Columns (ListTable context a) Source # 
Instance details

Defined in Rel8.Table.List

type Columns (ListTable context a)
type Context (ListTable context a) Source # 
Instance details

Defined in Rel8.Table.List

type Context (ListTable context a) = Context a
type FromExprs (ListTable context a) Source # 
Instance details

Defined in Rel8.Table.List

type FromExprs (ListTable context a) = [FromExprs a]

listTable :: Table Expr a => [a] -> ListTable Expr a Source #

Construct a ListTable from a list of expressions.

($*) :: Projecting a (Expr b) => Projection a (Expr b) -> ListTable Expr a -> Expr [b] infixl 4 Source #

Project a single expression out of a ListTable.

nameListTable Source #

Arguments

:: Table Name a 
=> a

The names of the columns of elements of the list.

-> ListTable Name a 

Construct a ListTable in the Name context. This can be useful if you have a ListTable that you are storing in a table and need to construct a TableSchema.

many :: Table Expr a => Query a -> Query (ListTable Expr a) Source #

Aggregate a Query into a ListTable. If the supplied query returns 0 rows, this function will produce a Query that returns one row containing the empty ListTable. If the supplied Query does return rows, many will return exactly one row, with a ListTable collecting all returned rows.

many is analogous to many from Control.Applicative.

manyExpr :: Sql DBType a => Query (Expr a) -> Query (Expr [a]) Source #

A version of many specialised to single expressions.

catListTable :: Table Expr a => ListTable Expr a -> Query a Source #

Expand a ListTable into a Query, where each row in the query is an element of the given ListTable.

catListTable is an inverse to many.

catList :: Sql DBType a => Expr [a] -> Query (Expr a) Source #

Expand an expression that contains a list into a Query, where each row in the query is an element of the given list.

catList is an inverse to manyExpr.

NonEmptyTable

data NonEmptyTable context a Source #

A NonEmptyTable value contains one or more instances of a. You construct NonEmptyTables with some or nonEmptyAgg.

Instances

Instances details
(Table context a, context ~ context') => Table context' (NonEmptyTable context a) Source # 
Instance details

Defined in Rel8.Table.NonEmpty

Associated Types

type Columns (NonEmptyTable context a) :: HTable Source #

type Context (NonEmptyTable context a) :: Context Source #

type FromExprs (NonEmptyTable context a) Source #

type Transpose context' (NonEmptyTable context a) Source #

Methods

toColumns :: NonEmptyTable context a -> Columns (NonEmptyTable context a) context' Source #

fromColumns :: Columns (NonEmptyTable context a) context' -> NonEmptyTable context a Source #

fromResult :: Columns (NonEmptyTable context a) Result -> FromExprs (NonEmptyTable context a) Source #

toResult :: FromExprs (NonEmptyTable context a) -> Columns (NonEmptyTable context a) Result Source #

Projectable (NonEmptyTable context) Source # 
Instance details

Defined in Rel8.Table.NonEmpty

Methods

project :: Projecting a b => Projection a b -> NonEmptyTable context a -> NonEmptyTable context b Source #

context ~ Expr => AltTable (NonEmptyTable context) Source # 
Instance details

Defined in Rel8.Table.NonEmpty

Methods

(<|>:) :: Table Expr a => NonEmptyTable context a -> NonEmptyTable context a -> NonEmptyTable context a Source #

(Table Expr a, context ~ Expr) => Semigroup (NonEmptyTable context a) Source # 
Instance details

Defined in Rel8.Table.NonEmpty

Methods

(<>) :: NonEmptyTable context a -> NonEmptyTable context a -> NonEmptyTable context a #

sconcat :: NonEmpty (NonEmptyTable context a) -> NonEmptyTable context a #

stimes :: Integral b => b -> NonEmptyTable context a -> NonEmptyTable context a #

(EqTable a, context ~ Expr) => EqTable (NonEmptyTable context a) Source # 
Instance details

Defined in Rel8.Table.NonEmpty

Methods

eqTable :: Columns (NonEmptyTable context a) (Dict (Sql DBEq)) Source #

(OrdTable a, context ~ Expr) => OrdTable (NonEmptyTable context a) Source # 
Instance details

Defined in Rel8.Table.NonEmpty

Methods

ordTable :: Columns (NonEmptyTable context a) (Dict (Sql DBOrd)) Source #

(ToExprs exprs a, context ~ Expr) => ToExprs (NonEmptyTable context exprs) (NonEmpty a) Source # 
Instance details

Defined in Rel8.Table.NonEmpty

type Transpose to (NonEmptyTable context a) Source # 
Instance details

Defined in Rel8.Table.NonEmpty

type Transpose to (NonEmptyTable context a) = NonEmptyTable to (Transpose to a)
type Columns (NonEmptyTable context a) Source # 
Instance details

Defined in Rel8.Table.NonEmpty

type Columns (NonEmptyTable context a)
type Context (NonEmptyTable context a) Source # 
Instance details

Defined in Rel8.Table.NonEmpty

type Context (NonEmptyTable context a) = Context a
type FromExprs (NonEmptyTable context a) Source # 
Instance details

Defined in Rel8.Table.NonEmpty

type FromExprs (NonEmptyTable context a) = NonEmpty (FromExprs a)

nonEmptyTable :: Table Expr a => NonEmpty a -> NonEmptyTable Expr a Source #

Construct a NonEmptyTable from a non-empty list of expressions.

($+) :: Projecting a (Expr b) => Projection a (Expr b) -> NonEmptyTable Expr a -> Expr (NonEmpty b) infixl 4 Source #

Project a single expression out of a NonEmptyTable.

nameNonEmptyTable Source #

Arguments

:: Table Name a 
=> a

The names of the columns of elements of the list.

-> NonEmptyTable Name a 

Construct a NonEmptyTable in the Name context. This can be useful if you have a NonEmptyTable that you are storing in a table and need to construct a TableSchema.

some :: Table Expr a => Query a -> Query (NonEmptyTable Expr a) Source #

Aggregate a Query into a NonEmptyTable. If the supplied query returns 0 rows, this function will produce a Query that is empty - that is, will produce zero NonEmptyTables. If the supplied Query does return rows, some will return exactly one row, with a NonEmptyTable collecting all returned rows.

some is analogous to some from Control.Applicative.

someExpr :: Sql DBType a => Query (Expr a) -> Query (Expr (NonEmpty a)) Source #

A version of many specialised to single expressions.

catNonEmptyTable :: Table Expr a => NonEmptyTable Expr a -> Query a Source #

Expand a NonEmptyTable into a Query, where each row in the query is an element of the given NonEmptyTable.

catNonEmptyTable is an inverse to some.

catNonEmpty :: Sql DBType a => Expr (NonEmpty a) -> Query (Expr a) Source #

Expand an expression that contains a non-empty list into a Query, where each row in the query is an element of the given list.

catNonEmpty is an inverse to someExpr.

ADT

data ADT t context Source #

Instances

Instances details
ADTable t => Rel8able (ADT t) Source # 
Instance details

Defined in Rel8.Table.ADT

Associated Types

type GColumns (ADT t) :: HTable

type GFromExprs (ADT t)

Methods

gfromColumns :: forall (context :: Context). SContext context -> GColumns (ADT t) context -> ADT t context

gtoColumns :: forall (context :: Context). SContext context -> ADT t context -> GColumns (ADT t) context

gfromResult :: GColumns (ADT t) Result -> GFromExprs (ADT t)

gtoResult :: GFromExprs (ADT t) -> GColumns (ADT t) Result

class (Generic (Record (t Result)), HTable (GColumnsADT t), GSerializeADT TSerialize TColumns (Eval (ADTRep t Expr)) (Eval (ADTRep t Result))) => ADTable t Source #

Instances

Instances details
(Generic (Record (t Result)), HTable (GColumnsADT t), GSerializeADT TSerialize TColumns (Eval (ADTRep t Expr)) (Eval (ADTRep t Result))) => ADTable t Source # 
Instance details

Defined in Rel8.Table.ADT

type BuildADT t name = GGBuild 'Sum name (ADTRep t) (ADT t Expr) Source #

buildADT :: forall t name. BuildableADT t name => BuildADT t name Source #

type ConstructADT t = forall r. GGConstruct 'Sum (ADTRep t) r Source #

constructADT :: forall t. ConstructableADT t => ConstructADT t -> ADT t Expr Source #

type DeconstructADT t r = GGDeconstruct 'Sum (ADTRep t) (ADT t Expr) r Source #

deconstructADT :: forall t r. (ConstructableADT t, Table Expr r) => DeconstructADT t r Source #

type NameADT t = GGName 'Sum (ADTRep t) (ADT t Name) Source #

nameADT :: forall t. ConstructableADT t => NameADT t Source #

type AggregateADT t = forall r. GGAggregate 'Sum (ADTRep t) r Source #

aggregateADT :: forall t. ConstructableADT t => AggregateADT t -> ADT t Expr -> ADT t Aggregate Source #

HKD

data HKD a f Source #

Instances

Instances details
HKDable a => Rel8able (HKD a) Source # 
Instance details

Defined in Rel8.Table.HKD

Associated Types

type GColumns (HKD a) :: HTable

type GFromExprs (HKD a)

Methods

gfromColumns :: forall (context :: Context). SContext context -> GColumns (HKD a) context -> HKD a context

gtoColumns :: forall (context :: Context). SContext context -> HKD a context -> GColumns (HKD a) context

gfromResult :: GColumns (HKD a) Result -> GFromExprs (HKD a)

gtoResult :: GFromExprs (HKD a) -> GColumns (HKD a) Result

(GTable (TTable f) TColumns (GRecord (GMap (TColumn f) (Rep a))), GColumns TColumns (GRecord (GMap (TColumn f) (Rep a))) ~ GColumnsHKD a, GContext TContext (GRecord (GMap (TColumn f) (Rep a))) ~ f, GRecordable (GMap (TColumn f) (Rep a))) => Generic (HKD a f) Source # 
Instance details

Defined in Rel8.Table.HKD

Associated Types

type Rep (HKD a f) :: Type -> Type #

Methods

from :: HKD a f -> Rep (HKD a f) x #

to :: Rep (HKD a f) x -> HKD a f #

type Rep (HKD a f) Source # 
Instance details

Defined in Rel8.Table.HKD

type Rep (HKD a f)

class (Generic (Record a), HTable (GColumns (HKD a)), KnownAlgebra (GAlgebra (Rep a)), Eval (GGSerialize (GAlgebra (Rep a)) TSerialize TColumns (Eval (HKDRep a Expr)) (Eval (HKDRep a Result))), GRecord (GMap (TColumn Result) (Rep a)) ~ Rep (Record a)) => HKDable a Source #

Instances

Instances details
(Generic (Record a), HTable (GColumns (HKD a)), KnownAlgebra (GAlgebra (Rep a)), Eval (GGSerialize (GAlgebra (Rep a)) TSerialize TColumns (Eval (HKDRep a Expr)) (Eval (HKDRep a Result))), GRecord (GMap (TColumn Result) (Rep a)) ~ Rep (Record a)) => HKDable a Source # 
Instance details

Defined in Rel8.Table.HKD

type BuildHKD a name = GGBuild (GAlgebra (Rep a)) name (HKDRep a) (HKD a Expr) Source #

buildHKD :: forall a name. BuildableHKD a name => BuildHKD a name Source #

type ConstructHKD a = forall r. GGConstruct (GAlgebra (Rep a)) (HKDRep a) r Source #

constructHKD :: forall a. ConstructableHKD a => ConstructHKD a -> HKD a Expr Source #

type DeconstructHKD a r = GGDeconstruct (GAlgebra (Rep a)) (HKDRep a) (HKD a Expr) r Source #

deconstructHKD :: forall a r. (ConstructableHKD a, Table Expr r) => DeconstructHKD a r Source #

type NameHKD a = GGName (GAlgebra (Rep a)) (HKDRep a) (HKD a Name) Source #

nameHKD :: forall a. ConstructableHKD a => NameHKD a Source #

type AggregateHKD a = forall r. GGAggregate (GAlgebra (Rep a)) (HKDRep a) r Source #

aggregateHKD :: forall a. ConstructableHKD a => AggregateHKD a -> HKD a Expr -> HKD a Aggregate Source #

Table schemas

data TableSchema names Source #

The schema for a table. This is used to specify the name and schema that a table belongs to (the FROM part of a SQL query), along with the schema of the columns within this table.

For each selectable table in your database, you should provide a TableSchema in order to interact with the table via Rel8.

Constructors

TableSchema 

Fields

  • name :: String

    The name of the table.

  • schema :: Maybe String

    The schema that this table belongs to. If Nothing, whatever is on the connection's search_path will be used.

  • columns :: names

    The columns of the table. Typically you would use a a higher-kinded data type here, parameterized by the ColumnSchema functor.

Instances

Instances details
Functor TableSchema Source # 
Instance details

Defined in Rel8.Schema.Table

Methods

fmap :: (a -> b) -> TableSchema a -> TableSchema b #

(<$) :: a -> TableSchema b -> TableSchema a #

data Name a Source #

A Name is the name of a column, as it would be defined in a table's schema definition. You can construct names by using the OverloadedStrings extension and writing string literals. This is typically done when providing a TableSchema value.

Instances

Instances details
Sql DBType a => Table Name (Name a) Source # 
Instance details

Defined in Rel8.Schema.Name

Associated Types

type Columns (Name a) :: HTable Source #

type Context (Name a) :: Context Source #

type FromExprs (Name a) Source #

type Transpose context' (Name a) Source #

Show (Name a) Source # 
Instance details

Defined in Rel8.Schema.Name

Methods

showsPrec :: Int -> Name a -> ShowS #

show :: Name a -> String #

showList :: [Name a] -> ShowS #

IsString (Name a) Source # 
Instance details

Defined in Rel8.Schema.Name

Methods

fromString :: String -> Name a #

type Transpose to (Name a) Source # 
Instance details

Defined in Rel8.Schema.Name

type Transpose to (Name a) = to a
type Columns (Name a) Source # 
Instance details

Defined in Rel8.Schema.Name

type Columns (Name a)
type Context (Name a) Source # 
Instance details

Defined in Rel8.Schema.Name

type Context (Name a) = Name
type FromExprs (Name a) Source # 
Instance details

Defined in Rel8.Schema.Name

type FromExprs (Name a) = a

namesFromLabels :: Table Name a => a Source #

Construct a table in the Name context containing the names of all columns. Nested column names will be combined with /.

See also: namesFromLabelsWith.

namesFromLabelsWith :: Table Name a => (NonEmpty String -> String) -> a Source #

Construct a table in the Name context containing the names of all columns. The supplied function can be used to transform column names.

This function can be used to generically derive the columns for a TableSchema. For example,

myTableSchema :: TableSchema (MyTable Name)
myTableSchema = TableSchema
  { columns = namesFromLabelsWith last
  }

will construct a TableSchema where each columns names exactly corresponds to the name of the Haskell field.

Expressions

data Expr a Source #

Typed SQL expressions.

Instances

Instances details
Sql DBType a => Table Expr (Expr a) Source # 
Instance details

Defined in Rel8.Expr

Associated Types

type Columns (Expr a) :: HTable Source #

type Context (Expr a) :: Context Source #

type FromExprs (Expr a) Source #

type Transpose context' (Expr a) Source #

(arg ~ Expr a, Sql DBType b) => Function arg (Expr b) Source # 
Instance details

Defined in Rel8.Expr.Function

Methods

applyArgument :: ([PrimExpr] -> PrimExpr) -> arg -> Expr b

Sql DBFloating a => Floating (Expr a) Source # 
Instance details

Defined in Rel8.Expr

Methods

pi :: Expr a #

exp :: Expr a -> Expr a #

log :: Expr a -> Expr a #

sqrt :: Expr a -> Expr a #

(**) :: Expr a -> Expr a -> Expr a #

logBase :: Expr a -> Expr a -> Expr a #

sin :: Expr a -> Expr a #

cos :: Expr a -> Expr a #

tan :: Expr a -> Expr a #

asin :: Expr a -> Expr a #

acos :: Expr a -> Expr a #

atan :: Expr a -> Expr a #

sinh :: Expr a -> Expr a #

cosh :: Expr a -> Expr a #

tanh :: Expr a -> Expr a #

asinh :: Expr a -> Expr a #

acosh :: Expr a -> Expr a #

atanh :: Expr a -> Expr a #

log1p :: Expr a -> Expr a #

expm1 :: Expr a -> Expr a #

log1pexp :: Expr a -> Expr a #

log1mexp :: Expr a -> Expr a #

Sql DBFractional a => Fractional (Expr a) Source # 
Instance details

Defined in Rel8.Expr

Methods

(/) :: Expr a -> Expr a -> Expr a #

recip :: Expr a -> Expr a #

fromRational :: Rational -> Expr a #

Sql DBNum a => Num (Expr a) Source # 
Instance details

Defined in Rel8.Expr

Methods

(+) :: Expr a -> Expr a -> Expr a #

(-) :: Expr a -> Expr a -> Expr a #

(*) :: Expr a -> Expr a -> Expr a #

negate :: Expr a -> Expr a #

abs :: Expr a -> Expr a #

signum :: Expr a -> Expr a #

fromInteger :: Integer -> Expr a #

Show (Expr a) Source # 
Instance details

Defined in Rel8.Expr

Methods

showsPrec :: Int -> Expr a -> ShowS #

show :: Expr a -> String #

showList :: [Expr a] -> ShowS #

(Sql IsString a, Sql DBType a) => IsString (Expr a) Source # 
Instance details

Defined in Rel8.Expr

Methods

fromString :: String -> Expr a #

Sql DBSemigroup a => Semigroup (Expr a) Source # 
Instance details

Defined in Rel8.Expr

Methods

(<>) :: Expr a -> Expr a -> Expr a #

sconcat :: NonEmpty (Expr a) -> Expr a #

stimes :: Integral b => b -> Expr a -> Expr a #

Sql DBMonoid a => Monoid (Expr a) Source # 
Instance details

Defined in Rel8.Expr

Methods

mempty :: Expr a #

mappend :: Expr a -> Expr a -> Expr a #

mconcat :: [Expr a] -> Expr a #

Sql DBEq a => EqTable (Expr a) Source # 
Instance details

Defined in Rel8.Table.Eq

Methods

eqTable :: Columns (Expr a) (Dict (Sql DBEq)) Source #

Sql DBOrd a => OrdTable (Expr a) Source # 
Instance details

Defined in Rel8.Table.Ord

Methods

ordTable :: Columns (Expr a) (Dict (Sql DBOrd)) Source #

Sql DBType a => Serializable (Expr a) a Source # 
Instance details

Defined in Rel8.Table.Serialize

(Sql DBType a, NotNull a, x ~ NonEmpty a) => ToExprs (Expr x) (NonEmpty a) Source # 
Instance details

Defined in Rel8.Table.Serialize

(Sql DBType a, NotNull a, x ~ Maybe a) => ToExprs (Expr x) (Maybe a) Source # 
Instance details

Defined in Rel8.Table.Serialize

(Sql DBType a, x ~ [a]) => ToExprs (Expr x) [a] Source # 
Instance details

Defined in Rel8.Table.Serialize

type Transpose to (Expr a) Source # 
Instance details

Defined in Rel8.Expr

type Transpose to (Expr a) = to a
type Columns (Expr a) Source # 
Instance details

Defined in Rel8.Expr

type Columns (Expr a)
type Context (Expr a) Source # 
Instance details

Defined in Rel8.Expr

type Context (Expr a) = Expr
type FromExprs (Expr a) Source # 
Instance details

Defined in Rel8.Expr

type FromExprs (Expr a) = a

class (constraint (Unnullify a), Nullable a) => Sql constraint a Source #

The Sql type class describes both null and not null database values, constrained by a specific class.

For example, if you see Sql DBEq a, this means any database type that supports equality, and a can either be exactly an a, or it could also be Maybe a.

Instances

Instances details
(constraint (Unnullify a), Nullable a) => Sql constraint a Source # 
Instance details

Defined in Rel8.Schema.Null

litExpr :: Sql DBType a => a -> Expr a Source #

Produce an expression from a literal.

Note that you can usually use lit, but litExpr can solve problems of inference in polymorphic code.

unsafeCastExpr :: Sql DBType b => Expr a -> Expr b Source #

Cast an expression to a different type. Corresponds to a CAST() function call.

unsafeLiteral :: String -> Expr a Source #

Unsafely construct an expression from literal SQL.

This is an escape hatch, and can be used if Rel8 can not adequately express the query you need. If you find yourself using this function, please let us know, as it may indicate that something is missing from Rel8!

null

class (Nullable a, IsMaybe a ~ 'False) => NotNull a Source #

nullify a means a cannot take null as a value.

Instances

Instances details
(Nullable a, IsMaybe a ~ 'False) => NotNull a Source # 
Instance details

Defined in Rel8.Schema.Null

class Nullable' (IsMaybe a) a => Nullable a Source #

Nullable a means that rel8 is able to check if the type a is a type that can take null values or not.

Instances

Instances details
Nullable' (IsMaybe a) a => Nullable a Source # 
Instance details

Defined in Rel8.Schema.Null

class IsMaybe a ~ IsMaybe b => Homonullable a b Source #

Homonullable a b means that both a and b can be null, or neither a or b can be null.

Instances

Instances details
IsMaybe a ~ IsMaybe b => Homonullable a b Source # 
Instance details

Defined in Rel8.Schema.Null

null :: DBType a => Expr (Maybe a) Source #

Corresponds to SQL null.

nullify :: NotNull a => Expr a -> Expr (Maybe a) Source #

Lift an expression that can't be null to a type that might be null. This is an identity operation in terms of any generated query, and just modifies the query's type.

nullable :: Table Expr b => b -> (Expr a -> b) -> Expr (Maybe a) -> b Source #

Like maybe, but to eliminate null.

isNull :: Expr (Maybe a) -> Expr Bool Source #

Like isNothing, but for null.

isNonNull :: Expr (Maybe a) -> Expr Bool Source #

Like isJust, but for null.

mapNull :: DBType b => (Expr a -> Expr b) -> Expr (Maybe a) -> Expr (Maybe b) Source #

Lift an operation on non-null values to an operation on possibly null values. When given null, mapNull f returns null.

This is like fmap for Maybe.

liftOpNull :: DBType c => (Expr a -> Expr b -> Expr c) -> Expr (Maybe a) -> Expr (Maybe b) -> Expr (Maybe c) Source #

Lift a binary operation on non-null expressions to an equivalent binary operator on possibly null expressions. If either of the final arguments are null, liftOpNull returns null.

This is like liftA2 for Maybe.

catNull :: Expr (Maybe a) -> Query (Expr a) Source #

Filter a Query that might return null to a Query without any nulls.

Corresponds to catMaybes.

coalesce :: Expr (Maybe Bool) -> Expr Bool Source #

Convert a Expr (Maybe Bool) to a Expr Bool by treating Nothing as False. This can be useful when combined with where_, which expects a Bool, and produces expressions that optimize better than general case analysis.

Boolean operations

class DBType a => DBEq a Source #

Database types that can be compared for equality in queries. If a type is an instance of DBEq, it means we can compare expressions for equality using the SQL = operator.

Instances

Instances details
DBEq Bool Source # 
Instance details

Defined in Rel8.Type.Eq

DBEq Char Source # 
Instance details

Defined in Rel8.Type.Eq

DBEq Double Source # 
Instance details

Defined in Rel8.Type.Eq

DBEq Float Source # 
Instance details

Defined in Rel8.Type.Eq

DBEq Int16 Source # 
Instance details

Defined in Rel8.Type.Eq

DBEq Int32 Source # 
Instance details

Defined in Rel8.Type.Eq

DBEq Int64 Source # 
Instance details

Defined in Rel8.Type.Eq

DBEq ByteString Source # 
Instance details

Defined in Rel8.Type.Eq

DBEq ByteString Source # 
Instance details

Defined in Rel8.Type.Eq

DBEq Scientific Source # 
Instance details

Defined in Rel8.Type.Eq

DBEq UTCTime Source # 
Instance details

Defined in Rel8.Type.Eq

DBEq Text Source # 
Instance details

Defined in Rel8.Type.Eq

DBEq Value Source # 
Instance details

Defined in Rel8.Type.Eq

DBEq Text Source # 
Instance details

Defined in Rel8.Type.Eq

DBEq UUID Source # 
Instance details

Defined in Rel8.Type.Eq

DBEq CalendarDiffTime Source # 
Instance details

Defined in Rel8.Type.Eq

DBEq Day Source # 
Instance details

Defined in Rel8.Type.Eq

DBEq TimeOfDay Source # 
Instance details

Defined in Rel8.Type.Eq

DBEq LocalTime Source # 
Instance details

Defined in Rel8.Type.Eq

Sql DBEq a => DBEq [a] Source # 
Instance details

Defined in Rel8.Type.Eq

Sql DBEq a => DBEq (NonEmpty a) Source # 
Instance details

Defined in Rel8.Type.Eq

DBEq (CI Text) Source # 
Instance details

Defined in Rel8.Type.Eq

DBEq (CI Text) Source # 
Instance details

Defined in Rel8.Type.Eq

DBEnum a => DBEq (Enum a) Source # 
Instance details

Defined in Rel8.Type.Enum

(DBComposite a, EqTable (HKD a Expr)) => DBEq (Composite a) Source # 
Instance details

Defined in Rel8.Type.Composite

true :: Expr Bool Source #

The SQL true literal.

false :: Expr Bool Source #

The SQL false literal.

not_ :: Expr Bool -> Expr Bool Source #

The SQL NOT operator.

(&&.) :: Expr Bool -> Expr Bool -> Expr Bool infixr 3 Source #

The SQL AND operator.

and_ :: Foldable f => f (Expr Bool) -> Expr Bool Source #

Fold AND over a collection of expressions.

(||.) :: Expr Bool -> Expr Bool -> Expr Bool infixr 2 Source #

The SQL OR operator.

or_ :: Foldable f => f (Expr Bool) -> Expr Bool Source #

Fold OR over a collection of expressions.

(==.) :: forall a. Sql DBEq a => Expr a -> Expr a -> Expr Bool infix 4 Source #

Compare two expressions for equality.

This corresponds to the SQL IS NOT DISTINCT FROM operator, and will equate null values as true. This differs from = which would return null. This operator matches Haskell's == operator. For an operator identical to SQL =, see ==?.

(/=.) :: forall a. Sql DBEq a => Expr a -> Expr a -> Expr Bool infix 4 Source #

Test if two expressions are different (not equal).

This corresponds to the SQL IS DISTINCT FROM operator, and will return false when comparing two null values. This differs from ordinary = which would return null. This operator is closer to Haskell's == operator. For an operator identical to SQL =, see /=?.

(==?) :: DBEq a => Expr (Maybe a) -> Expr (Maybe a) -> Expr Bool infix 4 Source #

Test if two expressions are equal. This operator is usually the best choice when forming join conditions, as PostgreSQL has a much harder time optimizing a join that has multiple True conditions.

This corresponds to the SQL = operator, though it will always return a Bool.

(/=?) :: DBEq a => Expr (Maybe a) -> Expr (Maybe a) -> Expr Bool infix 4 Source #

Test if two expressions are different.

This corresponds to the SQL <> operator, though it will always return a Bool.

in_ :: forall a f. (Sql DBEq a, Foldable f) => Expr a -> f (Expr a) -> Expr Bool Source #

Like the SQL IN operator, but implemented by folding over a list with ==. and ||..

boolExpr :: Expr a -> Expr a -> Expr Bool -> Expr a Source #

Eliminate a boolean-valued expression.

Corresponds to bool.

caseExpr :: [(Expr Bool, Expr a)] -> Expr a -> Expr a Source #

A multi-way ifthenelse statement. The first argument to caseExpr is a list of alternatives. The first alternative that is of the form (true, x) will be returned. If no such alternative is found, a fallback expression is returned.

Corresponds to a CASE expression in SQL.

like :: Expr Text -> Expr Text -> Expr Bool Source #

like x y corresponds to the expression y LIKE x.

Note that the arguments to like are swapped. This is to aid currying, so you can write expressions like filter (like "Rel%" . packageName) =<< each haskellPackages

ilike :: Expr Text -> Expr Text -> Expr Bool Source #

ilike x y corresponds to the expression y ILIKE x.

Note that the arguments to ilike are swapped. This is to aid currying, so you can write expressions like filter (ilike "Rel%" . packageName) =<< each haskellPackages

Ordering

class DBEq a => DBOrd a Source #

The class of database types that support the <, <=, > and >= operators.

Instances

Instances details
DBOrd Bool Source # 
Instance details

Defined in Rel8.Type.Ord

DBOrd Char Source # 
Instance details

Defined in Rel8.Type.Ord

DBOrd Double Source # 
Instance details

Defined in Rel8.Type.Ord

DBOrd Float Source # 
Instance details

Defined in Rel8.Type.Ord

DBOrd Int16 Source # 
Instance details

Defined in Rel8.Type.Ord

DBOrd Int32 Source # 
Instance details

Defined in Rel8.Type.Ord

DBOrd Int64 Source # 
Instance details

Defined in Rel8.Type.Ord

DBOrd ByteString Source # 
Instance details

Defined in Rel8.Type.Ord

DBOrd ByteString Source # 
Instance details

Defined in Rel8.Type.Ord

DBOrd Scientific Source # 
Instance details

Defined in Rel8.Type.Ord

DBOrd UTCTime Source # 
Instance details

Defined in Rel8.Type.Ord

DBOrd Text Source # 
Instance details

Defined in Rel8.Type.Ord

DBOrd Text Source # 
Instance details

Defined in Rel8.Type.Ord

DBOrd UUID Source # 
Instance details

Defined in Rel8.Type.Ord

DBOrd CalendarDiffTime Source # 
Instance details

Defined in Rel8.Type.Ord

DBOrd Day Source # 
Instance details

Defined in Rel8.Type.Ord

DBOrd TimeOfDay Source # 
Instance details

Defined in Rel8.Type.Ord

DBOrd LocalTime Source # 
Instance details

Defined in Rel8.Type.Ord

Sql DBOrd a => DBOrd [a] Source # 
Instance details

Defined in Rel8.Type.Ord

Sql DBOrd a => DBOrd (NonEmpty a) Source # 
Instance details

Defined in Rel8.Type.Ord

DBOrd (CI Text) Source # 
Instance details

Defined in Rel8.Type.Ord

DBOrd (CI Text) Source # 
Instance details

Defined in Rel8.Type.Ord

DBEnum a => DBOrd (Enum a) Source # 
Instance details

Defined in Rel8.Type.Enum

(DBComposite a, OrdTable (HKD a Expr)) => DBOrd (Composite a) Source # 
Instance details

Defined in Rel8.Type.Composite

(<.) :: forall a. Sql DBOrd a => Expr a -> Expr a -> Expr Bool infix 4 Source #

Corresponds to the SQL < operator. Note that this differs from SQL < as null will sort below any other value. For a version of < that exactly matches SQL, see (<?).

(<=.) :: forall a. Sql DBOrd a => Expr a -> Expr a -> Expr Bool infix 4 Source #

Corresponds to the SQL <= operator. Note that this differs from SQL <= as null will sort below any other value. For a version of <= that exactly matches SQL, see (<=?).

(>.) :: forall a. Sql DBOrd a => Expr a -> Expr a -> Expr Bool infix 4 Source #

Corresponds to the SQL > operator. Note that this differs from SQL > as null will sort below any other value. For a version of > that exactly matches SQL, see (>?).

(>=.) :: forall a. Sql DBOrd a => Expr a -> Expr a -> Expr Bool infix 4 Source #

Corresponds to the SQL >= operator. Note that this differs from SQL > as null will sort below any other value. For a version of >= that exactly matches SQL, see (>=?).

(<?) :: DBOrd a => Expr (Maybe a) -> Expr (Maybe a) -> Expr Bool infix 4 Source #

Corresponds to the SQL < operator. Returns null if either arguments are null.

(<=?) :: DBOrd a => Expr (Maybe a) -> Expr (Maybe a) -> Expr Bool infix 4 Source #

Corresponds to the SQL <= operator. Returns null if either arguments are null.

(>?) :: DBOrd a => Expr (Maybe a) -> Expr (Maybe a) -> Expr Bool infix 4 Source #

Corresponds to the SQL > operator. Returns null if either arguments are null.

(>=?) :: DBOrd a => Expr (Maybe a) -> Expr (Maybe a) -> Expr Bool infix 4 Source #

Corresponds to the SQL >= operator. Returns null if either arguments are null.

leastExpr :: forall a. Sql DBOrd a => Expr a -> Expr a -> Expr a Source #

Given two expressions, return the expression that sorts less than the other.

Corresponds to the SQL least() function.

greatestExpr :: forall a. Sql DBOrd a => Expr a -> Expr a -> Expr a Source #

Given two expressions, return the expression that sorts greater than the other.

Corresponds to the SQL greatest() function.

Functions

class Function arg res Source #

This type class exists to allow function to have arbitrary arity. It's mostly an implementation detail, and typical uses of Function shouldn't need this to be specified.

Minimal complete definition

applyArgument

Instances

Instances details
(arg ~ Expr a, Sql DBType b) => Function arg (Expr b) Source # 
Instance details

Defined in Rel8.Expr.Function

Methods

applyArgument :: ([PrimExpr] -> PrimExpr) -> arg -> Expr b

(arg ~ Expr a, Function args res) => Function arg (args -> res) Source # 
Instance details

Defined in Rel8.Expr.Function

Methods

applyArgument :: ([PrimExpr] -> PrimExpr) -> arg -> args -> res

function :: Function args result => String -> args -> result Source #

Construct an n-ary function that produces an Expr that when called runs a SQL function.

nullaryFunction :: Sql DBType a => String -> Expr a Source #

Construct a function call for functions with no arguments.

binaryOperator :: Sql DBType c => String -> Expr a -> Expr b -> Expr c Source #

Construct an expression by applying an infix binary operator to two operands.

Queries

data Query a Source #

The Query monad allows you to compose a SELECT query. This monad has semantics similar to the list ([]) monad.

Instances

Instances details
Monad Query Source # 
Instance details

Defined in Rel8.Query

Methods

(>>=) :: Query a -> (a -> Query b) -> Query b #

(>>) :: Query a -> Query b -> Query b #

return :: a -> Query a #

Functor Query Source # 
Instance details

Defined in Rel8.Query

Methods

fmap :: (a -> b) -> Query a -> Query b #

(<$) :: a -> Query b -> Query a #

Applicative Query Source # 
Instance details

Defined in Rel8.Query

Methods

pure :: a -> Query a #

(<*>) :: Query (a -> b) -> Query a -> Query b #

liftA2 :: (a -> b -> c) -> Query a -> Query b -> Query c #

(*>) :: Query a -> Query b -> Query b #

(<*) :: Query a -> Query b -> Query a #

Apply Query Source # 
Instance details

Defined in Rel8.Query

Methods

(<.>) :: Query (a -> b) -> Query a -> Query b #

(.>) :: Query a -> Query b -> Query b #

(<.) :: Query a -> Query b -> Query a #

liftF2 :: (a -> b -> c) -> Query a -> Query b -> Query c #

Bind Query Source # 
Instance details

Defined in Rel8.Query

Methods

(>>-) :: Query a -> (a -> Query b) -> Query b #

join :: Query (Query a) -> Query a #

Projectable Query Source # 
Instance details

Defined in Rel8.Query

Methods

project :: Projecting a b => Projection a b -> Query a -> Query b Source #

AlternativeTable Query Source #

emptyTable = values [].

Instance details

Defined in Rel8.Query

Methods

emptyTable :: Table Expr a => Query a Source #

AltTable Query Source #

<|>: = unionAll.

Instance details

Defined in Rel8.Query

Methods

(<|>:) :: Table Expr a => Query a -> Query a -> Query a Source #

showQuery :: Table Expr a => Query a -> String Source #

Convert a Query to a String containing a SELECT statement.

Projection

type Projection a b = Transpose (Field a) a -> Transpose (Field a) b Source #

A Projection a bs is a special type of function a -> b whereby the resulting b is guaranteed to be composed only from columns contained in a.

class Projectable f where Source #

Projectable f means that f is a kind of functor on Tables that allows the mapping of a Projection over its underlying columns.

Methods

project :: Projecting a b => Projection a b -> f a -> f b Source #

Map a Projection over f.

Instances

Instances details
Projectable Query Source # 
Instance details

Defined in Rel8.Query

Methods

project :: Projecting a b => Projection a b -> Query a -> Query b Source #

Projectable (NonEmptyTable context) Source # 
Instance details

Defined in Rel8.Table.NonEmpty

Methods

project :: Projecting a b => Projection a b -> NonEmptyTable context a -> NonEmptyTable context b Source #

Projectable (ListTable context) Source # 
Instance details

Defined in Rel8.Table.List

Methods

project :: Projecting a b => Projection a b -> ListTable context a -> ListTable context b Source #

Projectable (MaybeTable context) Source # 
Instance details

Defined in Rel8.Table.Maybe

Methods

project :: Projecting a b => Projection a b -> MaybeTable context a -> MaybeTable context b Source #

Projectable (Tabulation k) Source # 
Instance details

Defined in Rel8.Tabulate

Methods

project :: Projecting a b => Projection a b -> Tabulation k a -> Tabulation k b Source #

Projectable (TheseTable context a) Source # 
Instance details

Defined in Rel8.Table.These

Methods

project :: Projecting a0 b => Projection a0 b -> TheseTable context a a0 -> TheseTable context a b Source #

Projectable (EitherTable context a) Source # 
Instance details

Defined in Rel8.Table.Either

Methods

project :: Projecting a0 b => Projection a0 b -> EitherTable context a a0 -> EitherTable context a b Source #

class Biprojectable p where Source #

Biprojectable p means that p is a kind of bifunctor on Tables that allows the mapping of a pair of Projections over its underlying columns.

Methods

biproject :: (Projecting a b, Projecting c d) => Projection a b -> Projection c d -> p a c -> p b d Source #

Map a pair of Projections over p.

Instances

Instances details
Biprojectable Tabulation Source # 
Instance details

Defined in Rel8.Tabulate

Methods

biproject :: (Projecting a b, Projecting c d) => Projection a b -> Projection c d -> Tabulation a c -> Tabulation b d Source #

Biprojectable (TheseTable context) Source # 
Instance details

Defined in Rel8.Table.These

Methods

biproject :: (Projecting a b, Projecting c d) => Projection a b -> Projection c d -> TheseTable context a c -> TheseTable context b d Source #

Biprojectable (EitherTable context) Source # 
Instance details

Defined in Rel8.Table.Either

Methods

biproject :: (Projecting a b, Projecting c d) => Projection a b -> Projection c d -> EitherTable context a c -> EitherTable context b d Source #

class (Transposes (Context a) (Field a) a (Transpose (Field a) a), Transposes (Context a) (Field a) b (Transpose (Field a) b)) => Projecting a b Source #

The constraint Projecting a b ensures that Projection a b is a usable Projection.

Instances

Instances details
(Transposes (Context a) (Field a) a (Transpose (Field a) a), Transposes (Context a) (Field a) b (Transpose (Field a) b)) => Projecting a b Source # 
Instance details

Defined in Rel8.Table.Projection

data Field table a Source #

A special context used in the construction of Projections.

Instances

Instances details
Sql DBType a => Table (Field table) (Field table a) Source # 
Instance details

Defined in Rel8.Schema.Field

Associated Types

type Columns (Field table a) :: HTable Source #

type Context (Field table a) :: Context Source #

type FromExprs (Field table a) Source #

type Transpose context' (Field table a) Source #

Methods

toColumns :: Field table a -> Columns (Field table a) (Field table) Source #

fromColumns :: Columns (Field table a) (Field table) -> Field table a Source #

fromResult :: Columns (Field table a) Result -> FromExprs (Field table a) Source #

toResult :: FromExprs (Field table a) -> Columns (Field table a) Result Source #

type Transpose to (Field table a) Source # 
Instance details

Defined in Rel8.Schema.Field

type Transpose to (Field table a) = to a
type Columns (Field table a) Source # 
Instance details

Defined in Rel8.Schema.Field

type Columns (Field table a)
type Context (Field table a) Source # 
Instance details

Defined in Rel8.Schema.Field

type Context (Field table a) = Field table
type FromExprs (Field table a) Source # 
Instance details

Defined in Rel8.Schema.Field

type FromExprs (Field table a) = a

Selecting rows

class Transposes Name Expr names exprs => Selects names exprs Source #

Selects a b means that a is a schema (i.e., a Table of Names) for the Expr columns in b.

Instances

Instances details
Transposes Name Expr names exprs => Selects names exprs Source # 
Instance details

Defined in Rel8.Schema.Name

each :: Selects names exprs => TableSchema names -> Query exprs Source #

Select each row from a table definition. This is equivalent to FROM table.

values :: (Table Expr a, Foldable f) => f a -> Query a Source #

Construct a query that returns the given input list of rows. This is like folding a list of return statements under union, but uses the SQL VALUES expression for efficiency.

Filtering

filter :: (a -> Expr Bool) -> a -> Query a Source #

filter f x will be a zero-row query when f x is False, and will return x unchanged when f x is True. This is similar to guard, but as the predicate is separate from the argument, it is easy to use in a pipeline of Query transformations.

where_ :: Expr Bool -> Query () Source #

Drop any rows that don't match a predicate. where_ expr is equivalent to the SQL WHERE expr.

present :: Query a -> Query () Source #

Produce the empty query if the given query returns no rows. present is equivalent to WHERE EXISTS in SQL.

absent :: Query a -> Query () Source #

Produce the empty query if the given query returns rows. absent is equivalent to WHERE NOT EXISTS in SQL.

distinct :: EqTable a => Query a -> Query a Source #

Select all distinct rows from a query, removing duplicates. distinct q is equivalent to the SQL statement SELECT DISTINCT q.

distinctOn :: EqTable b => (a -> b) -> Query a -> Query a Source #

Select all distinct rows from a query, where rows are equivalent according to a projection. If multiple rows have the same projection, it is unspecified which row will be returned. If this matters, use distinctOnBy.

distinctOnBy :: EqTable b => (a -> b) -> Order a -> Query a -> Query a Source #

Select all distinct rows from a query, where rows are equivalent according to a projection. If there are multiple rows with the same projection, the first row according to the specified Order will be returned.

LIMIT/OFFSET

limit :: Word -> Query a -> Query a Source #

limit n select at most n rows from a query. limit n is equivalent to the SQL LIMIT n.

offset :: Word -> Query a -> Query a Source #

offset n drops the first n rows from a query. offset n is equivalent to the SQL OFFSET n.

UNION

union :: EqTable a => Query a -> Query a -> Query a Source #

Combine the results of two queries of the same type, collapsing duplicates. union a b is the same as the SQL statement a UNION b.

unionAll :: Table Expr a => Query a -> Query a -> Query a Source #

Combine the results of two queries of the same type, retaining duplicates. unionAll a b is the same as the SQL statement a UNION ALL b.

INTERSECT

intersect :: EqTable a => Query a -> Query a -> Query a Source #

Find the intersection of two queries, collapsing duplicates. intersect a b is the same as the SQL statement a INTERSECT b.

intersectAll :: EqTable a => Query a -> Query a -> Query a Source #

Find the intersection of two queries, retaining duplicates. intersectAll a b is the same as the SQL statement a INTERSECT ALL b.

EXCEPT

except :: EqTable a => Query a -> Query a -> Query a Source #

Find the difference of two queries, collapsing duplicates except a b is the same as the SQL statement a EXCEPT b.

exceptAll :: EqTable a => Query a -> Query a -> Query a Source #

Find the difference of two queries, retaining duplicates. exceptAll a b is the same as the SQL statement a EXCEPT ALL b.

EXISTS

exists :: Query a -> Query (Expr Bool) Source #

Checks if a query returns at least one row.

with :: (a -> Query b) -> a -> Query a Source #

with is similar to filter, but allows the predicate to be a full query.

with f a = a <$ present (f a), but this form matches filter.

withBy :: (a -> b -> Expr Bool) -> Query b -> a -> Query a Source #

Like with, but with a custom membership test.

without :: (a -> Query b) -> a -> Query a Source #

Filter rows where a -> Query b yields no rows.

withoutBy :: (a -> b -> Expr Bool) -> Query b -> a -> Query a Source #

Like without, but with a custom membership test.

Aggregation

data Aggregate a Source #

Aggregate is a special context used by aggregate.

Instances

Instances details
Sql DBType a => Table Aggregate (Aggregate a) Source # 
Instance details

Defined in Rel8.Aggregate

Associated Types

type Columns (Aggregate a) :: HTable Source #

type Context (Aggregate a) :: Context Source #

type FromExprs (Aggregate a) Source #

type Transpose context' (Aggregate a) Source #

type Transpose to (Aggregate a) Source # 
Instance details

Defined in Rel8.Aggregate

type Transpose to (Aggregate a) = to a
type Columns (Aggregate a) Source # 
Instance details

Defined in Rel8.Aggregate

type Context (Aggregate a) Source # 
Instance details

Defined in Rel8.Aggregate

type FromExprs (Aggregate a) Source # 
Instance details

Defined in Rel8.Aggregate

type FromExprs (Aggregate a) = a

class Transposes Aggregate Expr aggregates exprs => Aggregates aggregates exprs Source #

Aggregates a b means that the columns in a are all Aggregates for the Expr columns in b.

Instances

Instances details
Transposes Aggregate Expr aggregates exprs => Aggregates aggregates exprs Source # 
Instance details

Defined in Rel8.Aggregate

aggregate :: Aggregates aggregates exprs => Query aggregates -> Query exprs Source #

Apply an aggregation to all rows returned by a Query.

countRows :: Query a -> Query (Expr Int64) Source #

Count the number of rows returned by a query. Note that this is different from countStar, as even if the given query yields no rows, countRows will return 0.

groupBy :: forall exprs aggregates. (EqTable exprs, Aggregates aggregates exprs) => exprs -> aggregates Source #

Group equal tables together. This works by aggregating each column in the given table with groupByExpr.

listAgg :: Aggregates aggregates exprs => exprs -> ListTable Aggregate aggregates Source #

Aggregate rows into a single row containing an array of all aggregated rows. This can be used to associate multiple rows with a single row, without changing the over cardinality of the query. This allows you to essentially return a tree-like structure from queries.

For example, if we have a table of orders and each orders contains multiple items, we could aggregate the table of orders, pairing each order with its items:

ordersWithItems :: Query (Order Expr, ListTable Expr (Item Expr))
ordersWithItems = do
  order <- each orderSchema
  items aggregate $ listAgg <$ itemsFromOrder order
  return (order, items)

listAggExpr :: Sql DBType a => Expr a -> Aggregate [a] Source #

Collect expressions values as a list.

mode :: forall a. EqTable a => Query a -> Query a Source #

Return the most common row in a query.

nonEmptyAgg :: Aggregates aggregates exprs => exprs -> NonEmptyTable Aggregate aggregates Source #

Like listAgg, but the result is guaranteed to be a non-empty list.

nonEmptyAggExpr :: Sql DBType a => Expr a -> Aggregate (NonEmpty a) Source #

Collect expressions values as a non-empty list.

class DBOrd a => DBMax a Source #

The class of database types that support the max aggregation function.

Instances

Instances details
DBMax Char Source # 
Instance details

Defined in Rel8.Type.Ord

DBMax Double Source # 
Instance details

Defined in Rel8.Type.Ord

DBMax Float Source # 
Instance details

Defined in Rel8.Type.Ord

DBMax Int16 Source # 
Instance details

Defined in Rel8.Type.Ord

DBMax Int32 Source # 
Instance details

Defined in Rel8.Type.Ord

DBMax Int64 Source # 
Instance details

Defined in Rel8.Type.Ord

DBMax ByteString Source # 
Instance details

Defined in Rel8.Type.Ord

DBMax ByteString Source # 
Instance details

Defined in Rel8.Type.Ord

DBMax Scientific Source # 
Instance details

Defined in Rel8.Type.Ord

DBMax UTCTime Source # 
Instance details

Defined in Rel8.Type.Ord

DBMax Text Source # 
Instance details

Defined in Rel8.Type.Ord

DBMax Text Source # 
Instance details

Defined in Rel8.Type.Ord

DBMax CalendarDiffTime Source # 
Instance details

Defined in Rel8.Type.Ord

DBMax Day Source # 
Instance details

Defined in Rel8.Type.Ord

DBMax TimeOfDay Source # 
Instance details

Defined in Rel8.Type.Ord

DBMax LocalTime Source # 
Instance details

Defined in Rel8.Type.Ord

Sql DBMax a => DBMax [a] Source # 
Instance details

Defined in Rel8.Type.Ord

Sql DBMax a => DBMax (NonEmpty a) Source # 
Instance details

Defined in Rel8.Type.Ord

DBMax (CI Text) Source # 
Instance details

Defined in Rel8.Type.Ord

DBMax (CI Text) Source # 
Instance details

Defined in Rel8.Type.Ord

DBEnum a => DBMax (Enum a) Source # 
Instance details

Defined in Rel8.Type.Enum

(DBComposite a, OrdTable (HKD a Expr)) => DBMax (Composite a) Source # 
Instance details

Defined in Rel8.Type.Composite

max :: Sql DBMax a => Expr a -> Aggregate a Source #

Produce an aggregation for Expr a using the max function.

class DBOrd a => DBMin a Source #

The class of database types that support the min aggregation function.

Instances

Instances details
DBMin Char Source # 
Instance details

Defined in Rel8.Type.Ord

DBMin Double Source # 
Instance details

Defined in Rel8.Type.Ord

DBMin Float Source # 
Instance details

Defined in Rel8.Type.Ord

DBMin Int16 Source # 
Instance details

Defined in Rel8.Type.Ord

DBMin Int32 Source # 
Instance details

Defined in Rel8.Type.Ord

DBMin Int64 Source # 
Instance details

Defined in Rel8.Type.Ord

DBMin ByteString Source # 
Instance details

Defined in Rel8.Type.Ord

DBMin ByteString Source # 
Instance details

Defined in Rel8.Type.Ord

DBMin Scientific Source # 
Instance details

Defined in Rel8.Type.Ord

DBMin UTCTime Source # 
Instance details

Defined in Rel8.Type.Ord

DBMin Text Source # 
Instance details

Defined in Rel8.Type.Ord

DBMin Text Source # 
Instance details

Defined in Rel8.Type.Ord

DBMin CalendarDiffTime Source # 
Instance details

Defined in Rel8.Type.Ord

DBMin Day Source # 
Instance details

Defined in Rel8.Type.Ord

DBMin TimeOfDay Source # 
Instance details

Defined in Rel8.Type.Ord

DBMin LocalTime Source # 
Instance details

Defined in Rel8.Type.Ord

Sql DBMin a => DBMin [a] Source # 
Instance details

Defined in Rel8.Type.Ord

Sql DBMin a => DBMin (NonEmpty a) Source # 
Instance details

Defined in Rel8.Type.Ord

DBMin (CI Text) Source # 
Instance details

Defined in Rel8.Type.Ord

DBMin (CI Text) Source # 
Instance details

Defined in Rel8.Type.Ord

DBEnum a => DBMin (Enum a) Source # 
Instance details

Defined in Rel8.Type.Enum

(DBComposite a, OrdTable (HKD a Expr)) => DBMin (Composite a) Source # 
Instance details

Defined in Rel8.Type.Composite

min :: Sql DBMin a => Expr a -> Aggregate a Source #

Produce an aggregation for Expr a using the max function.

class DBType a => DBSum a Source #

The class of database types that support the sum() aggregation function.

Instances

Instances details
DBSum Double Source # 
Instance details

Defined in Rel8.Type.Sum

DBSum Float Source # 
Instance details

Defined in Rel8.Type.Sum

DBSum Int16 Source # 
Instance details

Defined in Rel8.Type.Sum

DBSum Int32 Source # 
Instance details

Defined in Rel8.Type.Sum

DBSum Int64 Source # 
Instance details

Defined in Rel8.Type.Sum

DBSum Scientific Source # 
Instance details

Defined in Rel8.Type.Sum

DBSum CalendarDiffTime Source # 
Instance details

Defined in Rel8.Type.Sum

sum :: Sql DBSum a => Expr a -> Aggregate a Source #

Corresponds to sum. Note that in SQL, sum is type changing - for example the sum of integer returns a bigint. Rel8 doesn't support this, and will add explicit casts back to the original input type. This can lead to overflows, and if you anticipate very large sums, you should upcast your input.

sumWhere :: (Sql DBNum a, Sql DBSum a) => Expr Bool -> Expr a -> Aggregate a Source #

Take the sum of all expressions that satisfy a predicate.

avg :: Sql DBSum a => Expr a -> Aggregate a Source #

Corresponds to avg. Note that in SQL, avg is type changing - for example, the avg of integer returns a numeric. Rel8 doesn't support this, and will add explicit casts back to the original input type. If you need a fractional result on an integral column, you should cast your input to Double or Scientific before calling avg.

class DBType a => DBString a Source #

The class of data types that support the string_agg() aggregation function.

Instances

Instances details
DBString ByteString Source # 
Instance details

Defined in Rel8.Type.String

DBString ByteString Source # 
Instance details

Defined in Rel8.Type.String

DBString Text Source # 
Instance details

Defined in Rel8.Type.String

DBString Text Source # 
Instance details

Defined in Rel8.Type.String

DBString (CI Text) Source # 
Instance details

Defined in Rel8.Type.String

DBString (CI Text) Source # 
Instance details

Defined in Rel8.Type.String

stringAgg :: Sql DBString a => Expr db -> Expr a -> Aggregate a Source #

Corresponds to string_agg().

count :: Expr a -> Aggregate Int64 Source #

Count the occurances of a single column. Corresponds to COUNT(a)

countStar :: Aggregate Int64 Source #

Corresponds to COUNT(*).

countDistinct :: Sql DBEq a => Expr a -> Aggregate Int64 Source #

Count the number of distinct occurances of a single column. Corresponds to COUNT(DISTINCT a)

countWhere :: Expr Bool -> Aggregate Int64 Source #

A count of the number of times a given expression is true.

and :: Expr Bool -> Aggregate Bool Source #

Corresponds to bool_and.

or :: Expr Bool -> Aggregate Bool Source #

Corresponds to bool_or.

Ordering

orderBy :: Order a -> Query a -> Query a Source #

Order the rows returned by a query.

data Order a Source #

An ordering expression for a. Primitive orderings are defined with asc and desc, and you can combine Order via its various instances.

A common pattern is to use <> to combine multiple orderings in sequence, and >$< to select individual columns.

Instances

Instances details
Contravariant Order Source # 
Instance details

Defined in Rel8.Order

Methods

contramap :: (a -> b) -> Order b -> Order a #

(>$) :: b -> Order b -> Order a #

Divisible Order Source # 
Instance details

Defined in Rel8.Order

Methods

divide :: (a -> (b, c)) -> Order b -> Order c -> Order a #

conquer :: Order a #

Decidable Order Source # 
Instance details

Defined in Rel8.Order

Methods

lose :: (a -> Void) -> Order a #

choose :: (a -> Either b c) -> Order b -> Order c -> Order a #

Semigroup (Order a) Source # 
Instance details

Defined in Rel8.Order

Methods

(<>) :: Order a -> Order a -> Order a #

sconcat :: NonEmpty (Order a) -> Order a #

stimes :: Integral b => b -> Order a -> Order a #

Monoid (Order a) Source # 
Instance details

Defined in Rel8.Order

Methods

mempty :: Order a #

mappend :: Order a -> Order a -> Order a #

mconcat :: [Order a] -> Order a #

asc :: DBOrd a => Order (Expr a) Source #

Sort a column in ascending order.

desc :: DBOrd a => Order (Expr a) Source #

Sort a column in descending order.

nullsFirst :: Order (Expr a) -> Order (Expr (Maybe a)) Source #

Transform an ordering so that null values appear first. This corresponds to NULLS FIRST in SQL.

nullsLast :: Order (Expr a) -> Order (Expr (Maybe a)) Source #

Transform an ordering so that null values appear first. This corresponds to NULLS LAST in SQL.

Window functions

indexed :: Query a -> Query (Expr Int64, a) Source #

Pair each row of a query with its index within the query.

Bindings

rebind :: Table Expr a => String -> a -> Query a Source #

rebind takes a variable name, some expressions, and binds each of them to a new variable in the SQL. The a returned consists only of these variables. It's essentially a let binding for Postgres expressions.

IO

class (ToExprs exprs a, a ~ FromExprs exprs) => Serializable exprs a | exprs -> a Source #

Serializable witnesses the one-to-one correspondence between the type sql, which contains SQL expressions, and the type haskell, which contains the Haskell decoding of rows containing sql SQL expressions.

Instances

Instances details
(ToExprs exprs a, a ~ FromExprs exprs) => Serializable exprs a Source # 
Instance details

Defined in Rel8.Table.Serialize

Sql DBType a => Serializable (Expr a) a Source # 
Instance details

Defined in Rel8.Table.Serialize

class Table Expr exprs => ToExprs exprs a Source #

ToExprs exprs a is evidence that the types exprs and a describe essentially the same type, but exprs is in the Expr context, and a is a normal Haskell type.

Instances

Instances details
(Sql DBType a, x ~ Expr a) => ToExprs x a Source # 
Instance details

Defined in Rel8.Table.Serialize

(Rel8able t', t' ~ Choose (Algebra t) t, x ~ t' Expr, result ~ Result) => ToExprs x (t result) Source # 
Instance details

Defined in Rel8.Table.Rel8able

(ToExprs exprs1 a, ToExprs exprs2 b, x ~ (exprs1, exprs2)) => ToExprs x (a, b) Source # 
Instance details

Defined in Rel8.Table.Serialize

(ToExprs exprs1 a, ToExprs exprs2 b, x ~ TheseTable Expr exprs1 exprs2) => ToExprs x (These a b) Source # 
Instance details

Defined in Rel8.Table.These

(ToExprs exprs1 a, ToExprs exprs2 b, x ~ EitherTable Expr exprs1 exprs2) => ToExprs x (Either a b) Source # 
Instance details

Defined in Rel8.Table.Either

(ToExprs exprs1 a, ToExprs exprs2 b, ToExprs exprs3 c, x ~ (exprs1, exprs2, exprs3)) => ToExprs x (a, b, c) Source # 
Instance details

Defined in Rel8.Table.Serialize

(ToExprs exprs1 a, ToExprs exprs2 b, ToExprs exprs3 c, ToExprs exprs4 d, x ~ (exprs1, exprs2, exprs3, exprs4)) => ToExprs x (a, b, c, d) Source # 
Instance details

Defined in Rel8.Table.Serialize

(ToExprs exprs1 a, ToExprs exprs2 b, ToExprs exprs3 c, ToExprs exprs4 d, ToExprs exprs5 e, x ~ (exprs1, exprs2, exprs3, exprs4, exprs5)) => ToExprs x (a, b, c, d, e) Source # 
Instance details

Defined in Rel8.Table.Serialize

(ToExprs exprs1 a, ToExprs exprs2 b, ToExprs exprs3 c, ToExprs exprs4 d, ToExprs exprs5 e, ToExprs exprs6 f, x ~ (exprs1, exprs2, exprs3, exprs4, exprs5, exprs6)) => ToExprs x (a, b, c, d, e, f) Source # 
Instance details

Defined in Rel8.Table.Serialize

(ToExprs exprs1 a, ToExprs exprs2 b, ToExprs exprs3 c, ToExprs exprs4 d, ToExprs exprs5 e, ToExprs exprs6 f, ToExprs exprs7 g, x ~ (exprs1, exprs2, exprs3, exprs4, exprs5, exprs6, exprs7)) => ToExprs x (a, b, c, d, e, f, g) Source # 
Instance details

Defined in Rel8.Table.Serialize

(Sql DBType a, NotNull a, x ~ NonEmpty a) => ToExprs (Expr x) (NonEmpty a) Source # 
Instance details

Defined in Rel8.Table.Serialize

(Sql DBType a, NotNull a, x ~ Maybe a) => ToExprs (Expr x) (Maybe a) Source # 
Instance details

Defined in Rel8.Table.Serialize

(Sql DBType a, x ~ [a]) => ToExprs (Expr x) [a] Source # 
Instance details

Defined in Rel8.Table.Serialize

(ToExprs exprs a, context ~ Expr) => ToExprs (NonEmptyTable context exprs) (NonEmpty a) Source # 
Instance details

Defined in Rel8.Table.NonEmpty

(ToExprs exprs a, context ~ Expr) => ToExprs (ListTable context exprs) [a] Source # 
Instance details

Defined in Rel8.Table.List

(ToExprs exprs a, context ~ Expr) => ToExprs (MaybeTable context exprs) (Maybe a) Source # 
Instance details

Defined in Rel8.Table.Maybe

type Result = Identity Source #

The Result context is the context used for decoded query results.

When a query is executed against a PostgreSQL database, Rel8 parses the returned rows, decoding each row into the Result context.

Running statements

To run queries and otherwise interact with a PostgreSQL database, Rel8 provides select, insert, update and delete functions. Note that insert, update and delete will generally need the DuplicateRecordFields language extension enabled.

SELECT

select :: forall exprs a. Serializable exprs a => Query exprs -> Statement () [a] Source #

Run a SELECT statement, returning all rows.

INSERT

data Insert a where Source #

The constituent parts of a SQL INSERT statement.

Constructors

Insert 

Fields

  • :: Selects names exprs
     
  • => { into :: TableSchema names

    Which table to insert into.

  •    , rows :: Query exprs

    The rows to insert. This can be an arbitrary query — use values insert a static list of rows.

  •    , onConflict :: OnConflict names

    What to do if the inserted rows conflict with data already in the table.

  •    , returning :: Returning names a

    What information to return on completion.

  •    } -> Insert a
     

data OnConflict names Source #

OnConflict represents the ON CONFLICT clause of an INSERT statement. This specifies what ought to happen when one or more of the rows proposed for insertion conflict with an existing row in the table.

Constructors

Abort

Abort the transaction if there are conflicting rows (Postgres' default)

DoNothing
ON CONFLICT DO NOTHING
DoUpdate (Upsert names)
ON CONFLICT DO UPDATE

data Upsert names where Source #

The ON CONFLICT (...) DO UPDATE clause of an INSERT statement, also known as "upsert".

When an existing row conflicts with a row proposed for insertion, ON CONFLICT DO UPDATE allows you to instead update this existing row. The conflicting row proposed for insertion is then "excluded", but its values can still be referenced from the SET and WHERE clauses of the UPDATE statement.

Upsert in Postgres requires an explicit set of "conflict targets" — the set of columns comprising the UNIQUE index from conflicts with which we would like to recover.

Constructors

Upsert 

Fields

  • :: (Selects names exprs, Projecting names index, excluded ~ exprs)
     
  • => { index :: Projection names index

    The set of conflict targets, projected from the set of columns for the whole table

  •    , set :: excluded -> exprs -> exprs

    How to update each selected row.

  •    , updateWhere :: excluded -> exprs -> Expr Bool

    Which rows to select for update.

  •    } -> Upsert names
     

insert :: Insert a -> Statement () a Source #

Run an Insert statement.

unsafeDefault :: Expr a Source #

Corresponds to the SQL DEFAULT expression.

This Expr is unsafe for numerous reasons, and should be used with care:

  1. This Expr only makes sense in an INSERT or UPDATE statement.
  2. Rel8 is not able to verify that a particular column actually has a DEFAULT value. Trying to use unsafeDefault where there is no default will cause a runtime crash
  3. DEFAULT values can not be transformed. For example, the innocuous Rel8 code unsafeDefault + 1 will crash, despite type checking.

Given all these caveats, we suggest avoiding the use of default values where possible, instead being explicit. A common scenario where default values are used is with auto-incrementing identifier columns. In this case, we suggest using nextval instead.

showInsert :: Insert a -> String Source #

Convert an Insert to a String containing an INSERT statement.

DELETE

data Delete a where Source #

The constituent parts of a DELETE statement.

Constructors

Delete 

Fields

  • :: Selects names exprs
     
  • => { from :: TableSchema names

    Which table to delete from.

  •    , using :: Query using

    USING clause — this can be used to join against other tables, and its results can be referenced in the WHERE clause

  •    , deleteWhere :: using -> exprs -> Expr Bool

    Which rows should be selected for deletion.

  •    , returning :: Returning names a

    What to return from the DELETE statement.

  •    } -> Delete a
     

delete :: Delete a -> Statement () a Source #

Run a Delete statement.

showDelete :: Delete a -> String Source #

Convert a Delete to a String containing a DELETE statement.

UPDATE

data Update a where Source #

The constituent parts of an UPDATE statement.

Constructors

Update 

Fields

  • :: Selects names exprs
     
  • => { target :: TableSchema names

    Which table to update.

  •    , from :: Query from

    FROM clause — this can be used to join against other tables, and its results can be referenced in the SET and WHERE clauses.

  •    , set :: from -> exprs -> exprs

    How to update each selected row.

  •    , updateWhere :: from -> exprs -> Expr Bool

    Which rows to select for update.

  •    , returning :: Returning names a

    What to return from the UPDATE statement.

  •    } -> Update a
     

update :: Update a -> Statement () a Source #

Run an UPDATE statement.

showUpdate :: Update a -> String Source #

Convert an Update to a String containing an UPDATE statement.

.. RETURNING

data Returning names a where Source #

Insert, Update and Delete all support returning either the number of rows affected, or the actual rows modified.

Constructors

NumberOfRowsAffected :: Returning names Int64

Return the number of rows affected.

Projection :: (Selects names exprs, Serializable returning a) => (exprs -> returning) -> Returning names [a]

Projection allows you to project out of the affected rows, which can be useful if you want to log exactly which rows were deleted, or to view a generated id (for example, if using a column with an autoincrementing counter via nextval).

Instances

Instances details
Functor (Returning names) Source # 
Instance details

Defined in Rel8.Statement.Returning

Methods

fmap :: (a -> b) -> Returning names a -> Returning names b #

(<$) :: a -> Returning names b -> Returning names a #

Applicative (Returning names) Source # 
Instance details

Defined in Rel8.Statement.Returning

Methods

pure :: a -> Returning names a #

(<*>) :: Returning names (a -> b) -> Returning names a -> Returning names b #

liftA2 :: (a -> b -> c) -> Returning names a -> Returning names b -> Returning names c #

(*>) :: Returning names a -> Returning names b -> Returning names b #

(<*) :: Returning names a -> Returning names b -> Returning names a #

Apply (Returning names) Source # 
Instance details

Defined in Rel8.Statement.Returning

Methods

(<.>) :: Returning names (a -> b) -> Returning names a -> Returning names b #

(.>) :: Returning names a -> Returning names b -> Returning names b #

(<.) :: Returning names a -> Returning names b -> Returning names a #

liftF2 :: (a -> b -> c) -> Returning names a -> Returning names b -> Returning names c #

CREATE VIEW

createView :: Selects names exprs => TableSchema names -> Query exprs -> Statement () () Source #

Given a TableSchema and Query, createView runs a CREATE VIEW statement that will save the given query as a view. This can be useful if you want to share Rel8 queries with other applications.

Sequences

evaluate :: Table Expr a => a -> Query a Source #

evaluate takes expressions that could potentially have side effects and "runs" them in the Query monad. The returned expressions have no side effects and can safely be reused.