on dev help sign in
full haddocks
commitef30eff99f7f63f41d2728c28fee4e00205b70cf authorEitan Chatav <eitan@Eitans-MacBook-Pro.local> dateThu 25 Apr 2019, 10:44 (7 years ago) parent41cf532
4 files changed+36−50
squeal-postgresql/src/Squeal/PostgreSQL/Binary.hs+32 squeal-postgresql/src/Squeal/PostgreSQL/Definition.hs+2 squeal-postgresql/src/Squeal/PostgreSQL/PQ.hs+1−1 squeal-postgresql/src/Squeal/PostgreSQL/Schema.hs+1−49
squeal-postgresql/src/Squeal/PostgreSQL/Binary.hs+32
@@ -215,6 +215,9 @@ module Squeal.PostgreSQL.Binary
215215 , FromFixArray (..)
216216 -- * Only
217217 , Only (..)
218+ -- * Oid
219+ , HasOid (..)
220+ , HasAliasedOid (..)
218221 ) where
219222
220223import BinaryParser
@@ -391,6 +394,35 @@ instance
391394 in
392395 composite . encoders . toRecord . getComposite
393396
397+-- | The object identifier of a `PGType`.
398+--
399+-- >>> :set -XTypeApplications
400+-- >>> oid @'PGbool
401+-- 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
424+
425+-- | Lifts a `HasOid` constraint to a field.
394426class HasAliasedOid (field :: (Symbol, NullityType)) where
395427 aliasedOid :: Word32
396428instance HasOid ty => HasAliasedOid (alias ::: nullity ty) where
squeal-postgresql/src/Squeal/PostgreSQL/Definition.hs+2
@@ -42,6 +42,7 @@ module Squeal.PostgreSQL.Definition
4242 , createTypeEnumFrom
4343 , createTypeComposite
4444 , createTypeCompositeFrom
45+ , FieldTyped (..)
4546 , createDomain
4647 , TableConstraintExpression (..)
4748 , check
@@ -1029,6 +1030,7 @@ createDomain dom ty condition =
10291030 <+> "AS" <+> renderTypeExpression ty
10301031 <+> "CHECK" <+> parenthesized (renderSQL condition) <> ";"
10311032
1033+-- | Lift `PGTyped` to a field
10321034class FieldTyped schemas ty where
10331035 fieldtype :: Aliased (TypeExpression schemas) ty
10341036instance (KnownSymbol alias, PGTyped schemas ty)
squeal-postgresql/src/Squeal/PostgreSQL/PQ.hs+1−1
@@ -659,7 +659,7 @@ okResult_ result = liftIO $ do
659659 msg <- LibPQ.resultErrorMessage result
660660 throw . PQException $ PQState status stateCode msg
661661
662−-- | Check if a `Result`'s status is either `LibPQ.CommandOk`
662+-- | Check if a `LibPQ.Result`'s status is either `LibPQ.CommandOk`
663663-- or `LibPQ.TuplesOk` otherwise `throw` a `PQException`.
664664okResult :: MonadIO io => K LibPQ.Result row -> io ()
665665okResult = okResult_ . unK
squeal-postgresql/src/Squeal/PostgreSQL/Schema.hs+1−49
@@ -66,7 +66,6 @@ module Squeal.PostgreSQL.Schema
6666 , IsNotElem
6767 , AllUnique
6868 -- * Type Classifications
69− , HasOid (..)
7069 , PGNum
7170 , PGIntegral
7271 , PGFloating
@@ -90,12 +89,12 @@ import Control.Category
9089import Data.Kind
9190import Data.Monoid hiding (All)
9291import Data.Type.Bool
93−import Data.Word (Word32)
9492import Generics.SOP
9593import GHC.TypeLits
9694import Prelude hiding (id, (.))
9795
9896import Squeal.PostgreSQL.Alias
97+import Squeal.PostgreSQL.List
9998import Squeal.PostgreSQL.Render
10099
101100-- | `PGType` is the promoted datakind of PostgreSQL types.
@@ -134,34 +133,6 @@ data PGType
134133 | PGtsquery -- ^ A tsquery value stores lexemes that are to be searched for
135134 | UnsafePGType Symbol -- ^ an escape hatch for unsupported PostgreSQL types
136135
137−-- | The object identifier of a `PGType`.
138−--
139−-- >>> :set -XTypeApplications
140−-- >>> oid @'PGbool
141−-- 16
142−class HasOid (ty :: PGType) where oid :: Word32
143−instance HasOid 'PGbool where oid = 16
144−instance HasOid 'PGint2 where oid = 21
145−instance HasOid 'PGint4 where oid = 23
146−instance HasOid 'PGint8 where oid = 20
147−instance HasOid 'PGnumeric where oid = 1700
148−instance HasOid 'PGfloat4 where oid = 700
149−instance HasOid 'PGfloat8 where oid = 701
150−instance HasOid ('PGchar n) where oid = 18
151−instance HasOid ('PGvarchar n) where oid = 1043
152−instance HasOid 'PGtext where oid = 25
153−instance HasOid 'PGbytea where oid = 17
154−instance HasOid 'PGtimestamp where oid = 1114
155−instance HasOid 'PGtimestamptz where oid = 1184
156−instance HasOid 'PGdate where oid = 1082
157−instance HasOid 'PGtime where oid = 1083
158−instance HasOid 'PGtimetz where oid = 1266
159−instance HasOid 'PGinterval where oid = 1186
160−instance HasOid 'PGuuid where oid = 2950
161−instance HasOid 'PGinet where oid = 869
162−instance HasOid 'PGjson where oid = 114
163−instance HasOid 'PGjsonb where oid = 3802
164−
165136-- | `NullityType` encodes the potential presence or definite absence of a
166137-- @NULL@ allowing operations which are sensitive to such to be well typed.
167138--
@@ -286,15 +257,6 @@ type family TableToColumns (table :: TableType) :: ColumnsType where
286257type family TableToRow (table :: TableType) :: RowType where
287258 TableToRow tab = ColumnsToRow (TableToColumns tab)
288259
289−-- | @Elem@ is a promoted `Data.List.elem`.
290−type family Elem x xs where
291− Elem x '[] = 'False
292− Elem x (x ': xs) = 'True
293− Elem x (_ ': xs) = Elem x xs
294−
295−-- | @In x xs@ is a constraint that proves that @x@ is in @xs@.
296−type family In x xs :: Constraint where In x xs = Elem x xs ~ 'True
297−
298260-- | Numeric Postgres types.
299261type PGNum =
300262 '[ 'PGint2, 'PGint4, 'PGint8, 'PGnumeric, 'PGfloat4, 'PGfloat8]
@@ -394,16 +356,6 @@ type family DropIfConstraintsInvolve column constraints where
394356 (DropIfConstraintsInvolve column constraints)
395357 (alias ::: constraint ': DropIfConstraintsInvolve column constraints)
396358
397−{- | Calculate the `Length` of a type level list
398−
399−>>> :kind! Length '[Char,String,Bool,Double]
400−Length '[Char,String,Bool,Double] :: Nat
401−= 4
402−-}
403−type family Length (xs :: [k]) :: Nat where
404− Length (x : xs) = 1 + Length xs
405− Length '[] = 0
406−
407359-- | A `SchemumType` is a user-defined type, either a `Table`,
408360-- `View` or `Typedef`.
409361data SchemumType