opaleye-0.9.5.0: An SQL-generating DSL targeting PostgreSQL
Safe HaskellSafe-Inferred
LanguageHaskell2010

Opaleye.MaybeFields

Description

MaybeFields is Opaleye's analogue to Maybe. You probably won't want to create values of type MaybeFields directly; instead they will appear as the result of left/right/outer join-like operations, such as optionalRestrict and optional.

Synopsis

MaybeFields type

data MaybeFields fields Source #

The Opaleye analogue of Maybe. A value of type MaybeFields a either contains a value of type a, or it contains nothing.

Instances

Instances details
Applicative MaybeFields Source # 
Instance details

Defined in Opaleye.Internal.MaybeFields

Methods

pure :: a -> MaybeFields a #

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

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

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

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

Functor MaybeFields Source # 
Instance details

Defined in Opaleye.Internal.MaybeFields

Methods

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

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

Monad MaybeFields Source # 
Instance details

Defined in Opaleye.Internal.MaybeFields

Methods

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

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

return :: a -> MaybeFields a #

Default (WithNulls Binaryspec) a b => Default Binaryspec (MaybeFields a) (MaybeFields b) Source # 
Instance details

Defined in Opaleye.Internal.MaybeFields

(Default ToFields a b, Default Nullspec a b) => Default ToFields (Maybe a) (MaybeFields b) Source # 
Instance details

Defined in Opaleye.Internal.MaybeFields

Methods

def :: ToFields (Maybe a) (MaybeFields b) #

Default (WithNulls Distinctspec) a b => Default Distinctspec (MaybeFields a) (MaybeFields b) Source # 
Instance details

Defined in Opaleye.Internal.Distinct

Default EqPP a b => Default EqPP (MaybeFields a) (MaybeFields b) Source # 
Instance details

Defined in Opaleye.Internal.MaybeFields

Methods

def :: EqPP (MaybeFields a) (MaybeFields b) #

Default IfPP a b => Default IfPP (MaybeFields a) (MaybeFields b) Source # 
Instance details

Defined in Opaleye.Internal.MaybeFields

Methods

def :: IfPP (MaybeFields a) (MaybeFields b) #

Default FromFields fields haskells => Default FromFields (MaybeFields fields) (Maybe haskells) Source # 
Instance details

Defined in Opaleye.Internal.MaybeFields

Methods

def :: FromFields (MaybeFields fields) (Maybe haskells) #

Default Unpackspec a b => Default Unpackspec (MaybeFields a) (MaybeFields b) Source # 
Instance details

Defined in Opaleye.Internal.MaybeFields

Default Valuesspec a b => Default Valuesspec (MaybeFields a) (MaybeFields b) Source # 
Instance details

Defined in Opaleye.Internal.MaybeFields

(Default (Inferrable FromFields) fields haskells, Maybe haskells ~ maybe_haskells) => Default (Inferrable FromFields) (MaybeFields fields) maybe_haskells Source # 
Instance details

Defined in Opaleye.Internal.MaybeFields

Methods

def :: Inferrable FromFields (MaybeFields fields) maybe_haskells #

Creating a MaybeFields

nothingFields :: Default Nullspec a a => MaybeFields a Source #

The Opaleye analogue of Nothing.

nothingFieldsOfTypeOf :: a -> MaybeFields a Source #

The Opaleye analogue of const Nothing. Can be useful to avoid type inference problems, because it doesn't pick up a type class constraint.

justFields :: a -> MaybeFields a Source #

The Opaleye analogue of Just. Equivalent to pure.

Using a MaybeFields

matchMaybe :: Default IfPP b b => MaybeFields a -> (Maybe a -> b) -> b Source #

Use a Haskell \case expression to pattern match on a MaybeFields.

example :: MaybeFields (Field SqlInt4) -> Field SqlInt4
example mf = matchMaybe mf $ \case
  Nothing -> 0
  Just x  -> x * 100

fromMaybeFields :: Default IfPP b b => b -> MaybeFields b -> b Source #

The Opaleye analogue of fromMaybe

maybeFields :: Default IfPP b b => b -> (a -> b) -> MaybeFields a -> b Source #

The Opaleye analogue of maybe

Creating a Select which returns MaybeFields

optional Source #

Arguments

:: Default Unpackspec a a 
=> SelectArr i a

Input query

-> SelectArr i (MaybeFields a)

The rows of the input query wrapped in "Just", unless the input query has no rows in which case a single row of "Nothing"

Convenient access to lateral left/right join functionality. Performs a LATERAL LEFT JOIN under the hood and has behaviour equivalent to the following Haskell function:

optional :: [a] -> [Maybe a]
optional q = case q of
    [] -> [Nothing]
    xs -> map Just xs

That is, if q :: SelectArr i a returns no rows, optional q :: SelectArr i (MaybeFields a) returns exactly one "Nothing" row. Otherwise, optional q returns exactly the rows of q wrapped in "Just". For example,

> let l1 = ["one", "two", "three"] :: [Field SqlText]
> runSelectI conn (optional (values l1))
[Just "one", Just "two", Just "three"]

> let l2 = [] :: [Field SqlText]
> runSelectI conn (optional (values l2))
[Nothing]

optionalRestrict is a special case of optional and could be written in terms of optional as follows (except that optionalRestrict doesn't use LATERAL under the hood and optional does).

optionalRestrict q = optional $ proc cond -> do
  a <- q -< ()
  restrict -< cond a
  returnA -< a

traverseMaybeFields :: (Default Unpackspec a a, Default Unpackspec b b) => SelectArr a b -> SelectArr (MaybeFields a) (MaybeFields b) Source #

traverseMaybeFields is analogous to Haskell's traverse :: (a -> [b]) -> Maybe a -> [Maybe b]. In particular, traverse has the following definition that generalises to traverseMaybeFields:

  • traverse _ Nothing = pure Nothing
  • traverse f (Just x) = fmap Just (f x)

Using a Select which returns MaybeFields

catMaybeFields :: SelectArr i (MaybeFields a) -> SelectArr i a Source #

The Opaleye analogue of catMaybes. Most commonly you will want to use this at type

catMaybeFields :: Select (MaybeFields a) -> Select a

maybeFieldsToSelect :: SelectArr (MaybeFields a) a Source #

The Opaleye analogue of maybeToList. Unless you are using arrow notation you'll probably find catMaybeFields easier to use.

Adaptors

data Nullspec fields fields' Source #

Instances

Instances details
ProductProfunctor Nullspec Source # 
Instance details

Defined in Opaleye.Internal.Values

Methods

purePP :: b -> Nullspec a b #

(****) :: Nullspec a (b -> c) -> Nullspec a b -> Nullspec a c #

empty :: Nullspec () () #

(***!) :: Nullspec a b -> Nullspec a' b' -> Nullspec (a, a') (b, b') #

Profunctor Nullspec Source # 
Instance details

Defined in Opaleye.Internal.Values

Methods

dimap :: (a -> b) -> (c -> d) -> Nullspec b c -> Nullspec a d #

lmap :: (a -> b) -> Nullspec b c -> Nullspec a c #

rmap :: (b -> c) -> Nullspec a b -> Nullspec a c #

(#.) :: forall a b c q. Coercible c b => q b c -> Nullspec a b -> Nullspec a c #

(.#) :: forall a b c q. Coercible b a => Nullspec b c -> q a b -> Nullspec a c #

IsSqlType b => Default Nullspec a (Field_ n b) Source # 
Instance details

Defined in Opaleye.Internal.Values

Methods

def :: Nullspec a (Field_ n b) #

Applicative (Nullspec a) Source # 
Instance details

Defined in Opaleye.Internal.Values

Methods

pure :: a0 -> Nullspec a a0 #

(<*>) :: Nullspec a (a0 -> b) -> Nullspec a a0 -> Nullspec a b #

liftA2 :: (a0 -> b -> c) -> Nullspec a a0 -> Nullspec a b -> Nullspec a c #

(*>) :: Nullspec a a0 -> Nullspec a b -> Nullspec a b #

(<*) :: Nullspec a a0 -> Nullspec a b -> Nullspec a a0 #

Functor (Nullspec a) Source # 
Instance details

Defined in Opaleye.Internal.Values

Methods

fmap :: (a0 -> b) -> Nullspec a a0 -> Nullspec a b #

(<$) :: a0 -> Nullspec a b -> Nullspec a a0 #

nullspecField :: forall a n sqlType. IsSqlType sqlType => Nullspec a (Field_ n sqlType) Source #

fromFieldsMaybeFields :: FromFields fields haskells -> FromFields (MaybeFields fields) (Maybe haskells) Source #

Explicit versions

maybeFieldsExplicit :: IfPP b b' -> b -> (a -> b) -> MaybeFields a -> b' Source #