From a244b72d2d325523043ba415f349c50fffa208f8 Mon Sep 17 00:00:00 2001 From: Eitan Chatav Date: Wed, 23 Oct 2019 10:58:28 -0700 Subject: [PATCH] naming --- .../src/Squeal/PostgreSQL/Binary.hs | 244 +++++++++--------- squeal-postgresql/src/Squeal/PostgreSQL/PQ.hs | 32 +-- squeal-postgresql/test/Property.hs | 4 +- 3 files changed, 140 insertions(+), 140 deletions(-) diff --git a/squeal-postgresql/src/Squeal/PostgreSQL/Binary.hs b/squeal-postgresql/src/Squeal/PostgreSQL/Binary.hs index 002fdcd..2f8180a 100644 --- a/squeal-postgresql/src/Squeal/PostgreSQL/Binary.hs +++ b/squeal-postgresql/src/Squeal/PostgreSQL/Binary.hs @@ -216,9 +216,9 @@ module Squeal.PostgreSQL.Binary -- * Only , Only (..) -- * Oid - , HasOid (..) - , HasOidParam (..) - , HasAliasedOid (..) + , OidOf (..) + , OidOfParam (..) + , OidOfField (..) ) where import BinaryParser @@ -312,24 +312,24 @@ instance Aeson.ToJSON x => ToParam (Json x) 'PGjson where instance Aeson.ToJSON x => ToParam (Jsonb x) 'PGjsonb where toParam = K . Encoding.jsonb_bytes . Lazy.ByteString.toStrict . Aeson.encode . getJsonb -instance (ToNullityParam x ty, ty ~ nullity pg, HasOid pg) +instance (ToNullityParam x ty, ty ~ nullity pg, OidOf pg) => ToParam (VarArray [x]) ('PGvararray ty) where toParam = K . Encoding.array_foldable (getOid (oidOf @pg)) (unK . toNullityParam @x @ty) . getVarArray -instance (ToParam x pg, HasOid pg) +instance (ToParam x pg, OidOf pg) => ToParam (VarArray (Vector x)) ('PGvararray ('NotNull pg)) where toParam = K . Encoding.array_vector (getOid (oidOf @pg)) (unK . toParam @x @pg) . getVarArray -instance (ToParam x pg, HasOid pg) +instance (ToParam x pg, OidOf pg) => ToParam (VarArray (Vector (Maybe x))) ('PGvararray ('Null pg)) where toParam = K . Encoding.nullableArray_vector (getOid (oidOf @pg)) (unK . toParam @x @pg) . getVarArray -instance (ToFixArray x dims ty, ty ~ nullity pg, HasOid pg) +instance (ToFixArray x dims ty, ty ~ nullity pg, OidOf pg) => ToParam (FixArray x) ('PGfixarray dims ty) where toParam = K . Encoding.array (getOid (oidOf @pg)) . unK . unK . toFixArray @x @dims @ty . getFixArray @@ -356,7 +356,7 @@ instance ( SListI fields , IsRecord x xs , AllZip ToField xs fields - , All HasAliasedOid fields + , All OidOfField fields ) => ToParam (Composite x) ('PGcomposite fields) where toParam = let @@ -364,7 +364,7 @@ instance encoders = htrans (Proxy @ToField) toField composite - :: All HasAliasedOid row + :: All OidOfField row => NP (K (Maybe Encoding.Encoding)) row -> K Encoding.Encoding ('PGcomposite row) composite fields = K $ @@ -381,18 +381,18 @@ instance int32BE (fromIntegral (lengthSList (Proxy @xs))) <> let each - :: HasAliasedOid field + :: OidOfField field => K (Maybe Encoding.Encoding) field -> Encoding.Encoding each (K field :: K (Maybe Encoding.Encoding) field) = - word32BE (getOid (aliasedOid @field)) + word32BE (getOid (oidOfField @field)) <> case field of Nothing -> int64BE (-1) Just value -> int32BE (fromIntegral (builderLength value)) <> value in - hcfoldMap (Proxy @HasAliasedOid) each fields + hcfoldMap (Proxy @OidOfField) each fields in composite . encoders . toRecord . getComposite @@ -402,118 +402,118 @@ instance -- >>> :set -XTypeApplications -- >>> oidOf @'PGbool -- Oid 16 -class HasOid (ty :: PGType) where oidOf :: LibPQ.Oid -instance HasOid 'PGbool where oidOf = LibPQ.Oid 16 -instance HasOid ('PGfixarray ns (null 'PGbool)) where oidOf = LibPQ.Oid 1000 -instance HasOid ('PGvararray (null 'PGbool)) where oidOf = LibPQ.Oid 1000 -instance HasOid 'PGint2 where oidOf = LibPQ.Oid 21 -instance HasOid ('PGfixarray ns (null 'PGint2)) where oidOf = LibPQ.Oid 1005 -instance HasOid ('PGvararray (null 'PGint2)) where oidOf = LibPQ.Oid 1005 -instance HasOid 'PGint4 where oidOf = LibPQ.Oid 23 -instance HasOid ('PGfixarray ns (null 'PGint4)) where oidOf = LibPQ.Oid 1007 -instance HasOid ('PGvararray (null 'PGint4)) where oidOf = LibPQ.Oid 1007 -instance HasOid 'PGint8 where oidOf = LibPQ.Oid 20 -instance HasOid ('PGfixarray ns (null 'PGint8)) where oidOf = LibPQ.Oid 1016 -instance HasOid ('PGvararray (null 'PGint8)) where oidOf = LibPQ.Oid 1016 -instance HasOid 'PGnumeric where oidOf = LibPQ.Oid 1700 -instance HasOid ('PGfixarray ns (null 'PGnumeric)) where oidOf = LibPQ.Oid 1231 -instance HasOid ('PGvararray (null 'PGnumeric)) where oidOf = LibPQ.Oid 1231 -instance HasOid 'PGfloat4 where oidOf = LibPQ.Oid 700 -instance HasOid ('PGfixarray ns (null 'PGfloat4)) where oidOf = LibPQ.Oid 1021 -instance HasOid ('PGvararray (null 'PGfloat4)) where oidOf = LibPQ.Oid 1021 -instance HasOid 'PGfloat8 where oidOf = LibPQ.Oid 701 -instance HasOid ('PGfixarray ns (null 'PGfloat8)) where oidOf = LibPQ.Oid 1022 -instance HasOid ('PGvararray (null 'PGfloat8)) where oidOf = LibPQ.Oid 1022 -instance HasOid 'PGmoney where oidOf = LibPQ.Oid 790 -instance HasOid ('PGfixarray ns (null 'PGmoney)) where oidOf = LibPQ.Oid 791 -instance HasOid ('PGvararray (null 'PGmoney)) where oidOf = LibPQ.Oid 791 -instance HasOid ('PGchar n) where oidOf = LibPQ.Oid 18 -instance HasOid ('PGfixarray ns (null ('PGchar n))) where oidOf = LibPQ.Oid 1002 -instance HasOid ('PGvararray (null ('PGchar n))) where oidOf = LibPQ.Oid 1002 -instance HasOid ('PGvarchar n) where oidOf = LibPQ.Oid 1043 -instance HasOid ('PGfixarray ns (null ('PGvarchar n))) where oidOf = LibPQ.Oid 1015 -instance HasOid ('PGvararray (null ('PGvarchar n))) where oidOf = LibPQ.Oid 1015 -instance HasOid 'PGtext where oidOf = LibPQ.Oid 25 -instance HasOid ('PGfixarray ns (null 'PGtext)) where oidOf = LibPQ.Oid 1009 -instance HasOid ('PGvararray (null 'PGtext)) where oidOf = LibPQ.Oid 1009 -instance HasOid 'PGbytea where oidOf = LibPQ.Oid 17 -instance HasOid ('PGfixarray ns (null 'PGbytea)) where oidOf = LibPQ.Oid 1001 -instance HasOid ('PGvararray (null 'PGbytea)) where oidOf = LibPQ.Oid 1001 -instance HasOid 'PGtimestamp where oidOf = LibPQ.Oid 1114 -instance HasOid ('PGfixarray ns (null 'PGtimestamp)) where oidOf = LibPQ.Oid 1115 -instance HasOid ('PGvararray (null 'PGtimestamp)) where oidOf = LibPQ.Oid 1115 -instance HasOid 'PGtimestamptz where oidOf = LibPQ.Oid 1184 -instance HasOid ('PGfixarray ns (null 'PGtimestamptz)) where oidOf = LibPQ.Oid 1185 -instance HasOid ('PGvararray (null 'PGtimestamptz)) where oidOf = LibPQ.Oid 1185 -instance HasOid 'PGdate where oidOf = LibPQ.Oid 1082 -instance HasOid ('PGfixarray ns (null 'PGdate)) where oidOf = LibPQ.Oid 1182 -instance HasOid ('PGvararray (null 'PGdate)) where oidOf = LibPQ.Oid 1182 -instance HasOid 'PGtime where oidOf = LibPQ.Oid 1083 -instance HasOid ('PGfixarray ns (null 'PGtime)) where oidOf = LibPQ.Oid 1183 -instance HasOid ('PGvararray (null 'PGtime)) where oidOf = LibPQ.Oid 1183 -instance HasOid 'PGtimetz where oidOf = LibPQ.Oid 1266 -instance HasOid ('PGfixarray ns (null 'PGtimetz)) where oidOf = LibPQ.Oid 1270 -instance HasOid ('PGvararray (null 'PGtimetz)) where oidOf = LibPQ.Oid 1270 -instance HasOid 'PGinterval where oidOf = LibPQ.Oid 1186 -instance HasOid ('PGfixarray ns (null 'PGinterval)) where oidOf = LibPQ.Oid 1187 -instance HasOid ('PGvararray (null 'PGinterval)) where oidOf = LibPQ.Oid 1187 -instance HasOid 'PGuuid where oidOf = LibPQ.Oid 2950 -instance HasOid ('PGfixarray ns (null 'PGuuid)) where oidOf = LibPQ.Oid 2951 -instance HasOid ('PGvararray (null 'PGuuid)) where oidOf = LibPQ.Oid 2951 -instance HasOid 'PGinet where oidOf = LibPQ.Oid 869 -instance HasOid ('PGfixarray ns (null 'PGinet)) where oidOf = LibPQ.Oid 1041 -instance HasOid ('PGvararray (null 'PGinet)) where oidOf = LibPQ.Oid 1041 -instance HasOid 'PGjson where oidOf = LibPQ.Oid 114 -instance HasOid ('PGfixarray ns (null 'PGjson)) where oidOf = LibPQ.Oid 199 -instance HasOid ('PGvararray (null 'PGjson)) where oidOf = LibPQ.Oid 199 -instance HasOid 'PGjsonb where oidOf = LibPQ.Oid 3802 -instance HasOid ('PGfixarray ns (null 'PGjsonb)) where oidOf = LibPQ.Oid 3807 -instance HasOid ('PGvararray (null 'PGjsonb)) where oidOf = LibPQ.Oid 3807 -instance HasOid 'PGtsvector where oidOf = LibPQ.Oid 3614 -instance HasOid ('PGfixarray ns (null 'PGtsvector)) where oidOf = LibPQ.Oid 3643 -instance HasOid ('PGvararray (null 'PGtsvector)) where oidOf = LibPQ.Oid 3643 -instance HasOid 'PGtsquery where oidOf = LibPQ.Oid 3615 -instance HasOid ('PGfixarray ns (null 'PGtsquery)) where oidOf = LibPQ.Oid 3645 -instance HasOid ('PGvararray (null 'PGtsquery)) where oidOf = LibPQ.Oid 3645 -instance HasOid 'PGoid where oidOf = LibPQ.Oid 26 -instance HasOid ('PGfixarray ns (null 'PGoid)) where oidOf = LibPQ.Oid 1028 -instance HasOid ('PGvararray (null 'PGoid)) where oidOf = LibPQ.Oid 1028 -instance HasOid ('PGrange 'PGint4) where oidOf = LibPQ.Oid 3904 -instance HasOid ('PGfixarray ns (null ('PGrange 'PGint4))) where oidOf = LibPQ.Oid 3905 -instance HasOid ('PGvararray (null ('PGrange 'PGint4))) where oidOf = LibPQ.Oid 3905 -instance HasOid ('PGrange 'PGint8) where oidOf = LibPQ.Oid 3926 -instance HasOid ('PGfixarray ns (null ('PGrange 'PGint8))) where oidOf = LibPQ.Oid 3927 -instance HasOid ('PGvararray (null ('PGrange 'PGint8))) where oidOf = LibPQ.Oid 3927 -instance HasOid ('PGrange 'PGnumeric) where oidOf = LibPQ.Oid 3906 -instance HasOid ('PGfixarray ns (null ('PGrange 'PGnumeric))) where oidOf = LibPQ.Oid 3907 -instance HasOid ('PGvararray (null ('PGrange 'PGnumeric))) where oidOf = LibPQ.Oid 3907 -instance HasOid ('PGrange 'PGtimestamp) where oidOf = LibPQ.Oid 3908 -instance HasOid ('PGfixarray ns (null ('PGrange 'PGtimestamp))) where oidOf = LibPQ.Oid 3909 -instance HasOid ('PGvararray (null ('PGrange 'PGtimestamp))) where oidOf = LibPQ.Oid 3909 -instance HasOid ('PGrange 'PGtimestamptz) where oidOf = LibPQ.Oid 3910 -instance HasOid ('PGfixarray ns (null ('PGrange 'PGtimestamptz))) where oidOf = LibPQ.Oid 3911 -instance HasOid ('PGvararray (null ('PGrange 'PGtimestamptz))) where oidOf = LibPQ.Oid 3911 -instance HasOid ('PGrange 'PGdate) where oidOf = LibPQ.Oid 3912 -instance HasOid ('PGfixarray ns (null ('PGrange 'PGdate))) where oidOf = LibPQ.Oid 3913 -instance HasOid ('PGvararray (null ('PGrange 'PGdate))) where oidOf = LibPQ.Oid 3913 -instance {-# OVERLAPPABLE #-} HasOid ('PGrange ty) where oidOf = LibPQ.invalidOid -instance {-# OVERLAPPABLE #-} HasOid ('PGfixarray ns (null ('PGrange ty))) where oidOf = LibPQ.invalidOid -instance {-# OVERLAPPABLE #-} HasOid ('PGvararray (null ('PGrange ty))) where oidOf = LibPQ.invalidOid -instance {-# OVERLAPPABLE #-} HasOid ('PGcomposite row) where oidOf = LibPQ.invalidOid -instance {-# OVERLAPPABLE #-} HasOid ('PGfixarray ns (null ('PGcomposite row))) where oidOf = LibPQ.invalidOid -instance {-# OVERLAPPABLE #-} HasOid ('PGvararray (null ('PGcomposite row))) where oidOf = LibPQ.invalidOid -instance {-# OVERLAPPABLE #-} HasOid ('PGenum labels) where oidOf = LibPQ.invalidOid -instance {-# OVERLAPPABLE #-} HasOid ('PGfixarray ns (null ('PGenum labels))) where oidOf = LibPQ.invalidOid -instance {-# OVERLAPPABLE #-} HasOid ('PGvararray (null ('PGenum labels))) where oidOf = LibPQ.invalidOid +class OidOf (ty :: PGType) where oidOf :: LibPQ.Oid +instance OidOf 'PGbool where oidOf = LibPQ.Oid 16 +instance OidOf ('PGfixarray ns (null 'PGbool)) where oidOf = LibPQ.Oid 1000 +instance OidOf ('PGvararray (null 'PGbool)) where oidOf = LibPQ.Oid 1000 +instance OidOf 'PGint2 where oidOf = LibPQ.Oid 21 +instance OidOf ('PGfixarray ns (null 'PGint2)) where oidOf = LibPQ.Oid 1005 +instance OidOf ('PGvararray (null 'PGint2)) where oidOf = LibPQ.Oid 1005 +instance OidOf 'PGint4 where oidOf = LibPQ.Oid 23 +instance OidOf ('PGfixarray ns (null 'PGint4)) where oidOf = LibPQ.Oid 1007 +instance OidOf ('PGvararray (null 'PGint4)) where oidOf = LibPQ.Oid 1007 +instance OidOf 'PGint8 where oidOf = LibPQ.Oid 20 +instance OidOf ('PGfixarray ns (null 'PGint8)) where oidOf = LibPQ.Oid 1016 +instance OidOf ('PGvararray (null 'PGint8)) where oidOf = LibPQ.Oid 1016 +instance OidOf 'PGnumeric where oidOf = LibPQ.Oid 1700 +instance OidOf ('PGfixarray ns (null 'PGnumeric)) where oidOf = LibPQ.Oid 1231 +instance OidOf ('PGvararray (null 'PGnumeric)) where oidOf = LibPQ.Oid 1231 +instance OidOf 'PGfloat4 where oidOf = LibPQ.Oid 700 +instance OidOf ('PGfixarray ns (null 'PGfloat4)) where oidOf = LibPQ.Oid 1021 +instance OidOf ('PGvararray (null 'PGfloat4)) where oidOf = LibPQ.Oid 1021 +instance OidOf 'PGfloat8 where oidOf = LibPQ.Oid 701 +instance OidOf ('PGfixarray ns (null 'PGfloat8)) where oidOf = LibPQ.Oid 1022 +instance OidOf ('PGvararray (null 'PGfloat8)) where oidOf = LibPQ.Oid 1022 +instance OidOf 'PGmoney where oidOf = LibPQ.Oid 790 +instance OidOf ('PGfixarray ns (null 'PGmoney)) where oidOf = LibPQ.Oid 791 +instance OidOf ('PGvararray (null 'PGmoney)) where oidOf = LibPQ.Oid 791 +instance OidOf ('PGchar n) where oidOf = LibPQ.Oid 18 +instance OidOf ('PGfixarray ns (null ('PGchar n))) where oidOf = LibPQ.Oid 1002 +instance OidOf ('PGvararray (null ('PGchar n))) where oidOf = LibPQ.Oid 1002 +instance OidOf ('PGvarchar n) where oidOf = LibPQ.Oid 1043 +instance OidOf ('PGfixarray ns (null ('PGvarchar n))) where oidOf = LibPQ.Oid 1015 +instance OidOf ('PGvararray (null ('PGvarchar n))) where oidOf = LibPQ.Oid 1015 +instance OidOf 'PGtext where oidOf = LibPQ.Oid 25 +instance OidOf ('PGfixarray ns (null 'PGtext)) where oidOf = LibPQ.Oid 1009 +instance OidOf ('PGvararray (null 'PGtext)) where oidOf = LibPQ.Oid 1009 +instance OidOf 'PGbytea where oidOf = LibPQ.Oid 17 +instance OidOf ('PGfixarray ns (null 'PGbytea)) where oidOf = LibPQ.Oid 1001 +instance OidOf ('PGvararray (null 'PGbytea)) where oidOf = LibPQ.Oid 1001 +instance OidOf 'PGtimestamp where oidOf = LibPQ.Oid 1114 +instance OidOf ('PGfixarray ns (null 'PGtimestamp)) where oidOf = LibPQ.Oid 1115 +instance OidOf ('PGvararray (null 'PGtimestamp)) where oidOf = LibPQ.Oid 1115 +instance OidOf 'PGtimestamptz where oidOf = LibPQ.Oid 1184 +instance OidOf ('PGfixarray ns (null 'PGtimestamptz)) where oidOf = LibPQ.Oid 1185 +instance OidOf ('PGvararray (null 'PGtimestamptz)) where oidOf = LibPQ.Oid 1185 +instance OidOf 'PGdate where oidOf = LibPQ.Oid 1082 +instance OidOf ('PGfixarray ns (null 'PGdate)) where oidOf = LibPQ.Oid 1182 +instance OidOf ('PGvararray (null 'PGdate)) where oidOf = LibPQ.Oid 1182 +instance OidOf 'PGtime where oidOf = LibPQ.Oid 1083 +instance OidOf ('PGfixarray ns (null 'PGtime)) where oidOf = LibPQ.Oid 1183 +instance OidOf ('PGvararray (null 'PGtime)) where oidOf = LibPQ.Oid 1183 +instance OidOf 'PGtimetz where oidOf = LibPQ.Oid 1266 +instance OidOf ('PGfixarray ns (null 'PGtimetz)) where oidOf = LibPQ.Oid 1270 +instance OidOf ('PGvararray (null 'PGtimetz)) where oidOf = LibPQ.Oid 1270 +instance OidOf 'PGinterval where oidOf = LibPQ.Oid 1186 +instance OidOf ('PGfixarray ns (null 'PGinterval)) where oidOf = LibPQ.Oid 1187 +instance OidOf ('PGvararray (null 'PGinterval)) where oidOf = LibPQ.Oid 1187 +instance OidOf 'PGuuid where oidOf = LibPQ.Oid 2950 +instance OidOf ('PGfixarray ns (null 'PGuuid)) where oidOf = LibPQ.Oid 2951 +instance OidOf ('PGvararray (null 'PGuuid)) where oidOf = LibPQ.Oid 2951 +instance OidOf 'PGinet where oidOf = LibPQ.Oid 869 +instance OidOf ('PGfixarray ns (null 'PGinet)) where oidOf = LibPQ.Oid 1041 +instance OidOf ('PGvararray (null 'PGinet)) where oidOf = LibPQ.Oid 1041 +instance OidOf 'PGjson where oidOf = LibPQ.Oid 114 +instance OidOf ('PGfixarray ns (null 'PGjson)) where oidOf = LibPQ.Oid 199 +instance OidOf ('PGvararray (null 'PGjson)) where oidOf = LibPQ.Oid 199 +instance OidOf 'PGjsonb where oidOf = LibPQ.Oid 3802 +instance OidOf ('PGfixarray ns (null 'PGjsonb)) where oidOf = LibPQ.Oid 3807 +instance OidOf ('PGvararray (null 'PGjsonb)) where oidOf = LibPQ.Oid 3807 +instance OidOf 'PGtsvector where oidOf = LibPQ.Oid 3614 +instance OidOf ('PGfixarray ns (null 'PGtsvector)) where oidOf = LibPQ.Oid 3643 +instance OidOf ('PGvararray (null 'PGtsvector)) where oidOf = LibPQ.Oid 3643 +instance OidOf 'PGtsquery where oidOf = LibPQ.Oid 3615 +instance OidOf ('PGfixarray ns (null 'PGtsquery)) where oidOf = LibPQ.Oid 3645 +instance OidOf ('PGvararray (null 'PGtsquery)) where oidOf = LibPQ.Oid 3645 +instance OidOf 'PGoid where oidOf = LibPQ.Oid 26 +instance OidOf ('PGfixarray ns (null 'PGoid)) where oidOf = LibPQ.Oid 1028 +instance OidOf ('PGvararray (null 'PGoid)) where oidOf = LibPQ.Oid 1028 +instance OidOf ('PGrange 'PGint4) where oidOf = LibPQ.Oid 3904 +instance OidOf ('PGfixarray ns (null ('PGrange 'PGint4))) where oidOf = LibPQ.Oid 3905 +instance OidOf ('PGvararray (null ('PGrange 'PGint4))) where oidOf = LibPQ.Oid 3905 +instance OidOf ('PGrange 'PGint8) where oidOf = LibPQ.Oid 3926 +instance OidOf ('PGfixarray ns (null ('PGrange 'PGint8))) where oidOf = LibPQ.Oid 3927 +instance OidOf ('PGvararray (null ('PGrange 'PGint8))) where oidOf = LibPQ.Oid 3927 +instance OidOf ('PGrange 'PGnumeric) where oidOf = LibPQ.Oid 3906 +instance OidOf ('PGfixarray ns (null ('PGrange 'PGnumeric))) where oidOf = LibPQ.Oid 3907 +instance OidOf ('PGvararray (null ('PGrange 'PGnumeric))) where oidOf = LibPQ.Oid 3907 +instance OidOf ('PGrange 'PGtimestamp) where oidOf = LibPQ.Oid 3908 +instance OidOf ('PGfixarray ns (null ('PGrange 'PGtimestamp))) where oidOf = LibPQ.Oid 3909 +instance OidOf ('PGvararray (null ('PGrange 'PGtimestamp))) where oidOf = LibPQ.Oid 3909 +instance OidOf ('PGrange 'PGtimestamptz) where oidOf = LibPQ.Oid 3910 +instance OidOf ('PGfixarray ns (null ('PGrange 'PGtimestamptz))) where oidOf = LibPQ.Oid 3911 +instance OidOf ('PGvararray (null ('PGrange 'PGtimestamptz))) where oidOf = LibPQ.Oid 3911 +instance OidOf ('PGrange 'PGdate) where oidOf = LibPQ.Oid 3912 +instance OidOf ('PGfixarray ns (null ('PGrange 'PGdate))) where oidOf = LibPQ.Oid 3913 +instance OidOf ('PGvararray (null ('PGrange 'PGdate))) where oidOf = LibPQ.Oid 3913 +instance {-# OVERLAPPABLE #-} OidOf ('PGrange ty) where oidOf = LibPQ.invalidOid +instance {-# OVERLAPPABLE #-} OidOf ('PGfixarray ns (null ('PGrange ty))) where oidOf = LibPQ.invalidOid +instance {-# OVERLAPPABLE #-} OidOf ('PGvararray (null ('PGrange ty))) where oidOf = LibPQ.invalidOid +instance {-# OVERLAPPABLE #-} OidOf ('PGcomposite row) where oidOf = LibPQ.invalidOid +instance {-# OVERLAPPABLE #-} OidOf ('PGfixarray ns (null ('PGcomposite row))) where oidOf = LibPQ.invalidOid +instance {-# OVERLAPPABLE #-} OidOf ('PGvararray (null ('PGcomposite row))) where oidOf = LibPQ.invalidOid +instance {-# OVERLAPPABLE #-} OidOf ('PGenum labels) where oidOf = LibPQ.invalidOid +instance {-# OVERLAPPABLE #-} OidOf ('PGfixarray ns (null ('PGenum labels))) where oidOf = LibPQ.invalidOid +instance {-# OVERLAPPABLE #-} OidOf ('PGvararray (null ('PGenum labels))) where oidOf = LibPQ.invalidOid -class HasOidParam (ty :: NullityType) where oidOfParam :: Oid -instance HasOid ty => HasOidParam (null ty) where oidOfParam = oidOf @ty +class OidOfParam (ty :: NullityType) where oidOfParam :: Oid +instance OidOf ty => OidOfParam (null ty) where oidOfParam = oidOf @ty --- | Lifts a `HasOid` constraint to a field. -class HasAliasedOid (field :: (Symbol, NullityType)) where - aliasedOid :: Oid -instance HasOid ty => HasAliasedOid (alias ::: nullity ty) where - aliasedOid = oidOf @ty +-- | Lifts a `OidOf` constraint to a field. +class OidOfField (field :: (Symbol, NullityType)) where + oidOfField :: Oid +instance OidOf ty => OidOfField (alias ::: nullity ty) where + oidOfField = oidOf @ty -- | A `ToNullityParam` constraint gives an encoding of a Haskell `Type` into -- into the binary format of a PostgreSQL `NullityType`. diff --git a/squeal-postgresql/src/Squeal/PostgreSQL/PQ.hs b/squeal-postgresql/src/Squeal/PostgreSQL/PQ.hs index 60493e7..3a80913 100644 --- a/squeal-postgresql/src/Squeal/PostgreSQL/PQ.hs +++ b/squeal-postgresql/src/Squeal/PostgreSQL/PQ.hs @@ -317,13 +317,13 @@ a default instance. -} class Monad pq => MonadPQ schemas pq | pq -> schemas where manipulateParams - :: (ToParams x params, All HasOidParam params) + :: (ToParams x params, All OidOfParam params) => Manipulation '[] schemas params ys -- ^ `insertInto`, `update` or `deleteFrom` -> x -> pq (K LibPQ.Result ys) default manipulateParams :: (MonadTrans t, MonadPQ schemas pq1, pq ~ t pq1) - => (ToParams x params, All HasOidParam params) + => (ToParams x params, All OidOfParam params) => Manipulation '[] schemas params ys -- ^ `insertInto`, `update` or `deleteFrom` -> x -> pq (K LibPQ.Result ys) @@ -331,7 +331,7 @@ class Monad pq => MonadPQ schemas pq | pq -> schemas where manipulateParams manipulation params manipulateParams_ - :: (ToParams x params, All HasOidParam params) + :: (ToParams x params, All OidOfParam params) => Manipulation '[] schemas params '[] -- ^ `insertInto`, `update` or `deleteFrom` -> x -> pq () @@ -344,7 +344,7 @@ class Monad pq => MonadPQ schemas pq | pq -> schemas where manipulate_ = void . manipulate runQueryParams - :: (ToParams x params, All HasOidParam params) + :: (ToParams x params, All OidOfParam params) => Query '[] '[] schemas params ys -- ^ `select` and friends -> x -> pq (K LibPQ.Result ys) @@ -357,19 +357,19 @@ class Monad pq => MonadPQ schemas pq | pq -> schemas where runQuery q = runQueryParams q () traversePrepared - :: (ToParams x params, Traversable list, All HasOidParam params) + :: (ToParams x params, Traversable list, All OidOfParam params) => Manipulation '[] schemas params ys -- ^ `insertInto`, `update`, or `deleteFrom`, and friends -> list x -> pq (list (K LibPQ.Result ys)) default traversePrepared :: (MonadTrans t, MonadPQ schemas pq1, pq ~ t pq1) - => (ToParams x params, Traversable list, All HasOidParam params) + => (ToParams x params, Traversable list, All OidOfParam params) => Manipulation '[] schemas params ys -> list x -> pq (list (K LibPQ.Result ys)) traversePrepared manipulation params = lift $ traversePrepared manipulation params forPrepared - :: (ToParams x params, Traversable list, All HasOidParam params) + :: (ToParams x params, Traversable list, All OidOfParam params) => list x -> Manipulation '[] schemas params ys -- ^ `insertInto`, `update` or `deleteFrom` @@ -377,13 +377,13 @@ class Monad pq => MonadPQ schemas pq | pq -> schemas where forPrepared = flip traversePrepared traversePrepared_ - :: (ToParams x params, Foldable list, All HasOidParam params) + :: (ToParams x params, Foldable list, All OidOfParam params) => Manipulation '[] schemas params '[] -- ^ `insertInto`, `update` or `deleteFrom` -> list x -> pq () default traversePrepared_ :: (MonadTrans t, MonadPQ schemas pq1, pq ~ t pq1) - => (ToParams x params, Foldable list, All HasOidParam params) + => (ToParams x params, Foldable list, All OidOfParam params) => Manipulation '[] schemas params '[] -- ^ `insertInto`, `update` or `deleteFrom` -> list x -> pq () @@ -391,7 +391,7 @@ class Monad pq => MonadPQ schemas pq | pq -> schemas where traversePrepared_ manipulation params forPrepared_ - :: (ToParams x params, Foldable list, All HasOidParam params) + :: (ToParams x params, Foldable list, All OidOfParam params) => list x -> Manipulation '[] schemas params '[] -- ^ `insertInto`, `update` or `deleteFrom` @@ -412,7 +412,7 @@ instance (MonadIO io, schemas0 ~ schemas, schemas1 ~ schemas) PQ $ \ (K conn) -> do let paramSet - :: forall param. HasOidParam param + :: forall param. OidOfParam param => K (Maybe Encoding.Encoding) param -> K (Maybe (LibPQ.Oid, ByteString, LibPQ.Format)) param paramSet (K maybeEncoding) = K $ @@ -420,7 +420,7 @@ instance (MonadIO io, schemas0 ~ schemas, schemas1 ~ schemas) (oidOfParam @param, encodingBytes encoding, LibPQ.Binary) params' = hcollapse - . hcmap (Proxy @HasOidParam) paramSet + . hcmap (Proxy @OidOfParam) paramSet $ toParams @x @ps params q' = q <> ";" resultMaybe <- liftIO $ LibPQ.execParams conn q' params' LibPQ.Binary @@ -436,10 +436,10 @@ instance (MonadIO io, schemas0 ~ schemas, schemas1 ~ schemas) PQ $ \ (K conn) -> liftIO $ do let temp = "temporary_statement" - paramOid :: forall p. HasOidParam p => K LibPQ.Oid p + paramOid :: forall p. OidOfParam p => K LibPQ.Oid p paramOid = K (oidOfParam @p) paramOids :: NP (K LibPQ.Oid) xs - paramOids = hcpure (Proxy @HasOidParam) paramOid + paramOids = hcpure (Proxy @OidOfParam) paramOid paramOids' :: [LibPQ.Oid] paramOids' = hcollapse paramOids prepResultMaybe <- LibPQ.prepare conn temp q (Just paramOids') @@ -470,10 +470,10 @@ instance (MonadIO io, schemas0 ~ schemas, schemas1 ~ schemas) PQ $ \ (K conn) -> liftIO $ do let temp = "temporary_statement" - paramOid :: forall p. HasOidParam p => K LibPQ.Oid p + paramOid :: forall p. OidOfParam p => K LibPQ.Oid p paramOid = K (oidOfParam @p) paramOids :: NP (K LibPQ.Oid) xs - paramOids = hcpure (Proxy @HasOidParam) paramOid + paramOids = hcpure (Proxy @OidOfParam) paramOid paramOids' :: [LibPQ.Oid] paramOids' = hcollapse paramOids prepResultMaybe <- LibPQ.prepare conn temp q (Just paramOids') diff --git a/squeal-postgresql/test/Property.hs b/squeal-postgresql/test/Property.hs index f125bb1..f2e74a9 100644 --- a/squeal-postgresql/test/Property.hs +++ b/squeal-postgresql/test/Property.hs @@ -92,14 +92,14 @@ roundtrips = Group "roundtrips" -- genTimeWithZone = (,) <$> genTimeOfDay <*> genTimeZone roundtrip - :: (HasOid ty, ToParam x ty, FromValue ty x, Show x, Eq x) + :: (OidOf ty, ToParam x ty, FromValue ty x, Show x, Eq x) => TypeExpression schemas ('NotNull ty) -> Gen x -> (PropertyName, Property) roundtrip = roundtripOn id roundtripOn - :: (HasOid ty, ToParam x ty, FromValue ty x, Show x, Eq x) + :: (OidOf ty, ToParam x ty, FromValue ty x, Show x, Eq x) => (x -> x) -> TypeExpression schemas ('NotNull ty) -> Gen x