on dev help sign in
tests
cd3decdEitan Chatav
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
184ys `from` xs = UnsafeSelection $
184ys `from` xs = UnsafeSelection $
185 renderProjection ys <> " FROM " <> renderRelation xs
185 renderProjection ys <> " FROM " <> renderRelation xs
186
186
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+
187newtype Query ps xss yss zs = UnsafeQuery { renderQuery :: ByteString }
193newtype Query ps xss yss zs = UnsafeQuery { renderQuery :: ByteString }
188newtype PreparedQuery ps xss yss zs =
194newtype PreparedQuery ps xss yss zs =
189 UnsafePreparedQuery { renderPreparedQuery :: ByteString }
195 UnsafePreparedQuery { renderPreparedQuery :: ByteString }
190
196
191select :: Selection ps xss ys -> Query ps xss xss ys
197select :: 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
18 it "correctly renders a simple SELECT query" $ do
18 it "correctly renders a simple SELECT query" $ do
19 renderQuery (select (sumAndCol1 `from` (table1 `where_` true)))
19 renderQuery (select (sumAndCol1 `from` (table1 `where_` true)))
20 `shouldBe`
20 `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;"
22 it "combines WHEREs using AND" $ do
22 it "combines WHEREs using AND" $ do
23 renderQuery (select (sumAndCol1 `from` (table1 `where_` true `where_` false)))
23 renderQuery (select (sumAndCol1 `from` (table1 `where_` true `where_` false)))
24 `shouldBe`
24 `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;"
26
30
27type Columns =
31type Columns =
28 '[ '("col1", 'PGInt4)
32 '[ '("col1", 'PGInt4)