-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathWithTest.java
More file actions
34 lines (27 loc) · 1.12 KB
/
Copy pathWithTest.java
File metadata and controls
34 lines (27 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package jaskell.sql;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import static jaskell.sql.SQL.l;
import static jaskell.sql.SQL.n;
import static jaskell.sql.SQL.select;
import static jaskell.sql.SQL.with;
public class WithTest {
@Test
public void BasicTest0(){
final String script =
"WITH t1 AS (SELECT n FROM t), t2 AS (SELECT m FROM t) SELECT m * n FROM t1 JOIN t2 ON t1.n != t2.m";
Query query = with("t1").as(select("n").from("t"))
.cte("t2").as(select("m").from("t"))
.select(l("m * n")).from("t1").join(n("t2")).on(n("t1.n").ne(n("t2.m")));
Assertions.assertEquals(script, query.script());
}
@Test
public void BasicTest1(){
final String script =
"WITH RECURSIVE t(f) AS (SELECT 1 UNION SELECT f+1 FROM t WHERE f < 100) SELECT f FROM t";
Query query = with().recursive().name("t(f)")
.as(select(l(1)).union().select(l("f+1")).from("t").where(n("f").lt(100)))
.select("f").from("t");
Assertions.assertEquals(script, query.script());
}
}