on dev help sign in
simplify schemum typedefs
130e392Eitan Chatav
squeal-postgresql/src/Squeal/PostgreSQL/Expression.hs+20−3
@@ -146,6 +146,9 @@ module Squeal.PostgreSQL.Expression
146 -- * Types
146 -- * Types
147 , TypeExpression (UnsafeTypeExpression, renderTypeExpression)
147 , TypeExpression (UnsafeTypeExpression, renderTypeExpression)
148 , PGTyped (pgtype)
148 , PGTyped (pgtype)
149+ , typedef
150+ , typetable
151+ , typeview
149 , bool
152 , bool
150 , int2
153 , int2
151 , smallint
154 , smallint
@@ -1581,9 +1584,23 @@ newtype TypeExpression (schema :: SchemaType) (ty :: NullityType)
1581 = UnsafeTypeExpression { renderTypeExpression :: ByteString }
1584 = UnsafeTypeExpression { renderTypeExpression :: ByteString }
1582 deriving (GHC.Generic,Show,Eq,Ord,NFData)
1585 deriving (GHC.Generic,Show,Eq,Ord,NFData)
1583
1586
1584−instance (Has alias schema schemum, SchemumToType schemum ~ ty)
1587+typedef
1588+ :: Has alias schema ('Typedef ty)
1589+ => Alias alias
1590+ -> TypeExpression schema (nullity ty)
1591+typedef = UnsafeTypeExpression . renderAlias
1592+
1593+typetable
1594+ :: Has alias schema ('Table tab)
1595+ => Alias alias
1585− => IsLabel alias (TypeExpression schema (nullity ty)) where
1596+ -> TypeExpression schema (nullity ('PGcomposite (TableToRow tab)))
1586− fromLabel = UnsafeTypeExpression (renderAlias (fromLabel @alias))
1597+typetable = UnsafeTypeExpression . renderAlias
1598+
1599+typeview
1600+ :: Has alias schema ('View view)
1601+ => Alias alias
1602+ -> TypeExpression schema (nullity ('PGcomposite view))
1603+typeview = UnsafeTypeExpression . renderAlias
1587
1604
1588-- | logical Boolean (true/false)
1605-- | logical Boolean (true/false)
1589bool :: TypeExpression schema (nullity 'PGbool)
1606bool :: TypeExpression schema (nullity 'PGbool)
squeal-postgresql/src/Squeal/PostgreSQL/Schema.hs−6
@@ -47,7 +47,6 @@ module Squeal.PostgreSQL.Schema
47 , TableType
47 , TableType
48 -- * Schema
48 -- * Schema
49 , SchemumType (..)
49 , SchemumType (..)
50− , SchemumToType
51 , SchemaType
50 , SchemaType
52 -- * Constraints
51 -- * Constraints
53 , (:=>)
52 , (:=>)
@@ -657,11 +656,6 @@ data SchemumType
657 | View RowType
656 | View RowType
658 | Typedef PGType
657 | Typedef PGType
659
658
660−type family SchemumToType (schemum :: SchemumType) :: PGType where
661− SchemumToType ('Typedef ty) = ty
662− SchemumToType ('Table table) = 'PGcomposite (TableToRow table)
663− SchemumToType ('View view) = 'PGcomposite view
664−
665-- | The schema of a database consists of a list of aliased,
659-- | The schema of a database consists of a list of aliased,
666-- user-defined `SchemumType`s.
660-- user-defined `SchemumType`s.
667type SchemaType = [(Symbol,SchemumType)]
661type SchemaType = [(Symbol,SchemumType)]