on dev help sign in
tests fixed
b856c24Eitan Chatav
squeal-postgresql/src/Squeal/PostgreSQL/Binary.hs+2−10
@@ -473,14 +473,6 @@ instance
473-- decoding `Null`s to `Maybe`s. You should not define instances for
473-- decoding `Null`s to `Maybe`s. You should not define instances for
474-- `FromColumnValue`, just use the provided instances.
474-- `FromColumnValue`, just use the provided instances.
475class FromColumnValue (pg :: (Symbol, NullityType)) (y :: (Symbol, Type)) where
475class FromColumnValue (pg :: (Symbol, NullityType)) (y :: (Symbol, Type)) where
476− -- | >>> :set -XTypeOperators -XOverloadedStrings
477− -- >>> newtype Id = Id { getId :: Int16 } deriving Show
478− -- >>> instance FromValue 'PGint2 Id where fromValue = fmap Id . fromValue
479− -- >>> fromColumnValue @("col" ::: 'NotNull 'PGint2) @Id (K (Just "\NUL\SOH"))
480− -- Id {getId = 1}
481− --
482− -- >>> fromColumnValue @("col" ::: 'Null 'PGint2) @(Maybe Id) (K (Just "\NUL\SOH"))
483− -- Just (Id {getId = 1})
484 fromColumnValue
476 fromColumnValue
485 :: K (Maybe Strict.ByteString) pg
477 :: K (Maybe Strict.ByteString) pg
486 -> (Either Strict.Text :.: P) y
478 -> (Either Strict.Text :.: P) y
@@ -512,7 +504,7 @@ class SListI result => FromRow (result :: RelationType) y where
512 -- >>> instance HasDatatypeInfo UserRow
504 -- >>> instance HasDatatypeInfo UserRow
513 -- >>> type User = '["userId" ::: 'NotNull 'PGint2, "userName" ::: 'Null 'PGtext]
505 -- >>> type User = '["userId" ::: 'NotNull 'PGint2, "userName" ::: 'Null 'PGtext]
514 -- >>> fromRow @User @UserRow (K (Just "\NUL\SOH") :* K (Just "bloodninja") :* Nil)
506 -- >>> fromRow @User @UserRow (K (Just "\NUL\SOH") :* K (Just "bloodninja") :* Nil)
515− -- UserRow {userId = UserId {getUserId = 1}, userName = Just "bloodninja"}
507+ -- Right (UserRow {userId = UserId {getUserId = 1}, userName = Just "bloodninja"})
516 fromRow :: NP (K (Maybe Strict.ByteString)) result -> Either Strict.Text y
508 fromRow :: NP (K (Maybe Strict.ByteString)) result -> Either Strict.Text y
517instance
509instance
518 ( SListI result
510 ( SListI result
@@ -532,7 +524,7 @@ instance
532-- K (Just "foo") :* Nil
524-- K (Just "foo") :* Nil
533--
525--
534-- >>> fromRow @'["fromOnly" ::: 'Null 'PGtext] @(Only (Maybe Text)) (K (Just "bar") :* Nil)
526-- >>> fromRow @'["fromOnly" ::: 'Null 'PGtext] @(Only (Maybe Text)) (K (Just "bar") :* Nil)
535−-- Only {fromOnly = Just "bar"}
527+-- Right (Only {fromOnly = Just "bar"})
536newtype Only x = Only { fromOnly :: x }
528newtype Only x = Only { fromOnly :: x }
537 deriving (Functor,Foldable,Traversable,Eq,Ord,Read,Show,GHC.Generic)
529 deriving (Functor,Foldable,Traversable,Eq,Ord,Read,Show,GHC.Generic)
538instance Generic (Only x)
530instance Generic (Only x)
squeal-postgresql/src/Squeal/PostgreSQL/Definition.hs+7−3
@@ -869,7 +869,11 @@ createTypeEnumFrom enum = createTypeEnum enum
869{- | `createTypeComposite` creates a composite type. The composite type is
869{- | `createTypeComposite` creates a composite type. The composite type is
870specified by a list of attribute names and data types.
870specified by a list of attribute names and data types.
871
871
872+>>> :{
872−>>> type PGcomplex = 'PGcomposite '["real" ::: 'PGfloat8, "imaginary" ::: 'PGfloat8]
873+type PGcomplex = 'PGcomposite
874+ '[ "real" ::: 'NotNull 'PGfloat8
875+ , "imaginary" ::: 'NotNull 'PGfloat8 ]
876+:}
873
877
874>>> :{
878>>> :{
875let
879let
@@ -897,7 +901,7 @@ createTypeComposite ty fields = UnsafeDefinition $
897
901
898-- | Composite types can also be generated from a Haskell type, for example
902-- | Composite types can also be generated from a Haskell type, for example
899--
903--
900−-- >>> data Complex = Complex {real :: Maybe Double, imaginary :: Maybe Double} deriving GHC.Generic
904+-- >>> data Complex = Complex {real :: Double, imaginary :: Double} deriving GHC.Generic
901-- >>> instance SOP.Generic Complex
905-- >>> instance SOP.Generic Complex
902-- >>> instance SOP.HasDatatypeInfo Complex
906-- >>> instance SOP.HasDatatypeInfo Complex
903-- >>> printSQL $ createTypeCompositeFrom @Complex #complex
907-- >>> printSQL $ createTypeCompositeFrom @Complex #complex
@@ -951,7 +955,7 @@ nullable ty = UnsafeColumnTypeExpression $ renderTypeExpression ty <+> "NULL"
951-- @NULL@ is not present in a column
955-- @NULL@ is not present in a column
952notNullable
956notNullable
953 :: TypeExpression schema (nullity ty)
957 :: TypeExpression schema (nullity ty)
954− -> ColumnTypeExpression schema (def :=> 'NotNull ty)
958+ -> ColumnTypeExpression schema ('NoDef :=> 'NotNull ty)
955notNullable ty = UnsafeColumnTypeExpression $ renderTypeExpression ty <+> "NOT NULL"
959notNullable ty = UnsafeColumnTypeExpression $ renderTypeExpression ty <+> "NOT NULL"
956
960
957-- | used in `createTable` commands as a column constraint to give a default
961-- | used in `createTable` commands as a column constraint to give a default
squeal-postgresql/src/Squeal/PostgreSQL/Expression.hs+9−4
@@ -395,7 +395,12 @@ instance (KnownSymbol label, label `In` labels) => IsPGlabel label
395-- | A row constructor is an expression that builds a row value
395-- | A row constructor is an expression that builds a row value
396-- (also called a composite value) using values for its member fields.
396-- (also called a composite value) using values for its member fields.
397--
397--
398+-- >>> :{
398−-- >>> type Complex = PGcomposite '["real" ::: 'PGfloat8, "imaginary" ::: 'PGfloat8]
399+-- type Complex = 'PGcomposite
400+-- '[ "real" ::: 'NotNull 'PGfloat8
401+-- , "imaginary" ::: 'NotNull 'PGfloat8 ]
402+-- :}
403+--
399-- >>> let i = row (0 `as` #real :* 1 `as` #imaginary) :: Expression '[] '[] 'Ungrouped '[] ('NotNull Complex)
404-- >>> let i = row (0 `as` #real :* 1 `as` #imaginary) :: Expression '[] '[] 'Ungrouped '[] ('NotNull Complex)
400-- >>> printSQL i
405-- >>> printSQL i
401-- ROW(0, 1)
406-- ROW(0, 1)
@@ -542,9 +547,9 @@ atan2_ y x = UnsafeExpression $
542cast
547cast
543 :: TypeExpression schema ty1
548 :: TypeExpression schema ty1
544 -- ^ type to cast as
549 -- ^ type to cast as
545− -> Expression schema relations grouping params (nullity ty0)
550+ -> Expression schema relations grouping params ty0
546 -- ^ value to convert
551 -- ^ value to convert
547− -> Expression schema relations grouping params (nullity ty1)
552+ -> Expression schema relations grouping params ty1
548cast ty x = UnsafeExpression $ parenthesized $
553cast ty x = UnsafeExpression $ parenthesized $
549 renderExpression x <+> "::" <+> renderTypeExpression ty
554 renderExpression x <+> "::" <+> renderTypeExpression ty
550
555
@@ -1208,7 +1213,7 @@ vararray
1208vararray ty = UnsafeTypeExpression $ renderTypeExpression ty <> "[]"
1213vararray ty = UnsafeTypeExpression $ renderTypeExpression ty <> "[]"
1209-- | fixed length array
1214-- | fixed length array
1210--
1215--
1211−-- >>> renderTypeExpression (fixarray (Proxy @2) json)
1216+-- >>> renderTypeExpression (fixarray @2 json)
1212-- "json[2]"
1217-- "json[2]"
1213fixarray
1218fixarray
1214 :: forall n schema nullity pg. KnownNat n
1219 :: forall n schema nullity pg. KnownNat n
squeal-postgresql/src/Squeal/PostgreSQL/Schema.hs+1−1
@@ -735,7 +735,7 @@ type family LabelsFrom (hask :: Type) :: [Type.ConstructorName] where
735-- >>> instance HasDatatypeInfo Row
735-- >>> instance HasDatatypeInfo Row
736-- >>> :kind! CompositeFrom Row
736-- >>> :kind! CompositeFrom Row
737-- CompositeFrom Row :: PGType
737-- CompositeFrom Row :: PGType
738−-- = 'PGcomposite '['("a", 'PGint2), '("b", 'PGtimestamp)]
738+-- = 'PGcomposite '["a" ::: 'Null 'PGint2, "b" ::: 'Null 'PGtimestamp]
739type family CompositeFrom (hask :: Type) :: PGType where
739type family CompositeFrom (hask :: Type) :: PGType where
740 CompositeFrom hask = 'PGcomposite (PGFieldsFrom hask)
740 CompositeFrom hask = 'PGcomposite (PGFieldsFrom hask)
741
741