on dev help sign in
simplify schemum typedefs
commit130e3929dc555abb7874d78d8cd348b8b7843e2e authorEitan Chatav <eitan.chatav@gmail.com> dateSat 18 Aug 2018, 11:41 (8 years ago) parent1f84414
2 files changed+20−9
squeal-postgresql/src/Squeal/PostgreSQL/Expression.hs+20−3 squeal-postgresql/src/Squeal/PostgreSQL/Schema.hs−6
squeal-postgresql/src/Squeal/PostgreSQL/Expression.hs+20−3
@@ -146,6 +146,9 @@ module Squeal.PostgreSQL.Expression
146146 -- * Types
147147 , TypeExpression (UnsafeTypeExpression, renderTypeExpression)
148148 , PGTyped (pgtype)
149+ , typedef
150+ , typetable
151+ , typeview
149152 , bool
150153 , int2
151154 , smallint
@@ -1581,9 +1584,23 @@ newtype TypeExpression (schema :: SchemaType) (ty :: NullityType)
15811584 = UnsafeTypeExpression { renderTypeExpression :: ByteString }
15821585 deriving (GHC.Generic,Show,Eq,Ord,NFData)
15831586
1584−instance (Has alias schema schemum, SchemumToType schemum ~ ty)
1585− => IsLabel alias (TypeExpression schema (nullity ty)) where
1586− fromLabel = UnsafeTypeExpression (renderAlias (fromLabel @alias))
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
1596+ -> TypeExpression schema (nullity ('PGcomposite (TableToRow tab)))
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
15871604
15881605-- | logical Boolean (true/false)
15891606bool :: TypeExpression schema (nullity 'PGbool)
squeal-postgresql/src/Squeal/PostgreSQL/Schema.hs−6
@@ -47,7 +47,6 @@ module Squeal.PostgreSQL.Schema
4747 , TableType
4848 -- * Schema
4949 , SchemumType (..)
50− , SchemumToType
5150 , SchemaType
5251 -- * Constraints
5352 , (:=>)
@@ -657,11 +656,6 @@ data SchemumType
657656 | View RowType
658657 | Typedef PGType
659658
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−
665659-- | The schema of a database consists of a list of aliased,
666660-- user-defined `SchemumType`s.
667661type SchemaType = [(Symbol,SchemumType)]