on dev help sign in
oid
commitf0f3e4f653ac5ee4f12a565739457e0109c1bb73 authorEitan Chatav <eitan@EEM109LMBP-1.simspace.lan> dateThu 15 Aug 2019, 13:19 (7 years ago) parent83c711a
5 files changed+40−38
squeal-postgresql/src/Squeal/PostgreSQL/Binary.hs+30−31 squeal-postgresql/src/Squeal/PostgreSQL/Expression/Type.hs+6 squeal-postgresql/src/Squeal/PostgreSQL/List.hs+1−1 squeal-postgresql/src/Squeal/PostgreSQL/PG.hs+2−6 squeal-postgresql/src/Squeal/PostgreSQL/Schema.hs+1
squeal-postgresql/src/Squeal/PostgreSQL/Binary.hs+30−31
@@ -274,11 +274,9 @@ class ToParam (x :: Type) (pg :: PGType) where
274274 toParam :: x -> K Encoding.Encoding pg
275275instance ToParam Bool 'PGbool where toParam = K . Encoding.bool
276276instance ToParam Int16 'PGint2 where toParam = K . Encoding.int2_int16
277−instance ToParam Word16 'PGint2 where toParam = K . Encoding.int2_word16
278277instance ToParam Int32 'PGint4 where toParam = K . Encoding.int4_int32
279−instance ToParam Word32 'PGint4 where toParam = K . Encoding.int4_word32
280278instance ToParam Int64 'PGint8 where toParam = K . Encoding.int8_int64
281−instance ToParam Word64 'PGint8 where toParam = K . Encoding.int8_word64
279+instance ToParam Word32 'PGoid where toParam = K . Encoding.int4_word32
282280instance ToParam Float 'PGfloat4 where toParam = K . Encoding.float4
283281instance ToParam Double 'PGfloat8 where toParam = K . Encoding.float8
284282instance ToParam Scientific 'PGnumeric where toParam = K . Encoding.numeric
@@ -314,21 +312,21 @@ instance Aeson.ToJSON x => ToParam (Jsonb x) 'PGjsonb where
314312instance (ToNullityParam x ty, ty ~ nullity pg, HasOid pg)
315313 => ToParam (VarArray [x]) ('PGvararray ty) where
316314 toParam = K
317− . Encoding.array_foldable (oid @pg) (unK . toNullityParam @x @ty)
315+ . Encoding.array_foldable (oidOf @pg) (unK . toNullityParam @x @ty)
318316 . getVarArray
319317instance (ToParam x pg, HasOid pg)
320318 => ToParam (VarArray (Vector x)) ('PGvararray ('NotNull pg)) where
321319 toParam = K
322− . Encoding.array_vector (oid @pg) (unK . toParam @x @pg)
320+ . Encoding.array_vector (oidOf @pg) (unK . toParam @x @pg)
323321 . getVarArray
324322instance (ToParam x pg, HasOid pg)
325323 => ToParam (VarArray (Vector (Maybe x))) ('PGvararray ('Null pg)) where
326324 toParam = K
327− . Encoding.nullableArray_vector (oid @pg) (unK . toParam @x @pg)
325+ . Encoding.nullableArray_vector (oidOf @pg) (unK . toParam @x @pg)
328326 . getVarArray
329327instance (ToFixArray x dims ty, ty ~ nullity pg, HasOid pg)
330328 => ToParam (FixArray x) ('PGfixarray dims ty) where
331− toParam = K . Encoding.array (oid @pg)
329+ toParam = K . Encoding.array (oidOf @pg)
332330 . unK . unK . toFixArray @x @dims @ty . getFixArray
333331instance
334332 ( IsEnumType x
@@ -397,36 +395,36 @@ instance
397395-- | The object identifier of a `PGType`.
398396--
399397-- >>> :set -XTypeApplications
400−-- >>> oid @'PGbool
398+-- >>> oidOf @'PGbool
401399-- 16
402−class HasOid (ty :: PGType) where oid :: Word32
403−instance HasOid 'PGbool where oid = 16
404−instance HasOid 'PGint2 where oid = 21
405−instance HasOid 'PGint4 where oid = 23
406−instance HasOid 'PGint8 where oid = 20
407−instance HasOid 'PGnumeric where oid = 1700
408−instance HasOid 'PGfloat4 where oid = 700
409−instance HasOid 'PGfloat8 where oid = 701
410−instance HasOid ('PGchar n) where oid = 18
411−instance HasOid ('PGvarchar n) where oid = 1043
412−instance HasOid 'PGtext where oid = 25
413−instance HasOid 'PGbytea where oid = 17
414−instance HasOid 'PGtimestamp where oid = 1114
415−instance HasOid 'PGtimestamptz where oid = 1184
416−instance HasOid 'PGdate where oid = 1082
417−instance HasOid 'PGtime where oid = 1083
418−instance HasOid 'PGtimetz where oid = 1266
419−instance HasOid 'PGinterval where oid = 1186
420−instance HasOid 'PGuuid where oid = 2950
421−instance HasOid 'PGinet where oid = 869
422−instance HasOid 'PGjson where oid = 114
423−instance HasOid 'PGjsonb where oid = 3802
400+class HasOid (ty :: PGType) where oidOf :: Word32
401+instance HasOid 'PGbool where oidOf = 16
402+instance HasOid 'PGint2 where oidOf = 21
403+instance HasOid 'PGint4 where oidOf = 23
404+instance HasOid 'PGint8 where oidOf = 20
405+instance HasOid 'PGnumeric where oidOf = 1700
406+instance HasOid 'PGfloat4 where oidOf = 700
407+instance HasOid 'PGfloat8 where oidOf = 701
408+instance HasOid ('PGchar n) where oidOf = 18
409+instance HasOid ('PGvarchar n) where oidOf = 1043
410+instance HasOid 'PGtext where oidOf = 25
411+instance HasOid 'PGbytea where oidOf = 17
412+instance HasOid 'PGtimestamp where oidOf = 1114
413+instance HasOid 'PGtimestamptz where oidOf = 1184
414+instance HasOid 'PGdate where oidOf = 1082
415+instance HasOid 'PGtime where oidOf = 1083
416+instance HasOid 'PGtimetz where oidOf = 1266
417+instance HasOid 'PGinterval where oidOf = 1186
418+instance HasOid 'PGuuid where oidOf = 2950
419+instance HasOid 'PGinet where oidOf = 869
420+instance HasOid 'PGjson where oidOf = 114
421+instance HasOid 'PGjsonb where oidOf = 3802
424422
425423-- | Lifts a `HasOid` constraint to a field.
426424class HasAliasedOid (field :: (Symbol, NullityType)) where
427425 aliasedOid :: Word32
428426instance HasOid ty => HasAliasedOid (alias ::: nullity ty) where
429− aliasedOid = oid @ty
427+ aliasedOid = oidOf @ty
430428
431429-- | A `ToNullityParam` constraint gives an encoding of a Haskell `Type` into
432430-- into the binary format of a PostgreSQL `NullityType`.
@@ -495,6 +493,7 @@ instance FromValue 'PGbool Bool where fromValue = Decoding.bool
495493instance FromValue 'PGint2 Int16 where fromValue = Decoding.int
496494instance FromValue 'PGint4 Int32 where fromValue = Decoding.int
497495instance FromValue 'PGint8 Int64 where fromValue = Decoding.int
496+instance FromValue 'PGoid Word32 where fromValue = Decoding.int
498497instance FromValue 'PGfloat4 Float where fromValue = Decoding.float4
499498instance FromValue 'PGfloat8 Double where fromValue = Decoding.float8
500499instance FromValue 'PGnumeric Scientific where fromValue = Decoding.numeric
squeal-postgresql/src/Squeal/PostgreSQL/Expression/Type.hs+6
@@ -68,6 +68,7 @@ module Squeal.PostgreSQL.Expression.Type
6868 , fixarray
6969 , tsvector
7070 , tsquery
71+ , oid
7172 ) where
7273
7374import Control.DeepSeq
@@ -270,6 +271,10 @@ tsvector = UnsafeTypeExpression "tsvector"
270271-- | text search document
271272tsquery :: TypeExpression schemas (null 'PGtsquery)
272273tsquery = UnsafeTypeExpression "tsquery"
274+-- | Object identifiers (OIDs) are used internally by PostgreSQL
275+-- as primary keys for various system tables.
276+oid :: TypeExpression schemas (null 'PGoid)
277+oid = UnsafeTypeExpression "oid"
273278
274279-- | `pgtype` is a demoted version of a `PGType`
275280class PGTyped schemas (ty :: NullityType) where
@@ -305,3 +310,4 @@ instance (SOP.All KnownNat dims, PGTyped schemas ty)
305310 pgtype = fixarray @dims (pgtype @schemas @ty)
306311instance PGTyped schemas (null 'PGtsvector) where pgtype = tsvector
307312instance PGTyped schemas (null 'PGtsquery) where pgtype = tsquery
313+instance PGTyped schemas (null 'PGoid) where pgtype = oid
squeal-postgresql/src/Squeal/PostgreSQL/List.hs+1−1
@@ -128,7 +128,7 @@ type family Elem x xs where
128128-- | @In x xs@ is a constraint that proves that @x@ is in @xs@.
129129type family In x xs :: Constraint where
130130 In x xs = If (Elem x xs) (() :: Constraint)
131− (TypeError ('ShowType x ':<>: 'Text "is not in " ':<>: 'ShowType xs))
131+ (TypeError ('ShowType x ':<>: 'Text " is not in " ':<>: 'ShowType xs))
132132
133133{- | Calculate the `Length` of a type level list
134134
squeal-postgresql/src/Squeal/PostgreSQL/PG.hs+2−6
@@ -63,7 +63,7 @@ import Data.Int (Int16, Int32, Int64)
6363import Data.Scientific (Scientific)
6464import Data.Time (Day, DiffTime, LocalTime, TimeOfDay, TimeZone, UTCTime)
6565import Data.Vector (Vector)
66−import Data.Word (Word16, Word32, Word64)
66+import Data.Word (Word32)
6767import Data.UUID.Types (UUID)
6868import GHC.TypeLits
6969import Network.IP.Addr (NetAddr, IP)
@@ -105,11 +105,7 @@ type instance PG Int32 = 'PGint4
105105-- | `PGint8`
106106type instance PG Int64 = 'PGint8
107107-- | `PGint2`
108−type instance PG Word16 = 'PGint2
109−-- | `PGint4`
110−type instance PG Word32 = 'PGint4
111−-- | `PGint8`
112−type instance PG Word64 = 'PGint8
108+type instance PG Word32 = 'PGoid
113109-- | `PGnumeric`
114110type instance PG Scientific = 'PGnumeric
115111-- | `PGfloat4`
squeal-postgresql/src/Squeal/PostgreSQL/Schema.hs+1
@@ -133,6 +133,7 @@ data PGType
133133 | PGcomposite RowType -- ^ a composite type represents the structure of a row or record; it is essentially just a list of field names and their data types.
134134 | PGtsvector -- ^ A tsvector value is a sorted list of distinct lexemes, which are words that have been normalized to merge different variants of the same word.
135135 | PGtsquery -- ^ A tsquery value stores lexemes that are to be searched for
136+ | PGoid -- Object identifiers (OIDs) are used internally by PostgreSQL as primary keys for various system tables.
136137 | UnsafePGType Symbol -- ^ an escape hatch for unsupported PostgreSQL types
137138
138139-- | `NullityType` encodes the potential presence or definite absence of a