on dev help sign in
ranges
commitdb95c02fd1bc32fc49a2dd5d7ba825bd773cda9b authorEitan Chatav <eitan@Eitans-MacBook-Pro.local> dateMon 1 Jul 2019, 10:28 (7 years ago) parent83c711a
4 files changed+39−3
squeal-postgresql/src/Squeal/PostgreSQL/Definition.hs+12−2 squeal-postgresql/src/Squeal/PostgreSQL/Expression.hs+1 squeal-postgresql/src/Squeal/PostgreSQL/Expression/Type.hs+24 squeal-postgresql/src/Squeal/PostgreSQL/Schema.hs+2−1
squeal-postgresql/src/Squeal/PostgreSQL/Definition.hs+12−2
@@ -45,6 +45,7 @@ module Squeal.PostgreSQL.Definition
4545 , createTypeCompositeFrom
4646 , FieldTyped (..)
4747 , createDomain
48+ , createTypeRange
4849 , TableConstraintExpression (..)
4950 , check
5051 , unique
@@ -1032,14 +1033,23 @@ CREATE DOMAIN "positive" AS real CHECK ((("value" > 0) AND "value" IS NOT NULL))
10321033createDomain
10331034 :: (Has sch schemas schema, KnownSymbol dom)
10341035 => QualifiedAlias sch dom
1035− -> (forall nullity. TypeExpression schemas (nullity ty))
1036+ -> (forall null. TypeExpression schemas (null ty))
10361037 -> (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)
10381039createDomain dom ty condition =
10391040 UnsafeDefinition $ "CREATE DOMAIN" <+> renderSQL dom
10401041 <+> "AS" <+> renderTypeExpression ty
10411042 <+> "CHECK" <+> parenthesized (renderSQL condition) <> ";"
10421043
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+
10431053-- | Lift `PGTyped` to a field
10441054class FieldTyped schemas ty where
10451055 fieldtype :: Aliased (TypeExpression schemas) ty
squeal-postgresql/src/Squeal/PostgreSQL/Expression.hs+1
@@ -361,6 +361,7 @@ class PGSubset container where
361361instance PGSubset 'PGjsonb
362362instance PGSubset 'PGtsquery
363363instance PGSubset ('PGvararray ty)
364+instance PGSubset ('PGrange ty)
364365
365366instance IsString
366367 (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
6868 , fixarray
6969 , tsvector
7070 , tsquery
71+ , int4range
72+ , int8range
73+ , numrange
74+ , tsrange
75+ , tstzrange
76+ , daterange
7177 ) where
7278
7379import Control.DeepSeq
@@ -270,6 +276,24 @@ tsvector = UnsafeTypeExpression "tsvector"
270276-- | text search document
271277tsquery :: TypeExpression schemas (null 'PGtsquery)
272278tsquery = 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"
273297
274298-- | `pgtype` is a demoted version of a `PGType`
275299class PGTyped schemas (ty :: NullityType) where
squeal-postgresql/src/Squeal/PostgreSQL/Schema.hs+2−1
@@ -132,7 +132,8 @@ data PGType
132132 | PGenum [Symbol] -- ^ enumerated (enum) types are data types that comprise a static, ordered set of values.
133133 | 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.
134134 | 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).
136137 | UnsafePGType Symbol -- ^ an escape hatch for unsupported PostgreSQL types
137138
138139-- | `NullityType` encodes the potential presence or definite absence of a