@@ -27,6 +27,7 @@ Squeal data definition language.
2727 , TypeInType
2828 , TypeOperators
2929 , UndecidableSuperClasses
30+ , UndecidableInstances
3031#-}
3132
3233module Squeal.PostgreSQL.Definition
@@ -34,6 +35,8 @@ module Squeal.PostgreSQL.Definition
3435 Definition (..)
3536 , (>>>)
3637 , manipDefinition
38+ , PGNullityTyped (..)
39+ , hask
3740 ) where
3841
3942import Control.Category
@@ -44,7 +47,10 @@ import Prelude hiding ((.), id)
4447
4548import qualified GHC.Generics as GHC
4649
50+import Squeal.PostgreSQL.Definition.Table.Column
51+import Squeal.PostgreSQL.Expression.Type
4752import Squeal.PostgreSQL.Manipulation
53+import Squeal.PostgreSQL.PG
4854import Squeal.PostgreSQL.Render
4955import Squeal.PostgreSQL.Schema
5056
@@ -79,3 +85,17 @@ manipDefinition
7985 -- ^ no input or output
8086 -> Definition schemas schemas
8187manipDefinition = UnsafeDefinition . (<> ";") . renderSQL
88+
89+class PGNullityTyped schemas (nullty :: NullityType) where
90+ pgNullityType :: ColumnTypeExpression schemas ('NoDef :=> nullty)
91+
92+instance PGTyped schemas ('Null ty) => PGNullityTyped schemas ('Null ty) where
93+ pgNullityType = nullable (pgtype @_ @('Null ty))
94+
95+instance PGTyped schemas ('NotNull ty) => PGNullityTyped schemas ('NotNull ty) where
96+ pgNullityType = notNullable (pgtype @_ @('NotNull ty))
97+
98+hask
99+ :: forall h schemas. PGNullityTyped schemas (NullPG h)
100+ => ColumnTypeExpression schemas ('NoDef :=> NullPG h)
101+hask = pgNullityType