@@ -23,16 +23,15 @@ Type expressions.
23 , ScopedTypeVariables
23 , ScopedTypeVariables
24 , TypeApplications
24 , TypeApplications
25 , TypeOperators
25 , TypeOperators
26− , UndecidableInstances
29module Squeal.PostgreSQL.Expression.Type
28module Squeal.PostgreSQL.Expression.Type
30− ( -- * type casting
29+ ( TypeExpression (..)
33 , inferredtype
32 , inferredtype
34− -- * type expressions
33+ , PGTyped (..)
35− , TypeExpression (..)
34+ , FieldTyped (..)
37 , typetable
36 , typetable
38 , typeview
37 , typeview
@@ -79,22 +78,6 @@ module Squeal.PostgreSQL.Expression.Type
80 , tstzrange
79 , tstzrange
81 , daterange
80 , daterange
82− -- * column type definitions
83− , ColumnTypeExpression (..)
96− , PGNullityTyped (..)
100import Control.DeepSeq
83import Control.DeepSeq
@@ -108,7 +91,6 @@ import qualified Generics.SOP as SOP
109import Squeal.PostgreSQL.Alias
92import Squeal.PostgreSQL.Alias
110import Squeal.PostgreSQL.Expression
93import Squeal.PostgreSQL.Expression
111−import Squeal.PostgreSQL.PG
112import Squeal.PostgreSQL.Render
94import Squeal.PostgreSQL.Render
113import Squeal.PostgreSQL.Schema
95import Squeal.PostgreSQL.Schema
@@ -150,7 +132,6 @@ astype = cast
150inferredtype
132inferredtype
151 :: PGTyped schemas ty
133 :: PGTyped schemas ty
152 => Expression outer common grp schemas params from ty
134 => Expression outer common grp schemas params from ty
154 -> Expression outer common grp schemas params from ty
135 -> Expression outer common grp schemas params from ty
155inferredtype = astype pgtype
136inferredtype = astype pgtype
@@ -170,7 +151,6 @@ instance RenderSQL (TypeExpression schemas ty) where
171 :: (Has sch schemas schema, Has td schema ('Typedef ty))
152 :: (Has sch schemas schema, Has td schema ('Typedef ty))
172 => QualifiedAlias sch td
153 => QualifiedAlias sch td
174 -> TypeExpression schemas (null ty)
154 -> TypeExpression schemas (null ty)
175typedef = UnsafeTypeExpression . renderSQL
155typedef = UnsafeTypeExpression . renderSQL
@@ -179,7 +159,6 @@ typedef = UnsafeTypeExpression . renderSQL
180 :: (Has sch schemas schema, Has tab schema ('Table table))
160 :: (Has sch schemas schema, Has tab schema ('Table table))
181 => QualifiedAlias sch tab
161 => QualifiedAlias sch tab
183 -> TypeExpression schemas (null ('PGcomposite (TableToRow table)))
162 -> TypeExpression schemas (null ('PGcomposite (TableToRow table)))
184typetable = UnsafeTypeExpression . renderSQL
163typetable = UnsafeTypeExpression . renderSQL
@@ -188,7 +167,6 @@ typetable = UnsafeTypeExpression . renderSQL
189 :: (Has sch schemas schema, Has vw schema ('View view))
168 :: (Has sch schemas schema, Has vw schema ('View view))
190 => QualifiedAlias sch vw
169 => QualifiedAlias sch vw
192 -> TypeExpression schemas (null ('PGcomposite view))
170 -> TypeExpression schemas (null ('PGcomposite view))
193typeview = UnsafeTypeExpression . renderSQL
171typeview = UnsafeTypeExpression . renderSQL
@@ -375,72 +353,3 @@ class FieldTyped schemas ty where
375instance (KnownSymbol alias, PGTyped schemas ty)
353instance (KnownSymbol alias, PGTyped schemas ty)
376 => FieldTyped schemas (alias ::: ty) where
354 => FieldTyped schemas (alias ::: ty) where
377 fieldtype = pgtype `As` Alias
355 fieldtype = pgtype `As` Alias
379−-- | `ColumnTypeExpression`s are used in `createTable` commands.
380−newtype ColumnTypeExpression (schemas :: SchemasType) (ty :: ColumnType)
381− = UnsafeColumnTypeExpression { renderColumnTypeExpression :: ByteString }
382− deriving (GHC.Generic,Show,Eq,Ord,NFData)
383−instance RenderSQL (ColumnTypeExpression schemas ty) where
384− renderSQL = renderColumnTypeExpression
386−-- | used in `createTable` commands as a column constraint to note that
387−-- @NULL@ may be present in a column
389− :: TypeExpression schemas (nullity ty)
390− -> ColumnTypeExpression schemas ('NoDef :=> 'Null ty)
391−nullable ty = UnsafeColumnTypeExpression $ renderSQL ty <+> "NULL"
393−-- | used in `createTable` commands as a column constraint to ensure
394−-- @NULL@ is not present in a column
396− :: TypeExpression schemas (nullity ty)
397− -> ColumnTypeExpression schemas ('NoDef :=> 'NotNull ty)
398−notNullable ty = UnsafeColumnTypeExpression $ renderSQL ty <+> "NOT NULL"
400−-- | used in `createTable` commands as a column constraint to give a default
402− :: Expression '[] '[] 'Ungrouped schemas '[] '[] ty
403− -> ColumnTypeExpression schemas ('NoDef :=> ty)
404− -> ColumnTypeExpression schemas ('Def :=> ty)
405−default_ x ty = UnsafeColumnTypeExpression $
406− renderSQL ty <+> "DEFAULT" <+> renderExpression x
408−-- | not a true type, but merely a notational convenience for creating
409−-- unique identifier columns with type `PGint2`
411− :: ColumnTypeExpression schemas ('Def :=> 'NotNull 'PGint2)
412−serial2 = UnsafeColumnTypeExpression "serial2"
413−smallserial = UnsafeColumnTypeExpression "smallserial"
414−-- | not a true type, but merely a notational convenience for creating
415−-- unique identifier columns with type `PGint4`
417− :: ColumnTypeExpression schemas ('Def :=> 'NotNull 'PGint4)
418−serial4 = UnsafeColumnTypeExpression "serial4"
419−serial = UnsafeColumnTypeExpression "serial"
420−-- | not a true type, but merely a notational convenience for creating
421−-- unique identifier columns with type `PGint8`
423− :: ColumnTypeExpression schemas ('Def :=> 'NotNull 'PGint8)
424−serial8 = UnsafeColumnTypeExpression "serial8"
425−bigserial = UnsafeColumnTypeExpression "bigserial"
427−-- | Like @PGTyped@ but also accounts for nullity.
428−class PGNullityTyped schemas (nullty :: NullityType) where
429− pgNullityType :: ColumnTypeExpression schemas ('NoDef :=> nullty)
431−instance PGTyped schemas ('Null ty) => PGNullityTyped schemas ('Null ty) where
432− pgNullityType = nullable (pgtype @_ @('Null ty))
434−instance PGTyped schemas ('NotNull ty) => PGNullityTyped schemas ('NotNull ty) where
435− pgNullityType = notNullable (pgtype @_ @('NotNull ty))
437−-- | Allow you to specify pg column types in relation to haskell types.
438−-- >>> printSQL $ hask @(Maybe String)
441−-- >>> printSQL $ hask @Double
444− :: forall hask schemas. PGNullityTyped schemas (NullPG hask)
445− => ColumnTypeExpression schemas ('NoDef :=> NullPG hask)