on dev help sign in
PGTyped and FieldTyped
commit4b85613f73752300428233a10404b9110e226649 authorEitan Chatav <eitan.chatav@gmail.com> dateWed 11 Jul 2018, 22:59 (8 years ago) parentb599986
2 files changed+34−35
squeal-postgresql/src/Squeal/PostgreSQL/Definition.hs+7−9 squeal-postgresql/src/Squeal/PostgreSQL/Expression.hs+27−26
squeal-postgresql/src/Squeal/PostgreSQL/Definition.hs+7−9
@@ -908,22 +908,20 @@ createTypeComposite ty fields = UnsafeDefinition $
908908-- CREATE TYPE "complex" AS ("real" float8, "imaginary" float8);
909909createTypeCompositeFrom
910910 :: forall hask ty schema.
911− ( SOP.All (BaseTyped schema) (PGFieldsFrom hask)
912− , KnownSymbol ty
913− )
911+ ( SOP.All (FieldTyped schema) (PGFieldsFrom hask)
912+ , KnownSymbol ty )
914913 => Alias ty
915914 -- ^ name of the user defined composite type
916915 -> Definition schema (Create ty ( 'Typedef (CompositeFrom hask)) schema)
917916createTypeCompositeFrom ty = createTypeComposite ty
918− (SOP.hcpure (SOP.Proxy :: SOP.Proxy (BaseTyped schema)) basetype
917+ (SOP.hcpure (SOP.Proxy :: SOP.Proxy (FieldTyped schema)) fieldtype
919918 :: NP (Aliased (TypeExpression schema)) (PGFieldsFrom hask))
920−
921919
922−class BaseTyped (schema :: SchemaType) (ty :: (Symbol,NullityType)) where
923− basetype :: Aliased (TypeExpression schema) ty
920+class FieldTyped schema ty where
921+ fieldtype :: Aliased (TypeExpression schema) ty
924922instance (KnownSymbol alias, PGTyped schema ty)
925− => BaseTyped schema (alias ::: nullity ty) where
926− basetype = pgtype @schema @ty `As` Alias @alias
923+ => FieldTyped schema (alias ::: ty) where
924+ fieldtype = pgtype `As` Alias
927925
928926-- | Drop a type.
929927--
squeal-postgresql/src/Squeal/PostgreSQL/Expression.hs+27−26
@@ -211,9 +211,9 @@ instance {-# OVERLAPPABLE #-} (KnownNat n, HasParameter (n-1) schema params ty)
211211-- >>> printSQL expr
212212-- ($1 :: int4)
213213param
214− :: forall n schema params relations grouping nullity ty
215− . (PGTyped schema ty, HasParameter n schema params (nullity ty))
216− => Expression schema relations grouping params (nullity ty) -- ^ param
214+ :: forall n schema params relations grouping ty
215+ . (PGTyped schema ty, HasParameter n schema params ty)
216+ => Expression schema relations grouping params ty -- ^ param
217217param = parameter @n pgtype
218218
219219instance (HasUnique relation relations columns, Has column columns ty)
@@ -1223,32 +1223,33 @@ fixarray ty = UnsafeTypeExpression $
12231223 renderTypeExpression ty <> "[" <> renderNat @n <> "]"
12241224
12251225-- | `pgtype` is a demoted version of a `PGType`
1226−class PGTyped schema (ty :: PGType) where pgtype :: TypeExpression schema (nullity ty)
1227−instance PGTyped schema 'PGbool where pgtype = bool
1228−instance PGTyped schema 'PGint2 where pgtype = int2
1229−instance PGTyped schema 'PGint4 where pgtype = int4
1230−instance PGTyped schema 'PGint8 where pgtype = int8
1231−instance PGTyped schema 'PGnumeric where pgtype = numeric
1232−instance PGTyped schema 'PGfloat4 where pgtype = float4
1233−instance PGTyped schema 'PGfloat8 where pgtype = float8
1234−instance PGTyped schema 'PGtext where pgtype = text
1226+class PGTyped schema (ty :: NullityType) where
1227+ pgtype :: TypeExpression schema ty
1228+instance PGTyped schema (nullity 'PGbool) where pgtype = bool
1229+instance PGTyped schema (nullity 'PGint2) where pgtype = int2
1230+instance PGTyped schema (nullity 'PGint4) where pgtype = int4
1231+instance PGTyped schema (nullity 'PGint8) where pgtype = int8
1232+instance PGTyped schema (nullity 'PGnumeric) where pgtype = numeric
1233+instance PGTyped schema (nullity 'PGfloat4) where pgtype = float4
1234+instance PGTyped schema (nullity 'PGfloat8) where pgtype = float8
1235+instance PGTyped schema (nullity 'PGtext) where pgtype = text
12351236instance (KnownNat n, 1 <= n)
1236− => PGTyped schema ('PGchar n) where pgtype = char @n
1237+ => PGTyped schema (nullity ('PGchar n)) where pgtype = char @n
12371238instance (KnownNat n, 1 <= n)
1238− => PGTyped schema ('PGvarchar n) where pgtype = varchar @n
1239−instance PGTyped schema 'PGbytea where pgtype = bytea
1240−instance PGTyped schema 'PGtimestamp where pgtype = timestamp
1241−instance PGTyped schema 'PGtimestamptz where pgtype = timestampWithTimeZone
1242−instance PGTyped schema 'PGdate where pgtype = date
1243−instance PGTyped schema 'PGtime where pgtype = time
1244−instance PGTyped schema 'PGtimetz where pgtype = timeWithTimeZone
1245−instance PGTyped schema 'PGinterval where pgtype = interval
1246−instance PGTyped schema 'PGuuid where pgtype = uuid
1247−instance PGTyped schema 'PGjson where pgtype = json
1248−instance PGTyped schema 'PGjsonb where pgtype = jsonb
1239+ => PGTyped schema (nullity ('PGvarchar n)) where pgtype = varchar @n
1240+instance PGTyped schema (nullity 'PGbytea) where pgtype = bytea
1241+instance PGTyped schema (nullity 'PGtimestamp) where pgtype = timestamp
1242+instance PGTyped schema (nullity 'PGtimestamptz) where pgtype = timestampWithTimeZone
1243+instance PGTyped schema (nullity 'PGdate) where pgtype = date
1244+instance PGTyped schema (nullity 'PGtime) where pgtype = time
1245+instance PGTyped schema (nullity 'PGtimetz) where pgtype = timeWithTimeZone
1246+instance PGTyped schema (nullity 'PGinterval) where pgtype = interval
1247+instance PGTyped schema (nullity 'PGuuid) where pgtype = uuid
1248+instance PGTyped schema (nullity 'PGjson) where pgtype = json
1249+instance PGTyped schema (nullity 'PGjsonb) where pgtype = jsonb
12491250instance PGTyped schema ty
1250− => PGTyped schema ('PGvararray (nullity ty)) where
1251+ => PGTyped schema (nullity ('PGvararray ty)) where
12511252 pgtype = vararray (pgtype @schema @ty)
12521253instance (KnownNat n, PGTyped schema ty)
1253− => PGTyped schema ('PGfixarray n (nullity ty)) where
1254+ => PGTyped schema (nullity ('PGfixarray n ty)) where
12541255 pgtype = fixarray @n (pgtype @schema @ty)