on dev help sign in
small change
266d19dEitan Chatav
squeel-postgresql/src/Squeel/PostgreSQL/Statement.hs+9−15
@@ -388,15 +388,6 @@ data By
388 => (Alias table, Alias column)
388 => (Alias table, Alias column)
389 -> By tables '(table, column)
389 -> By tables '(table, column)
390
390
391−by
392− :: ( KnownSymbol table
393− , tables ~ '[table ::: columns]
394− , HasColumn column columns ty
395− )
396− => Alias column
397− -> By tables '(table, column)
398−by column = By (Alias (proxy# :: Proxy# (table :: Symbol)), column)
399−
400renderBy :: By tables tabcolty -> ByteString
391renderBy :: By tables tabcolty -> ByteString
401renderBy (By (table, column)) = renderAlias table <> "." <> renderAlias column
392renderBy (By (table, column)) = renderAlias table <> "." <> renderAlias column
402
393
@@ -429,12 +420,17 @@ renderHavingClause = \case
429
420
430class (KnownSymbol table, KnownSymbol column)
421class (KnownSymbol table, KnownSymbol column)
431 => GroupedBy table column bys where
422 => GroupedBy table column bys where
432− getGroup
423+ getGroup1
424+ :: (tables ~ '[table ::: columns], HasColumn column columns ty)
425+ => Proxy# column
426+ -> Expression params tables ('Grouped bys) ty
427+ getGroup1 column = UnsafeExpression $ fromString (symbolVal' column)
428+ getGroup2
433 :: (HasTable table tables columns, HasColumn column columns ty)
429 :: (HasTable table tables columns, HasColumn column columns ty)
434 => Alias table
430 => Alias table
435 -> Alias column
431 -> Alias column
436 -> Expression params tables ('Grouped bys) ty
432 -> Expression params tables ('Grouped bys) ty
437− getGroup table column = UnsafeExpression $
433+ getGroup2 table column = UnsafeExpression $
438 renderAlias table <> "." <> renderAlias column
434 renderAlias table <> "." <> renderAlias column
439instance {-# OVERLAPPING #-} (KnownSymbol table, KnownSymbol column)
435instance {-# OVERLAPPING #-} (KnownSymbol table, KnownSymbol column)
440 => GroupedBy table column '[ '(table,column)]
436 => GroupedBy table column '[ '(table,column)]
@@ -449,16 +445,14 @@ instance
449 , HasColumn column columns ty
445 , HasColumn column columns ty
450 , GroupedBy table column bys
446 , GroupedBy table column bys
451 ) => IsLabel column
447 ) => IsLabel column
452− (Expression params tables ('Grouped bys) ty) where
448+ (Expression params tables ('Grouped bys) ty) where fromLabel = getGroup1
453− fromLabel p = getGroup (Alias (proxy# :: Proxy# table)) (Alias p)
454
449
455instance
450instance
456 ( HasTable table tables columns
451 ( HasTable table tables columns
457 , HasColumn column columns ty
452 , HasColumn column columns ty
458 , GroupedBy table column bys
453 , GroupedBy table column bys
459 ) => TableColumn table column
454 ) => TableColumn table column
460− (Expression params tables ('Grouped bys) ty) where
455+ (Expression params tables ('Grouped bys) ty) where (&.) = getGroup2
461− (&.) = getGroup
462
456
463unsafeAggregate
457unsafeAggregate
464 :: ByteString
458 :: ByteString
squeel-postgresql/test/Squeel/PostgreSQL/StatementSpec.hs+3−3
@@ -85,14 +85,14 @@ spec = do
85 statement = select
85 statement = select
86 (sum_ #col2 `As` #sum :* #col1 `As` #col1 :* Nil)
86 (sum_ #col2 `As` #sum :* #col1 `As` #col1 :* Nil)
87 ( from (Table (#table1 `As` #table1))
87 ( from (Table (#table1 `As` #table1))
88− & group (by #col1 :* Nil)
88+ & group (By (#table1,#col1) :* Nil)
89 & having ((#col1 + sum_ #col2) >* 1) )
89 & having ((#col1 + sum_ #col2) >* 1) )
90 statement `queryRenders`
90 statement `queryRenders`
91 "SELECT\
91 "SELECT\
92− \ sum(col2) AS sum, table1.col1 AS col1\
92+ \ sum(col2) AS sum, col1 AS col1\
93 \ FROM table1 AS table1\
93 \ FROM table1 AS table1\
94 \ GROUP BY table1.col1\
94 \ GROUP BY table1.col1\
95− \ HAVING ((table1.col1 + sum(col2)) > 1);"
95+ \ HAVING ((col1 + sum(col2)) > 1);"
96 it "correctly renders simple INSERTs" $ do
96 it "correctly renders simple INSERTs" $ do
97 let
97 let
98 statement :: Manipulation Tables '[] '[]
98 statement :: Manipulation Tables '[] '[]