on dev help sign in
Joinable
ff7665aEitan Chatav
squeal-postgresql/src/Squeal/PostgreSQL/Binary.hs+12−3
@@ -634,9 +634,18 @@ instance
634 = fmap fromRecord
634 = fmap fromRecord
635 . hsequence'
635 . hsequence'
636 . htrans (Proxy @FromField) fromField
636 . htrans (Proxy @FromField) fromField
637−instance (FromField (col ::: pgkey) (col ::: key), FromRow pgval val)
637+instance (FromField (col ::: pg) (col ::: hask))
638− => FromRow (col ::: pgkey ': pgval) (P (col ::: key), val) where
638+ => FromRow '[col ::: pg] (P (col ::: hask)) where
639− fromRow (key :* val) = (,) <$> (unComp . fromField) key <*> fromRow val
639+ fromRow (pg :* Nil) = (unComp . fromField) pg
640+instance
641+ ( Joinable row1 row2
642+ , row ~ Join row1 row2
643+ , FromRow row1 hask1
644+ , FromRow row2 hask2
645+ , SListI row
646+ ) => FromRow row (hask1, hask2) where
647+ fromRow row = case disjoin @row1 @row2 row of
648+ (row1, row2) -> (,) <$> fromRow row1 <*> fromRow row2
640
649
641-- | `Only` is a 1-tuple type, useful for encoding a single parameter with
650-- | `Only` is a 1-tuple type, useful for encoding a single parameter with
642-- `toParams` or decoding a single value with `fromRow`.
651-- `toParams` or decoding a single value with `fromRow`.
squeal-postgresql/src/Squeal/PostgreSQL/Expression.hs+3−3
@@ -1217,7 +1217,7 @@ jsonbBuildArray
1217jsonbBuildArray = unsafeVariadicFunction "jsonb_build_array"
1217jsonbBuildArray = unsafeVariadicFunction "jsonb_build_array"
1218
1218
1219unsafeRowFunction
1219unsafeRowFunction
1220− :: SOP.All SOP.Top elems
1220+ :: SOP.SListI elems
1221 => NP (Aliased (Expression outer grp commons schemas params from)) elems
1221 => NP (Aliased (Expression outer grp commons schemas params from)) elems
1222 -> [ByteString]
1222 -> [ByteString]
1223unsafeRowFunction =
1223unsafeRowFunction =
@@ -1232,7 +1232,7 @@ unsafeRowFunction =
1232-- argument list. The elements of the argument list must alternate between text
1232-- argument list. The elements of the argument list must alternate between text
1233-- and values.
1233-- and values.
1234jsonBuildObject
1234jsonBuildObject
1235− :: SOP.All SOP.Top elems
1235+ :: SOP.SListI elems
1236 => NP (Aliased (Expression outer grp commons schemas params from)) elems
1236 => NP (Aliased (Expression outer grp commons schemas params from)) elems
1237 -> Expression outer grp commons schemas params from (nullity 'PGjson)
1237 -> Expression outer grp commons schemas params from (nullity 'PGjson)
1238jsonBuildObject
1238jsonBuildObject
@@ -1245,7 +1245,7 @@ jsonBuildObject
1245-- variadic argument list. The elements of the argument list must alternate
1245-- variadic argument list. The elements of the argument list must alternate
1246-- between text and values.
1246-- between text and values.
1247jsonbBuildObject
1247jsonbBuildObject
1248− :: SOP.All SOP.Top elems
1248+ :: SOP.SListI elems
1249 => NP (Aliased (Expression outer grp commons schemas params from)) elems
1249 => NP (Aliased (Expression outer grp commons schemas params from)) elems
1250 -> Expression outer grp commons schemas params from (nullity 'PGjsonb)
1250 -> Expression outer grp commons schemas params from (nullity 'PGjsonb)
1251jsonbBuildObject
1251jsonbBuildObject
squeal-postgresql/src/Squeal/PostgreSQL/Schema.hs+12−5
@@ -92,7 +92,7 @@ module Squeal.PostgreSQL.Schema
92 , Rename
92 , Rename
93 , DropIfConstraintsInvolve
93 , DropIfConstraintsInvolve
94 -- * Lists
94 -- * Lists
95− , Join
95+ , Joinable (..)
96 , Elem
96 , Elem
97 , In
97 , In
98 , Length
98 , Length
@@ -628,9 +628,15 @@ type family NullifyFrom (tables :: FromType) :: FromType where
628
628
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)
634
640
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]
825-}
831-}
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)
829
836
830type family RowOf (fields :: [(Symbol, Type)]) :: RowType where
837type family RowOf (fields :: [(Symbol, Type)]) :: RowType where