on dev help sign in
small change
commit266d19de1b47916584b94227f93352285e18f4eb authorEitan Chatav <eitan.chatav@gmail.com> dateTue 8 Aug 2017, 16:56 (9 years ago) parentcc58b75
2 files changed+12−18
squeel-postgresql/src/Squeel/PostgreSQL/Statement.hs+9−15 squeel-postgresql/test/Squeel/PostgreSQL/StatementSpec.hs+3−3
squeel-postgresql/src/Squeel/PostgreSQL/Statement.hs+9−15
@@ -388,15 +388,6 @@ data By
388388 => (Alias table, Alias column)
389389 -> By tables '(table, column)
390390
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−
400391renderBy :: By tables tabcolty -> ByteString
401392renderBy (By (table, column)) = renderAlias table <> "." <> renderAlias column
402393
@@ -429,12 +420,17 @@ renderHavingClause = \case
429420
430421class (KnownSymbol table, KnownSymbol column)
431422 => 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
433429 :: (HasTable table tables columns, HasColumn column columns ty)
434430 => Alias table
435431 -> Alias column
436432 -> Expression params tables ('Grouped bys) ty
437− getGroup table column = UnsafeExpression $
433+ getGroup2 table column = UnsafeExpression $
438434 renderAlias table <> "." <> renderAlias column
439435instance {-# OVERLAPPING #-} (KnownSymbol table, KnownSymbol column)
440436 => GroupedBy table column '[ '(table,column)]
@@ -449,16 +445,14 @@ instance
449445 , HasColumn column columns ty
450446 , GroupedBy table column bys
451447 ) => IsLabel column
452− (Expression params tables ('Grouped bys) ty) where
453− fromLabel p = getGroup (Alias (proxy# :: Proxy# table)) (Alias p)
448+ (Expression params tables ('Grouped bys) ty) where fromLabel = getGroup1
454449
455450instance
456451 ( HasTable table tables columns
457452 , HasColumn column columns ty
458453 , GroupedBy table column bys
459454 ) => TableColumn table column
460− (Expression params tables ('Grouped bys) ty) where
461− (&.) = getGroup
455+ (Expression params tables ('Grouped bys) ty) where (&.) = getGroup2
462456
463457unsafeAggregate
464458 :: ByteString
squeel-postgresql/test/Squeel/PostgreSQL/StatementSpec.hs+3−3
@@ -85,14 +85,14 @@ spec = do
8585 statement = select
8686 (sum_ #col2 `As` #sum :* #col1 `As` #col1 :* Nil)
8787 ( from (Table (#table1 `As` #table1))
88− & group (by #col1 :* Nil)
88+ & group (By (#table1,#col1) :* Nil)
8989 & having ((#col1 + sum_ #col2) >* 1) )
9090 statement `queryRenders`
9191 "SELECT\
92− \ sum(col2) AS sum, table1.col1 AS col1\
92+ \ sum(col2) AS sum, col1 AS col1\
9393 \ FROM table1 AS table1\
9494 \ GROUP BY table1.col1\
95− \ HAVING ((table1.col1 + sum(col2)) > 1);"
95+ \ HAVING ((col1 + sum(col2)) > 1);"
9696 it "correctly renders simple INSERTs" $ do
9797 let
9898 statement :: Manipulation Tables '[] '[]