on dev help sign in
frompg
commit9d2c6652ada6eec7042f375edcf5e006f7313f36 authorEitan Chatav <eitan@Eitans-MacBook-Pro.local> dateThu 14 Mar 2019, 22:17 (8 years ago) parentd2a0e5f
2 files changed+22−5
squeal-postgresql/src/Squeal/PostgreSQL/Binary.hs+18−5 squeal-postgresql/src/Squeal/PostgreSQL/Query.hs+4
squeal-postgresql/src/Squeal/PostgreSQL/Binary.hs+18−5
@@ -208,6 +208,7 @@ module Squeal.PostgreSQL.Binary
208208 , TuplePG
209209 , RowPG
210210 , LabelsPG
211+ , FromPG
211212 -- * Storage newtypes
212213 , Money (..)
213214 , Json (..)
@@ -884,12 +885,9 @@ type family RowPG (hask :: Type) :: RowType where
884885 RowPG (P (col ::: head)) = '[col ::: NullPG head]
885886 RowPG hask = RowOf (RecordCodeOf hask)
886887
887−type family RowOf (fields :: [(Symbol, Type)]) :: RowType where
888+type family RowOf (record :: [(Symbol, Type)]) :: RowType where
888889 RowOf '[] = '[]
889− RowOf (field ': fields) = FieldPG field ': RowOf fields
890−
891−type family FieldPG (field :: (Symbol, Type)) :: (Symbol, NullityType) where
892− FieldPG (field ::: hask) = field ::: NullPG hask
890+ RowOf (col ::: ty ': record) = col ::: NullPG ty ': RowOf record
893891
894892{- | `NullPG` turns a Haskell type into a `NullityType`.
895893
@@ -957,3 +955,18 @@ type family ConstructorNamesOf (constructors :: [Type.ConstructorInfo])
957955 ConstructorNamesOf '[] = '[]
958956 ConstructorNamesOf (constructor ': constructors) =
959957 ConstructorNameOf constructor ': ConstructorNamesOf constructors
958+
959+type family FromPG (hask :: Type) :: FromType where
960+ FromPG (hask1, hask2) = Join (FromPG hask1) (FromPG hask2)
961+ FromPG (hask1, hask2, hask3) =
962+ Join (FromPG hask1) (FromPG (hask2, hask3))
963+ FromPG (hask1, hask2, hask3, hask4) =
964+ Join (FromPG hask1) (FromPG (hask2, hask3, hask4))
965+ FromPG (hask1, hask2, hask3, hask4, hask5) =
966+ Join (FromPG hask1) (FromPG (hask2, hask3, hask4, hask5))
967+ FromPG (P (col ::: hask)) = '[col ::: RowPG hask]
968+ FromPG hask = FromOf (RecordCodeOf hask)
969+
970+type family FromOf (record :: [(Symbol, Type)]) :: FromType where
971+ FromOf '[] = '[]
972+ FromOf (tab ::: ty ': record) = tab ::: RowPG ty ': FromOf record
squeal-postgresql/src/Squeal/PostgreSQL/Query.hs+4
@@ -879,6 +879,10 @@ jsonbToRecordSet = unsafeRecordFunction "jsonb_to_record_set"
879879FROM clauses
880880-----------------------------------------}
881881
882+type family FromClause_ schemas params from where
883+ FromClause_ schemas params from =
884+ FromClause schemas (TuplePG params) (FromPG from)
885+
882886{- |
883887A `FromClause` can be a table name, or a derived table such
884888as a subquery, a @JOIN@ construct, or complex combinations of these.