on dev help sign in
tests fixed
commitb856c246f783eaee083718e3d98ef9ec2f2329e9 authorEitan Chatav <eitan.chatav@gmail.com> dateWed 11 Jul 2018, 22:17 (8 years ago) parent8898027
4 files changed+19−18
squeal-postgresql/src/Squeal/PostgreSQL/Binary.hs+2−10 squeal-postgresql/src/Squeal/PostgreSQL/Definition.hs+7−3 squeal-postgresql/src/Squeal/PostgreSQL/Expression.hs+9−4 squeal-postgresql/src/Squeal/PostgreSQL/Schema.hs+1−1
squeal-postgresql/src/Squeal/PostgreSQL/Binary.hs+2−10
@@ -473,14 +473,6 @@ instance
473473-- decoding `Null`s to `Maybe`s. You should not define instances for
474474-- `FromColumnValue`, just use the provided instances.
475475class 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})
484476 fromColumnValue
485477 :: K (Maybe Strict.ByteString) pg
486478 -> (Either Strict.Text :.: P) y
@@ -512,7 +504,7 @@ class SListI result => FromRow (result :: RelationType) y where
512504 -- >>> instance HasDatatypeInfo UserRow
513505 -- >>> type User = '["userId" ::: 'NotNull 'PGint2, "userName" ::: 'Null 'PGtext]
514506 -- >>> 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"})
516508 fromRow :: NP (K (Maybe Strict.ByteString)) result -> Either Strict.Text y
517509instance
518510 ( SListI result
@@ -532,7 +524,7 @@ instance
532524-- K (Just "foo") :* Nil
533525--
534526-- >>> fromRow @'["fromOnly" ::: 'Null 'PGtext] @(Only (Maybe Text)) (K (Just "bar") :* Nil)
535−-- Only {fromOnly = Just "bar"}
527+-- Right (Only {fromOnly = Just "bar"})
536528newtype Only x = Only { fromOnly :: x }
537529 deriving (Functor,Foldable,Traversable,Eq,Ord,Read,Show,GHC.Generic)
538530instance Generic (Only x)
squeal-postgresql/src/Squeal/PostgreSQL/Definition.hs+7−3
@@ -869,7 +869,11 @@ createTypeEnumFrom enum = createTypeEnum enum
869869{- | `createTypeComposite` creates a composite type. The composite type is
870870specified by a list of attribute names and data types.
871871
872−>>> type PGcomplex = 'PGcomposite '["real" ::: 'PGfloat8, "imaginary" ::: 'PGfloat8]
872+>>> :{
873+type PGcomplex = 'PGcomposite
874+ '[ "real" ::: 'NotNull 'PGfloat8
875+ , "imaginary" ::: 'NotNull 'PGfloat8 ]
876+:}
873877
874878>>> :{
875879let
@@ -897,7 +901,7 @@ createTypeComposite ty fields = UnsafeDefinition $
897901
898902-- | Composite types can also be generated from a Haskell type, for example
899903--
900−-- >>> data Complex = Complex {real :: Maybe Double, imaginary :: Maybe Double} deriving GHC.Generic
904+-- >>> data Complex = Complex {real :: Double, imaginary :: Double} deriving GHC.Generic
901905-- >>> instance SOP.Generic Complex
902906-- >>> instance SOP.HasDatatypeInfo Complex
903907-- >>> printSQL $ createTypeCompositeFrom @Complex #complex
@@ -951,7 +955,7 @@ nullable ty = UnsafeColumnTypeExpression $ renderTypeExpression ty <+> "NULL"
951955-- @NULL@ is not present in a column
952956notNullable
953957 :: TypeExpression schema (nullity ty)
954− -> ColumnTypeExpression schema (def :=> 'NotNull ty)
958+ -> ColumnTypeExpression schema ('NoDef :=> 'NotNull ty)
955959notNullable ty = UnsafeColumnTypeExpression $ renderTypeExpression ty <+> "NOT NULL"
956960
957961-- | 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
395395-- | A row constructor is an expression that builds a row value
396396-- (also called a composite value) using values for its member fields.
397397--
398−-- >>> type Complex = PGcomposite '["real" ::: 'PGfloat8, "imaginary" ::: 'PGfloat8]
398+-- >>> :{
399+-- type Complex = 'PGcomposite
400+-- '[ "real" ::: 'NotNull 'PGfloat8
401+-- , "imaginary" ::: 'NotNull 'PGfloat8 ]
402+-- :}
403+--
399404-- >>> let i = row (0 `as` #real :* 1 `as` #imaginary) :: Expression '[] '[] 'Ungrouped '[] ('NotNull Complex)
400405-- >>> printSQL i
401406-- ROW(0, 1)
@@ -542,9 +547,9 @@ atan2_ y x = UnsafeExpression $
542547cast
543548 :: TypeExpression schema ty1
544549 -- ^ type to cast as
545− -> Expression schema relations grouping params (nullity ty0)
550+ -> Expression schema relations grouping params ty0
546551 -- ^ value to convert
547− -> Expression schema relations grouping params (nullity ty1)
552+ -> Expression schema relations grouping params ty1
548553cast ty x = UnsafeExpression $ parenthesized $
549554 renderExpression x <+> "::" <+> renderTypeExpression ty
550555
@@ -1208,7 +1213,7 @@ vararray
12081213vararray ty = UnsafeTypeExpression $ renderTypeExpression ty <> "[]"
12091214-- | fixed length array
12101215--
1211−-- >>> renderTypeExpression (fixarray (Proxy @2) json)
1216+-- >>> renderTypeExpression (fixarray @2 json)
12121217-- "json[2]"
12131218fixarray
12141219 :: 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
735735-- >>> instance HasDatatypeInfo Row
736736-- >>> :kind! CompositeFrom Row
737737-- CompositeFrom Row :: PGType
738−-- = 'PGcomposite '['("a", 'PGint2), '("b", 'PGtimestamp)]
738+-- = 'PGcomposite '["a" ::: 'Null 'PGint2, "b" ::: 'Null 'PGtimestamp]
739739type family CompositeFrom (hask :: Type) :: PGType where
740740 CompositeFrom hask = 'PGcomposite (PGFieldsFrom hask)
741741