on ce39e5d help sign in
39 lines 973 B history raw
1{-# LANGUAGE
2 DataKinds
3 , OverloadedLabels
4 , OverloadedStrings
5#-}
7module Squeel.PostgreSQL.QuerySpec where
9import Data.Boolean
10import Data.Vinyl
11import Test.Hspec
13import Squeel.PostgreSQL.Query
14import Squeel.PostgreSQL.Type
16spec :: Spec
17spec = do
18 it "correctly renders a simple SELECT query" $ do
19 renderQuery (select (sumAndCol1 `from` (table1 `where_` true)))
20 `shouldBe`
21 "SELECT col1+col2 AS sum, col1 AS col1 FROM table1 WHERE TRUE"
22 it "combines WHEREs using AND" $ do
23 renderQuery (select (sumAndCol1 `from` (table1 `where_` true `where_` false)))
24 `shouldBe`
25 "SELECT col1+col2 AS sum, col1 AS col1 FROM table1 WHERE TRUE AND FALSE"
27type Columns =
28 '[ '("col1", 'PGInt4)
29 , '("col2", 'PGInt4)
30 ]
32sumAndCol1 :: Projection '[] Columns
33 '[ '("sum", 'PGInt4)
34 , '("col1", 'PGInt4)
35 ]
36sumAndCol1 = project ((#col1 + #col2) `As` #sum :& #col1 :& RNil)
38table1 :: Relation '[] '[ '("table1", Columns)] Columns
39table1 = #table1