@@ -92,7 +92,7 @@ module Squeal.PostgreSQL.Schema
9292 , Rename
9393 , DropIfConstraintsInvolve
9494 -- * Lists
95− , Join
95+ , Joinable (..)
9696 , Elem
9797 , In
9898 , Length
@@ -628,9 +628,15 @@ type family NullifyFrom (tables :: FromType) :: FromType where
628628
629629-- | `Join` is simply promoted `++` and is used in @JOIN@s in
630630-- `Squeal.PostgreSQL.Query.FromClause`s.
631−type family Join xs ys where
632− Join '[] ys = ys
633− Join (x ': xs) ys = x ': Join xs ys
631+class Joinable xs ys where
632+ type family Join (xs :: [k]) (ys :: [k]) :: [k]
633+ disjoin :: NP expr (Join xs ys) -> (NP expr xs, NP expr ys)
634+instance Joinable '[] ys where
635+ type Join '[] ys = ys
636+ disjoin list = (Nil, list)
637+instance Joinable xs ys => Joinable (x ': xs) ys where
638+ type Join (x ': xs) ys = x ': Join xs ys
639+ disjoin (x :* xsys) = case disjoin xsys of (xs,ys) -> (x :* xs, ys)
634640
635641-- | @Create alias x xs@ adds @alias ::: x@ to the end of @xs@ and is used in
636642-- `Squeal.PostgreSQL.Definition.createTable` statements and in @ALTER TABLE@
@@ -824,7 +830,8 @@ RowPG Person :: [(Symbol, NullityType)]
824830= '["name" ::: 'NotNull 'PGtext, "age" ::: 'NotNull 'PGint4]
825831-}
826832type family RowPG (hask :: Type) :: RowType where
827− RowPG (P (col ::: head), tail) = col ::: NullPG head ': RowPG tail
833+ RowPG (hask1, hask2) = Join (RowPG hask1) (RowPG hask2)
834+ RowPG (P (col ::: head)) = '[col ::: NullPG head]
828835 RowPG hask = RowOf (RecordCodeOf hask)
829836
830837type family RowOf (fields :: [(Symbol, Type)]) :: RowType where