-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
37 lines (29 loc) · 1.33 KB
/
Copy pathMain.java
File metadata and controls
37 lines (29 loc) · 1.33 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
35
36
37
import sql.context.Context;
import sql.language.Expression;
import sql.language.impl.From;
import sql.language.impl.Limit;
import sql.language.impl.Select;
import sql.language.impl.Where;
import java.util.Arrays;
import java.util.Collections;
public class Main {
public static void main(String[] args) {
Context context = new Context();
query(context, new Select(Collections.singletonList("firstName"), new From("people")));
query(context, new Select(Arrays.asList("firstName", "lastName"), new From("people")));
query(context, new Limit(1, new Select(Arrays.asList("firstName", "lastName"), new From("people"))));
query(context, new Select(Collections.singletonList("*"), new From("pet")));
query(context, new Select(Arrays.asList("firstName", "lastName"),
new From("people",
Where.builder()
.withPredicate("firstName", firstName -> firstName.startsWith("J") && firstName.endsWith("n"))
.withPredicate("lastName", lastName -> lastName.endsWith("i"))
.build()
)
));
}
private static void query(Context context, Expression expression) {
System.out.println(expression.interpret(context));
System.out.println();
}
}