on dev help sign in
by Nil
commit6216d167d0f28f5b776b6e23ed63e02a0f8eda62 authorEitan Chatav <eitan.chatav@gmail.com> dateMon 2 Jul 2018, 16:39 (8 years ago) parent17fbe57
1 file changed+14−1
squeal-postgresql/src/Squeal/PostgreSQL/Query.hs+14−1
squeal-postgresql/src/Squeal/PostgreSQL/Query.hs+14−1
@@ -11,14 +11,17 @@ Squeal queries.
1111{-# LANGUAGE
1212 DeriveGeneric
1313 , FlexibleContexts
14+ , FlexibleInstances
1415 , GADTs
1516 , GeneralizedNewtypeDeriving
1617 , LambdaCase
18+ , MultiParamTypeClasses
1719 , OverloadedStrings
1820 , StandaloneDeriving
1921 , TypeFamilies
2022 , TypeInType
2123 , TypeOperators
24+ , UndecidableInstances
2225#-}
2326
2427module Squeal.PostgreSQL.Query
@@ -188,7 +191,7 @@ let
188191 query =
189192 select (sum_ #col2 `as` #sum :* #col1)
190193 ( from (table (#tab `as` #table1))
191− & group (By #col1 :* Nil)
194+ & group (#table1 ! #col1)
192195 & having (#col1 + sum_ #col2 .> 1) )
193196in printSQL query
194197:}
@@ -795,6 +798,16 @@ deriving instance Show (By relations by)
795798deriving instance Eq (By relations by)
796799deriving instance Ord (By relations by)
797800
801+instance (HasUnique rel rels cols, Has col cols ty, by ~ '(rel, col))
802+ => IsLabel col (By rels by) where fromLabel = By fromLabel
803+instance (HasUnique rel rels cols, Has col cols ty, bys ~ '[ '(rel, col)])
804+ => IsLabel col (NP (By rels) bys) where fromLabel = By fromLabel :* Nil
805+instance (Has rel rels cols, Has col cols ty, by ~ '(rel, col))
806+ => IsQualified rel col (By rels by) where (!) = curry By2
807+instance (Has rel rels cols, Has col cols ty, bys ~ '[ '(rel, col)])
808+ => IsQualified rel col (NP (By rels) bys) where
809+ rel ! col = By2 (rel, col) :* Nil
810+
798811-- | Renders a `By`.
799812renderBy :: By relations by -> ByteString
800813renderBy = \case