on dev help sign in
some type families!
5f4d34eEitan Chatav
squeal-postgresql/src/Squeal/PostgreSQL/Schema.hs+13−2
@@ -828,11 +828,19 @@ type family FieldTypeOf (maybe :: Type) where
828 FieldTypeOf ty = TypeError
828 FieldTypeOf ty = TypeError
829 ('Text "FieldTypeOf error: non-Maybe type " ':<>: 'ShowType ty)
829 ('Text "FieldTypeOf error: non-Maybe type " ':<>: 'ShowType ty)
830
830
831+type family NullityTypeOf (hask :: Type) where
832+ NullityTypeOf (Maybe hask) = 'Null (PG hask)
833+ NullityTypeOf hask = 'NotNull (PG hask)
834+
831-- | Calculate the types of fields.
835-- | Calculate the types of fields.
832type family FieldTypesOf (fields :: [Type]) where
836type family FieldTypesOf (fields :: [Type]) where
833 FieldTypesOf '[] = '[]
837 FieldTypesOf '[] = '[]
834 FieldTypesOf (field ': fields) = FieldTypeOf field ': FieldTypesOf fields
838 FieldTypesOf (field ': fields) = FieldTypeOf field ': FieldTypesOf fields
835
839
840+type family NullityTypesOf (hasks :: [Type]) where
841+ NullityTypesOf '[] = '[]
842+ NullityTypesOf (hask ': hasks) = NullityTypeOf hask ': NullityTypesOf hasks
843+
836-- | Inspect the code of an algebraic datatype and ensure it's a product,
844-- | Inspect the code of an algebraic datatype and ensure it's a product,
837-- otherwise generate a type error
845-- otherwise generate a type error
838type family RecordCodeOf (hask :: Type) (code ::[[Type]]) :: [Type] where
846type family RecordCodeOf (hask :: Type) (code ::[[Type]]) :: [Type] where
@@ -840,5 +848,8 @@ type family RecordCodeOf (hask :: Type) (code ::[[Type]]) :: [Type] where
840 RecordCodeOf hask _tys = TypeError
848 RecordCodeOf hask _tys = TypeError
841 ('Text "RecordCodeOf error: non-Record type " ':<>: 'ShowType hask)
849 ('Text "RecordCodeOf error: non-Record type " ':<>: 'ShowType hask)
842
850
843−type family ParamsFrom (hask :: Type) :: [NullityType]
851+type family ParamsFrom (hask :: Type) :: [NullityType] where
852+ ParamsFrom hask = NullityTypesOf (RecordCodeOf hask (Code hask))
853+
844−type family ResultFrom (hask :: Type) :: RelationType
854+type family ResultFrom (hask :: Type) :: RelationType where
855+ ResultFrom hask = ZipAs (FieldNamesFrom hask) (ParamsFrom hask)