on dev help sign in
With ~> From
commita1b7db82ddf8b53afcdef1d306ea242e7d19a6d4 authorEitan Chatav <eitan.chatav@gmail.com> dateThu 21 Jun 2018, 21:16 (8 years ago) parentb1b34c1
3 files changed+59−68
squeal-postgresql/src/Squeal/PostgreSQL/Binary.hs+13−13 squeal-postgresql/src/Squeal/PostgreSQL/Definition.hs+17−17 squeal-postgresql/src/Squeal/PostgreSQL/Schema.hs+29−38
squeal-postgresql/src/Squeal/PostgreSQL/Binary.hs+13−13
@@ -68,8 +68,8 @@ We can create the equivalent Postgres types directly from their Haskell types.
6868
6969>>> :{
7070type Schema =
71− '[ "schwarma" ::: 'Typedef (EnumWith Schwarma)
72− , "person" ::: 'Typedef (CompositeWith Person)
71+ '[ "schwarma" ::: 'Typedef (EnumFrom Schwarma)
72+ , "person" ::: 'Typedef (CompositeFrom Person)
7373 ]
7474:}
7575
@@ -77,8 +77,8 @@ type Schema =
7777let
7878 setup :: Definition '[] Schema
7979 setup =
80− createTypeEnumWith @Schwarma #schwarma >>>
81− createTypeCompositeWith @Person #person
80+ createTypeEnumFrom @Schwarma #schwarma >>>
81+ createTypeCompositeFrom @Person #person
8282:}
8383
8484Then we can perform roundtrip queries;
@@ -86,16 +86,16 @@ Then we can perform roundtrip queries;
8686>>> :{
8787let
8888 qry1 :: Query Schema
89− '[ 'NotNull (EnumWith Schwarma)]
90− '["fromOnly" ::: 'NotNull (EnumWith Schwarma)]
89+ '[ 'NotNull (EnumFrom Schwarma)]
90+ '["fromOnly" ::: 'NotNull (EnumFrom Schwarma)]
9191 qry1 = values_ (parameter @1 #schwarma `As` #fromOnly :* Nil)
9292:}
9393
9494>>> :{
9595let
9696 qry2 :: Query Schema
97− '[ 'NotNull (CompositeWith Person)]
98− '["fromOnly" ::: 'NotNull (CompositeWith Person)]
97+ '[ 'NotNull (CompositeFrom Person)]
98+ '["fromOnly" ::: 'NotNull (CompositeFrom Person)]
9999 qry2 = values_ (parameter @1 #person `As` #fromOnly :* Nil)
100100:}
101101
@@ -241,7 +241,7 @@ instance (HasOid pg, ToParam x pg)
241241instance
242242 ( IsEnumType x
243243 , HasDatatypeInfo x
244− , LabelsWith x ~ labels
244+ , LabelsFrom x ~ labels
245245 ) => ToParam x ('PGenum labels) where
246246 toParam =
247247 let
@@ -261,7 +261,7 @@ instance
261261 , MapMaybes xs
262262 , IsProductType x (Maybes xs)
263263 , AllZip ToAliasedParam xs fields
264− , FieldNamesWith x ~ AliasesOf fields
264+ , FieldNamesFrom x ~ AliasesOf fields
265265 , All HasAliasedOid fields
266266 ) => ToParam x ('PGcomposite fields) where
267267 toParam =
@@ -397,7 +397,7 @@ instance FromValue pg y => FromValue ('PGfixarray n pg) (Vector (Maybe y)) where
397397instance
398398 ( IsEnumType y
399399 , HasDatatypeInfo y
400− , LabelsWith y ~ labels
400+ , LabelsFrom y ~ labels
401401 ) => FromValue ('PGenum labels) y where
402402 fromValue _ =
403403 let
@@ -422,7 +422,7 @@ instance
422422 , MapMaybes ys
423423 , IsProductType y (Maybes ys)
424424 , AllZip FromAliasedValue fields ys
425− , FieldNamesWith y ~ AliasesOf fields
425+ , FieldNamesFrom y ~ AliasesOf fields
426426 ) => FromValue ('PGcomposite fields) y where
427427 fromValue =
428428 let
@@ -515,7 +515,7 @@ instance
515515 ( SListI results
516516 , IsProductType y ys
517517 , AllZip FromColumnValue results ys
518− , FieldNamesWith y ~ AliasesOf results
518+ , FieldNamesFrom y ~ AliasesOf results
519519 ) => FromRow results y where
520520 fromRow
521521 = to . SOP . Z . htrans (Proxy @FromColumnValue) (I . fromColumnValue)
squeal-postgresql/src/Squeal/PostgreSQL/Definition.hs+17−17
@@ -68,9 +68,9 @@ module Squeal.PostgreSQL.Definition
6868 , dropView
6969 -- * Types
7070 , createTypeEnum
71− , createTypeEnumWith
71+ , createTypeEnumFrom
7272 , createTypeComposite
73− , createTypeCompositeWith
73+ , createTypeCompositeFrom
7474 , dropType
7575 -- * Columns
7676 , ColumnTypeExpression (..)
@@ -835,19 +835,19 @@ createTypeEnum enum labels = UnsafeDefinition $
835835-- >>> data Schwarma = Beef | Lamb | Chicken deriving GHC.Generic
836836-- >>> instance SOP.Generic Schwarma
837837-- >>> instance SOP.HasDatatypeInfo Schwarma
838−-- >>> printSQL $ createTypeEnumWith @Schwarma #schwarma
838+-- >>> printSQL $ createTypeEnumFrom @Schwarma #schwarma
839839-- CREATE TYPE "schwarma" AS ENUM ('Beef', 'Lamb', 'Chicken');
840−createTypeEnumWith
840+createTypeEnumFrom
841841 :: forall hask enum schema.
842842 ( SOP.Generic hask
843− , SOP.All KnownSymbol (LabelsWith hask)
843+ , SOP.All KnownSymbol (LabelsFrom hask)
844844 , KnownSymbol enum
845845 )
846846 => Alias enum
847847 -- ^ name of the user defined enumerated type
848− -> Definition schema (Create enum ('Typedef (EnumWith hask)) schema)
849−createTypeEnumWith enum = createTypeEnum enum
850− (SOP.hpure label :: NP PGlabel (LabelsWith hask))
848+ -> Definition schema (Create enum ('Typedef (EnumFrom hask)) schema)
849+createTypeEnumFrom enum = createTypeEnum enum
850+ (SOP.hpure label :: NP PGlabel (LabelsFrom hask))
851851
852852-- | `createTypeComposite` creates a composite type. The composite type is
853853-- specified by a list of attribute names and data types.
@@ -874,28 +874,28 @@ createTypeComposite ty fields = UnsafeDefinition $
874874-- >>> data Complex = Complex {real :: Maybe Double, imaginary :: Maybe Double} deriving GHC.Generic
875875-- >>> instance SOP.Generic Complex
876876-- >>> instance SOP.HasDatatypeInfo Complex
877−-- >>> printSQL $ createTypeCompositeWith @Complex #complex
877+-- >>> printSQL $ createTypeCompositeFrom @Complex #complex
878878-- CREATE TYPE "complex" AS ("real" float8, "imaginary" float8);
879−createTypeCompositeWith
879+createTypeCompositeFrom
880880 :: forall hask ty schema.
881− ( ZipAliased (FieldNamesWith hask) (FieldTypesWith hask)
882− , SOP.All (PGTyped schema) (FieldTypesWith hask)
881+ ( ZipAliased (FieldNamesFrom hask) (FieldTypesFrom hask)
882+ , SOP.All (PGTyped schema) (FieldTypesFrom hask)
883883 , KnownSymbol ty
884884 )
885885 => Alias ty
886886 -- ^ name of the user defined composite type
887− -> Definition schema (Create ty ( 'Typedef (CompositeWith hask)) schema)
888−createTypeCompositeWith ty = createTypeComposite ty $ zipAs
889− (SOP.hpure Alias :: NP Alias (FieldNamesWith hask))
887+ -> Definition schema (Create ty ( 'Typedef (CompositeFrom hask)) schema)
888+createTypeCompositeFrom ty = createTypeComposite ty $ zipAs
889+ (SOP.hpure Alias :: NP Alias (FieldNamesFrom hask))
890890 (SOP.hcpure (SOP.Proxy :: SOP.Proxy (PGTyped schema)) pgtype
891− :: NP (TypeExpression schema) (FieldTypesWith hask))
891+ :: NP (TypeExpression schema) (FieldTypesFrom hask))
892892
893893-- | Drop a type.
894894--
895895-- >>> data Schwarma = Beef | Lamb | Chicken deriving GHC.Generic
896896-- >>> instance SOP.Generic Schwarma
897897-- >>> instance SOP.HasDatatypeInfo Schwarma
898−-- >>> printSQL (dropType #schwarma :: Definition '["schwarma" ::: 'Typedef (EnumWith Schwarma)] '[])
898+-- >>> printSQL (dropType #schwarma :: Definition '["schwarma" ::: 'Typedef (EnumFrom Schwarma)] '[])
899899-- DROP TYPE "schwarma";
900900dropType
901901 :: Has tydef schema ('Typedef ty)
squeal-postgresql/src/Squeal/PostgreSQL/Schema.hs+29−38
@@ -100,15 +100,13 @@ module Squeal.PostgreSQL.Schema
100100 , PGlabel (..)
101101 , renderLabel
102102 , renderLabels
103− , LabelOf
104− , LabelsOf
105103 -- * Embedding
106104 , PG
107− , EnumWith
108− , LabelsWith
109− , CompositeWith
110− , FieldNamesWith
111− , FieldTypesWith
105+ , EnumFrom
106+ , LabelsFrom
107+ , CompositeFrom
108+ , FieldNamesFrom
109+ , FieldTypesFrom
112110 , ConstructorsOf
113111 , ConstructorNameOf
114112 , ConstructorNamesOf
@@ -682,13 +680,6 @@ renderLabels
682680 :: All KnownSymbol labels => NP PGlabel labels -> [ByteString]
683681renderLabels = hcollapse
684682 . hcmap (Proxy @KnownSymbol) (K . renderLabel)
685−-- | Gets the name of a type constructor
686−type family LabelOf (cons :: Type.ConstructorInfo) :: Symbol where
687− LabelOf ('Type.Constructor name) = name
688−-- | Gets the names of a list of type constructors
689−type family LabelsOf (conss :: [Type.ConstructorInfo]) :: [Symbol] where
690− LabelsOf '[] = '[]
691− LabelsOf (cons ': conss) = LabelOf cons ': LabelsOf conss
692683
693684-- | The `PG` type family embeds a subset of Haskell types
694685-- as Postgres basic types.
@@ -724,32 +715,32 @@ type family PG (hask :: Type) :: PGType where
724715 PG ty = TypeError
725716 ('Text "There is no Postgres basic type for " ':<>: 'ShowType ty)
726717
727−-- | The `EnumWith` type family embeds Haskell enum types, ADTs with
718+-- | The `EnumFrom` type family embeds Haskell enum types, ADTs with
728719-- nullary constructors, as Postgres enum types
729720--
730721-- >>> data Schwarma = Beef | Lamb | Chicken deriving GHC.Generic
731722-- >>> instance Generic Schwarma
732723-- >>> instance HasDatatypeInfo Schwarma
733−-- >>> :kind! EnumWith Schwarma
734−-- EnumWith Schwarma :: PGType
724+-- >>> :kind! EnumFrom Schwarma
725+-- EnumFrom Schwarma :: PGType
735726-- = 'PGenum '["Beef", "Lamb", "Chicken"]
736−type family EnumWith (hask :: Type) :: PGType where
737− EnumWith hask = 'PGenum (LabelsWith hask)
727+type family EnumFrom (hask :: Type) :: PGType where
728+ EnumFrom hask = 'PGenum (LabelsFrom hask)
738729
739−-- | The `LabelsWith` type family calculates the constructors of a
730+-- | The `LabelsFrom` type family calculates the constructors of a
740731-- Haskell enum type.
741732--
742733-- >>> data Schwarma = Beef | Lamb | Chicken deriving GHC.Generic
743734-- >>> instance Generic Schwarma
744735-- >>> instance HasDatatypeInfo Schwarma
745−-- >>> :kind! LabelsWith Schwarma
746−-- LabelsWith Schwarma :: [Type.ConstructorName]
736+-- >>> :kind! LabelsFrom Schwarma
737+-- LabelsFrom Schwarma :: [Type.ConstructorName]
747738-- = '["Beef", "Lamb", "Chicken"]
748−type family LabelsWith (hask :: Type) :: [Type.ConstructorName] where
749− LabelsWith hask =
739+type family LabelsFrom (hask :: Type) :: [Type.ConstructorName] where
740+ LabelsFrom hask =
750741 ConstructorNamesOf (ConstructorsOf (DatatypeInfoOf hask))
751742
752−-- | The `CompositeWith` type family embeds Haskell record types as
743+-- | The `CompositeFrom` type family embeds Haskell record types as
753744-- Postgres composite types, as long as the record fields
754745-- are `Maybe`s of Haskell types that can be embedded as basic types
755746-- with the `PG` type family.
@@ -757,30 +748,30 @@ type family LabelsWith (hask :: Type) :: [Type.ConstructorName] where
757748-- >>> data Row = Row { a :: Maybe Int16, b :: Maybe LocalTime } deriving GHC.Generic
758749-- >>> instance Generic Row
759750-- >>> instance HasDatatypeInfo Row
760−-- >>> :kind! CompositeWith Row
761−-- CompositeWith Row :: PGType
751+-- >>> :kind! CompositeFrom Row
752+-- CompositeFrom Row :: PGType
762753-- = 'PGcomposite '['("a", 'PGint2), '("b", 'PGtimestamp)]
763−type family CompositeWith (hask :: Type) :: PGType where
764− CompositeWith hask =
765− 'PGcomposite (ZipAs (FieldNamesWith hask) (FieldTypesWith hask))
754+type family CompositeFrom (hask :: Type) :: PGType where
755+ CompositeFrom hask =
756+ 'PGcomposite (ZipAs (FieldNamesFrom hask) (FieldTypesFrom hask))
766757
767758-- | >>> data Row = Row { a :: Maybe Int16, b :: Maybe LocalTime } deriving GHC.Generic
768759-- >>> instance Generic Row
769760-- >>> instance HasDatatypeInfo Row
770−-- >>> :kind! FieldNamesWith Row
771−-- FieldNamesWith Row :: [Type.FieldName]
761+-- >>> :kind! FieldNamesFrom Row
762+-- FieldNamesFrom Row :: [Type.FieldName]
772763-- = '["a", "b"]
773−type family FieldNamesWith (hask :: Type) :: [Type.FieldName] where
774− FieldNamesWith hask = FieldNamesOf (FieldsOf (DatatypeInfoOf hask))
764+type family FieldNamesFrom (hask :: Type) :: [Type.FieldName] where
765+ FieldNamesFrom hask = FieldNamesOf (FieldsOf (DatatypeInfoOf hask))
775766
776767-- | >>> data Row = Row { a :: Maybe Int16, b :: Maybe LocalTime } deriving GHC.Generic
777768-- >>> instance Generic Row
778769-- >>> instance HasDatatypeInfo Row
779−-- >>> :kind! FieldTypesWith Row
780−-- FieldTypesWith Row :: [PGType]
770+-- >>> :kind! FieldTypesFrom Row
771+-- FieldTypesFrom Row :: [PGType]
781772-- = '['PGint2, 'PGtimestamp]
782−type family FieldTypesWith (hask :: Type) :: [PGType] where
783− FieldTypesWith hask = FieldTypesOf (RecordCodeOf hask (Code hask))
773+type family FieldTypesFrom (hask :: Type) :: [PGType] where
774+ FieldTypesFrom hask = FieldTypesOf (RecordCodeOf hask (Code hask))
784775
785776-- | Calculates constructors of a datatype.
786777type family ConstructorsOf (datatype :: Type.DatatypeInfo)