on dev help sign in
fix with
30f62cfEitan Chatav
squeal-postgresql/src/Squeal/PostgreSQL/Manipulation.hs+2−4
@@ -204,14 +204,12 @@ newtype Manipulation
204 deriving (GHC.Generic,Show,Eq,Ord,NFData)
204 deriving (GHC.Generic,Show,Eq,Ord,NFData)
205instance RenderSQL (Manipulation db params columns) where
205instance RenderSQL (Manipulation db params columns) where
206 renderSQL = renderManipulation
206 renderSQL = renderManipulation
207−{--------------FIX WITH
208−
209instance With Manipulation where
207instance With Manipulation where
210− with Done manip = manip
208+ with Done manip = UnsafeManipulation $ renderManipulation manip
211 with (cte :>> ctes) manip = UnsafeManipulation $
209 with (cte :>> ctes) manip = UnsafeManipulation $
212 "WITH" <+> renderCommonTableExpressions renderManipulation cte ctes
210 "WITH" <+> renderCommonTableExpressions renderManipulation cte ctes
213 <+> renderManipulation manip
211 <+> renderManipulation manip
214−-}
212+
215-- | Convert a `Query` into a `Manipulation`.
213-- | Convert a `Query` into a `Manipulation`.
216queryStatement
214queryStatement
217 :: Query db params columns
215 :: Query db params columns
squeal-postgresql/src/Squeal/PostgreSQL/Query.hs+30−25
@@ -47,7 +47,7 @@ module Squeal.PostgreSQL.Query
47 , except
47 , except
48 , exceptAll
48 , exceptAll
49 -- ** With
49 -- ** With
50− -- , With (with)
50+ , With (with)
51 , CommonTableExpression (..)
51 , CommonTableExpression (..)
52 , renderCommonTableExpression
52 , renderCommonTableExpression
53 , renderCommonTableExpressions
53 , renderCommonTableExpressions
@@ -1362,35 +1362,43 @@ rowGteAny = unsafeRowSubqueryExpression ">= ANY"
1362-- | A `CommonTableExpression` is an auxiliary statement in a `with` clause.
1362-- | A `CommonTableExpression` is an auxiliary statement in a `with` clause.
1363data CommonTableExpression statement
1363data CommonTableExpression statement
1364 (params :: [NullityType])
1364 (params :: [NullityType])
1365+ (db :: DBType)
1365 (schema0 :: SchemaType)
1366 (schema0 :: SchemaType)
1366 (schema1 :: SchemaType) where
1367 (schema1 :: SchemaType) where
1367 CommonTableExpression
1368 CommonTableExpression
1369+ :: Has "public" db schema
1368− :: Aliased (statement schema params) (alias ::: cte)
1370+ => Aliased (statement db params) (alias ::: cte)
1369 -> CommonTableExpression
1371 -> CommonTableExpression
1370− statement params schema (alias ::: 'View cte ': schema)
1372+ statement params db schema (alias ::: 'View cte ': schema)
1373+instance
1374+ ( KnownSymbol vw
1375+ , Has "public" db schema
1371−instance (KnownSymbol alias, schema1 ~ (alias ::: 'View cte ': schema))
1376+ , schema1 ~ (vw ::: 'View cte ': schema)
1372− => Aliasable alias
1377+ ) => Aliasable vw
1373− (statement schema params cte)
1378+ (statement db params cte)
1374− (CommonTableExpression statement params schema schema1) where
1379+ (CommonTableExpression statement params db schema schema1) where
1375− statement `as` alias = CommonTableExpression (statement `as` alias)
1380+ statement `as` vw = CommonTableExpression (statement `as` vw)
1381+instance
1382+ ( KnownSymbol vw
1383+ , Has "public" db schema
1376−instance (KnownSymbol alias, schema1 ~ (alias ::: 'View cte ': schema))
1384+ , schema1 ~ (vw ::: 'View cte ': schema)
1377− => Aliasable alias (statement schema params cte)
1385+ ) => Aliasable vw (statement db params cte)
1378− (AlignedList (CommonTableExpression statement params) schema schema1) where
1386+ (AlignedList (CommonTableExpression statement params db) schema schema1) where
1379− statement `as` alias = single (statement `as` alias)
1387+ statement `as` vw = single (statement `as` vw)
1380
1388
1381-- | render a `CommonTableExpression`.
1389-- | render a `CommonTableExpression`.
1382renderCommonTableExpression
1390renderCommonTableExpression
1383− :: (forall sch ps row. statement ps sch row -> ByteString) -- ^ render statement
1391+ :: (forall db ps row. statement db ps row -> ByteString) -- ^ render statement
1384− -> CommonTableExpression statement params schema0 schema1 -> ByteString
1392+ -> CommonTableExpression statement params db0 schema0 schema1 -> ByteString
1385renderCommonTableExpression renderStatement
1393renderCommonTableExpression renderStatement
1386 (CommonTableExpression (statement `As` alias)) =
1394 (CommonTableExpression (statement `As` alias)) =
1387 renderAlias alias <+> "AS" <+> parenthesized (renderStatement statement)
1395 renderAlias alias <+> "AS" <+> parenthesized (renderStatement statement)
1388
1396
1389-- | render a non-empty `AlignedList` of `CommonTableExpression`s.
1397-- | render a non-empty `AlignedList` of `CommonTableExpression`s.
1390renderCommonTableExpressions
1398renderCommonTableExpressions
1391− :: (forall sch ps row. statement ps sch row -> ByteString) -- ^ render statement
1399+ :: (forall db ps row. statement db ps row -> ByteString) -- ^ render statement
1392− -> CommonTableExpression statement params schema0 schema1
1400+ -> CommonTableExpression statement params db0 schema0 schema1
1393− -> AlignedList (CommonTableExpression statement params) schema1 schema2
1401+ -> AlignedList (CommonTableExpression statement params db0) schema1 schema2
1394 -> ByteString
1402 -> ByteString
1395renderCommonTableExpressions renderStatement cte ctes =
1403renderCommonTableExpressions renderStatement cte ctes =
1396 renderCommonTableExpression renderStatement cte <> case ctes of
1404 renderCommonTableExpression renderStatement cte <> case ctes of
@@ -1398,22 +1406,19 @@ renderCommonTableExpressions renderStatement cte ctes =
1398 cte' :>> ctes' -> "," <+>
1406 cte' :>> ctes' -> "," <+>
1399 renderCommonTableExpressions renderStatement cte' ctes'
1407 renderCommonTableExpressions renderStatement cte' ctes'
1400
1408
1401−{---------------FIX WITH
1402−
1403-- | `with` provides a way to write auxiliary statements for use in a larger query.
1409-- | `with` provides a way to write auxiliary statements for use in a larger query.
1404-- These statements, referred to as `CommonTableExpression`s, can be thought of as
1410-- These statements, referred to as `CommonTableExpression`s, can be thought of as
1405-- defining temporary tables that exist just for one query.
1411-- defining temporary tables that exist just for one query.
1406class With statement where
1412class With statement where
1407 with
1413 with
1414+ :: Has "public" db0 schema0
1408− :: AlignedList (CommonTableExpression statement params) schema0 schema1
1415+ => AlignedList (CommonTableExpression statement params db0) schema0 schema1
1409 -- ^ common table expressions
1416 -- ^ common table expressions
1410− -> statement schema1 params row
1417+ -> statement (Alter "public" schema1 db0) params row
1411 -- ^ larger query
1418 -- ^ larger query
1412− -> statement schema0 params row
1419+ -> statement db0 params row
1413instance With Query where
1420instance With Query where
1414− with Done query = query
1421+ with Done query = UnsafeQuery $ renderQuery query
1415 with (cte :>> ctes) query = UnsafeQuery $
1422 with (cte :>> ctes) query = UnsafeQuery $
1416 "WITH" <+> renderCommonTableExpressions renderQuery cte ctes
1423 "WITH" <+> renderCommonTableExpressions renderQuery cte ctes
1417 <+> renderQuery query
1424 <+> renderQuery query
1418−
1419−-}