@@ -92,7 +92,7 @@ module Squeal.PostgreSQL.Schema
93 , DropIfConstraintsInvolve
93 , DropIfConstraintsInvolve
94 -- * Lists
94 -- * Lists
95− , Join
95+ , Joinable (..)
@@ -628,9 +628,15 @@ type family NullifyFrom (tables :: FromType) :: FromType where
629-- | `Join` is simply promoted `++` and is used in @JOIN@s in
629-- | `Join` is simply promoted `++` and is used in @JOIN@s in
630-- `Squeal.PostgreSQL.Query.FromClause`s.
630-- `Squeal.PostgreSQL.Query.FromClause`s.
631+class Joinable xs ys where
631−type family Join 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
632− Join '[] ys = ys
635+ type Join '[] ys = ys
636+ disjoin list = (Nil, list)
637+instance Joinable xs ys => Joinable (x ': xs) ys where
633− Join (x ': xs) ys = x ': Join xs ys
638+ type Join (x ': xs) ys = x ': Join xs ys
639+ disjoin (x :* xsys) = case disjoin xsys of (xs,ys) -> (x :* xs, ys)
635-- | @Create alias x xs@ adds @alias ::: x@ to the end of @xs@ and is used in
641-- | @Create alias x xs@ adds @alias ::: x@ to the end of @xs@ and is used in
636-- `Squeal.PostgreSQL.Definition.createTable` statements and in @ALTER TABLE@
642-- `Squeal.PostgreSQL.Definition.createTable` statements and in @ALTER TABLE@
@@ -824,7 +830,8 @@ RowPG Person :: [(Symbol, NullityType)]
824= '["name" ::: 'NotNull 'PGtext, "age" ::: 'NotNull 'PGint4]
830= '["name" ::: 'NotNull 'PGtext, "age" ::: 'NotNull 'PGint4]
826type family RowPG (hask :: Type) :: RowType where
832type 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]
828 RowPG hask = RowOf (RecordCodeOf hask)
835 RowPG hask = RowOf (RecordCodeOf hask)
830type family RowOf (fields :: [(Symbol, Type)]) :: RowType where
837type family RowOf (fields :: [(Symbol, Type)]) :: RowType where