on dev help sign in
push through adding schema kind
6e5f5f5Eitan Chatav
squeal-postgresql/src/Squeal/PostgreSQL/Definition.hs+9−13
@@ -248,7 +248,7 @@ check
248 , HasAll aliases (TableToRelation table) subcolumns )
248 , HasAll aliases (TableToRelation table) subcolumns )
249 => NP Alias aliases
249 => NP Alias aliases
250 -- ^ specify the subcolumns which are getting checked
250 -- ^ specify the subcolumns which are getting checked
251− -> (forall tab. Condition '[tab ::: subcolumns] 'Ungrouped '[])
251+ -> (forall tab. Condition schema '[tab ::: subcolumns] 'Ungrouped '[])
252 -- ^ a closed `Condition` on those subcolumns
252 -- ^ a closed `Condition` on those subcolumns
253 -> TableConstraintExpression schema alias ('Check aliases)
253 -> TableConstraintExpression schema alias ('Check aliases)
254check _cols condition = UnsafeTableConstraintExpression $
254check _cols condition = UnsafeTableConstraintExpression $
@@ -695,7 +695,7 @@ newtype AlterColumn (schema :: SchemaType) (ty0 :: ColumnType) (ty1 :: ColumnTyp
695-- :}
695-- :}
696-- "ALTER TABLE \"tab\" ALTER COLUMN \"col\" SET DEFAULT 5;"
696-- "ALTER TABLE \"tab\" ALTER COLUMN \"col\" SET DEFAULT 5;"
697setDefault
697setDefault
698− :: Expression '[] 'Ungrouped '[] ty -- ^ default value to set
698+ :: Expression schema '[] 'Ungrouped '[] ty -- ^ default value to set
699 -> AlterColumn schema (constraint :=> ty) ('Def :=> ty)
699 -> AlterColumn schema (constraint :=> ty) ('Def :=> ty)
700setDefault expression = UnsafeAlterColumn $
700setDefault expression = UnsafeAlterColumn $
701 "SET DEFAULT" <+> renderExpression expression
701 "SET DEFAULT" <+> renderExpression expression
@@ -847,7 +847,7 @@ createTypeComposite
847 :: (KnownSymbol ty, SOP.SListI fields)
847 :: (KnownSymbol ty, SOP.SListI fields)
848 => Alias ty
848 => Alias ty
849 -- ^ name of the user defined composite type
849 -- ^ name of the user defined composite type
850− -> NP (Aliased TypeExpression) fields
850+ -> NP (Aliased (TypeExpression schema)) fields
851 -- ^ list of attribute names and data types
851 -- ^ list of attribute names and data types
852 -> Definition schema (Create ty ('Typedef ('PGcomposite fields)) schema)
852 -> Definition schema (Create ty ('Typedef ('PGcomposite fields)) schema)
853createTypeComposite ty fields = UnsafeDefinition $
853createTypeComposite ty fields = UnsafeDefinition $
@@ -864,7 +864,7 @@ createTypeComposite ty fields = UnsafeDefinition $
864createTypeCompositeWith
864createTypeCompositeWith
865 :: forall hask ty schema.
865 :: forall hask ty schema.
866 ( ZipAliased (FieldNamesWith hask) (FieldTypesWith hask)
866 ( ZipAliased (FieldNamesWith hask) (FieldTypesWith hask)
867− , SOP.All PGTyped (FieldTypesWith hask)
867+ , SOP.All (PGTyped schema) (FieldTypesWith hask)
868 , KnownSymbol ty
868 , KnownSymbol ty
869 )
869 )
870 => Alias ty
870 => Alias ty
@@ -872,8 +872,8 @@ createTypeCompositeWith
872 -> Definition schema (Create ty ( 'Typedef (CompositeWith hask)) schema)
872 -> Definition schema (Create ty ( 'Typedef (CompositeWith hask)) schema)
873createTypeCompositeWith ty = createTypeComposite ty $ zipAs
873createTypeCompositeWith ty = createTypeComposite ty $ zipAs
874 (SOP.hpure Alias :: NP Alias (FieldNamesWith hask))
874 (SOP.hpure Alias :: NP Alias (FieldNamesWith hask))
875− (SOP.hcpure (SOP.Proxy :: SOP.Proxy PGTyped) pgtype
875+ (SOP.hcpure (SOP.Proxy :: SOP.Proxy (PGTyped schema)) pgtype
876− :: NP TypeExpression (FieldTypesWith hask))
876+ :: NP (TypeExpression schema) (FieldTypesWith hask))
877
877
878-- | Drop a type.
878-- | Drop a type.
879--
879--
@@ -894,27 +894,23 @@ newtype ColumnTypeExpression (schema :: SchemaType) (ty :: ColumnType)
894 = UnsafeColumnTypeExpression { renderColumnTypeExpression :: ByteString }
894 = UnsafeColumnTypeExpression { renderColumnTypeExpression :: ByteString }
895 deriving (GHC.Generic,Show,Eq,Ord,NFData)
895 deriving (GHC.Generic,Show,Eq,Ord,NFData)
896
896
897−instance (Has alias schema ('Typedef ty))
898− => IsLabel alias (ColumnTypeExpression schema ('NoDef :=> 'NotNull ty)) where
899− fromLabel = UnsafeColumnTypeExpression (renderAlias (fromLabel @alias) <+> "NOT NULL")
900−
901-- | used in `createTable` commands as a column constraint to note that
897-- | used in `createTable` commands as a column constraint to note that
902-- @NULL@ may be present in a column
898-- @NULL@ may be present in a column
903nullable
899nullable
904− :: TypeExpression ty
900+ :: TypeExpression schema ty
905 -> ColumnTypeExpression schema ('NoDef :=> 'Null ty)
901 -> ColumnTypeExpression schema ('NoDef :=> 'Null ty)
906nullable ty = UnsafeColumnTypeExpression $ renderTypeExpression ty <+> "NULL"
902nullable ty = UnsafeColumnTypeExpression $ renderTypeExpression ty <+> "NULL"
907
903
908-- | used in `createTable` commands as a column constraint to ensure
904-- | used in `createTable` commands as a column constraint to ensure
909-- @NULL@ is not present in a column
905-- @NULL@ is not present in a column
910notNullable
906notNullable
911− :: TypeExpression ty
907+ :: TypeExpression schema ty
912 -> ColumnTypeExpression schema (def :=> 'NotNull ty)
908 -> ColumnTypeExpression schema (def :=> 'NotNull ty)
913notNullable ty = UnsafeColumnTypeExpression $ renderTypeExpression ty <+> "NOT NULL"
909notNullable ty = UnsafeColumnTypeExpression $ renderTypeExpression ty <+> "NOT NULL"
914
910
915-- | used in `createTable` commands as a column constraint to give a default
911-- | used in `createTable` commands as a column constraint to give a default
916default_
912default_
917− :: Expression '[] 'Ungrouped '[] ty
913+ :: Expression schema '[] 'Ungrouped '[] ty
918 -> ColumnTypeExpression schema ('NoDef :=> ty)
914 -> ColumnTypeExpression schema ('NoDef :=> ty)
919 -> ColumnTypeExpression schema ('Def :=> ty)
915 -> ColumnTypeExpression schema ('Def :=> ty)
920default_ x ty = UnsafeColumnTypeExpression $
916default_ x ty = UnsafeColumnTypeExpression $
squeal-postgresql/src/Squeal/PostgreSQL/Expression.hs+250−236
@@ -30,7 +30,8 @@ Squeal expressions are the atoms used to build statements.
30module Squeal.PostgreSQL.Expression
30module Squeal.PostgreSQL.Expression
31 ( -- * Expression
31 ( -- * Expression
32 Expression (UnsafeExpression, renderExpression)
32 Expression (UnsafeExpression, renderExpression)
33− , HasParameter (param)
33+ , HasParameter (parameter)
34+ , param
34 -- ** Null
35 -- ** Null
35 , null_
36 , null_
36 , notNull
37 , notNull
@@ -163,6 +164,7 @@ values from primitive expression using arithmetic, logical,
163and other operations.
164and other operations.
164-}
165-}
165newtype Expression
166newtype Expression
167+ (schema :: SchemaType)
166 (relations :: RelationsType)
168 (relations :: RelationsType)
167 (grouping :: Grouping)
169 (grouping :: Grouping)
168 (params :: [NullityType])
170 (params :: [NullityType])
@@ -178,43 +180,51 @@ supplied externally to a SQL statement.
178separately from the SQL command string, in which case `param`s are used to
180separately from the SQL command string, in which case `param`s are used to
179refer to the out-of-line data values.
181refer to the out-of-line data values.
180-}
182-}
181−class (PGTyped (PGTypeOf ty), KnownNat n) => HasParameter
183+class KnownNat n => HasParameter
182 (n :: Nat)
184 (n :: Nat)
185+ (schema :: SchemaType)
183 (params :: [NullityType])
186 (params :: [NullityType])
184 (ty :: NullityType)
187 (ty :: NullityType)
185 | n params -> ty where
188 | n params -> ty where
189+ parameter
190+ :: TypeExpression schema (PGTypeOf ty)
186− param :: Expression relations grouping params ty
191+ -> Expression schema relations grouping params ty
187− param = UnsafeExpression $ parenthesized $
192+ parameter ty = UnsafeExpression $ parenthesized $
188 "$" <> renderNat (Proxy @n) <+> "::"
193 "$" <> renderNat (Proxy @n) <+> "::"
189− <+> renderTypeExpression (pgtype @(PGTypeOf ty))
194+ <+> renderTypeExpression ty
190−instance {-# OVERLAPPING #-} PGTyped (PGTypeOf ty1)
191− => HasParameter 1 (ty1:tys) ty1
195+instance {-# OVERLAPPING #-} HasParameter 1 schema (ty1:tys) ty1
192−instance {-# OVERLAPPABLE #-} (KnownNat n, HasParameter (n-1) params ty)
196+instance {-# OVERLAPPABLE #-} (KnownNat n, HasParameter (n-1) schema params ty)
193− => HasParameter n (ty' : params) ty
197+ => HasParameter n schema (ty' : params) ty
198+
199+param
200+ :: forall n schema params relations grouping ty
201+ . (PGTyped schema (PGTypeOf ty), HasParameter n schema params ty)
202+ => Expression schema relations grouping params ty
203+param = parameter @n pgtype
194
204
195instance (HasUnique relation relations columns, Has column columns ty)
205instance (HasUnique relation relations columns, Has column columns ty)
196− => IsLabel column (Expression relations 'Ungrouped params ty) where
206+ => IsLabel column (Expression schema relations 'Ungrouped params ty) where
197 fromLabel = UnsafeExpression $ renderAlias (Alias @column)
207 fromLabel = UnsafeExpression $ renderAlias (Alias @column)
198instance (HasUnique relation relations columns, Has column columns ty)
208instance (HasUnique relation relations columns, Has column columns ty)
199 => IsLabel column
209 => IsLabel column
200− (Aliased (Expression relations 'Ungrouped params) (column ::: ty)) where
210+ (Aliased (Expression schema relations 'Ungrouped params) (column ::: ty)) where
201 fromLabel = fromLabel @column `As` Alias @column
211 fromLabel = fromLabel @column `As` Alias @column
202instance (HasUnique relation relations columns, Has column columns ty)
212instance (HasUnique relation relations columns, Has column columns ty)
203 => IsLabel column
213 => IsLabel column
204− (NP (Aliased (Expression relations 'Ungrouped params)) '[column ::: ty]) where
214+ (NP (Aliased (Expression schema relations 'Ungrouped params)) '[column ::: ty]) where
205 fromLabel = fromLabel @column :* Nil
215 fromLabel = fromLabel @column :* Nil
206
216
207instance (Has relation relations columns, Has column columns ty)
217instance (Has relation relations columns, Has column columns ty)
208− => IsQualified relation column (Expression relations 'Ungrouped params ty) where
218+ => IsQualified relation column (Expression schema relations 'Ungrouped params ty) where
209 relation ! column = UnsafeExpression $
219 relation ! column = UnsafeExpression $
210 renderAlias relation <> "." <> renderAlias column
220 renderAlias relation <> "." <> renderAlias column
211instance (Has relation relations columns, Has column columns ty)
221instance (Has relation relations columns, Has column columns ty)
212 => IsQualified relation column
222 => IsQualified relation column
213− (Aliased (Expression relations 'Ungrouped params) (column ::: ty)) where
223+ (Aliased (Expression schema relations 'Ungrouped params) (column ::: ty)) where
214 relation ! column = relation ! column `As` column
224 relation ! column = relation ! column `As` column
215instance (Has relation relations columns, Has column columns ty)
225instance (Has relation relations columns, Has column columns ty)
216 => IsQualified relation column
226 => IsQualified relation column
217− (NP (Aliased (Expression relations 'Ungrouped params)) '[column ::: ty]) where
227+ (NP (Aliased (Expression schema relations 'Ungrouped params)) '[column ::: ty]) where
218 relation ! column = relation ! column :* Nil
228 relation ! column = relation ! column :* Nil
219
229
220instance
230instance
@@ -222,14 +232,14 @@ instance
222 , Has column columns ty
232 , Has column columns ty
223 , GroupedBy relation column bys
233 , GroupedBy relation column bys
224 ) => IsLabel column
234 ) => IsLabel column
225− (Expression relations ('Grouped bys) params ty) where
235+ (Expression schema relations ('Grouped bys) params ty) where
226 fromLabel = UnsafeExpression $ renderAlias (Alias @column)
236 fromLabel = UnsafeExpression $ renderAlias (Alias @column)
227instance
237instance
228 ( HasUnique relation relations columns
238 ( HasUnique relation relations columns
229 , Has column columns ty
239 , Has column columns ty
230 , GroupedBy relation column bys
240 , GroupedBy relation column bys
231 ) => IsLabel column
241 ) => IsLabel column
232− ( Aliased (Expression relations ('Grouped bys) params)
242+ ( Aliased (Expression schema relations ('Grouped bys) params)
233 (column ::: ty) ) where
243 (column ::: ty) ) where
234 fromLabel = fromLabel @column `As` Alias @column
244 fromLabel = fromLabel @column `As` Alias @column
235instance
245instance
@@ -237,7 +247,7 @@ instance
237 , Has column columns ty
247 , Has column columns ty
238 , GroupedBy relation column bys
248 , GroupedBy relation column bys
239 ) => IsLabel column
249 ) => IsLabel column
240− ( NP (Aliased (Expression relations ('Grouped bys) params))
250+ ( NP (Aliased (Expression schema relations ('Grouped bys) params))
241 '[column ::: ty] ) where
251 '[column ::: ty] ) where
242 fromLabel = fromLabel @column :* Nil
252 fromLabel = fromLabel @column :* Nil
243
253
@@ -246,7 +256,7 @@ instance
246 , Has column columns ty
256 , Has column columns ty
247 , GroupedBy relation column bys
257 , GroupedBy relation column bys
248 ) => IsQualified relation column
258 ) => IsQualified relation column
249− (Expression relations ('Grouped bys) params ty) where
259+ (Expression schema relations ('Grouped bys) params ty) where
250 relation ! column = UnsafeExpression $
260 relation ! column = UnsafeExpression $
251 renderAlias relation <> "." <> renderAlias column
261 renderAlias relation <> "." <> renderAlias column
252instance
262instance
@@ -254,7 +264,7 @@ instance
254 , Has column columns ty
264 , Has column columns ty
255 , GroupedBy relation column bys
265 , GroupedBy relation column bys
256 ) => IsQualified relation column
266 ) => IsQualified relation column
257− (Aliased (Expression relations ('Grouped bys) params)
267+ (Aliased (Expression schema relations ('Grouped bys) params)
258 (column ::: ty)) where
268 (column ::: ty)) where
259 relation ! column = relation ! column `As` column
269 relation ! column = relation ! column `As` column
260instance
270instance
@@ -262,7 +272,7 @@ instance
262 , Has column columns ty
272 , Has column columns ty
263 , GroupedBy relation column bys
273 , GroupedBy relation column bys
264 ) => IsQualified relation column
274 ) => IsQualified relation column
265− ( NP (Aliased (Expression relations ('Grouped bys) params))
275+ ( NP (Aliased (Expression schema relations ('Grouped bys) params))
266 '[column ::: ty]) where
276 '[column ::: ty]) where
267 relation ! column = relation ! column :* Nil
277 relation ! column = relation ! column :* Nil
268
278
@@ -270,7 +280,7 @@ instance
270--
280--
271-- >>> renderExpression $ null_
281-- >>> renderExpression $ null_
272-- "NULL"
282-- "NULL"
273−null_ :: Expression rels grouping params ('Null ty)
283+null_ :: Expression schema rels grouping params ('Null ty)
274null_ = UnsafeExpression "NULL"
284null_ = UnsafeExpression "NULL"
275
285
276-- | analagous to `Just`
286-- | analagous to `Just`
@@ -278,8 +288,8 @@ null_ = UnsafeExpression "NULL"
278-- >>> renderExpression $ notNull true
288-- >>> renderExpression $ notNull true
279-- "TRUE"
289-- "TRUE"
280notNull
290notNull
281− :: Expression rels grouping params ('NotNull ty)
291+ :: Expression schema rels grouping params ('NotNull ty)
282− -> Expression rels grouping params ('Null ty)
292+ -> Expression schema rels grouping params ('Null ty)
283notNull = UnsafeExpression . renderExpression
293notNull = UnsafeExpression . renderExpression
284
294
285-- | return the leftmost value which is not NULL
295-- | return the leftmost value which is not NULL
@@ -287,11 +297,11 @@ notNull = UnsafeExpression . renderExpression
287-- >>> renderExpression $ coalesce [null_, notNull true] false
297-- >>> renderExpression $ coalesce [null_, notNull true] false
288-- "COALESCE(NULL, TRUE, FALSE)"
298-- "COALESCE(NULL, TRUE, FALSE)"
289coalesce
299coalesce
290− :: [Expression relations grouping params ('Null ty)]
300+ :: [Expression schema relations grouping params ('Null ty)]
291 -- ^ @NULL@s may be present
301 -- ^ @NULL@s may be present
292− -> Expression relations grouping params ('NotNull ty)
302+ -> Expression schema relations grouping params ('NotNull ty)
293 -- ^ @NULL@ is absent
303 -- ^ @NULL@ is absent
294− -> Expression relations grouping params ('NotNull ty)
304+ -> Expression schema relations grouping params ('NotNull ty)
295coalesce nullxs notNullx = UnsafeExpression $
305coalesce nullxs notNullx = UnsafeExpression $
296 "COALESCE" <> parenthesized (commaSeparated
306 "COALESCE" <> parenthesized (commaSeparated
297 ((renderExpression <$> nullxs) <> [renderExpression notNullx]))
307 ((renderExpression <$> nullxs) <> [renderExpression notNullx]))
@@ -301,26 +311,26 @@ coalesce nullxs notNullx = UnsafeExpression $
301-- >>> renderExpression $ fromNull true null_
311-- >>> renderExpression $ fromNull true null_
302-- "COALESCE(NULL, TRUE)"
312-- "COALESCE(NULL, TRUE)"
303fromNull
313fromNull
304− :: Expression relations grouping params ('NotNull ty)
314+ :: Expression schema relations grouping params ('NotNull ty)
305 -- ^ what to convert @NULL@ to
315 -- ^ what to convert @NULL@ to
306− -> Expression relations grouping params ('Null ty)
316+ -> Expression schema relations grouping params ('Null ty)
307− -> Expression relations grouping params ('NotNull ty)
317+ -> Expression schema relations grouping params ('NotNull ty)
308fromNull notNullx nullx = coalesce [nullx] notNullx
318fromNull notNullx nullx = coalesce [nullx] notNullx
309
319
310-- | >>> renderExpression $ null_ & isNull
320-- | >>> renderExpression $ null_ & isNull
311-- "NULL IS NULL"
321-- "NULL IS NULL"
312isNull
322isNull
313− :: Expression relations grouping params ('Null ty)
323+ :: Expression schema relations grouping params ('Null ty)
314 -- ^ possibly @NULL@
324 -- ^ possibly @NULL@
315− -> Condition relations grouping params
325+ -> Condition schema relations grouping params
316isNull x = UnsafeExpression $ renderExpression x <+> "IS NULL"
326isNull x = UnsafeExpression $ renderExpression x <+> "IS NULL"
317
327
318-- | >>> renderExpression $ null_ & isNotNull
328-- | >>> renderExpression $ null_ & isNotNull
319-- "NULL IS NOT NULL"
329-- "NULL IS NOT NULL"
320isNotNull
330isNotNull
321− :: Expression relations grouping params ('Null ty)
331+ :: Expression schema relations grouping params ('Null ty)
322 -- ^ possibly @NULL@
332 -- ^ possibly @NULL@
323− -> Condition relations grouping params
333+ -> Condition schema relations grouping params
324isNotNull x = UnsafeExpression $ renderExpression x <+> "IS NOT NULL"
334isNotNull x = UnsafeExpression $ renderExpression x <+> "IS NOT NULL"
325
335
326-- | analagous to `maybe` using @IS NULL@
336-- | analagous to `maybe` using @IS NULL@
@@ -328,13 +338,13 @@ isNotNull x = UnsafeExpression $ renderExpression x <+> "IS NOT NULL"
328-- >>> renderExpression $ matchNull true not_ null_
338-- >>> renderExpression $ matchNull true not_ null_
329-- "CASE WHEN NULL IS NULL THEN TRUE ELSE (NOT NULL) END"
339-- "CASE WHEN NULL IS NULL THEN TRUE ELSE (NOT NULL) END"
330matchNull
340matchNull
331− :: Expression relations grouping params (nullty)
341+ :: Expression schema relations grouping params (nullty)
332 -- ^ what to convert @NULL@ to
342 -- ^ what to convert @NULL@ to
333− -> ( Expression relations grouping params ('NotNull ty)
343+ -> ( Expression schema relations grouping params ('NotNull ty)
334− -> Expression relations grouping params (nullty) )
344+ -> Expression schema relations grouping params (nullty) )
335 -- ^ function to perform when @NULL@ is absent
345 -- ^ function to perform when @NULL@ is absent
336− -> Expression relations grouping params ('Null ty)
346+ -> Expression schema relations grouping params ('Null ty)
337− -> Expression relations grouping params (nullty)
347+ -> Expression schema relations grouping params (nullty)
338matchNull y f x = ifThenElse (isNull x) y
348matchNull y f x = ifThenElse (isNull x) y
339 (f (UnsafeExpression (renderExpression x)))
349 (f (UnsafeExpression (renderExpression x)))
340
350
@@ -345,25 +355,25 @@ matchNull y f x = ifThenElse (isNull x) y
345-- >>> renderExpression @_ @_ @'[_] $ fromNull false (nullIf false (param @1))
355-- >>> renderExpression @_ @_ @'[_] $ fromNull false (nullIf false (param @1))
346-- "COALESCE(NULL IF (FALSE, ($1 :: bool)), FALSE)"
356-- "COALESCE(NULL IF (FALSE, ($1 :: bool)), FALSE)"
347nullIf
357nullIf
348− :: Expression relations grouping params ('NotNull ty)
358+ :: Expression schema relations grouping params ('NotNull ty)
349 -- ^ @NULL@ is absent
359 -- ^ @NULL@ is absent
350− -> Expression relations grouping params ('NotNull ty)
360+ -> Expression schema relations grouping params ('NotNull ty)
351 -- ^ @NULL@ is absent
361 -- ^ @NULL@ is absent
352− -> Expression relations grouping params ('Null ty)
362+ -> Expression schema relations grouping params ('Null ty)
353nullIf x y = UnsafeExpression $ "NULL IF" <+> parenthesized
363nullIf x y = UnsafeExpression $ "NULL IF" <+> parenthesized
354 (renderExpression x <> ", " <> renderExpression y)
364 (renderExpression x <> ", " <> renderExpression y)
355
365
356-- | >>> renderExpression $ array [null_, notNull false, notNull true]
366-- | >>> renderExpression $ array [null_, notNull false, notNull true]
357-- "ARRAY[NULL, FALSE, TRUE]"
367-- "ARRAY[NULL, FALSE, TRUE]"
358array
368array
359− :: [Expression relations grouping params ('Null ty)]
369+ :: [Expression schema relations grouping params ('Null ty)]
360 -- ^ array elements
370 -- ^ array elements
361− -> Expression relations grouping params (nullity ('PGvararray ty))
371+ -> Expression schema relations grouping params (nullity ('PGvararray ty))
362array xs = UnsafeExpression $
372array xs = UnsafeExpression $
363 "ARRAY[" <> commaSeparated (renderExpression <$> xs) <> "]"
373 "ARRAY[" <> commaSeparated (renderExpression <$> xs) <> "]"
364
374
365instance (KnownSymbol label, label `In` labels) => IsPGlabel label
375instance (KnownSymbol label, label `In` labels) => IsPGlabel label
366− (Expression relations grouping params (nullity ('PGenum labels))) where
376+ (Expression schema relations grouping params (nullity ('PGenum labels))) where
367 label = UnsafeExpression $ renderLabel (PGlabel @label)
377 label = UnsafeExpression $ renderLabel (PGlabel @label)
368
378
369-- | A row constructor is an expression that builds a row value
379-- | A row constructor is an expression that builds a row value
@@ -375,47 +385,47 @@ instance (KnownSymbol label, label `In` labels) => IsPGlabel label
375-- "ROW(0, 1)"
385-- "ROW(0, 1)"
376row
386row
377 :: SListI (Nulls fields)
387 :: SListI (Nulls fields)
378− => NP (Aliased (Expression relation grouping params)) (Nulls fields)
388+ => NP (Aliased (Expression schema relations grouping params)) (Nulls fields)
379 -- ^ zero or more expressions for the row field values
389 -- ^ zero or more expressions for the row field values
380− -> Expression relation grouping params (nullity ('PGcomposite fields))
390+ -> Expression schema relations grouping params (nullity ('PGcomposite fields))
381row exprs = UnsafeExpression $ "ROW" <> parenthesized
391row exprs = UnsafeExpression $ "ROW" <> parenthesized
382 (renderCommaSeparated (\ (expr `As` _) -> renderExpression expr) exprs)
392 (renderCommaSeparated (\ (expr `As` _) -> renderExpression expr) exprs)
383
393
384instance Has field fields ty => IsLabel field
394instance Has field fields ty => IsLabel field
385− ( Expression relation grouping params (nullity ('PGcomposite fields))
395+ ( Expression schema relation grouping params (nullity ('PGcomposite fields))
386− -> Expression relation grouping params ('Null ty) ) where
396+ -> Expression schema relation grouping params ('Null ty) ) where
387 fromLabel expr = UnsafeExpression $
397 fromLabel expr = UnsafeExpression $
388 parenthesized (renderExpression expr) <> "." <>
398 parenthesized (renderExpression expr) <> "." <>
389 fromString (symbolVal (Proxy @field))
399 fromString (symbolVal (Proxy @field))
390
400
391instance Semigroup
401instance Semigroup
392− (Expression relations grouping params (nullity ('PGvararray ty))) where
402+ (Expression schema relations grouping params (nullity ('PGvararray ty))) where
393 (<>) = unsafeBinaryOp "||"
403 (<>) = unsafeBinaryOp "||"
394
404
395instance Monoid
405instance Monoid
396− (Expression relations grouping params (nullity ('PGvararray ty))) where
406+ (Expression schema relations grouping params (nullity ('PGvararray ty))) where
397 mempty = array []
407 mempty = array []
398 mappend = (<>)
408 mappend = (<>)
399
409
400-- | >>> renderExpression @_ @_ @'[_] $ greatest currentTimestamp [param @1]
410-- | >>> renderExpression @_ @_ @'[_] $ greatest currentTimestamp [param @1]
401-- "GREATEST(CURRENT_TIMESTAMP, ($1 :: timestamp with time zone))"
411-- "GREATEST(CURRENT_TIMESTAMP, ($1 :: timestamp with time zone))"
402greatest
412greatest
403− :: Expression relations grouping params (nullty)
413+ :: Expression schema relations grouping params (nullty)
404 -- ^ needs at least 1 argument
414 -- ^ needs at least 1 argument
405− -> [Expression relations grouping params (nullty)]
415+ -> [Expression schema relations grouping params (nullty)]
406 -- ^ or more
416 -- ^ or more
407− -> Expression relations grouping params (nullty)
417+ -> Expression schema relations grouping params (nullty)
408greatest x xs = UnsafeExpression $ "GREATEST("
418greatest x xs = UnsafeExpression $ "GREATEST("
409 <> commaSeparated (renderExpression <$> (x:xs)) <> ")"
419 <> commaSeparated (renderExpression <$> (x:xs)) <> ")"
410
420
411-- | >>> renderExpression $ least currentTimestamp [null_]
421-- | >>> renderExpression $ least currentTimestamp [null_]
412-- "LEAST(CURRENT_TIMESTAMP, NULL)"
422-- "LEAST(CURRENT_TIMESTAMP, NULL)"
413least
423least
414− :: Expression relations grouping params (nullty)
424+ :: Expression schema relations grouping params (nullty)
415 -- ^ needs at least 1 argument
425 -- ^ needs at least 1 argument
416− -> [Expression relations grouping params (nullty)]
426+ -> [Expression schema relations grouping params (nullty)]
417 -- ^ or more
427 -- ^ or more
418− -> Expression relations grouping params (nullty)
428+ -> Expression schema relations grouping params (nullty)
419least x xs = UnsafeExpression $ "LEAST("
429least x xs = UnsafeExpression $ "LEAST("
420 <> commaSeparated (renderExpression <$> (x:xs)) <> ")"
430 <> commaSeparated (renderExpression <$> (x:xs)) <> ")"
421
431
@@ -424,9 +434,9 @@ least x xs = UnsafeExpression $ "LEAST("
424unsafeBinaryOp
434unsafeBinaryOp
425 :: ByteString
435 :: ByteString
426 -- ^ operator
436 -- ^ operator
427− -> Expression relations grouping params (ty0)
437+ -> Expression schema relations grouping params (ty0)
428− -> Expression relations grouping params (ty1)
438+ -> Expression schema relations grouping params (ty1)
429− -> Expression relations grouping params (ty2)
439+ -> Expression schema relations grouping params (ty2)
430unsafeBinaryOp op x y = UnsafeExpression $ parenthesized $
440unsafeBinaryOp op x y = UnsafeExpression $ parenthesized $
431 renderExpression x <+> op <+> renderExpression y
441 renderExpression x <+> op <+> renderExpression y
432
442
@@ -435,8 +445,8 @@ unsafeBinaryOp op x y = UnsafeExpression $ parenthesized $
435unsafeUnaryOp
445unsafeUnaryOp
436 :: ByteString
446 :: ByteString
437 -- ^ operator
447 -- ^ operator
438− -> Expression relations grouping params (ty0)
448+ -> Expression schema relations grouping params (ty0)
439− -> Expression relations grouping params (ty1)
449+ -> Expression schema relations grouping params (ty1)
440unsafeUnaryOp op x = UnsafeExpression $ parenthesized $
450unsafeUnaryOp op x = UnsafeExpression $ parenthesized $
441 op <+> renderExpression x
451 op <+> renderExpression x
442
452
@@ -445,13 +455,13 @@ unsafeUnaryOp op x = UnsafeExpression $ parenthesized $
445unsafeFunction
455unsafeFunction
446 :: ByteString
456 :: ByteString
447 -- ^ function
457 -- ^ function
448− -> Expression relations grouping params (xty)
458+ -> Expression schema relations grouping params (xty)
449− -> Expression relations grouping params (yty)
459+ -> Expression schema relations grouping params (yty)
450unsafeFunction fun x = UnsafeExpression $
460unsafeFunction fun x = UnsafeExpression $
451 fun <> parenthesized (renderExpression x)
461 fun <> parenthesized (renderExpression x)
452
462
453instance PGNum ty
463instance PGNum ty
454− => Num (Expression relations grouping params (nullity ty)) where
464+ => Num (Expression schema relations grouping params (nullity ty)) where
455 (+) = unsafeBinaryOp "+"
465 (+) = unsafeBinaryOp "+"
456 (-) = unsafeBinaryOp "-"
466 (-) = unsafeBinaryOp "-"
457 (*) = unsafeBinaryOp "*"
467 (*) = unsafeBinaryOp "*"
@@ -463,12 +473,12 @@ instance PGNum ty
463 . show
473 . show
464
474
465instance (PGNum ty, PGFloating ty) => Fractional
475instance (PGNum ty, PGFloating ty) => Fractional
466− (Expression relations grouping params (nullity ty)) where
476+ (Expression schema relations grouping params (nullity ty)) where
467 (/) = unsafeBinaryOp "/"
477 (/) = unsafeBinaryOp "/"
468 fromRational x = fromInteger (numerator x) / fromInteger (denominator x)
478 fromRational x = fromInteger (numerator x) / fromInteger (denominator x)
469
479
470instance (PGNum ty, PGFloating ty) => Floating
480instance (PGNum ty, PGFloating ty) => Floating
471− (Expression relations grouping params (nullity ty)) where
481+ (Expression schema relations grouping params (nullity ty)) where
472 pi = UnsafeExpression "pi()"
482 pi = UnsafeExpression "pi()"
473 exp = unsafeFunction "exp"
483 exp = unsafeFunction "exp"
474 log = unsafeFunction "ln"
484 log = unsafeFunction "ln"
@@ -491,18 +501,18 @@ instance (PGNum ty, PGFloating ty) => Floating
491
501
492-- | >>> :{
502-- | >>> :{
493-- let
503-- let
494−-- expression :: Expression relations grouping params (nullity 'PGfloat4)
504+-- expression :: Expression schema relations grouping params (nullity 'PGfloat4)
495-- expression = atan2_ pi 2
505-- expression = atan2_ pi 2
496-- in renderExpression expression
506-- in renderExpression expression
497-- :}
507-- :}
498-- "atan2(pi(), 2)"
508-- "atan2(pi(), 2)"
499atan2_
509atan2_
500 :: PGFloating float
510 :: PGFloating float
501− => Expression relations grouping params (nullity float)
511+ => Expression schema relations grouping params (nullity float)
502 -- ^ numerator
512 -- ^ numerator
503− -> Expression relations grouping params (nullity float)
513+ -> Expression schema relations grouping params (nullity float)
504 -- ^ denominator
514 -- ^ denominator
505− -> Expression relations grouping params (nullity float)
515+ -> Expression schema relations grouping params (nullity float)
506atan2_ y x = UnsafeExpression $
516atan2_ y x = UnsafeExpression $
507 "atan2(" <> renderExpression y <> ", " <> renderExpression x <> ")"
517 "atan2(" <> renderExpression y <> ", " <> renderExpression x <> ")"
508
518
@@ -513,11 +523,11 @@ atan2_ y x = UnsafeExpression $
513-- | >>> renderExpression $ true & cast int4
523-- | >>> renderExpression $ true & cast int4
514-- "(TRUE :: int4)"
524-- "(TRUE :: int4)"
515cast
525cast
516− :: TypeExpression ty1
526+ :: TypeExpression schema ty1
517 -- ^ type to cast as
527 -- ^ type to cast as
518− -> Expression relations grouping params (nullity ty0)
528+ -> Expression schema relations grouping params (nullity ty0)
519 -- ^ value to convert
529 -- ^ value to convert
520− -> Expression relations grouping params (nullity ty1)
530+ -> Expression schema relations grouping params (nullity ty1)
521cast ty x = UnsafeExpression $ parenthesized $
531cast ty x = UnsafeExpression $ parenthesized $
522 renderExpression x <+> "::" <+> renderTypeExpression ty
532 renderExpression x <+> "::" <+> renderTypeExpression ty
523
533
@@ -525,135 +535,135 @@ cast ty x = UnsafeExpression $ parenthesized $
525--
535--
526-- >>> :{
536-- >>> :{
527-- let
537-- let
528−-- expression :: Expression relations grouping params (nullity 'PGint2)
538+-- expression :: Expression schema relations grouping params (nullity 'PGint2)
529-- expression = 5 `quot_` 2
539-- expression = 5 `quot_` 2
530-- in renderExpression expression
540-- in renderExpression expression
531-- :}
541-- :}
532-- "(5 / 2)"
542-- "(5 / 2)"
533quot_
543quot_
534 :: PGIntegral int
544 :: PGIntegral int
535− => Expression relations grouping params (nullity int)
545+ => Expression schema relations grouping params (nullity int)
536 -- ^ numerator
546 -- ^ numerator
537− -> Expression relations grouping params (nullity int)
547+ -> Expression schema relations grouping params (nullity int)
538 -- ^ denominator
548 -- ^ denominator
539− -> Expression relations grouping params (nullity int)
549+ -> Expression schema relations grouping params (nullity int)
540quot_ = unsafeBinaryOp "/"
550quot_ = unsafeBinaryOp "/"
541
551
542-- | remainder upon integer division
552-- | remainder upon integer division
543--
553--
544-- >>> :{
554-- >>> :{
545-- let
555-- let
546−-- expression :: Expression relations grouping params (nullity 'PGint2)
556+-- expression :: Expression schema relations grouping params (nullity 'PGint2)
547-- expression = 5 `rem_` 2
557-- expression = 5 `rem_` 2
548-- in renderExpression expression
558-- in renderExpression expression
549-- :}
559-- :}
550-- "(5 % 2)"
560-- "(5 % 2)"
551rem_
561rem_
552 :: PGIntegral int
562 :: PGIntegral int
553− => Expression relations grouping params (nullity int)
563+ => Expression schema relations grouping params (nullity int)
554 -- ^ numerator
564 -- ^ numerator
555− -> Expression relations grouping params (nullity int)
565+ -> Expression schema relations grouping params (nullity int)
556 -- ^ denominator
566 -- ^ denominator
557− -> Expression relations grouping params (nullity int)
567+ -> Expression schema relations grouping params (nullity int)
558rem_ = unsafeBinaryOp "%"
568rem_ = unsafeBinaryOp "%"
559
569
560-- | >>> :{
570-- | >>> :{
561-- let
571-- let
562−-- expression :: Expression relations grouping params (nullity 'PGfloat4)
572+-- expression :: Expression schema relations grouping params (nullity 'PGfloat4)
563-- expression = trunc pi
573-- expression = trunc pi
564-- in renderExpression expression
574-- in renderExpression expression
565-- :}
575-- :}
566-- "trunc(pi())"
576-- "trunc(pi())"
567trunc
577trunc
568 :: PGFloating frac
578 :: PGFloating frac
569− => Expression relations grouping params (nullity frac)
579+ => Expression schema relations grouping params (nullity frac)
570 -- ^ fractional number
580 -- ^ fractional number
571− -> Expression relations grouping params (nullity frac)
581+ -> Expression schema relations grouping params (nullity frac)
572trunc = unsafeFunction "trunc"
582trunc = unsafeFunction "trunc"
573
583
574-- | >>> :{
584-- | >>> :{
575-- let
585-- let
576−-- expression :: Expression relations grouping params (nullity 'PGfloat4)
586+-- expression :: Expression schema relations grouping params (nullity 'PGfloat4)
577-- expression = round_ pi
587-- expression = round_ pi
578-- in renderExpression expression
588-- in renderExpression expression
579-- :}
589-- :}
580-- "round(pi())"
590-- "round(pi())"
581round_
591round_
582 :: PGFloating frac
592 :: PGFloating frac
583− => Expression relations grouping params (nullity frac)
593+ => Expression schema relations grouping params (nullity frac)
584 -- ^ fractional number
594 -- ^ fractional number
585− -> Expression relations grouping params (nullity frac)
595+ -> Expression schema relations grouping params (nullity frac)
586round_ = unsafeFunction "round"
596round_ = unsafeFunction "round"
587
597
588-- | >>> :{
598-- | >>> :{
589-- let
599-- let
590−-- expression :: Expression relations grouping params (nullity 'PGfloat4)
600+-- expression :: Expression schema relations grouping params (nullity 'PGfloat4)
591-- expression = ceiling_ pi
601-- expression = ceiling_ pi
592-- in renderExpression expression
602-- in renderExpression expression
593-- :}
603-- :}
594-- "ceiling(pi())"
604-- "ceiling(pi())"
595ceiling_
605ceiling_
596 :: PGFloating frac
606 :: PGFloating frac
597− => Expression relations grouping params (nullity frac)
607+ => Expression schema relations grouping params (nullity frac)
598 -- ^ fractional number
608 -- ^ fractional number
599− -> Expression relations grouping params (nullity frac)
609+ -> Expression schema relations grouping params (nullity frac)
600ceiling_ = unsafeFunction "ceiling"
610ceiling_ = unsafeFunction "ceiling"
601
611
602-- | A `Condition` is a boolean valued `Expression`. While SQL allows
612-- | A `Condition` is a boolean valued `Expression`. While SQL allows
603-- conditions to have @NULL@, Squeal instead chooses to disallow @NULL@,
613-- conditions to have @NULL@, Squeal instead chooses to disallow @NULL@,
604-- forcing one to handle the case of @NULL@ explicitly to produce
614-- forcing one to handle the case of @NULL@ explicitly to produce
605-- a `Condition`.
615-- a `Condition`.
606−type Condition relations grouping params =
616+type Condition schema relations grouping params =
607− Expression relations grouping params ('NotNull 'PGbool)
617+ Expression schema relations grouping params ('NotNull 'PGbool)
608
618
609-- | >>> renderExpression true
619-- | >>> renderExpression true
610-- "TRUE"
620-- "TRUE"
611−true :: Condition relations grouping params
621+true :: Condition schema relations grouping params
612true = UnsafeExpression "TRUE"
622true = UnsafeExpression "TRUE"
613
623
614-- | >>> renderExpression false
624-- | >>> renderExpression false
615-- "FALSE"
625-- "FALSE"
616−false :: Condition relations grouping params
626+false :: Condition schema relations grouping params
617false = UnsafeExpression "FALSE"
627false = UnsafeExpression "FALSE"
618
628
619-- | >>> renderExpression $ not_ true
629-- | >>> renderExpression $ not_ true
620-- "(NOT TRUE)"
630-- "(NOT TRUE)"
621not_
631not_
622− :: Condition relations grouping params
632+ :: Condition schema relations grouping params
623− -> Condition relations grouping params
633+ -> Condition schema relations grouping params
624not_ = unsafeUnaryOp "NOT"
634not_ = unsafeUnaryOp "NOT"
625
635
626-- | >>> renderExpression $ true .&& false
636-- | >>> renderExpression $ true .&& false
627-- "(TRUE AND FALSE)"
637-- "(TRUE AND FALSE)"
628(.&&)
638(.&&)
629− :: Condition relations grouping params
639+ :: Condition schema relations grouping params
630− -> Condition relations grouping params
640+ -> Condition schema relations grouping params
631− -> Condition relations grouping params
641+ -> Condition schema relations grouping params
632(.&&) = unsafeBinaryOp "AND"
642(.&&) = unsafeBinaryOp "AND"
633
643
634-- | >>> renderExpression $ true .|| false
644-- | >>> renderExpression $ true .|| false
635-- "(TRUE OR FALSE)"
645-- "(TRUE OR FALSE)"
636(.||)
646(.||)
637− :: Condition relations grouping params
647+ :: Condition schema relations grouping params
638− -> Condition relations grouping params
648+ -> Condition schema relations grouping params
639− -> Condition relations grouping params
649+ -> Condition schema relations grouping params
640(.||) = unsafeBinaryOp "OR"
650(.||) = unsafeBinaryOp "OR"
641
651
642-- | >>> :{
652-- | >>> :{
643-- let
653-- let
644−-- expression :: Expression relations grouping params (nullity 'PGint2)
654+-- expression :: Expression schema relations grouping params (nullity 'PGint2)
645-- expression = caseWhenThenElse [(true, 1), (false, 2)] 3
655-- expression = caseWhenThenElse [(true, 1), (false, 2)] 3
646-- in renderExpression expression
656-- in renderExpression expression
647-- :}
657-- :}
648-- "CASE WHEN TRUE THEN 1 WHEN FALSE THEN 2 ELSE 3 END"
658-- "CASE WHEN TRUE THEN 1 WHEN FALSE THEN 2 ELSE 3 END"
649caseWhenThenElse
659caseWhenThenElse
650− :: [ ( Condition relations grouping params
660+ :: [ ( Condition schema relations grouping params
651− , Expression relations grouping params (ty)
661+ , Expression schema relations grouping params (ty)
652 ) ]
662 ) ]
653 -- ^ whens and thens
663 -- ^ whens and thens
654− -> Expression relations grouping params (ty)
664+ -> Expression schema relations grouping params (ty)
655 -- ^ else
665 -- ^ else
656− -> Expression relations grouping params (ty)
666+ -> Expression schema relations grouping params (ty)
657caseWhenThenElse whenThens else_ = UnsafeExpression $ mconcat
667caseWhenThenElse whenThens else_ = UnsafeExpression $ mconcat
658 [ "CASE"
668 [ "CASE"
659 , mconcat
669 , mconcat
@@ -669,16 +679,16 @@ caseWhenThenElse whenThens else_ = UnsafeExpression $ mconcat
669
679
670-- | >>> :{
680-- | >>> :{
671-- let
681-- let
672−-- expression :: Expression relations grouping params (nullity 'PGint2)
682+-- expression :: Expression schema relations grouping params (nullity 'PGint2)
673-- expression = ifThenElse true 1 0
683-- expression = ifThenElse true 1 0
674-- in renderExpression expression
684-- in renderExpression expression
675-- :}
685-- :}
676-- "CASE WHEN TRUE THEN 1 ELSE 0 END"
686-- "CASE WHEN TRUE THEN 1 ELSE 0 END"
677ifThenElse
687ifThenElse
678− :: Condition relations grouping params
688+ :: Condition schema relations grouping params
679− -> Expression relations grouping params (ty) -- ^ then
689+ -> Expression schema relations grouping params (ty) -- ^ then
680− -> Expression relations grouping params (ty) -- ^ else
690+ -> Expression schema relations grouping params (ty) -- ^ else
681− -> Expression relations grouping params (ty)
691+ -> Expression schema relations grouping params (ty)
682ifThenElse if_ then_ else_ = caseWhenThenElse [(if_,then_)] else_
692ifThenElse if_ then_ else_ = caseWhenThenElse [(if_,then_)] else_
683
693
684-- | Comparison operations like `.==`, `./=`, `.>`, `.>=`, `.<` and `.<=`
694-- | Comparison operations like `.==`, `./=`, `.>`, `.>=`, `.<` and `.<=`
@@ -687,85 +697,85 @@ ifThenElse if_ then_ else_ = caseWhenThenElse [(if_,then_)] else_
687-- >>> renderExpression $ notNull true .== null_
697-- >>> renderExpression $ notNull true .== null_
688-- "(TRUE = NULL)"
698-- "(TRUE = NULL)"
689(.==)
699(.==)
690− :: Expression relations grouping params (nullity ty) -- ^ lhs
700+ :: Expression schema relations grouping params (nullity ty) -- ^ lhs
691− -> Expression relations grouping params (nullity ty) -- ^ rhs
701+ -> Expression schema relations grouping params (nullity ty) -- ^ rhs
692− -> Expression relations grouping params (nullity 'PGbool)
702+ -> Expression schema relations grouping params (nullity 'PGbool)
693(.==) = unsafeBinaryOp "="
703(.==) = unsafeBinaryOp "="
694infix 4 .==
704infix 4 .==
695
705
696-- | >>> renderExpression $ notNull true ./= null_
706-- | >>> renderExpression $ notNull true ./= null_
697-- "(TRUE <> NULL)"
707-- "(TRUE <> NULL)"
698(./=)
708(./=)
699− :: Expression relations grouping params (nullity ty) -- ^ lhs
709+ :: Expression schema relations grouping params (nullity ty) -- ^ lhs
700− -> Expression relations grouping params (nullity ty) -- ^ rhs
710+ -> Expression schema relations grouping params (nullity ty) -- ^ rhs
701− -> Expression relations grouping params (nullity 'PGbool)
711+ -> Expression schema relations grouping params (nullity 'PGbool)
702(./=) = unsafeBinaryOp "<>"
712(./=) = unsafeBinaryOp "<>"
703infix 4 ./=
713infix 4 ./=
704
714
705-- | >>> renderExpression $ notNull true .>= null_
715-- | >>> renderExpression $ notNull true .>= null_
706-- "(TRUE >= NULL)"
716-- "(TRUE >= NULL)"
707(.>=)
717(.>=)
708− :: Expression relations grouping params (nullity ty) -- ^ lhs
718+ :: Expression schema relations grouping params (nullity ty) -- ^ lhs
709− -> Expression relations grouping params (nullity ty) -- ^ rhs
719+ -> Expression schema relations grouping params (nullity ty) -- ^ rhs
710− -> Expression relations grouping params (nullity 'PGbool)
720+ -> Expression schema relations grouping params (nullity 'PGbool)
711(.>=) = unsafeBinaryOp ">="
721(.>=) = unsafeBinaryOp ">="
712infix 4 .>=
722infix 4 .>=
713
723
714-- | >>> renderExpression $ notNull true .< null_
724-- | >>> renderExpression $ notNull true .< null_
715-- "(TRUE < NULL)"
725-- "(TRUE < NULL)"
716(.<)
726(.<)
717− :: Expression relations grouping params (nullity ty) -- ^ lhs
727+ :: Expression schema relations grouping params (nullity ty) -- ^ lhs
718− -> Expression relations grouping params (nullity ty) -- ^ rhs
728+ -> Expression schema relations grouping params (nullity ty) -- ^ rhs
719− -> Expression relations grouping params (nullity 'PGbool)
729+ -> Expression schema relations grouping params (nullity 'PGbool)
720(.<) = unsafeBinaryOp "<"
730(.<) = unsafeBinaryOp "<"
721infix 4 .<
731infix 4 .<
722
732
723-- | >>> renderExpression $ notNull true .<= null_
733-- | >>> renderExpression $ notNull true .<= null_
724-- "(TRUE <= NULL)"
734-- "(TRUE <= NULL)"
725(.<=)
735(.<=)
726− :: Expression relations grouping params (nullity ty) -- ^ lhs
736+ :: Expression schema relations grouping params (nullity ty) -- ^ lhs
727− -> Expression relations grouping params (nullity ty) -- ^ rhs
737+ -> Expression schema relations grouping params (nullity ty) -- ^ rhs
728− -> Expression relations grouping params (nullity 'PGbool)
738+ -> Expression schema relations grouping params (nullity 'PGbool)
729(.<=) = unsafeBinaryOp "<="
739(.<=) = unsafeBinaryOp "<="
730infix 4 .<=
740infix 4 .<=
731
741
732-- | >>> renderExpression $ notNull true .> null_
742-- | >>> renderExpression $ notNull true .> null_
733-- "(TRUE > NULL)"
743-- "(TRUE > NULL)"
734(.>)
744(.>)
735− :: Expression relations grouping params (nullity ty) -- ^ lhs
745+ :: Expression schema relations grouping params (nullity ty) -- ^ lhs
736− -> Expression relations grouping params (nullity ty) -- ^ rhs
746+ -> Expression schema relations grouping params (nullity ty) -- ^ rhs
737− -> Expression relations grouping params (nullity 'PGbool)
747+ -> Expression schema relations grouping params (nullity 'PGbool)
738(.>) = unsafeBinaryOp ">"
748(.>) = unsafeBinaryOp ">"
739infix 4 .>
749infix 4 .>
740
750
741-- | >>> renderExpression currentDate
751-- | >>> renderExpression currentDate
742-- "CURRENT_DATE"
752-- "CURRENT_DATE"
743currentDate
753currentDate
744− :: Expression relations grouping params (nullity 'PGdate)
754+ :: Expression schema relations grouping params (nullity 'PGdate)
745currentDate = UnsafeExpression "CURRENT_DATE"
755currentDate = UnsafeExpression "CURRENT_DATE"
746
756
747-- | >>> renderExpression currentTime
757-- | >>> renderExpression currentTime
748-- "CURRENT_TIME"
758-- "CURRENT_TIME"
749currentTime
759currentTime
750− :: Expression relations grouping params (nullity 'PGtimetz)
760+ :: Expression schema relations grouping params (nullity 'PGtimetz)
751currentTime = UnsafeExpression "CURRENT_TIME"
761currentTime = UnsafeExpression "CURRENT_TIME"
752
762
753-- | >>> renderExpression currentTimestamp
763-- | >>> renderExpression currentTimestamp
754-- "CURRENT_TIMESTAMP"
764-- "CURRENT_TIMESTAMP"
755currentTimestamp
765currentTimestamp
756− :: Expression relations grouping params (nullity 'PGtimestamptz)
766+ :: Expression schema relations grouping params (nullity 'PGtimestamptz)
757currentTimestamp = UnsafeExpression "CURRENT_TIMESTAMP"
767currentTimestamp = UnsafeExpression "CURRENT_TIMESTAMP"
758
768
759-- | >>> renderExpression localTime
769-- | >>> renderExpression localTime
760-- "LOCALTIME"
770-- "LOCALTIME"
761localTime
771localTime
762− :: Expression relations grouping params (nullity 'PGtime)
772+ :: Expression schema relations grouping params (nullity 'PGtime)
763localTime = UnsafeExpression "LOCALTIME"
773localTime = UnsafeExpression "LOCALTIME"
764
774
765-- | >>> renderExpression localTimestamp
775-- | >>> renderExpression localTimestamp
766-- "LOCALTIMESTAMP"
776-- "LOCALTIMESTAMP"
767localTimestamp
777localTimestamp
768− :: Expression relations grouping params (nullity 'PGtimestamp)
778+ :: Expression schema relations grouping params (nullity 'PGtimestamp)
769localTimestamp = UnsafeExpression "LOCALTIMESTAMP"
779localTimestamp = UnsafeExpression "LOCALTIMESTAMP"
770
780
771{-----------------------------------------
781{-----------------------------------------
@@ -773,7 +783,7 @@ text
773-----------------------------------------}
783-----------------------------------------}
774
784
775instance IsString
785instance IsString
776− (Expression relations grouping params (nullity 'PGtext)) where
786+ (Expression schema relations grouping params (nullity 'PGtext)) where
777 fromString str = UnsafeExpression $
787 fromString str = UnsafeExpression $
778 "E\'" <> fromString (escape =<< str) <> "\'"
788 "E\'" <> fromString (escape =<< str) <> "\'"
779 where
789 where
@@ -789,36 +799,36 @@ instance IsString
789 c -> [c]
799 c -> [c]
790
800
791instance Semigroup
801instance Semigroup
792− (Expression relations grouping params (nullity 'PGtext)) where
802+ (Expression schema relations grouping params (nullity 'PGtext)) where
793 (<>) = unsafeBinaryOp "||"
803 (<>) = unsafeBinaryOp "||"
794
804
795instance Monoid
805instance Monoid
796− (Expression relations grouping params (nullity 'PGtext)) where
806+ (Expression schema relations grouping params (nullity 'PGtext)) where
797 mempty = fromString ""
807 mempty = fromString ""
798 mappend = (<>)
808 mappend = (<>)
799
809
800-- | >>> renderExpression $ lower "ARRRGGG"
810-- | >>> renderExpression $ lower "ARRRGGG"
801-- "lower(E'ARRRGGG')"
811-- "lower(E'ARRRGGG')"
802lower
812lower
803− :: Expression relations grouping params (nullity 'PGtext)
813+ :: Expression schema relations grouping params (nullity 'PGtext)
804 -- ^ string to lower case
814 -- ^ string to lower case
805− -> Expression relations grouping params (nullity 'PGtext)
815+ -> Expression schema relations grouping params (nullity 'PGtext)
806lower = unsafeFunction "lower"
816lower = unsafeFunction "lower"
807
817
808-- | >>> renderExpression $ upper "eeee"
818-- | >>> renderExpression $ upper "eeee"
809-- "upper(E'eeee')"
819-- "upper(E'eeee')"
810upper
820upper
811− :: Expression relations grouping params (nullity 'PGtext)
821+ :: Expression schema relations grouping params (nullity 'PGtext)
812 -- ^ string to upper case
822 -- ^ string to upper case
813− -> Expression relations grouping params (nullity 'PGtext)
823+ -> Expression schema relations grouping params (nullity 'PGtext)
814upper = unsafeFunction "upper"
824upper = unsafeFunction "upper"
815
825
816-- | >>> renderExpression $ charLength "four"
826-- | >>> renderExpression $ charLength "four"
817-- "char_length(E'four')"
827-- "char_length(E'four')"
818charLength
828charLength
819− :: Expression relations grouping params (nullity 'PGtext)
829+ :: Expression schema relations grouping params (nullity 'PGtext)
820 -- ^ string to measure
830 -- ^ string to measure
821− -> Expression relations grouping params (nullity 'PGint4)
831+ -> Expression schema relations grouping params (nullity 'PGint4)
822charLength = unsafeFunction "char_length"
832charLength = unsafeFunction "char_length"
823
833
824-- | The `like` expression returns true if the @string@ matches
834-- | The `like` expression returns true if the @string@ matches
@@ -831,11 +841,11 @@ charLength = unsafeFunction "char_length"
831-- >>> renderExpression $ "abc" `like` "a%"
841-- >>> renderExpression $ "abc" `like` "a%"
832-- "(E'abc' LIKE E'a%')"
842-- "(E'abc' LIKE E'a%')"
833like
843like
834− :: Expression relations grouping params (nullity 'PGtext)
844+ :: Expression schema relations grouping params (nullity 'PGtext)
835 -- ^ string
845 -- ^ string
836− -> Expression relations grouping params (nullity 'PGtext)
846+ -> Expression schema relations grouping params (nullity 'PGtext)
837 -- ^ pattern
847 -- ^ pattern
838− -> Expression relations grouping params (nullity 'PGbool)
848+ -> Expression schema relations grouping params (nullity 'PGbool)
839like = unsafeBinaryOp "LIKE"
849like = unsafeBinaryOp "LIKE"
840
850
841{-----------------------------------------
851{-----------------------------------------
@@ -845,16 +855,16 @@ aggregation
845-- | escape hatch to define aggregate functions
855-- | escape hatch to define aggregate functions
846unsafeAggregate
856unsafeAggregate
847 :: ByteString -- ^ aggregate function
857 :: ByteString -- ^ aggregate function
848− -> Expression relations 'Ungrouped params (xty)
858+ -> Expression schema relations 'Ungrouped params (xty)
849− -> Expression relations ('Grouped bys) params (yty)
859+ -> Expression schema relations ('Grouped bys) params (yty)
850unsafeAggregate fun x = UnsafeExpression $ mconcat
860unsafeAggregate fun x = UnsafeExpression $ mconcat
851 [fun, "(", renderExpression x, ")"]
861 [fun, "(", renderExpression x, ")"]
852
862
853-- | escape hatch to define aggregate functions over distinct values
863-- | escape hatch to define aggregate functions over distinct values
854unsafeAggregateDistinct
864unsafeAggregateDistinct
855 :: ByteString -- ^ aggregate function
865 :: ByteString -- ^ aggregate function
856− -> Expression relations 'Ungrouped params (xty)
866+ -> Expression schema relations 'Ungrouped params (xty)
857− -> Expression relations ('Grouped bys) params (yty)
867+ -> Expression schema relations ('Grouped bys) params (yty)
858unsafeAggregateDistinct fun x = UnsafeExpression $ mconcat
868unsafeAggregateDistinct fun x = UnsafeExpression $ mconcat
859 [fun, "(DISTINCT ", renderExpression x, ")"]
869 [fun, "(DISTINCT ", renderExpression x, ")"]
860
870
@@ -867,9 +877,9 @@ unsafeAggregateDistinct fun x = UnsafeExpression $ mconcat
867-- "sum(\"col\")"
877-- "sum(\"col\")"
868sum_
878sum_
869 :: PGNum ty
879 :: PGNum ty
870− => Expression relations 'Ungrouped params (nullity ty)
880+ => Expression schema relations 'Ungrouped params (nullity ty)
871 -- ^ what to sum
881 -- ^ what to sum
872− -> Expression relations ('Grouped bys) params (nullity ty)
882+ -> Expression schema relations ('Grouped bys) params (nullity ty)
873sum_ = unsafeAggregate "sum"
883sum_ = unsafeAggregate "sum"
874
884
875-- | >>> :{
885-- | >>> :{
@@ -881,18 +891,18 @@ sum_ = unsafeAggregate "sum"
881-- "sum(DISTINCT \"col\")"
891-- "sum(DISTINCT \"col\")"
882sumDistinct
892sumDistinct
883 :: PGNum ty
893 :: PGNum ty
884− => Expression relations 'Ungrouped params (nullity ty)
894+ => Expression schema relations 'Ungrouped params (nullity ty)
885 -- ^ what to sum
895 -- ^ what to sum
886− -> Expression relations ('Grouped bys) params (nullity ty)
896+ -> Expression schema relations ('Grouped bys) params (nullity ty)
887sumDistinct = unsafeAggregateDistinct "sum"
897sumDistinct = unsafeAggregateDistinct "sum"
888
898
889-- | A constraint for `PGType`s that you can take averages of and the resulting
899-- | A constraint for `PGType`s that you can take averages of and the resulting
890-- `PGType`.
900-- `PGType`.
891class PGAvg ty avg | ty -> avg where
901class PGAvg ty avg | ty -> avg where
892 avg, avgDistinct
902 avg, avgDistinct
893− :: Expression relations 'Ungrouped params (nullity ty)
903+ :: Expression schema relations 'Ungrouped params (nullity ty)
894 -- ^ what to average
904 -- ^ what to average
895− -> Expression relations ('Grouped bys) params (nullity avg)
905+ -> Expression schema relations ('Grouped bys) params (nullity avg)
896 avg = unsafeAggregate "avg"
906 avg = unsafeAggregate "avg"
897 avgDistinct = unsafeAggregateDistinct "avg"
907 avgDistinct = unsafeAggregateDistinct "avg"
898instance PGAvg 'PGint2 'PGnumeric
908instance PGAvg 'PGint2 'PGnumeric
@@ -912,9 +922,9 @@ instance PGAvg 'PGinterval 'PGinterval
912-- "bit_and(\"col\")"
922-- "bit_and(\"col\")"
913bitAnd
923bitAnd
914 :: PGIntegral int
924 :: PGIntegral int
915− => Expression relations 'Ungrouped params (nullity int)
925+ => Expression schema relations 'Ungrouped params (nullity int)
916 -- ^ what to aggregate
926 -- ^ what to aggregate
917− -> Expression relations ('Grouped bys) params (nullity int)
927+ -> Expression schema relations ('Grouped bys) params (nullity int)
918bitAnd = unsafeAggregate "bit_and"
928bitAnd = unsafeAggregate "bit_and"
919
929
920-- | >>> :{
930-- | >>> :{
@@ -926,9 +936,9 @@ bitAnd = unsafeAggregate "bit_and"
926-- "bit_or(\"col\")"
936-- "bit_or(\"col\")"
927bitOr
937bitOr
928 :: PGIntegral int
938 :: PGIntegral int
929− => Expression relations 'Ungrouped params (nullity int)
939+ => Expression schema relations 'Ungrouped params (nullity int)
930 -- ^ what to aggregate
940 -- ^ what to aggregate
931− -> Expression relations ('Grouped bys) params (nullity int)
941+ -> Expression schema relations ('Grouped bys) params (nullity int)
932bitOr = unsafeAggregate "bit_or"
942bitOr = unsafeAggregate "bit_or"
933
943
934-- | >>> :{
944-- | >>> :{
@@ -940,9 +950,9 @@ bitOr = unsafeAggregate "bit_or"
940-- "bit_and(DISTINCT \"col\")"
950-- "bit_and(DISTINCT \"col\")"
941bitAndDistinct
951bitAndDistinct
942 :: PGIntegral int
952 :: PGIntegral int
943− => Expression relations 'Ungrouped params (nullity int)
953+ => Expression schema relations 'Ungrouped params (nullity int)
944 -- ^ what to aggregate
954 -- ^ what to aggregate
945− -> Expression relations ('Grouped bys) params (nullity int)
955+ -> Expression schema relations ('Grouped bys) params (nullity int)
946bitAndDistinct = unsafeAggregateDistinct "bit_and"
956bitAndDistinct = unsafeAggregateDistinct "bit_and"
947
957
948-- | >>> :{
958-- | >>> :{
@@ -954,9 +964,9 @@ bitAndDistinct = unsafeAggregateDistinct "bit_and"
954-- "bit_or(DISTINCT \"col\")"
964-- "bit_or(DISTINCT \"col\")"
955bitOrDistinct
965bitOrDistinct
956 :: PGIntegral int
966 :: PGIntegral int
957− => Expression relations 'Ungrouped params (nullity int)
967+ => Expression schema relations 'Ungrouped params (nullity int)
958 -- ^ what to aggregate
968 -- ^ what to aggregate
959− -> Expression relations ('Grouped bys) params (nullity int)
969+ -> Expression schema relations ('Grouped bys) params (nullity int)
960bitOrDistinct = unsafeAggregateDistinct "bit_or"
970bitOrDistinct = unsafeAggregateDistinct "bit_or"
961
971
962-- | >>> :{
972-- | >>> :{
@@ -967,9 +977,9 @@ bitOrDistinct = unsafeAggregateDistinct "bit_or"
967-- :}
977-- :}
968-- "bool_and(\"col\")"
978-- "bool_and(\"col\")"
969boolAnd
979boolAnd
970− :: Expression relations 'Ungrouped params (nullity 'PGbool)
980+ :: Expression schema relations 'Ungrouped params (nullity 'PGbool)
971 -- ^ what to aggregate
981 -- ^ what to aggregate
972− -> Expression relations ('Grouped bys) params (nullity 'PGbool)
982+ -> Expression schema relations ('Grouped bys) params (nullity 'PGbool)
973boolAnd = unsafeAggregate "bool_and"
983boolAnd = unsafeAggregate "bool_and"
974
984
975-- | >>> :{
985-- | >>> :{
@@ -980,9 +990,9 @@ boolAnd = unsafeAggregate "bool_and"
980-- :}
990-- :}
981-- "bool_or(\"col\")"
991-- "bool_or(\"col\")"
982boolOr
992boolOr
983− :: Expression relations 'Ungrouped params (nullity 'PGbool)
993+ :: Expression schema relations 'Ungrouped params (nullity 'PGbool)
984 -- ^ what to aggregate
994 -- ^ what to aggregate
985− -> Expression relations ('Grouped bys) params (nullity 'PGbool)
995+ -> Expression schema relations ('Grouped bys) params (nullity 'PGbool)
986boolOr = unsafeAggregate "bool_or"
996boolOr = unsafeAggregate "bool_or"
987
997
988-- | >>> :{
998-- | >>> :{
@@ -993,9 +1003,9 @@ boolOr = unsafeAggregate "bool_or"
993-- :}
1003-- :}
994-- "bool_and(DISTINCT \"col\")"
1004-- "bool_and(DISTINCT \"col\")"
995boolAndDistinct
1005boolAndDistinct
996− :: Expression relations 'Ungrouped params (nullity 'PGbool)
1006+ :: Expression schema relations 'Ungrouped params (nullity 'PGbool)
997 -- ^ what to aggregate
1007 -- ^ what to aggregate
998− -> Expression relations ('Grouped bys) params (nullity 'PGbool)
1008+ -> Expression schema relations ('Grouped bys) params (nullity 'PGbool)
999boolAndDistinct = unsafeAggregateDistinct "bool_and"
1009boolAndDistinct = unsafeAggregateDistinct "bool_and"
1000
1010
1001-- | >>> :{
1011-- | >>> :{
@@ -1006,9 +1016,9 @@ boolAndDistinct = unsafeAggregateDistinct "bool_and"
1006-- :}
1016-- :}
1007-- "bool_or(DISTINCT \"col\")"
1017-- "bool_or(DISTINCT \"col\")"
1008boolOrDistinct
1018boolOrDistinct
1009− :: Expression relations 'Ungrouped params (nullity 'PGbool)
1019+ :: Expression schema relations 'Ungrouped params (nullity 'PGbool)
1010 -- ^ what to aggregate
1020 -- ^ what to aggregate
1011− -> Expression relations ('Grouped bys) params (nullity 'PGbool)
1021+ -> Expression schema relations ('Grouped bys) params (nullity 'PGbool)
1012boolOrDistinct = unsafeAggregateDistinct "bool_or"
1022boolOrDistinct = unsafeAggregateDistinct "bool_or"
1013
1023
1014-- | A special aggregation that does not require an input
1024-- | A special aggregation that does not require an input
@@ -1016,7 +1026,7 @@ boolOrDistinct = unsafeAggregateDistinct "bool_or"
1016-- >>> renderExpression countStar
1026-- >>> renderExpression countStar
1017-- "count(*)"
1027-- "count(*)"
1018countStar
1028countStar
1019− :: Expression relations ('Grouped bys) params ('NotNull 'PGint8)
1029+ :: Expression schema relations ('Grouped bys) params ('NotNull 'PGint8)
1020countStar = UnsafeExpression $ "count(*)"
1030countStar = UnsafeExpression $ "count(*)"
1021
1031
1022-- | >>> :{
1032-- | >>> :{
@@ -1027,9 +1037,9 @@ countStar = UnsafeExpression $ "count(*)"
1027-- :}
1037-- :}
1028-- "count(\"col\")"
1038-- "count(\"col\")"
1029count
1039count
1030− :: Expression relations 'Ungrouped params ty
1040+ :: Expression schema relations 'Ungrouped params ty
1031 -- ^ what to count
1041 -- ^ what to count
1032− -> Expression relations ('Grouped bys) params ('NotNull 'PGint8)
1042+ -> Expression schema relations ('Grouped bys) params ('NotNull 'PGint8)
1033count = unsafeAggregate "count"
1043count = unsafeAggregate "count"
1034
1044
1035-- | >>> :{
1045-- | >>> :{
@@ -1040,9 +1050,9 @@ count = unsafeAggregate "count"
1040-- :}
1050-- :}
1041-- "count(DISTINCT \"col\")"
1051-- "count(DISTINCT \"col\")"
1042countDistinct
1052countDistinct
1043− :: Expression relations 'Ungrouped params ty
1053+ :: Expression schema relations 'Ungrouped params ty
1044 -- ^ what to count
1054 -- ^ what to count
1045− -> Expression relations ('Grouped bys) params ('NotNull 'PGint8)
1055+ -> Expression schema relations ('Grouped bys) params ('NotNull 'PGint8)
1046countDistinct = unsafeAggregateDistinct "count"
1056countDistinct = unsafeAggregateDistinct "count"
1047
1057
1048-- | synonym for `boolAnd`
1058-- | synonym for `boolAnd`
@@ -1055,9 +1065,9 @@ countDistinct = unsafeAggregateDistinct "count"
1055-- :}
1065-- :}
1056-- "every(\"col\")"
1066-- "every(\"col\")"
1057every
1067every
1058− :: Expression relations 'Ungrouped params (nullity 'PGbool)
1068+ :: Expression schema relations 'Ungrouped params (nullity 'PGbool)
1059 -- ^ what to aggregate
1069 -- ^ what to aggregate
1060− -> Expression relations ('Grouped bys) params (nullity 'PGbool)
1070+ -> Expression schema relations ('Grouped bys) params (nullity 'PGbool)
1061every = unsafeAggregate "every"
1071every = unsafeAggregate "every"
1062
1072
1063-- | synonym for `boolAndDistinct`
1073-- | synonym for `boolAndDistinct`
@@ -1070,16 +1080,16 @@ every = unsafeAggregate "every"
1070-- :}
1080-- :}
1071-- "every(DISTINCT \"col\")"
1081-- "every(DISTINCT \"col\")"
1072everyDistinct
1082everyDistinct
1073− :: Expression relations 'Ungrouped params (nullity 'PGbool)
1083+ :: Expression schema relations 'Ungrouped params (nullity 'PGbool)
1074 -- ^ what to aggregate
1084 -- ^ what to aggregate
1075− -> Expression relations ('Grouped bys) params (nullity 'PGbool)
1085+ -> Expression schema relations ('Grouped bys) params (nullity 'PGbool)
1076everyDistinct = unsafeAggregateDistinct "every"
1086everyDistinct = unsafeAggregateDistinct "every"
1077
1087
1078-- | minimum and maximum aggregation
1088-- | minimum and maximum aggregation
1079max_, min_, maxDistinct, minDistinct
1089max_, min_, maxDistinct, minDistinct
1080− :: Expression relations 'Ungrouped params (nullity ty)
1090+ :: Expression schema relations 'Ungrouped params (nullity ty)
1081 -- ^ what to aggregate
1091 -- ^ what to aggregate
1082− -> Expression relations ('Grouped bys) params (nullity ty)
1092+ -> Expression schema relations ('Grouped bys) params (nullity ty)
1083max_ = unsafeAggregate "max"
1093max_ = unsafeAggregate "max"
1084min_ = unsafeAggregate "min"
1094min_ = unsafeAggregate "min"
1085maxDistinct = unsafeAggregateDistinct "max"
1095maxDistinct = unsafeAggregateDistinct "max"
@@ -1090,92 +1100,96 @@ type expressions
1090-----------------------------------------}
1100-----------------------------------------}
1091
1101
1092-- | `TypeExpression`s are used in `cast`s and `createTable` commands.
1102-- | `TypeExpression`s are used in `cast`s and `createTable` commands.
1093−newtype TypeExpression (ty :: PGType)
1103+newtype TypeExpression (schema :: SchemaType) (ty :: PGType)
1094 = UnsafeTypeExpression { renderTypeExpression :: ByteString }
1104 = UnsafeTypeExpression { renderTypeExpression :: ByteString }
1095 deriving (GHC.Generic,Show,Eq,Ord,NFData)
1105 deriving (GHC.Generic,Show,Eq,Ord,NFData)
1096
1106
1107+instance (Has alias schema ('Typedef ty))
1108+ => IsLabel alias (TypeExpression schema ty) where
1109+ fromLabel = UnsafeTypeExpression (renderAlias (fromLabel @alias))
1110+
1097-- | logical Boolean (true/false)
1111-- | logical Boolean (true/false)
1098−bool :: TypeExpression 'PGbool
1112+bool :: TypeExpression schema 'PGbool
1099bool = UnsafeTypeExpression "bool"
1113bool = UnsafeTypeExpression "bool"
1100-- | signed two-byte integer
1114-- | signed two-byte integer
1101−int2, smallint :: TypeExpression 'PGint2
1115+int2, smallint :: TypeExpression schema 'PGint2
1102int2 = UnsafeTypeExpression "int2"
1116int2 = UnsafeTypeExpression "int2"
1103smallint = UnsafeTypeExpression "smallint"
1117smallint = UnsafeTypeExpression "smallint"
1104-- | signed four-byte integer
1118-- | signed four-byte integer
1105−int4, int, integer :: TypeExpression 'PGint4
1119+int4, int, integer :: TypeExpression schema 'PGint4
1106int4 = UnsafeTypeExpression "int4"
1120int4 = UnsafeTypeExpression "int4"
1107int = UnsafeTypeExpression "int"
1121int = UnsafeTypeExpression "int"
1108integer = UnsafeTypeExpression "integer"
1122integer = UnsafeTypeExpression "integer"
1109-- | signed eight-byte integer
1123-- | signed eight-byte integer
1110−int8, bigint :: TypeExpression 'PGint8
1124+int8, bigint :: TypeExpression schema 'PGint8
1111int8 = UnsafeTypeExpression "int8"
1125int8 = UnsafeTypeExpression "int8"
1112bigint = UnsafeTypeExpression "bigint"
1126bigint = UnsafeTypeExpression "bigint"
1113-- | arbitrary precision numeric type
1127-- | arbitrary precision numeric type
1114−numeric :: TypeExpression 'PGnumeric
1128+numeric :: TypeExpression schema 'PGnumeric
1115numeric = UnsafeTypeExpression "numeric"
1129numeric = UnsafeTypeExpression "numeric"
1116-- | single precision floating-point number (4 bytes)
1130-- | single precision floating-point number (4 bytes)
1117−float4, real :: TypeExpression 'PGfloat4
1131+float4, real :: TypeExpression schema 'PGfloat4
1118float4 = UnsafeTypeExpression "float4"
1132float4 = UnsafeTypeExpression "float4"
1119real = UnsafeTypeExpression "real"
1133real = UnsafeTypeExpression "real"
1120-- | double precision floating-point number (8 bytes)
1134-- | double precision floating-point number (8 bytes)
1121−float8, doublePrecision :: TypeExpression 'PGfloat8
1135+float8, doublePrecision :: TypeExpression schema 'PGfloat8
1122float8 = UnsafeTypeExpression "float8"
1136float8 = UnsafeTypeExpression "float8"
1123doublePrecision = UnsafeTypeExpression "double precision"
1137doublePrecision = UnsafeTypeExpression "double precision"
1124-- | variable-length character string
1138-- | variable-length character string
1125−text :: TypeExpression 'PGtext
1139+text :: TypeExpression schema 'PGtext
1126text = UnsafeTypeExpression "text"
1140text = UnsafeTypeExpression "text"
1127-- | fixed-length character string
1141-- | fixed-length character string
1128char, character
1142char, character
1129 :: (KnownNat n, 1 <= n)
1143 :: (KnownNat n, 1 <= n)
1130 => proxy n
1144 => proxy n
1131− -> TypeExpression ('PGchar n)
1145+ -> TypeExpression schema ('PGchar n)
1132char p = UnsafeTypeExpression $ "char(" <> renderNat p <> ")"
1146char p = UnsafeTypeExpression $ "char(" <> renderNat p <> ")"
1133character p = UnsafeTypeExpression $ "character(" <> renderNat p <> ")"
1147character p = UnsafeTypeExpression $ "character(" <> renderNat p <> ")"
1134-- | variable-length character string
1148-- | variable-length character string
1135varchar, characterVarying
1149varchar, characterVarying
1136 :: (KnownNat n, 1 <= n)
1150 :: (KnownNat n, 1 <= n)
1137 => proxy n
1151 => proxy n
1138− -> TypeExpression ('PGvarchar n)
1152+ -> TypeExpression schema ('PGvarchar n)
1139varchar p = UnsafeTypeExpression $ "varchar(" <> renderNat p <> ")"
1153varchar p = UnsafeTypeExpression $ "varchar(" <> renderNat p <> ")"
1140characterVarying p = UnsafeTypeExpression $
1154characterVarying p = UnsafeTypeExpression $
1141 "character varying(" <> renderNat p <> ")"
1155 "character varying(" <> renderNat p <> ")"
1142-- | binary data ("byte array")
1156-- | binary data ("byte array")
1143−bytea :: TypeExpression 'PGbytea
1157+bytea :: TypeExpression schema 'PGbytea
1144bytea = UnsafeTypeExpression "bytea"
1158bytea = UnsafeTypeExpression "bytea"
1145-- | date and time (no time zone)
1159-- | date and time (no time zone)
1146−timestamp :: TypeExpression 'PGtimestamp
1160+timestamp :: TypeExpression schema 'PGtimestamp
1147timestamp = UnsafeTypeExpression "timestamp"
1161timestamp = UnsafeTypeExpression "timestamp"
1148-- | date and time, including time zone
1162-- | date and time, including time zone
1149−timestampWithTimeZone :: TypeExpression 'PGtimestamptz
1163+timestampWithTimeZone :: TypeExpression schema 'PGtimestamptz
1150timestampWithTimeZone = UnsafeTypeExpression "timestamp with time zone"
1164timestampWithTimeZone = UnsafeTypeExpression "timestamp with time zone"
1151-- | calendar date (year, month, day)
1165-- | calendar date (year, month, day)
1152−date :: TypeExpression 'PGdate
1166+date :: TypeExpression schema 'PGdate
1153date = UnsafeTypeExpression "date"
1167date = UnsafeTypeExpression "date"
1154-- | time of day (no time zone)
1168-- | time of day (no time zone)
1155−time :: TypeExpression 'PGtime
1169+time :: TypeExpression schema 'PGtime
1156time = UnsafeTypeExpression "time"
1170time = UnsafeTypeExpression "time"
1157-- | time of day, including time zone
1171-- | time of day, including time zone
1158−timeWithTimeZone :: TypeExpression 'PGtimetz
1172+timeWithTimeZone :: TypeExpression schema 'PGtimetz
1159timeWithTimeZone = UnsafeTypeExpression "time with time zone"
1173timeWithTimeZone = UnsafeTypeExpression "time with time zone"
1160-- | time span
1174-- | time span
1161−interval :: TypeExpression 'PGinterval
1175+interval :: TypeExpression schema 'PGinterval
1162interval = UnsafeTypeExpression "interval"
1176interval = UnsafeTypeExpression "interval"
1163-- | universally unique identifier
1177-- | universally unique identifier
1164−uuid :: TypeExpression 'PGuuid
1178+uuid :: TypeExpression schema 'PGuuid
1165uuid = UnsafeTypeExpression "uuid"
1179uuid = UnsafeTypeExpression "uuid"
1166-- | IPv4 or IPv6 host address
1180-- | IPv4 or IPv6 host address
1167−inet :: TypeExpression 'PGinet
1181+inet :: TypeExpression schema 'PGinet
1168inet = UnsafeTypeExpression "inet"
1182inet = UnsafeTypeExpression "inet"
1169-- | textual JSON data
1183-- | textual JSON data
1170−json :: TypeExpression 'PGjson
1184+json :: TypeExpression schema 'PGjson
1171json = UnsafeTypeExpression "json"
1185json = UnsafeTypeExpression "json"
1172-- | binary JSON data, decomposed
1186-- | binary JSON data, decomposed
1173−jsonb :: TypeExpression 'PGjsonb
1187+jsonb :: TypeExpression schema 'PGjsonb
1174jsonb = UnsafeTypeExpression "jsonb"
1188jsonb = UnsafeTypeExpression "jsonb"
1175-- | variable length array
1189-- | variable length array
1176vararray
1190vararray
1177− :: TypeExpression pg
1191+ :: TypeExpression schema pg
1178− -> TypeExpression ('PGvararray pg)
1192+ -> TypeExpression schema ('PGvararray pg)
1179vararray ty = UnsafeTypeExpression $ renderTypeExpression ty <> "[]"
1193vararray ty = UnsafeTypeExpression $ renderTypeExpression ty <> "[]"
1180-- | fixed length array
1194-- | fixed length array
1181--
1195--
@@ -1184,36 +1198,36 @@ vararray ty = UnsafeTypeExpression $ renderTypeExpression ty <> "[]"
1184fixarray
1198fixarray
1185 :: KnownNat n
1199 :: KnownNat n
1186 => proxy n
1200 => proxy n
1187− -> TypeExpression pg
1201+ -> TypeExpression schema pg
1188− -> TypeExpression ('PGfixarray n pg)
1202+ -> TypeExpression schema ('PGfixarray n pg)
1189fixarray p ty = UnsafeTypeExpression $
1203fixarray p ty = UnsafeTypeExpression $
1190 renderTypeExpression ty <> "[" <> renderNat p <> "]"
1204 renderTypeExpression ty <> "[" <> renderNat p <> "]"
1191
1205
1192-- | `pgtype` is a demoted version of a `PGType`
1206-- | `pgtype` is a demoted version of a `PGType`
1193−class PGTyped (ty :: PGType) where pgtype :: TypeExpression ty
1207+class PGTyped schema (ty :: PGType) where pgtype :: TypeExpression schema ty
1194−instance PGTyped 'PGbool where pgtype = bool
1208+instance PGTyped schema 'PGbool where pgtype = bool
1195−instance PGTyped 'PGint2 where pgtype = int2
1209+instance PGTyped schema 'PGint2 where pgtype = int2
1196−instance PGTyped 'PGint4 where pgtype = int4
1210+instance PGTyped schema 'PGint4 where pgtype = int4
1197−instance PGTyped 'PGint8 where pgtype = int8
1211+instance PGTyped schema 'PGint8 where pgtype = int8
1198−instance PGTyped 'PGnumeric where pgtype = numeric
1212+instance PGTyped schema 'PGnumeric where pgtype = numeric
1199−instance PGTyped 'PGfloat4 where pgtype = float4
1213+instance PGTyped schema 'PGfloat4 where pgtype = float4
1200−instance PGTyped 'PGfloat8 where pgtype = float8
1214+instance PGTyped schema 'PGfloat8 where pgtype = float8
1201−instance PGTyped 'PGtext where pgtype = text
1215+instance PGTyped schema 'PGtext where pgtype = text
1202instance (KnownNat n, 1 <= n)
1216instance (KnownNat n, 1 <= n)
1203− => PGTyped ('PGchar n) where pgtype = char (Proxy @n)
1217+ => PGTyped schema ('PGchar n) where pgtype = char (Proxy @n)
1204instance (KnownNat n, 1 <= n)
1218instance (KnownNat n, 1 <= n)
1205− => PGTyped ('PGvarchar n) where pgtype = varchar (Proxy @n)
1219+ => PGTyped schema ('PGvarchar n) where pgtype = varchar (Proxy @n)
1206−instance PGTyped 'PGbytea where pgtype = bytea
1220+instance PGTyped schema 'PGbytea where pgtype = bytea
1207−instance PGTyped 'PGtimestamp where pgtype = timestamp
1221+instance PGTyped schema 'PGtimestamp where pgtype = timestamp
1208−instance PGTyped 'PGtimestamptz where pgtype = timestampWithTimeZone
1222+instance PGTyped schema 'PGtimestamptz where pgtype = timestampWithTimeZone
1209−instance PGTyped 'PGdate where pgtype = date
1223+instance PGTyped schema 'PGdate where pgtype = date
1210−instance PGTyped 'PGtime where pgtype = time
1224+instance PGTyped schema 'PGtime where pgtype = time
1211−instance PGTyped 'PGtimetz where pgtype = timeWithTimeZone
1225+instance PGTyped schema 'PGtimetz where pgtype = timeWithTimeZone
1212−instance PGTyped 'PGinterval where pgtype = interval
1226+instance PGTyped schema 'PGinterval where pgtype = interval
1213−instance PGTyped 'PGuuid where pgtype = uuid
1227+instance PGTyped schema 'PGuuid where pgtype = uuid
1214−instance PGTyped 'PGjson where pgtype = json
1228+instance PGTyped schema 'PGjson where pgtype = json
1215−instance PGTyped 'PGjsonb where pgtype = jsonb
1229+instance PGTyped schema 'PGjsonb where pgtype = jsonb
1216−instance PGTyped ty => PGTyped ('PGvararray ty) where
1230+instance PGTyped schema ty => PGTyped schema ('PGvararray ty) where
1217− pgtype = vararray (pgtype @ty)
1231+ pgtype = vararray (pgtype @schema @ty)
1218−instance (KnownNat n, PGTyped ty) => PGTyped ('PGfixarray n ty) where
1232+instance (KnownNat n, PGTyped schema ty) => PGTyped schema ('PGfixarray n ty) where
1219− pgtype = fixarray (Proxy @n) (pgtype @ty)
1233+ pgtype = fixarray (Proxy @n) (pgtype @schema @ty)
squeal-postgresql/src/Squeal/PostgreSQL/Manipulation.hs+40−38
@@ -211,11 +211,11 @@ insertRows
211 , Has tab schema ('Table table)
211 , Has tab schema ('Table table)
212 , columns ~ TableToColumns table )
212 , columns ~ TableToColumns table )
213 => Alias tab -- ^ table to insert into
213 => Alias tab -- ^ table to insert into
214− -> NP (Aliased (ColumnValue '[] params)) columns -- ^ row to insert
214+ -> NP (Aliased (ColumnValue schema '[] params)) columns -- ^ row to insert
215− -> [NP (Aliased (ColumnValue '[] params)) columns] -- ^ more rows to insert
215+ -> [NP (Aliased (ColumnValue schema '[] params)) columns] -- ^ more rows to insert
216− -> ConflictClause columns params
216+ -> ConflictClause schema columns params
217 -- ^ what to do in case of constraint conflict
217 -- ^ what to do in case of constraint conflict
218− -> ReturningClause columns params results -- ^ results to return
218+ -> ReturningClause schema columns params results -- ^ results to return
219 -> Manipulation schema params results
219 -> Manipulation schema params results
220insertRows tab rw rws conflict returning = UnsafeManipulation $
220insertRows tab rw rws conflict returning = UnsafeManipulation $
221 "INSERT" <+> "INTO" <+> renderAlias tab
221 "INSERT" <+> "INTO" <+> renderAlias tab
@@ -228,7 +228,7 @@ insertRows tab rw rws conflict returning = UnsafeManipulation $
228 <> renderReturningClause returning
228 <> renderReturningClause returning
229 where
229 where
230 renderAliasPart, renderColumnValuePart
230 renderAliasPart, renderColumnValuePart
231− :: Aliased (ColumnValue '[] params) ty -> ByteString
231+ :: Aliased (ColumnValue schema '[] params) ty -> ByteString
232 renderAliasPart (_ `As` name) = renderAlias name
232 renderAliasPart (_ `As` name) = renderAlias name
233 renderColumnValuePart (value `As` _) = case value of
233 renderColumnValuePart (value `As` _) = case value of
234 Default -> "DEFAULT"
234 Default -> "DEFAULT"
@@ -241,10 +241,10 @@ insertRow
241 , Has tab schema ('Table table)
241 , Has tab schema ('Table table)
242 , columns ~ TableToColumns table )
242 , columns ~ TableToColumns table )
243 => Alias tab -- ^ table to insert into
243 => Alias tab -- ^ table to insert into
244− -> NP (Aliased (ColumnValue '[] params)) columns -- ^ row to insert
244+ -> NP (Aliased (ColumnValue schema '[] params)) columns -- ^ row to insert
245− -> ConflictClause columns params
245+ -> ConflictClause schema columns params
246 -- ^ what to do in case of constraint conflict
246 -- ^ what to do in case of constraint conflict
247− -> ReturningClause columns params results -- ^ results to return
247+ -> ReturningClause schema columns params results -- ^ results to return
248 -> Manipulation schema params results
248 -> Manipulation schema params results
249insertRow tab rw = insertRows tab rw []
249insertRow tab rw = insertRows tab rw []
250
250
@@ -254,8 +254,8 @@ insertRows_
254 , Has tab schema ('Table table)
254 , Has tab schema ('Table table)
255 , columns ~ TableToColumns table )
255 , columns ~ TableToColumns table )
256 => Alias tab -- ^ table to insert into
256 => Alias tab -- ^ table to insert into
257− -> NP (Aliased (ColumnValue '[] params)) columns -- ^ row to insert
257+ -> NP (Aliased (ColumnValue schema '[] params)) columns -- ^ row to insert
258− -> [NP (Aliased (ColumnValue '[] params)) columns] -- ^ more rows to insert
258+ -> [NP (Aliased (ColumnValue schema '[] params)) columns] -- ^ more rows to insert
259 -> Manipulation schema params '[]
259 -> Manipulation schema params '[]
260insertRows_ tab rw rws =
260insertRows_ tab rw rws =
261 insertRows tab rw rws OnConflictDoRaise (Returning Nil)
261 insertRows tab rw rws OnConflictDoRaise (Returning Nil)
@@ -266,7 +266,7 @@ insertRow_
266 , Has tab schema ('Table table)
266 , Has tab schema ('Table table)
267 , columns ~ TableToColumns table )
267 , columns ~ TableToColumns table )
268 => Alias tab -- ^ table to insert into
268 => Alias tab -- ^ table to insert into
269− -> NP (Aliased (ColumnValue '[] params)) columns -- ^ row to insert
269+ -> NP (Aliased (ColumnValue schema '[] params)) columns -- ^ row to insert
270 -> Manipulation schema params '[]
270 -> Manipulation schema params '[]
271insertRow_ tab rw = insertRow tab rw OnConflictDoRaise (Returning Nil)
271insertRow_ tab rw = insertRow tab rw OnConflictDoRaise (Returning Nil)
272
272
@@ -278,9 +278,9 @@ insertQuery
278 , columns ~ TableToColumns table )
278 , columns ~ TableToColumns table )
279 => Alias tab -- ^ table to insert into
279 => Alias tab -- ^ table to insert into
280 -> Query schema params (ColumnsToRelation columns)
280 -> Query schema params (ColumnsToRelation columns)
281− -> ConflictClause columns params
281+ -> ConflictClause schema columns params
282 -- ^ what to do in case of constraint conflict
282 -- ^ what to do in case of constraint conflict
283− -> ReturningClause columns params results -- ^ results to return
283+ -> ReturningClause schema columns params results -- ^ results to return
284 -> Manipulation schema params results
284 -> Manipulation schema params results
285insertQuery tab query conflict returning = UnsafeManipulation $
285insertQuery tab query conflict returning = UnsafeManipulation $
286 "INSERT" <+> "INTO" <+> renderAlias tab
286 "INSERT" <+> "INTO" <+> renderAlias tab
@@ -305,15 +305,16 @@ insertQuery_ tab query =
305-- `Set` a value to be an `Expression`, relative to the given
305-- `Set` a value to be an `Expression`, relative to the given
306-- row for an update, and closed for an insert.
306-- row for an update, and closed for an insert.
307data ColumnValue
307data ColumnValue
308+ (schema :: SchemaType)
308 (columns :: RelationType)
309 (columns :: RelationType)
309 (params :: [NullityType])
310 (params :: [NullityType])
310 (ty :: ColumnType)
311 (ty :: ColumnType)
311 where
312 where
312− Same :: ColumnValue (column ': columns) params ty
313+ Same :: ColumnValue schema (column ': columns) params ty
313− Default :: ColumnValue columns params ('Def :=> ty)
314+ Default :: ColumnValue schema columns params ('Def :=> ty)
314 Set
315 Set
315− :: (forall table. Expression '[table ::: columns] 'Ungrouped params ty)
316+ :: (forall table. Expression schema '[table ::: columns] 'Ungrouped params ty)
316− -> ColumnValue columns params (constraint :=> ty)
317+ -> ColumnValue schema columns params (constraint :=> ty)
317
318
318-- | A `ReturningClause` computes and return value(s) based
319-- | A `ReturningClause` computes and return value(s) based
319-- on each row actually inserted, updated or deleted. This is primarily
320-- on each row actually inserted, updated or deleted. This is primarily
@@ -326,22 +327,23 @@ data ColumnValue
326-- in the row. Use @Returning Nil@ in the common case where no return
327-- in the row. Use @Returning Nil@ in the common case where no return
327-- values are desired.
328-- values are desired.
328data ReturningClause
329data ReturningClause
330+ (schema :: SchemaType)
329 (columns :: ColumnsType)
331 (columns :: ColumnsType)
330 (params :: [NullityType])
332 (params :: [NullityType])
331 (results :: RelationType)
333 (results :: RelationType)
332 where
334 where
333 ReturningStar
335 ReturningStar
334 :: results ~ ColumnsToRelation columns
336 :: results ~ ColumnsToRelation columns
335− => ReturningClause columns params results
337+ => ReturningClause schema columns params results
336 Returning
338 Returning
337 :: rel ~ ColumnsToRelation columns
339 :: rel ~ ColumnsToRelation columns
338− => NP (Aliased (Expression '[table ::: rel] 'Ungrouped params)) results
340+ => NP (Aliased (Expression schema '[table ::: rel] 'Ungrouped params)) results
339− -> ReturningClause columns params results
341+ -> ReturningClause schema columns params results
340
342
341-- | Render a `ReturningClause`.
343-- | Render a `ReturningClause`.
342renderReturningClause
344renderReturningClause
343 :: SOP.SListI results
345 :: SOP.SListI results
344− => ReturningClause params columns results
346+ => ReturningClause schema params columns results
345 -> ByteString
347 -> ByteString
346renderReturningClause = \case
348renderReturningClause = \case
347 ReturningStar -> " RETURNING *"
349 ReturningStar -> " RETURNING *"
@@ -354,18 +356,18 @@ renderReturningClause = \case
354-- `OnConflictDoNothing` simply avoids inserting a row.
356-- `OnConflictDoNothing` simply avoids inserting a row.
355-- `OnConflictDoUpdate` updates the existing row that conflicts with the row
357-- `OnConflictDoUpdate` updates the existing row that conflicts with the row
356-- proposed for insertion.
358-- proposed for insertion.
357−data ConflictClause (columns :: ColumnsType) params where
359+data ConflictClause (schema :: SchemaType) (columns :: ColumnsType) params where
358− OnConflictDoRaise :: ConflictClause columns params
360+ OnConflictDoRaise :: ConflictClause schema columns params
359− OnConflictDoNothing :: ConflictClause columns params
361+ OnConflictDoNothing :: ConflictClause schema columns params
360 OnConflictDoUpdate
362 OnConflictDoUpdate
361− :: NP (Aliased (ColumnValue (ColumnsToRelation columns) params)) columns
363+ :: NP (Aliased (ColumnValue schema (ColumnsToRelation columns) params)) columns
362− -> [Condition '[table ::: ColumnsToRelation columns] 'Ungrouped params]
364+ -> [Condition schema '[table ::: ColumnsToRelation columns] 'Ungrouped params]
363− -> ConflictClause columns params
365+ -> ConflictClause schema columns params
364
366
365-- | Render a `ConflictClause`.
367-- | Render a `ConflictClause`.
366renderConflictClause
368renderConflictClause
367 :: SOP.SListI columns
369 :: SOP.SListI columns
368− => ConflictClause columns params
370+ => ConflictClause schema columns params
369 -> ByteString
371 -> ByteString
370renderConflictClause = \case
372renderConflictClause = \case
371 OnConflictDoRaise -> ""
373 OnConflictDoRaise -> ""
@@ -378,7 +380,7 @@ renderConflictClause = \case
378 wh:whs -> " WHERE" <+> renderExpression (foldr (.&&) wh whs)
380 wh:whs -> " WHERE" <+> renderExpression (foldr (.&&) wh whs)
379 where
381 where
380 renderUpdate
382 renderUpdate
381− :: Aliased (ColumnValue columns params) column
383+ :: Aliased (ColumnValue schema columns params) column
382 -> Maybe ByteString
384 -> Maybe ByteString
383 renderUpdate = \case
385 renderUpdate = \case
384 Same `As` _ -> Nothing
386 Same `As` _ -> Nothing
@@ -399,11 +401,11 @@ update
399 , Has tab schema ('Table table)
401 , Has tab schema ('Table table)
400 , columns ~ TableToColumns table )
402 , columns ~ TableToColumns table )
401 => Alias tab -- ^ table to update
403 => Alias tab -- ^ table to update
402− -> NP (Aliased (ColumnValue (ColumnsToRelation columns) params)) columns
404+ -> NP (Aliased (ColumnValue schema (ColumnsToRelation columns) params)) columns
403 -- ^ modified values to replace old values
405 -- ^ modified values to replace old values
404− -> Condition '[tab ::: ColumnsToRelation columns] 'Ungrouped params
406+ -> Condition schema '[tab ::: ColumnsToRelation columns] 'Ungrouped params
405 -- ^ condition under which to perform update on a row
407 -- ^ condition under which to perform update on a row
406− -> ReturningClause columns params results -- ^ results to return
408+ -> ReturningClause schema columns params results -- ^ results to return
407 -> Manipulation schema params results
409 -> Manipulation schema params results
408update tab columns wh returning = UnsafeManipulation $
410update tab columns wh returning = UnsafeManipulation $
409 "UPDATE"
411 "UPDATE"
@@ -414,7 +416,7 @@ update tab columns wh returning = UnsafeManipulation $
414 <> renderReturningClause returning
416 <> renderReturningClause returning
415 where
417 where
416 renderUpdate
418 renderUpdate
417− :: Aliased (ColumnValue columns params) column
419+ :: Aliased (ColumnValue schema columns params) column
418 -> Maybe ByteString
420 -> Maybe ByteString
419 renderUpdate = \case
421 renderUpdate = \case
420 Same `As` _ -> Nothing
422 Same `As` _ -> Nothing
@@ -429,9 +431,9 @@ update_
429 , Has tab schema ('Table table)
431 , Has tab schema ('Table table)
430 , columns ~ TableToColumns table )
432 , columns ~ TableToColumns table )
431 => Alias tab -- ^ table to update
433 => Alias tab -- ^ table to update
432− -> NP (Aliased (ColumnValue (ColumnsToRelation columns) params)) columns
434+ -> NP (Aliased (ColumnValue schema (ColumnsToRelation columns) params)) columns
433 -- ^ modified values to replace old values
435 -- ^ modified values to replace old values
434− -> Condition '[tab ::: ColumnsToRelation columns] 'Ungrouped params
436+ -> Condition schema '[tab ::: ColumnsToRelation columns] 'Ungrouped params
435 -- ^ condition under which to perform update on a row
437 -- ^ condition under which to perform update on a row
436 -> Manipulation schema params '[]
438 -> Manipulation schema params '[]
437update_ tab columns wh = update tab columns wh (Returning Nil)
439update_ tab columns wh = update tab columns wh (Returning Nil)
@@ -446,9 +448,9 @@ deleteFrom
446 , Has tab schema ('Table table)
448 , Has tab schema ('Table table)
447 , columns ~ TableToColumns table )
449 , columns ~ TableToColumns table )
448 => Alias tab -- ^ table to delete from
450 => Alias tab -- ^ table to delete from
449− -> Condition '[tab ::: ColumnsToRelation columns] 'Ungrouped params
451+ -> Condition schema '[tab ::: ColumnsToRelation columns] 'Ungrouped params
450 -- ^ condition under which to delete a row
452 -- ^ condition under which to delete a row
451− -> ReturningClause columns params results -- ^ results to return
453+ -> ReturningClause schema columns params results -- ^ results to return
452 -> Manipulation schema params results
454 -> Manipulation schema params results
453deleteFrom tab wh returning = UnsafeManipulation $
455deleteFrom tab wh returning = UnsafeManipulation $
454 "DELETE FROM" <+> renderAlias tab
456 "DELETE FROM" <+> renderAlias tab
@@ -460,7 +462,7 @@ deleteFrom_
460 :: ( Has tab schema ('Table table)
462 :: ( Has tab schema ('Table table)
461 , columns ~ TableToColumns table )
463 , columns ~ TableToColumns table )
462 => Alias tab -- ^ table to delete from
464 => Alias tab -- ^ table to delete from
463− -> Condition '[tab ::: ColumnsToRelation columns] 'Ungrouped params
465+ -> Condition schema '[tab ::: ColumnsToRelation columns] 'Ungrouped params
464 -- ^ condition under which to delete a row
466 -- ^ condition under which to delete a row
465 -> Manipulation schema params '[]
467 -> Manipulation schema params '[]
466deleteFrom_ tab wh = deleteFrom tab wh (Returning Nil)
468deleteFrom_ tab wh = deleteFrom tab wh (Returning Nil)
squeal-postgresql/src/Squeal/PostgreSQL/Query.hs+39−39
@@ -359,7 +359,7 @@ SELECT queries
359-- the intermediate table are actually output.
359-- the intermediate table are actually output.
360select
360select
361 :: SListI columns
361 :: SListI columns
362− => NP (Aliased (Expression relations grouping params)) (column ': columns)
362+ => NP (Aliased (Expression schema relations grouping params)) (column ': columns)
363 -- ^ select list
363 -- ^ select list
364 -> TableExpression schema params relations grouping
364 -> TableExpression schema params relations grouping
365 -- ^ intermediate virtual table
365 -- ^ intermediate virtual table
@@ -373,7 +373,7 @@ select list rels = UnsafeQuery $
373-- be subject to the elimination of duplicate rows using `selectDistinct`.
373-- be subject to the elimination of duplicate rows using `selectDistinct`.
374selectDistinct
374selectDistinct
375 :: SListI columns
375 :: SListI columns
376− => NP (Aliased (Expression relations 'Ungrouped params)) (column ': columns)
376+ => NP (Aliased (Expression schema relations 'Ungrouped params)) (column ': columns)
377 -- ^ select list
377 -- ^ select list
378 -> TableExpression schema params relations 'Ungrouped
378 -> TableExpression schema params relations 'Ungrouped
379 -- ^ intermediate virtual table
379 -- ^ intermediate virtual table
@@ -438,8 +438,8 @@ selectDistinctDotStar rel relations = UnsafeQuery $
438-- "SELECT * FROM (VALUES (1, E'one')) AS t (\"a\", \"b\")"
438-- "SELECT * FROM (VALUES (1, E'one')) AS t (\"a\", \"b\")"
439values
439values
440 :: SListI cols
440 :: SListI cols
441− => NP (Aliased (Expression '[] 'Ungrouped params)) cols
441+ => NP (Aliased (Expression schema '[] 'Ungrouped params)) cols
442− -> [NP (Aliased (Expression '[] 'Ungrouped params)) cols]
442+ -> [NP (Aliased (Expression schema '[] 'Ungrouped params)) cols]
443 -- ^ When more than one row is specified, all the rows must
443 -- ^ When more than one row is specified, all the rows must
444 -- must have the same number of elements
444 -- must have the same number of elements
445 -> Query schema params cols
445 -> Query schema params cols
@@ -453,7 +453,7 @@ values rw rws = UnsafeQuery $ "SELECT * FROM"
453 <+> parenthesized (renderCommaSeparated renderAliasPart rw)
453 <+> parenthesized (renderCommaSeparated renderAliasPart rw)
454 where
454 where
455 renderAliasPart, renderValuePart
455 renderAliasPart, renderValuePart
456− :: Aliased (Expression '[] 'Ungrouped params) ty -> ByteString
456+ :: Aliased (Expression schema '[] 'Ungrouped params) ty -> ByteString
457 renderAliasPart (_ `As` name) = renderAlias name
457 renderAliasPart (_ `As` name) = renderAlias name
458 renderValuePart (value `As` _) = renderExpression value
458 renderValuePart (value `As` _) = renderExpression value
459
459
@@ -461,7 +461,7 @@ values rw rws = UnsafeQuery $ "SELECT * FROM"
461-- specified by value expressions.
461-- specified by value expressions.
462values_
462values_
463 :: SListI cols
463 :: SListI cols
464− => NP (Aliased (Expression '[] 'Ungrouped params)) cols
464+ => NP (Aliased (Expression schema '[] 'Ungrouped params)) cols
465 -- ^ one row of values
465 -- ^ one row of values
466 -> Query schema params cols
466 -> Query schema params cols
467values_ rw = values rw []
467values_ rw = values rw []
@@ -485,7 +485,7 @@ data TableExpression
485 { fromClause :: FromClause schema params relations
485 { fromClause :: FromClause schema params relations
486 -- ^ A table reference that can be a table name, or a derived table such
486 -- ^ A table reference that can be a table name, or a derived table such
487 -- as a subquery, a @JOIN@ construct, or complex combinations of these.
487 -- as a subquery, a @JOIN@ construct, or complex combinations of these.
488− , whereClause :: [Condition relations 'Ungrouped params]
488+ , whereClause :: [Condition schema relations 'Ungrouped params]
489 -- ^ optional search coditions, combined with `.&&`. After the processing
489 -- ^ optional search coditions, combined with `.&&`. After the processing
490 -- of the `fromClause` is done, each row of the derived virtual table
490 -- of the `fromClause` is done, each row of the derived virtual table
491 -- is checked against the search condition. If the result of the
491 -- is checked against the search condition. If the result of the
@@ -501,13 +501,13 @@ data TableExpression
501 -- set of rows having common values into one group row that represents all
501 -- set of rows having common values into one group row that represents all
502 -- rows in the group. This is done to eliminate redundancy in the output
502 -- rows in the group. This is done to eliminate redundancy in the output
503 -- and/or compute aggregates that apply to these groups.
503 -- and/or compute aggregates that apply to these groups.
504− , havingClause :: HavingClause relations grouping params
504+ , havingClause :: HavingClause schema relations grouping params
505 -- ^ If a table has been grouped using `groupBy`, but only certain groups
505 -- ^ If a table has been grouped using `groupBy`, but only certain groups
506 -- are of interest, the `havingClause` can be used, much like a
506 -- are of interest, the `havingClause` can be used, much like a
507 -- `whereClause`, to eliminate groups from the result. Expressions in the
507 -- `whereClause`, to eliminate groups from the result. Expressions in the
508 -- `havingClause` can refer both to grouped expressions and to ungrouped
508 -- `havingClause` can refer both to grouped expressions and to ungrouped
509 -- expressions (which necessarily involve an aggregate function).
509 -- expressions (which necessarily involve an aggregate function).
510− , orderByClause :: [SortExpression relations grouping params]
510+ , orderByClause :: [SortExpression schema relations grouping params]
511 -- ^ The `orderByClause` is for optional sorting. When more than one
511 -- ^ The `orderByClause` is for optional sorting. When more than one
512 -- `SortExpression` is specified, the later (right) values are used to sort
512 -- `SortExpression` is specified, the later (right) values are used to sort
513 -- rows that are equal according to the earlier (left) values.
513 -- rows that are equal according to the earlier (left) values.
@@ -566,7 +566,7 @@ from rels = TableExpression rels [] NoGroups NoHaving [] [] []
566-- | A `where_` is an endomorphism of `TableExpression`s which adds a
566-- | A `where_` is an endomorphism of `TableExpression`s which adds a
567-- search condition to the `whereClause`.
567-- search condition to the `whereClause`.
568where_
568where_
569− :: Condition relations 'Ungrouped params -- ^ filtering condition
569+ :: Condition schema relations 'Ungrouped params -- ^ filtering condition
570 -> TableExpression schema params relations grouping
570 -> TableExpression schema params relations grouping
571 -> TableExpression schema params relations grouping
571 -> TableExpression schema params relations grouping
572where_ wh rels = rels {whereClause = wh : whereClause rels}
572where_ wh rels = rels {whereClause = wh : whereClause rels}
@@ -592,7 +592,7 @@ group bys rels = TableExpression
592-- | A `having` is an endomorphism of `TableExpression`s which adds a
592-- | A `having` is an endomorphism of `TableExpression`s which adds a
593-- search condition to the `havingClause`.
593-- search condition to the `havingClause`.
594having
594having
595− :: Condition relations ('Grouped bys) params -- ^ having condition
595+ :: Condition schema relations ('Grouped bys) params -- ^ having condition
596 -> TableExpression schema params relations ('Grouped bys)
596 -> TableExpression schema params relations ('Grouped bys)
597 -> TableExpression schema params relations ('Grouped bys)
597 -> TableExpression schema params relations ('Grouped bys)
598having hv rels = rels
598having hv rels = rels
@@ -601,7 +601,7 @@ having hv rels = rels
601-- | An `orderBy` is an endomorphism of `TableExpression`s which appends an
601-- | An `orderBy` is an endomorphism of `TableExpression`s which appends an
602-- ordering to the right of the `orderByClause`.
602-- ordering to the right of the `orderByClause`.
603orderBy
603orderBy
604− :: [SortExpression relations grouping params] -- ^ sort expressions
604+ :: [SortExpression schema relations grouping params] -- ^ sort expressions
605 -> TableExpression schema params relations grouping
605 -> TableExpression schema params relations grouping
606 -> TableExpression schema params relations grouping
606 -> TableExpression schema params relations grouping
607orderBy srts rels = rels {orderByClause = orderByClause rels ++ srts}
607orderBy srts rels = rels {orderByClause = orderByClause rels ++ srts}
@@ -677,7 +677,7 @@ the @on@ condition.
677innerJoin
677innerJoin
678 :: FromClause schema params right
678 :: FromClause schema params right
679 -- ^ right
679 -- ^ right
680− -> Condition (Join left right) 'Ungrouped params
680+ -> Condition schema (Join left right) 'Ungrouped params
681 -- ^ @on@ condition
681 -- ^ @on@ condition
682 -> FromClause schema params left
682 -> FromClause schema params left
683 -- ^ left
683 -- ^ left
@@ -694,7 +694,7 @@ innerJoin right on left = UnsafeFromClause $
694leftOuterJoin
694leftOuterJoin
695 :: FromClause schema params right
695 :: FromClause schema params right
696 -- ^ right
696 -- ^ right
697− -> Condition (Join left right) 'Ungrouped params
697+ -> Condition schema (Join left right) 'Ungrouped params
698 -- ^ @on@ condition
698 -- ^ @on@ condition
699 -> FromClause schema params left
699 -> FromClause schema params left
700 -- ^ left
700 -- ^ left
@@ -712,7 +712,7 @@ leftOuterJoin right on left = UnsafeFromClause $
712rightOuterJoin
712rightOuterJoin
713 :: FromClause schema params right
713 :: FromClause schema params right
714 -- ^ right
714 -- ^ right
715− -> Condition (Join left right) 'Ungrouped params
715+ -> Condition schema (Join left right) 'Ungrouped params
716 -- ^ @on@ condition
716 -- ^ @on@ condition
717 -> FromClause schema params left
717 -> FromClause schema params left
718 -- ^ left
718 -- ^ left
@@ -731,7 +731,7 @@ rightOuterJoin right on left = UnsafeFromClause $
731fullOuterJoin
731fullOuterJoin
732 :: FromClause schema params right
732 :: FromClause schema params right
733 -- ^ right
733 -- ^ right
734− -> Condition (Join left right) 'Ungrouped params
734+ -> Condition schema (Join left right) 'Ungrouped params
735 -- ^ @on@ condition
735 -- ^ @on@ condition
736 -> FromClause schema params left
736 -> FromClause schema params left
737 -- ^ left
737 -- ^ left
@@ -795,17 +795,17 @@ renderGroupByClause = \case
795-- An `Ungrouped` `TableExpression` may only use `NoHaving` while a `Grouped`
795-- An `Ungrouped` `TableExpression` may only use `NoHaving` while a `Grouped`
796-- `TableExpression` must use `Having` whose conditions are combined with
796-- `TableExpression` must use `Having` whose conditions are combined with
797-- `.&&`.
797-- `.&&`.
798−data HavingClause relations grouping params where
798+data HavingClause schema relations grouping params where
799− NoHaving :: HavingClause relations 'Ungrouped params
799+ NoHaving :: HavingClause schema relations 'Ungrouped params
800 Having
800 Having
801− :: [Condition relations ('Grouped bys) params]
801+ :: [Condition schema relations ('Grouped bys) params]
802− -> HavingClause relations ('Grouped bys) params
802+ -> HavingClause schema relations ('Grouped bys) params
803−deriving instance Show (HavingClause relations grouping params)
803+deriving instance Show (HavingClause schema relations grouping params)
804−deriving instance Eq (HavingClause relations grouping params)
804+deriving instance Eq (HavingClause schema relations grouping params)
805−deriving instance Ord (HavingClause relations grouping params)
805+deriving instance Ord (HavingClause schema relations grouping params)
806
806
807-- | Render a `HavingClause`.
807-- | Render a `HavingClause`.
808−renderHavingClause :: HavingClause relations grouping params -> ByteString
808+renderHavingClause :: HavingClause schema relations grouping params -> ByteString
809renderHavingClause = \case
809renderHavingClause = \case
810 NoHaving -> ""
810 NoHaving -> ""
811 Having [] -> ""
811 Having [] -> ""
@@ -824,29 +824,29 @@ Sorting
824-- `AscNullsLast`, `DescNullsFirst` and `DescNullsLast` options are used to
824-- `AscNullsLast`, `DescNullsFirst` and `DescNullsLast` options are used to
825-- determine whether nulls appear before or after non-null values in the sort
825-- determine whether nulls appear before or after non-null values in the sort
826-- ordering of a `Null` result column.
826-- ordering of a `Null` result column.
827−data SortExpression relations grouping params where
827+data SortExpression schema relations grouping params where
828 Asc
828 Asc
829− :: Expression relations grouping params ('NotNull ty)
829+ :: Expression schema relations grouping params ('NotNull ty)
830− -> SortExpression relations grouping params
830+ -> SortExpression schema relations grouping params
831 Desc
831 Desc
832− :: Expression relations grouping params ('NotNull ty)
832+ :: Expression schema relations grouping params ('NotNull ty)
833− -> SortExpression relations grouping params
833+ -> SortExpression schema relations grouping params
834 AscNullsFirst
834 AscNullsFirst
835− :: Expression relations grouping params ('Null ty)
835+ :: Expression schema relations grouping params ('Null ty)
836− -> SortExpression relations grouping params
836+ -> SortExpression schema relations grouping params
837 AscNullsLast
837 AscNullsLast
838− :: Expression relations grouping params ('Null ty)
838+ :: Expression schema relations grouping params ('Null ty)
839− -> SortExpression relations grouping params
839+ -> SortExpression schema relations grouping params
840 DescNullsFirst
840 DescNullsFirst
841− :: Expression relations grouping params ('Null ty)
841+ :: Expression schema relations grouping params ('Null ty)
842− -> SortExpression relations grouping params
842+ -> SortExpression schema relations grouping params
843 DescNullsLast
843 DescNullsLast
844− :: Expression relations grouping params ('Null ty)
844+ :: Expression schema relations grouping params ('Null ty)
845− -> SortExpression relations grouping params
845+ -> SortExpression schema relations grouping params
846−deriving instance Show (SortExpression relations grouping params)
846+deriving instance Show (SortExpression schema relations grouping params)
847
847
848-- | Render a `SortExpression`.
848-- | Render a `SortExpression`.
849−renderSortExpression :: SortExpression relations grouping params -> ByteString
849+renderSortExpression :: SortExpression schema relations grouping params -> ByteString
850renderSortExpression = \case
850renderSortExpression = \case
851 Asc expression -> renderExpression expression <+> "ASC"
851 Asc expression -> renderExpression expression <+> "ASC"
852 Desc expression -> renderExpression expression <+> "DESC"
852 Desc expression -> renderExpression expression <+> "DESC"