on dev help sign in
tests
commitcd3decde3100ba42415b08335adba0af8cf4ab00 authorEitan Chatav <eitan.chatav@gmail.com> dateSat 22 Apr 2017, 14:27 (10 years ago) parentce39e5d
2 files changed+13−3
squeel-postgresql/src/Squeel/PostgreSQL/Query.hs+7−1 squeel-postgresql/test/Squeel/PostgreSQL/QuerySpec.hs+6−2
squeel-postgresql/src/Squeel/PostgreSQL/Query.hs+7−1
@@ -184,9 +184,15 @@ from :: Projection ps xs ys -> Relation ps xss xs -> Selection ps xss ys
184184ys `from` xs = UnsafeSelection $
185185 renderProjection ys <> " FROM " <> renderRelation xs
186186
187+subselect :: Selection ps xss ys -> Relation ps xss ys
188+subselect selection = Relation
189+ { tabulation = UnsafeTabulation $ "SELECT " <> renderSelection selection
190+ , restriction = Nothing
191+ }
192+
187193newtype Query ps xss yss zs = UnsafeQuery { renderQuery :: ByteString }
188194newtype PreparedQuery ps xss yss zs =
189195 UnsafePreparedQuery { renderPreparedQuery :: ByteString }
190196
191197select :: Selection ps xss ys -> Query ps xss xss ys
192−select selection = UnsafeQuery $ "SELECT " <> renderSelection selection
198+select selection = UnsafeQuery $ "SELECT " <> renderSelection selection <> ";"
squeel-postgresql/test/Squeel/PostgreSQL/QuerySpec.hs+6−2
@@ -18,11 +18,15 @@ spec = do
1818 it "correctly renders a simple SELECT query" $ do
1919 renderQuery (select (sumAndCol1 `from` (table1 `where_` true)))
2020 `shouldBe`
21− "SELECT col1+col2 AS sum, col1 AS col1 FROM table1 WHERE TRUE"
21+ "SELECT col1+col2 AS sum, col1 AS col1 FROM table1 WHERE TRUE;"
2222 it "combines WHEREs using AND" $ do
2323 renderQuery (select (sumAndCol1 `from` (table1 `where_` true `where_` false)))
2424 `shouldBe`
25− "SELECT col1+col2 AS sum, col1 AS col1 FROM table1 WHERE TRUE AND FALSE"
25+ "SELECT col1+col2 AS sum, col1 AS col1 FROM table1 WHERE TRUE AND FALSE;"
26+ it "performs subSELECTs" $ do
27+ renderQuery (select (star `from` subselect (sumAndCol1 `from` table1)))
28+ `shouldBe`
29+ "SELECT * FROM SELECT col1+col2 AS sum, col1 AS col1 FROM table1;"
2630
2731type Columns =
2832 '[ '("col1", 'PGInt4)