Use type families instead of empty classes (#220)
* Use type families instead of empty classes * It's not possible to expand a closed type family. Co-authored-by: Matt Parsons <parsonsmatt@gmail.com> Co-authored-by: Matt Parsons <parsonsmatt@gmail.com>
This commit is contained in:
parent
b35713c09f
commit
eb91208e94
@ -220,6 +220,7 @@ import qualified Control.Monad.Trans.Writer as W
|
|||||||
#if __GLASGOW_HASKELL__ < 804
|
#if __GLASGOW_HASKELL__ < 804
|
||||||
import Data.Semigroup
|
import Data.Semigroup
|
||||||
#endif
|
#endif
|
||||||
|
import Data.Kind (Constraint)
|
||||||
import Data.Proxy (Proxy(..))
|
import Data.Proxy (Proxy(..))
|
||||||
import qualified Data.Text.Lazy.Builder as TLB
|
import qualified Data.Text.Lazy.Builder as TLB
|
||||||
import Database.Esqueleto.Internal.Internal hiding (From, from, on)
|
import Database.Esqueleto.Internal.Internal hiding (From, from, on)
|
||||||
@ -719,15 +720,15 @@ data From a where
|
|||||||
|
|
||||||
-- | 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
|
||||||
-- a bit too lenient as it allowed to much. Expanding this class should not be needed.
|
-- a bit too lenient as it allowed to much.
|
||||||
--
|
--
|
||||||
-- @since 3.4.0.0
|
-- @since 3.4.0.0
|
||||||
class ValidOnClauseValue a where
|
type family ValidOnClauseValue a :: Constraint where
|
||||||
instance ValidOnClauseValue (From a) where
|
ValidOnClauseValue (From a) = ()
|
||||||
instance ValidOnClauseValue (SqlQuery a) where
|
ValidOnClauseValue (SqlQuery a) = ()
|
||||||
instance ValidOnClauseValue (SqlSetOperation a) where
|
ValidOnClauseValue (SqlSetOperation a) = ()
|
||||||
instance ValidOnClauseValue (a -> SqlQuery b) where
|
ValidOnClauseValue (a -> SqlQuery b) = ()
|
||||||
instance {-# OVERLAPPABLE #-} (TypeError ('Text "Illegal use of ON")) => ValidOnClauseValue a where
|
ValidOnClauseValue _ = TypeError ('Text "Illegal use of ON")
|
||||||
|
|
||||||
-- | An @ON@ clause that describes how two tables are related. This should be
|
-- | An @ON@ clause that describes how two tables are related. This should be
|
||||||
-- used as an infix operator after a 'JOIN'. For example,
|
-- used as an infix operator after a 'JOIN'. For example,
|
||||||
@ -772,9 +773,9 @@ type family IsLateral a where
|
|||||||
IsLateral (a -> SqlQuery b) = Lateral
|
IsLateral (a -> SqlQuery b) = Lateral
|
||||||
IsLateral a = NotLateral
|
IsLateral a = NotLateral
|
||||||
|
|
||||||
class ErrorOnLateral a where
|
type family ErrorOnLateral a :: Constraint where
|
||||||
instance (TypeError ('Text "LATERAL can only be used for INNER, LEFT, and CROSS join kinds.")) => ErrorOnLateral (a -> SqlQuery b) where
|
ErrorOnLateral (a -> SqlQuery b) = TypeError ('Text "LATERAL can only be used for INNER, LEFT, and CROSS join kinds.")
|
||||||
instance {-# OVERLAPPABLE #-} ErrorOnLateral a where
|
ErrorOnLateral _ = ()
|
||||||
|
|
||||||
{-- Type class magic to allow the use of the `InnerJoin` family of data constructors in from --}
|
{-- Type class magic to allow the use of the `InnerJoin` family of data constructors in from --}
|
||||||
class ToFrom a where
|
class ToFrom a where
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user