on dev help sign in
ranges
db95c02Eitan Chatav
squeal-postgresql/src/Squeal/PostgreSQL/Definition.hs+12−2
@@ -45,6 +45,7 @@ module Squeal.PostgreSQL.Definition
45 , createTypeCompositeFrom
45 , createTypeCompositeFrom
46 , FieldTyped (..)
46 , FieldTyped (..)
47 , createDomain
47 , createDomain
48+ , createTypeRange
48 , TableConstraintExpression (..)
49 , TableConstraintExpression (..)
49 , check
50 , check
50 , unique
51 , unique
@@ -1032,14 +1033,23 @@ CREATE DOMAIN "positive" AS real CHECK ((("value" > 0) AND "value" IS NOT NULL))
1032createDomain
1033createDomain
1033 :: (Has sch schemas schema, KnownSymbol dom)
1034 :: (Has sch schemas schema, KnownSymbol dom)
1034 => QualifiedAlias sch dom
1035 => QualifiedAlias sch dom
1035− -> (forall nullity. TypeExpression schemas (nullity ty))
1036+ -> (forall null. TypeExpression schemas (null ty))
1036 -> (forall tab. Condition '[] '[] 'Ungrouped schemas '[] '[tab ::: '["value" ::: 'Null ty]])
1037 -> (forall tab. Condition '[] '[] 'Ungrouped schemas '[] '[tab ::: '["value" ::: 'Null ty]])
1037− -> Definition schemas (Alter sch (Create alias ('Typedef ty) schema) schemas)
1038+ -> Definition schemas (Alter sch (Create dom ('Typedef ty) schema) schemas)
1038createDomain dom ty condition =
1039createDomain dom ty condition =
1039 UnsafeDefinition $ "CREATE DOMAIN" <+> renderSQL dom
1040 UnsafeDefinition $ "CREATE DOMAIN" <+> renderSQL dom
1040 <+> "AS" <+> renderTypeExpression ty
1041 <+> "AS" <+> renderTypeExpression ty
1041 <+> "CHECK" <+> parenthesized (renderSQL condition) <> ";"
1042 <+> "CHECK" <+> parenthesized (renderSQL condition) <> ";"
1042
1043
1044+createTypeRange
1045+ :: (Has sch schemas schema, KnownSymbol range)
1046+ => QualifiedAlias sch range
1047+ -> (forall null. TypeExpression schemas (null ty))
1048+ -> Definition schemas (Alter sch (Create range ('Typedef ('PGrange ty)) schema) schemas)
1049+createTypeRange range ty = UnsafeDefinition $
1050+ "CREATE" <+> "TYPE" <+> renderSQL range <+> "AS" <+> "RANGE" <+>
1051+ parenthesized ("subtype" <+> "=" <+> renderTypeExpression ty)
1052+
1043-- | Lift `PGTyped` to a field
1053-- | Lift `PGTyped` to a field
1044class FieldTyped schemas ty where
1054class FieldTyped schemas ty where
1045 fieldtype :: Aliased (TypeExpression schemas) ty
1055 fieldtype :: Aliased (TypeExpression schemas) ty
squeal-postgresql/src/Squeal/PostgreSQL/Expression.hs+1
@@ -361,6 +361,7 @@ class PGSubset container where
361instance PGSubset 'PGjsonb
361instance PGSubset 'PGjsonb
362instance PGSubset 'PGtsquery
362instance PGSubset 'PGtsquery
363instance PGSubset ('PGvararray ty)
363instance PGSubset ('PGvararray ty)
364+instance PGSubset ('PGrange ty)
364
365
365instance IsString
366instance IsString
366 (Expression outer commons grp schemas params from (null 'PGtext)) where
367 (Expression outer commons grp schemas params from (null 'PGtext)) where
squeal-postgresql/src/Squeal/PostgreSQL/Expression/Type.hs+24
@@ -68,6 +68,12 @@ module Squeal.PostgreSQL.Expression.Type
68 , fixarray
68 , fixarray
69 , tsvector
69 , tsvector
70 , tsquery
70 , tsquery
71+ , int4range
72+ , int8range
73+ , numrange
74+ , tsrange
75+ , tstzrange
76+ , daterange
71 ) where
77 ) where
72
78
73import Control.DeepSeq
79import Control.DeepSeq
@@ -270,6 +276,24 @@ tsvector = UnsafeTypeExpression "tsvector"
270-- | text search document
276-- | text search document
271tsquery :: TypeExpression schemas (null 'PGtsquery)
277tsquery :: TypeExpression schemas (null 'PGtsquery)
272tsquery = UnsafeTypeExpression "tsquery"
278tsquery = UnsafeTypeExpression "tsquery"
279+-- | Range of integer
280+int4range :: TypeExpression schemas (null ('PGrange 'PGint4))
281+int4range = UnsafeTypeExpression "int4range"
282+-- | Range of bigint
283+int8range :: TypeExpression schemas (null ('PGrange 'PGint8))
284+int8range = UnsafeTypeExpression "int8range"
285+-- | Range of numeric
286+numrange :: TypeExpression schemas (null ('PGrange 'PGnumeric))
287+numrange = UnsafeTypeExpression "numrange"
288+-- | Range of timestamp without time zone
289+tsrange :: TypeExpression schemas (null ('PGrange 'PGtimestamp))
290+tsrange = UnsafeTypeExpression "tsrange"
291+-- | Range of timestamp with time zone
292+tstzrange :: TypeExpression schemas (null ('PGrange 'PGtimestamptz))
293+tstzrange = UnsafeTypeExpression "tstzrange"
294+-- | Range of date
295+daterange :: TypeExpression schemas (null ('PGrange 'PGdate))
296+daterange = UnsafeTypeExpression "daterange"
273
297
274-- | `pgtype` is a demoted version of a `PGType`
298-- | `pgtype` is a demoted version of a `PGType`
275class PGTyped schemas (ty :: NullityType) where
299class PGTyped schemas (ty :: NullityType) where
squeal-postgresql/src/Squeal/PostgreSQL/Schema.hs+2−1
@@ -132,7 +132,8 @@ data PGType
132 | PGenum [Symbol] -- ^ enumerated (enum) types are data types that comprise a static, ordered set of values.
132 | PGenum [Symbol] -- ^ enumerated (enum) types are data types that comprise a static, ordered set of values.
133 | PGcomposite RowType -- ^ a composite type represents the structure of a row or record; it is essentially just a list of field names and their data types.
133 | PGcomposite RowType -- ^ a composite type represents the structure of a row or record; it is essentially just a list of field names and their data types.
134 | PGtsvector -- ^ A tsvector value is a sorted list of distinct lexemes, which are words that have been normalized to merge different variants of the same word.
134 | PGtsvector -- ^ A tsvector value is a sorted list of distinct lexemes, which are words that have been normalized to merge different variants of the same word.
135− | PGtsquery -- ^ A tsquery value stores lexemes that are to be searched for
135+ | PGtsquery -- ^ A tsquery value stores lexemes that are to be searched for.
136+ | PGrange PGType -- ^ Range types are data types representing a range of values of some element type (called the range's subtype).
136 | UnsafePGType Symbol -- ^ an escape hatch for unsupported PostgreSQL types
137 | UnsafePGType Symbol -- ^ an escape hatch for unsupported PostgreSQL types
137
138
138-- | `NullityType` encodes the potential presence or definite absence of a
139-- | `NullityType` encodes the potential presence or definite absence of a