Merge branch 'master' into format-config
This commit is contained in:
commit
51c546aed3
@ -1,3 +1,9 @@
|
|||||||
|
3.4.0.1
|
||||||
|
=======
|
||||||
|
- @arthurxavierx
|
||||||
|
- [#221](https://github.com/bitemyapp/esqueleto/pull/221)
|
||||||
|
- Deprecate `ToAliasT` and `ToAliasReferenceT`
|
||||||
|
|
||||||
3.4.0.0
|
3.4.0.0
|
||||||
=======
|
=======
|
||||||
- @belevy, @charukiewicz
|
- @belevy, @charukiewicz
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
cabal-version: 1.12
|
cabal-version: 1.12
|
||||||
|
|
||||||
name: esqueleto
|
name: esqueleto
|
||||||
version: 3.4.0.0
|
version: 3.4.0.1
|
||||||
synopsis: Type-safe EDSL for SQL queries on persistent backends.
|
synopsis: Type-safe EDSL for SQL queries on persistent backends.
|
||||||
description: @esqueleto@ is a bare bones, type-safe EDSL for SQL queries that works with unmodified @persistent@ SQL backends. Its language closely resembles SQL, so you don't have to learn new concepts, just new syntax, and it's fairly easy to predict the generated SQL and optimize it for your backend. Most kinds of errors committed when writing SQL are caught as compile-time errors---although it is possible to write type-checked @esqueleto@ queries that fail at runtime.
|
description: @esqueleto@ is a bare bones, type-safe EDSL for SQL queries that works with unmodified @persistent@ SQL backends. Its language closely resembles SQL, so you don't have to learn new concepts, just new syntax, and it's fairly easy to predict the generated SQL and optimize it for your backend. Most kinds of errors committed when writing SQL are caught as compile-time errors---although it is possible to write type-checked @esqueleto@ queries that fail at runtime.
|
||||||
.
|
.
|
||||||
|
|||||||
@ -56,9 +56,7 @@ module Database.Esqueleto.Experimental
|
|||||||
, ToMaybe(..)
|
, ToMaybe(..)
|
||||||
, ToMaybeT
|
, ToMaybeT
|
||||||
, ToAlias(..)
|
, ToAlias(..)
|
||||||
, ToAliasT
|
|
||||||
, ToAliasReference(..)
|
, ToAliasReference(..)
|
||||||
, ToAliasReferenceT
|
|
||||||
-- * The Normal Stuff
|
-- * The Normal Stuff
|
||||||
|
|
||||||
, where_
|
, where_
|
||||||
@ -649,89 +647,75 @@ pattern SelectQuery q = SelectQueryP Never q
|
|||||||
-- select $ from $ Table \@People
|
-- select $ from $ Table \@People
|
||||||
-- @
|
-- @
|
||||||
data From a where
|
data From a where
|
||||||
Table
|
Table
|
||||||
:: PersistEntity ent
|
:: PersistEntity ent
|
||||||
=> From (SqlExpr (Entity ent))
|
=> From (SqlExpr (Entity ent))
|
||||||
SubQuery
|
SubQuery
|
||||||
:: ( SqlSelect a' r
|
:: ( SqlSelect a r
|
||||||
, SqlSelect a'' r'
|
, ToAlias a
|
||||||
, ToAlias a
|
, ToAliasReference a
|
||||||
, a' ~ ToAliasT a
|
)
|
||||||
, ToAliasReference a'
|
=> SqlQuery a
|
||||||
, ToAliasReferenceT a' ~ a''
|
-> From a
|
||||||
)
|
FromCte
|
||||||
=> SqlQuery a
|
:: Ident
|
||||||
-> From a''
|
-> a
|
||||||
FromCte
|
-> From a
|
||||||
:: Ident
|
SqlSetOperation
|
||||||
-> a
|
:: ( SqlSelect a r
|
||||||
-> From a
|
, ToAlias a
|
||||||
SqlSetOperation
|
, ToAliasReference a
|
||||||
:: ( SqlSelect a' r
|
)
|
||||||
, ToAlias a
|
=> SqlSetOperation a
|
||||||
, a' ~ ToAliasT a
|
-> From a
|
||||||
, ToAliasReference a'
|
InnerJoinFrom
|
||||||
, ToAliasReferenceT a' ~ a''
|
:: From a
|
||||||
)
|
-> (From b, (a :& b) -> SqlExpr (Value Bool))
|
||||||
=> SqlSetOperation a
|
-> From (a :& b)
|
||||||
-> From a''
|
InnerJoinFromLateral
|
||||||
InnerJoinFrom
|
:: ( SqlSelect b r
|
||||||
:: From a
|
, ToAlias b
|
||||||
-> (From b, (a :& b) -> SqlExpr (Value Bool))
|
, ToAliasReference b
|
||||||
-> From (a :& b)
|
)
|
||||||
InnerJoinFromLateral
|
=> From a
|
||||||
:: ( SqlSelect b' r
|
-> ((a -> SqlQuery b), (a :& b) -> SqlExpr (Value Bool))
|
||||||
, SqlSelect b'' r'
|
-> From (a :& b)
|
||||||
, ToAlias b
|
CrossJoinFrom
|
||||||
, b' ~ ToAliasT b
|
:: From a
|
||||||
, ToAliasReference b'
|
-> From b
|
||||||
, ToAliasReferenceT b' ~ b''
|
-> From (a :& b)
|
||||||
)
|
CrossJoinFromLateral
|
||||||
=> From a
|
:: ( SqlSelect b r
|
||||||
-> ((a -> SqlQuery b), (a :& b'') -> SqlExpr (Value Bool))
|
, ToAlias b
|
||||||
-> From (a :& b'')
|
, ToAliasReference b
|
||||||
CrossJoinFrom
|
)
|
||||||
:: From a
|
=> From a
|
||||||
-> From b
|
-> (a -> SqlQuery b)
|
||||||
-> From (a :& b)
|
-> From (a :& b)
|
||||||
CrossJoinFromLateral
|
LeftJoinFrom
|
||||||
:: ( SqlSelect b' r
|
:: ToMaybe b
|
||||||
, SqlSelect b'' r'
|
=> From a
|
||||||
, ToAlias b
|
-> (From b, (a :& ToMaybeT b) -> SqlExpr (Value Bool))
|
||||||
, b' ~ ToAliasT b
|
-> From (a :& ToMaybeT b)
|
||||||
, ToAliasReference b'
|
LeftJoinFromLateral
|
||||||
, ToAliasReferenceT b' ~ b''
|
:: ( SqlSelect b r
|
||||||
)
|
, ToAlias b
|
||||||
=> From a
|
, ToAliasReference b
|
||||||
-> (a -> SqlQuery b)
|
, ToMaybe b
|
||||||
-> From (a :& b'')
|
)
|
||||||
LeftJoinFrom
|
=> From a
|
||||||
:: ToMaybe b
|
-> ((a -> SqlQuery b), (a :& ToMaybeT b) -> SqlExpr (Value Bool))
|
||||||
=> From a
|
-> From (a :& ToMaybeT b)
|
||||||
-> (From b, (a :& ToMaybeT b) -> SqlExpr (Value Bool))
|
RightJoinFrom
|
||||||
-> From (a :& ToMaybeT b)
|
:: ToMaybe a
|
||||||
LeftJoinFromLateral
|
=> From a
|
||||||
:: ( SqlSelect b' r
|
-> (From b, (ToMaybeT a :& b) -> SqlExpr (Value Bool))
|
||||||
, SqlSelect b'' r'
|
-> From (ToMaybeT a :& b)
|
||||||
, ToAlias b
|
FullJoinFrom
|
||||||
, b' ~ ToAliasT b
|
:: (ToMaybe a, ToMaybe b )
|
||||||
, ToAliasReference b'
|
=> From a
|
||||||
, ToAliasReferenceT b' ~ b''
|
-> (From b, (ToMaybeT a :& ToMaybeT b) -> SqlExpr (Value Bool))
|
||||||
, ToMaybe b''
|
-> From (ToMaybeT a :& ToMaybeT b)
|
||||||
)
|
|
||||||
=> From a
|
|
||||||
-> ((a -> SqlQuery b), (a :& ToMaybeT b'') -> SqlExpr (Value Bool))
|
|
||||||
-> From (a :& ToMaybeT b'')
|
|
||||||
RightJoinFrom
|
|
||||||
:: ToMaybe a
|
|
||||||
=> From a
|
|
||||||
-> (From b, (ToMaybeT a :& b) -> SqlExpr (Value Bool))
|
|
||||||
-> From (ToMaybeT a :& b)
|
|
||||||
FullJoinFrom
|
|
||||||
:: (ToMaybe a, ToMaybe b )
|
|
||||||
=> From a
|
|
||||||
-> (From b, (ToMaybeT a :& ToMaybeT b) -> SqlExpr (Value Bool))
|
|
||||||
-> From (ToMaybeT a :& ToMaybeT b)
|
|
||||||
|
|
||||||
-- | Constraint for `on`. Ensures that only types that require an `on` can be used on
|
-- | Constraint for `on`. Ensures that only types that require an `on` can be used on
|
||||||
-- the left hand side. This was previously reusing the ToFrom class which was actually
|
-- the left hand side. This was previously reusing the ToFrom class which was actually
|
||||||
@ -763,23 +747,24 @@ type JoinErrorMsg jk = 'Text "Missing on statement for " ':<>: 'Text jk
|
|||||||
|
|
||||||
type family ToFromT a where
|
type family ToFromT a where
|
||||||
ToFromT (From a) = a
|
ToFromT (From a) = a
|
||||||
ToFromT (SqlQuery a) = ToAliasReferenceT (ToAliasT a)
|
ToFromT (SqlQuery a) = a
|
||||||
ToFromT (Union a b) = ToAliasReferenceT (ToAliasT (SetOperationT a))
|
ToFromT (Union a b) = SetOperationT a
|
||||||
ToFromT (UnionAll a b) = ToAliasReferenceT (ToAliasT (SetOperationT a))
|
ToFromT (UnionAll a b) = SetOperationT a
|
||||||
ToFromT (Except a b) = ToAliasReferenceT (ToAliasT (SetOperationT a))
|
ToFromT (Except a b) = SetOperationT a
|
||||||
ToFromT (Intersect a b) = ToAliasReferenceT (ToAliasT (SetOperationT a))
|
ToFromT (Intersect a b) = SetOperationT a
|
||||||
ToFromT (SqlSetOperation a) = ToAliasReferenceT (ToAliasT a)
|
ToFromT (SqlSetOperation a) = a
|
||||||
ToFromT (InnerJoin a (b, c -> SqlExpr (Value Bool))) = c
|
ToFromT (InnerJoin a (b, c -> SqlExpr (Value Bool))) = c
|
||||||
ToFromT (LeftOuterJoin a (b, c -> SqlExpr (Value Bool))) = c
|
ToFromT (LeftOuterJoin a (b, c -> SqlExpr (Value Bool))) = c
|
||||||
ToFromT (RightOuterJoin a (b, c -> SqlExpr (Value Bool))) = c
|
ToFromT (RightOuterJoin a (b, c -> SqlExpr (Value Bool))) = c
|
||||||
ToFromT (FullOuterJoin a (b, c -> SqlExpr (Value Bool))) = c
|
ToFromT (FullOuterJoin a (b, c -> SqlExpr (Value Bool))) = c
|
||||||
ToFromT (CrossJoin a (c -> SqlQuery b)) = ToFromT a :& ToAliasReferenceT (ToAliasT b)
|
ToFromT (CrossJoin a (c -> SqlQuery b)) = ToFromT a :& b
|
||||||
ToFromT (CrossJoin a b) = ToFromT a :& ToFromT b
|
ToFromT (CrossJoin a b) = ToFromT a :& ToFromT b
|
||||||
ToFromT (InnerJoin a b) = TypeError (JoinErrorMsg "InnerJoin")
|
ToFromT (InnerJoin a b) = TypeError (JoinErrorMsg "InnerJoin")
|
||||||
ToFromT (LeftOuterJoin a b) = TypeError (JoinErrorMsg "LeftOuterJoin")
|
ToFromT (LeftOuterJoin a b) = TypeError (JoinErrorMsg "LeftOuterJoin")
|
||||||
ToFromT (RightOuterJoin a b) = TypeError (JoinErrorMsg "RightOuterJoin")
|
ToFromT (RightOuterJoin a b) = TypeError (JoinErrorMsg "RightOuterJoin")
|
||||||
ToFromT (FullOuterJoin a b) = TypeError (JoinErrorMsg "FullOuterJoin")
|
ToFromT (FullOuterJoin a b) = TypeError (JoinErrorMsg "FullOuterJoin")
|
||||||
|
|
||||||
|
|
||||||
data Lateral
|
data Lateral
|
||||||
data NotLateral
|
data NotLateral
|
||||||
|
|
||||||
@ -805,104 +790,60 @@ instance {-# OVERLAPPABLE #-} ToFrom (LeftOuterJoin a b) where
|
|||||||
instance {-# OVERLAPPABLE #-} ToFrom (RightOuterJoin a b) where
|
instance {-# OVERLAPPABLE #-} ToFrom (RightOuterJoin a b) where
|
||||||
toFrom = undefined
|
toFrom = undefined
|
||||||
instance {-# OVERLAPPABLE #-} ToFrom (FullOuterJoin a b) where
|
instance {-# OVERLAPPABLE #-} ToFrom (FullOuterJoin a b) where
|
||||||
toFrom = undefined
|
|
||||||
|
|
||||||
instance
|
toFrom = undefined
|
||||||
( ToAlias a
|
|
||||||
, a' ~ ToAliasT a
|
|
||||||
, ToAliasReference a'
|
|
||||||
, a'' ~ ToAliasReferenceT a'
|
|
||||||
, SqlSelect a' r'
|
|
||||||
, SqlSelect a'' r'
|
|
||||||
)
|
|
||||||
=>
|
|
||||||
ToFrom (SqlQuery a)
|
|
||||||
where
|
|
||||||
toFrom = SubQuery
|
|
||||||
|
|
||||||
instance
|
instance ( ToAlias a
|
||||||
( SqlSelect c' r
|
, ToAliasReference a
|
||||||
, SqlSelect c'' r'
|
, SqlSelect a r
|
||||||
, ToAlias c
|
) => ToFrom (SqlQuery a) where
|
||||||
, c' ~ ToAliasT c
|
toFrom = SubQuery
|
||||||
, ToAliasReference c'
|
|
||||||
, ToAliasReferenceT c' ~ c''
|
|
||||||
, ToSetOperation a c
|
|
||||||
, ToSetOperation b c
|
|
||||||
, c ~ SetOperationT a
|
|
||||||
)
|
|
||||||
=>
|
|
||||||
ToFrom (Union a b)
|
|
||||||
where
|
|
||||||
toFrom u = SqlSetOperation $ toSetOperation u
|
|
||||||
|
|
||||||
instance
|
instance ( SqlSelect c r
|
||||||
( SqlSelect c' r
|
, ToAlias c
|
||||||
, SqlSelect c'' r'
|
, ToAliasReference c
|
||||||
, ToAlias c
|
, ToSetOperation a c
|
||||||
, c' ~ ToAliasT c
|
, ToSetOperation b c
|
||||||
, ToAliasReference c'
|
, c ~ SetOperationT a
|
||||||
, ToAliasReferenceT c' ~ c''
|
) => ToFrom (Union a b) where
|
||||||
, ToSetOperation a c
|
toFrom u = SqlSetOperation $ toSetOperation u
|
||||||
, ToSetOperation b c
|
|
||||||
, c ~ SetOperationT a
|
|
||||||
)
|
|
||||||
=>
|
|
||||||
ToFrom (UnionAll a b)
|
|
||||||
where
|
|
||||||
toFrom u = SqlSetOperation $ toSetOperation u
|
|
||||||
|
|
||||||
instance
|
instance ( SqlSelect c r
|
||||||
( SqlSelect a' r
|
, ToAlias c
|
||||||
, SqlSelect a'' r'
|
, ToAliasReference c
|
||||||
, ToAlias a
|
, ToSetOperation a c
|
||||||
, a' ~ ToAliasT a
|
, ToSetOperation b c
|
||||||
, ToAliasReference a'
|
, c ~ SetOperationT a
|
||||||
, ToAliasReferenceT a' ~ a''
|
) => ToFrom (UnionAll a b) where
|
||||||
)
|
toFrom u = SqlSetOperation $ toSetOperation u
|
||||||
=>
|
|
||||||
ToFrom (SqlSetOperation a)
|
instance (SqlSelect a r, ToAlias a, ToAliasReference a) => ToFrom (SqlSetOperation a) where
|
||||||
where
|
-- If someone uses just a plain SelectQuery it should behave like a normal subquery
|
||||||
-- If someone uses just a plain SelectQuery it should behave like a normal subquery
|
toFrom (SelectQueryP _ q) = SubQuery q
|
||||||
toFrom (SelectQueryP _ q) = SubQuery q
|
-- Otherwise use the SqlSetOperation
|
||||||
-- Otherwise use the SqlSetOperation
|
toFrom q = SqlSetOperation q
|
||||||
toFrom q = SqlSetOperation q
|
|
||||||
|
|
||||||
class ToInnerJoin lateral lhs rhs res where
|
class ToInnerJoin lateral lhs rhs res where
|
||||||
toInnerJoin :: Proxy lateral -> lhs -> rhs -> (res -> SqlExpr (Value Bool)) -> From res
|
toInnerJoin :: Proxy lateral -> lhs -> rhs -> (res -> SqlExpr (Value Bool)) -> From res
|
||||||
|
|
||||||
instance
|
instance ( SqlSelect b r
|
||||||
( SqlSelect bAlias r
|
, ToAlias b
|
||||||
, SqlSelect bAliasRef r'
|
, ToAliasReference b
|
||||||
, ToAlias b
|
, ToFrom a
|
||||||
, bAlias ~ ToAliasT b
|
, ToFromT a ~ a'
|
||||||
, ToAliasReference bAlias
|
) => ToInnerJoin Lateral a (a' -> SqlQuery b) (a' :& b) where
|
||||||
, bAliasRef ~ ToAliasReferenceT bAlias
|
toInnerJoin _ lhs q on' = InnerJoinFromLateral (toFrom lhs) (q, on')
|
||||||
, ToFrom a
|
|
||||||
, ToFromT a ~ a'
|
|
||||||
)
|
|
||||||
=>
|
|
||||||
ToInnerJoin Lateral a (a' -> SqlQuery b) (a' :& bAliasRef)
|
|
||||||
where
|
|
||||||
toInnerJoin _ lhs q on' = InnerJoinFromLateral (toFrom lhs) (q, on')
|
|
||||||
|
|
||||||
instance
|
instance (ToFrom a, ToFromT a ~ a', ToFrom b, ToFromT b ~ b')
|
||||||
(ToFrom a, ToFromT a ~ a', ToFrom b, ToFromT b ~ b')
|
=> ToInnerJoin NotLateral a b (a' :& b') where
|
||||||
=>
|
toInnerJoin _ lhs rhs on' = InnerJoinFrom (toFrom lhs) (toFrom rhs, on')
|
||||||
ToInnerJoin NotLateral a b (a' :& b')
|
|
||||||
where
|
|
||||||
toInnerJoin _ lhs rhs on' = InnerJoinFrom (toFrom lhs) (toFrom rhs, on')
|
|
||||||
|
|
||||||
instance
|
instance ( ToFrom a
|
||||||
( ToFrom a
|
, ToFromT a ~ a'
|
||||||
, ToFromT a ~ a'
|
, ToInnerJoin (IsLateral b) a b b'
|
||||||
, ToInnerJoin (IsLateral b) a b b'
|
) => ToFrom (InnerJoin a (b, b' -> SqlExpr (Value Bool))) where
|
||||||
)
|
toFrom (InnerJoin lhs (rhs, on')) =
|
||||||
=>
|
let
|
||||||
ToFrom (InnerJoin a (b, b' -> SqlExpr (Value Bool)))
|
|
||||||
where
|
|
||||||
toFrom (InnerJoin lhs (rhs, on')) =
|
|
||||||
let
|
|
||||||
toProxy :: b -> Proxy (IsLateral b)
|
toProxy :: b -> Proxy (IsLateral b)
|
||||||
toProxy _ = Proxy
|
toProxy _ = Proxy
|
||||||
in toInnerJoin (toProxy rhs) lhs rhs on'
|
in toInnerJoin (toProxy rhs) lhs rhs on'
|
||||||
@ -918,61 +859,43 @@ instance
|
|||||||
toFrom (CrossJoin lhs rhs) = CrossJoinFrom (toFrom lhs) (toFrom rhs)
|
toFrom (CrossJoin lhs rhs) = CrossJoinFrom (toFrom lhs) (toFrom rhs)
|
||||||
|
|
||||||
instance {-# OVERLAPPING #-}
|
instance {-# OVERLAPPING #-}
|
||||||
( ToFrom a
|
|
||||||
, ToFromT a ~ a'
|
( ToFrom a
|
||||||
, SqlSelect bAlias r
|
, ToFromT a ~ a'
|
||||||
, SqlSelect bAliasRef r'
|
, SqlSelect b r
|
||||||
, ToAlias b
|
, ToAlias b
|
||||||
, bAlias ~ ToAliasT b
|
, ToAliasReference b
|
||||||
, ToAliasReference bAlias
|
)
|
||||||
, bAliasRef ~ ToAliasReferenceT bAlias
|
=> ToFrom (CrossJoin a (a' -> SqlQuery b)) where
|
||||||
)
|
toFrom (CrossJoin lhs q) = CrossJoinFromLateral (toFrom lhs) q
|
||||||
=>
|
|
||||||
ToFrom (CrossJoin a (a' -> SqlQuery b))
|
|
||||||
where
|
|
||||||
toFrom (CrossJoin lhs q) = CrossJoinFromLateral (toFrom lhs) q
|
|
||||||
|
|
||||||
class ToLeftJoin lateral lhs rhs res where
|
class ToLeftJoin lateral lhs rhs res where
|
||||||
toLeftJoin :: Proxy lateral -> lhs -> rhs -> (res -> SqlExpr (Value Bool)) -> From res
|
toLeftJoin :: Proxy lateral -> lhs -> rhs -> (res -> SqlExpr (Value Bool)) -> From res
|
||||||
|
|
||||||
instance
|
instance ( ToFrom a
|
||||||
( ToFrom a
|
, ToFromT a ~ a'
|
||||||
, ToFromT a ~ a'
|
, SqlSelect b r
|
||||||
, SqlSelect bAlias r
|
, ToAlias b
|
||||||
, SqlSelect bAliasRef r'
|
, ToAliasReference b
|
||||||
, ToAlias b
|
, ToMaybe b
|
||||||
, bAlias ~ ToAliasT b
|
, mb ~ ToMaybeT b
|
||||||
, ToAliasReference bAlias
|
) => ToLeftJoin Lateral a (a' -> SqlQuery b) (a' :& mb) where
|
||||||
, bAliasRef ~ ToAliasReferenceT bAlias
|
toLeftJoin _ lhs q on' = LeftJoinFromLateral (toFrom lhs) (q, on')
|
||||||
, ToMaybe bAliasRef
|
|
||||||
, mb ~ ToMaybeT bAliasRef
|
|
||||||
)
|
|
||||||
=>
|
|
||||||
ToLeftJoin Lateral a (a' -> SqlQuery b) (a' :& mb)
|
|
||||||
where
|
|
||||||
toLeftJoin _ lhs q on' = LeftJoinFromLateral (toFrom lhs) (q, on')
|
|
||||||
|
|
||||||
instance
|
instance ( ToFrom a
|
||||||
( ToFrom a
|
, ToFromT a ~ a'
|
||||||
, ToFromT a ~ a'
|
, ToFrom b
|
||||||
, ToFrom b
|
, ToFromT b ~ b'
|
||||||
, ToFromT b ~ b'
|
, ToMaybe b'
|
||||||
, ToMaybe b'
|
, mb ~ ToMaybeT b'
|
||||||
, mb ~ ToMaybeT b'
|
) => ToLeftJoin NotLateral a b (a' :& mb) where
|
||||||
)
|
toLeftJoin _ lhs rhs on' = LeftJoinFrom (toFrom lhs) (toFrom rhs, on')
|
||||||
=>
|
|
||||||
ToLeftJoin NotLateral a b (a' :& mb)
|
|
||||||
where
|
|
||||||
toLeftJoin _ lhs rhs on' = LeftJoinFrom (toFrom lhs) (toFrom rhs, on')
|
|
||||||
|
|
||||||
instance
|
instance ( ToLeftJoin (IsLateral b) a b b'
|
||||||
( ToLeftJoin (IsLateral b) a b b'
|
) => ToFrom (LeftOuterJoin a (b, b' -> SqlExpr (Value Bool))) where
|
||||||
)
|
toFrom (LeftOuterJoin lhs (rhs, on')) =
|
||||||
=>
|
let
|
||||||
ToFrom (LeftOuterJoin a (b, b' -> SqlExpr (Value Bool)))
|
toProxy :: b -> Proxy (IsLateral b)
|
||||||
where
|
|
||||||
toFrom (LeftOuterJoin lhs (rhs, on')) =
|
|
||||||
let toProxy :: b -> Proxy (IsLateral b)
|
|
||||||
toProxy _ = Proxy
|
toProxy _ = Proxy
|
||||||
in toLeftJoin (toProxy rhs) lhs rhs on'
|
in toLeftJoin (toProxy rhs) lhs rhs on'
|
||||||
|
|
||||||
@ -1245,18 +1168,13 @@ from parts = do
|
|||||||
let ret = (toMaybe leftVal) :& (toMaybe rightVal)
|
let ret = (toMaybe leftVal) :& (toMaybe rightVal)
|
||||||
pure $ (ret, FromJoin leftFrom FullOuterJoinKind rightFrom (Just (on' ret)))
|
pure $ (ret, FromJoin leftFrom FullOuterJoinKind rightFrom (Just (on' ret)))
|
||||||
|
|
||||||
fromSubQuery
|
fromSubQuery
|
||||||
::
|
::
|
||||||
( SqlSelect a' r
|
( SqlSelect a r
|
||||||
, SqlSelect a'' r'
|
|
||||||
, ToAlias a
|
, ToAlias a
|
||||||
, a' ~ ToAliasT a
|
, ToAliasReference a
|
||||||
, ToAliasReference a'
|
|
||||||
, ToAliasReferenceT a' ~ a''
|
|
||||||
)
|
)
|
||||||
=> SubQueryType
|
=> SubQueryType -> SqlQuery a -> SqlQuery (a, FromClause)
|
||||||
-> SqlQuery a
|
|
||||||
-> SqlQuery (ToAliasReferenceT (ToAliasT a), FromClause)
|
|
||||||
fromSubQuery subqueryType subquery = do
|
fromSubQuery subqueryType subquery = do
|
||||||
-- We want to update the IdentState without writing the query to side data
|
-- We want to update the IdentState without writing the query to side data
|
||||||
(ret, sideData) <- Q $ W.censor (\_ -> mempty) $ W.listen $ unQ subquery
|
(ret, sideData) <- Q $ W.censor (\_ -> mempty) $ W.listen $ unQ subquery
|
||||||
@ -1293,9 +1211,9 @@ fromSubQuery subqueryType subquery = do
|
|||||||
--
|
--
|
||||||
-- /Since: 3.4.0.0/
|
-- /Since: 3.4.0.0/
|
||||||
with :: ( ToAlias a
|
with :: ( ToAlias a
|
||||||
, ToAliasReference (ToAliasT a)
|
, ToAliasReference a
|
||||||
, SqlSelect (ToAliasT a) r
|
, SqlSelect a r
|
||||||
) => SqlQuery a -> SqlQuery (From (ToAliasReferenceT (ToAliasT a)))
|
) => SqlQuery a -> SqlQuery (From a)
|
||||||
with query = do
|
with query = do
|
||||||
(ret, sideData) <- Q $ W.censor (\_ -> mempty) $ W.listen $ unQ query
|
(ret, sideData) <- Q $ W.censor (\_ -> mempty) $ W.listen $ unQ query
|
||||||
aliasedValue <- toAlias ret
|
aliasedValue <- toAlias ret
|
||||||
@ -1339,16 +1257,14 @@ with query = do
|
|||||||
--
|
--
|
||||||
-- /Since: 3.4.0.0/
|
-- /Since: 3.4.0.0/
|
||||||
withRecursive :: ( ToAlias a
|
withRecursive :: ( ToAlias a
|
||||||
, ToAliasReference (ToAliasT a)
|
, ToAliasReference a
|
||||||
, SqlSelect a r
|
, SqlSelect a r
|
||||||
, SqlSelect (ToAliasT a) r
|
|
||||||
, ref ~ ToAliasReferenceT (ToAliasT a)
|
|
||||||
, RecursiveCteUnion unionKind
|
, RecursiveCteUnion unionKind
|
||||||
)
|
)
|
||||||
=> SqlQuery a
|
=> SqlQuery a
|
||||||
-> unionKind
|
-> unionKind
|
||||||
-> (From ref -> SqlQuery a)
|
-> (From a -> SqlQuery a)
|
||||||
-> SqlQuery (From ref)
|
-> SqlQuery (From a)
|
||||||
withRecursive baseCase unionKind recursiveCase = do
|
withRecursive baseCase unionKind recursiveCase = do
|
||||||
(ret, sideData) <- Q $ W.censor (\_ -> mempty) $ W.listen $ unQ baseCase
|
(ret, sideData) <- Q $ W.censor (\_ -> mempty) $ W.listen $ unQ baseCase
|
||||||
aliasedValue <- toAlias ret
|
aliasedValue <- toAlias ret
|
||||||
@ -1365,21 +1281,12 @@ withRecursive baseCase unionKind recursiveCase = do
|
|||||||
Q $ W.tell mempty{sdCteClause = [clause]}
|
Q $ W.tell mempty{sdCteClause = [clause]}
|
||||||
pure refFrom
|
pure refFrom
|
||||||
|
|
||||||
type family ToAliasT a where
|
{-# DEPRECATED ToAliasT "This type alias doesn't do anything. Please delete it. Will be removed in the next release." #-}
|
||||||
ToAliasT (SqlExpr (Value a)) = SqlExpr (Value a)
|
type ToAliasT a = a
|
||||||
ToAliasT (SqlExpr (Entity a)) = SqlExpr (Entity a)
|
|
||||||
ToAliasT (SqlExpr (Maybe (Entity a))) = SqlExpr (Maybe (Entity a))
|
|
||||||
ToAliasT (a, b) = (ToAliasT a, ToAliasT b)
|
|
||||||
ToAliasT (a, b, c) = (ToAliasT a, ToAliasT b, ToAliasT c)
|
|
||||||
ToAliasT (a, b, c, d) = (ToAliasT a, ToAliasT b, ToAliasT c, ToAliasT d)
|
|
||||||
ToAliasT (a, b, c, d, e) = (ToAliasT a, ToAliasT b, ToAliasT c, ToAliasT d, ToAliasT e)
|
|
||||||
ToAliasT (a, b, c, d, e, f) = (ToAliasT a, ToAliasT b, ToAliasT c, ToAliasT d, ToAliasT e, ToAliasT f)
|
|
||||||
ToAliasT (a, b, c, d, e, f, g) = (ToAliasT a, ToAliasT b, ToAliasT c, ToAliasT d, ToAliasT e, ToAliasT f, ToAliasT g)
|
|
||||||
ToAliasT (a, b, c, d, e, f, g, h) = (ToAliasT a, ToAliasT b, ToAliasT c, ToAliasT d, ToAliasT e, ToAliasT f, ToAliasT g, ToAliasT h)
|
|
||||||
|
|
||||||
-- Tedious tuple magic
|
-- Tedious tuple magic
|
||||||
class ToAlias a where
|
class ToAlias a where
|
||||||
toAlias :: a -> SqlQuery (ToAliasT a)
|
toAlias :: a -> SqlQuery a
|
||||||
|
|
||||||
instance ToAlias (SqlExpr (Value a)) where
|
instance ToAlias (SqlExpr (Value a)) where
|
||||||
toAlias v@(EAliasedValue _ _) = pure v
|
toAlias v@(EAliasedValue _ _) = pure v
|
||||||
@ -1451,22 +1358,12 @@ instance ( ToAlias a
|
|||||||
) => ToAlias (a,b,c,d,e,f,g,h) where
|
) => ToAlias (a,b,c,d,e,f,g,h) where
|
||||||
toAlias x = to8 <$> (toAlias $ from8 x)
|
toAlias x = to8 <$> (toAlias $ from8 x)
|
||||||
|
|
||||||
|
{-# DEPRECATED ToAliasReferenceT "This type alias doesn't do anything. Please delete it. Will be removed in the next release." #-}
|
||||||
type family ToAliasReferenceT a where
|
type ToAliasReferenceT a = a
|
||||||
ToAliasReferenceT (SqlExpr (Value a)) = SqlExpr (Value a)
|
|
||||||
ToAliasReferenceT (SqlExpr (Entity a)) = SqlExpr (Entity a)
|
|
||||||
ToAliasReferenceT (SqlExpr (Maybe (Entity a))) = SqlExpr (Maybe (Entity a))
|
|
||||||
ToAliasReferenceT (a,b) = (ToAliasReferenceT a, ToAliasReferenceT b)
|
|
||||||
ToAliasReferenceT (a,b,c) = (ToAliasReferenceT a, ToAliasReferenceT b, ToAliasReferenceT c)
|
|
||||||
ToAliasReferenceT (a, b, c, d) = (ToAliasReferenceT a, ToAliasReferenceT b, ToAliasReferenceT c, ToAliasReferenceT d)
|
|
||||||
ToAliasReferenceT (a, b, c, d, e) = (ToAliasReferenceT a, ToAliasReferenceT b, ToAliasReferenceT c, ToAliasReferenceT d, ToAliasReferenceT e)
|
|
||||||
ToAliasReferenceT (a, b, c, d, e, f) = (ToAliasReferenceT a, ToAliasReferenceT b, ToAliasReferenceT c, ToAliasReferenceT d, ToAliasReferenceT e, ToAliasReferenceT f)
|
|
||||||
ToAliasReferenceT (a, b, c, d, e, f, g) = (ToAliasReferenceT a, ToAliasReferenceT b, ToAliasReferenceT c, ToAliasReferenceT d, ToAliasReferenceT e, ToAliasReferenceT f, ToAliasReferenceT g)
|
|
||||||
ToAliasReferenceT (a, b, c, d, e, f, g, h) = (ToAliasReferenceT a, ToAliasReferenceT b, ToAliasReferenceT c, ToAliasReferenceT d, ToAliasReferenceT e, ToAliasReferenceT f, ToAliasReferenceT g, ToAliasReferenceT h)
|
|
||||||
|
|
||||||
-- more tedious tuple magic
|
-- more tedious tuple magic
|
||||||
class ToAliasReference a where
|
class ToAliasReference a where
|
||||||
toAliasReference :: Ident -> a -> SqlQuery (ToAliasReferenceT a)
|
toAliasReference :: Ident -> a -> SqlQuery a
|
||||||
|
|
||||||
instance ToAliasReference (SqlExpr (Value a)) where
|
instance ToAliasReference (SqlExpr (Value a)) where
|
||||||
toAliasReference aliasSource (EAliasedValue aliasIdent _) = pure $ EValueReference aliasSource (\_ -> aliasIdent)
|
toAliasReference aliasSource (EAliasedValue aliasIdent _) = pure $ EValueReference aliasSource (\_ -> aliasIdent)
|
||||||
@ -1482,6 +1379,7 @@ instance ToAliasReference (SqlExpr (Entity a)) where
|
|||||||
instance ToAliasReference (SqlExpr (Maybe (Entity a))) where
|
instance ToAliasReference (SqlExpr (Maybe (Entity a))) where
|
||||||
toAliasReference s (EMaybe e) = EMaybe <$> toAliasReference s e
|
toAliasReference s (EMaybe e) = EMaybe <$> toAliasReference s e
|
||||||
|
|
||||||
|
|
||||||
instance (ToAliasReference a, ToAliasReference b) => ToAliasReference (a, b) where
|
instance (ToAliasReference a, ToAliasReference b) => ToAliasReference (a, b) where
|
||||||
toAliasReference ident (a,b) = (,) <$> (toAliasReference ident a) <*> (toAliasReference ident b)
|
toAliasReference ident (a,b) = (,) <$> (toAliasReference ident a) <*> (toAliasReference ident b)
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user