Skip to content

Commit ab4870c

Browse files
committed
another incremental query check-in
1 parent 2080db7 commit ab4870c

1 file changed

Lines changed: 51 additions & 1 deletion

File tree

‎src/java/datomic/samples/Query.java‎

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,57 @@ public static void main(String[] args) {
6565
" [?release :release/name ?release-name]]",
6666
db, Util.list("Paul McCartney", "George Harrison"));
6767
pause();
68-
68+
69+
System.out.println("This query accepts a list of relations, also a list, and destructures the arguments in " +
70+
"the :in clause.");
71+
results = Peer.query("[:find ?release " +
72+
":in $ [[?artist-name ?release-name]] " +
73+
":where [?artist :artist/name ?artist-name] " +
74+
" [?release :release/artists ?artist] " +
75+
" [?release :release/name ?release-name]]",
76+
db, Util.list(Util.list("John Lennon", "Mind Games"),
77+
Util.list("Paul McCartney", "Ram")));
78+
System.out.println(results);
79+
pause();
80+
81+
System.out.println("This query returns a collection of relations, all artists and their releases.");
82+
results = Peer.query("[:find ?artist-name ?release-name " +
83+
":where [?release :release/name ?release-name] " +
84+
" [?release :release/artists ?artist] " +
85+
" [?artist :artist/name ?artist-name]]",
86+
db);
87+
System.out.println(results);
88+
pause();
89+
90+
System.out.println("This query returns a list of releases by using a find specification.");
91+
results = Peer.query("[:find [?release-name ...]" +
92+
" :in $ ?artist-name " +
93+
" :where [?artist :artist/name ?artist-name] " +
94+
" [?release :release/artists ?artist] " +
95+
" [?release :release/name ?release-name]]",
96+
db, "John Lennon");
97+
System.out.println(results);
98+
pause();
99+
100+
System.out.println("This query returns values from multiple attributes to provide artist's start date.");
101+
results = Peer.query("[:find [?year ?month ?day] " +
102+
" :in $ ?name " +
103+
" :where [?artist :artist/name ?name] " +
104+
" [?artist :artist/startDay ?day] " +
105+
" [?artist :artist/startMonth ?month] " +
106+
" [?artist :artist/startYear ?year]]",
107+
db, "John Lennon");
108+
System.out.println(results);
109+
pause();
110+
111+
System.out.println("Return just the year of start date using a scalar find specification.");
112+
Long year = Peer.query("[:find ?year . " +
113+
" :in $ ?name " +
114+
" :where [?artist :artist/name ?name] " +
115+
" [?artist :artist/startYear ?year]]",
116+
db, "John Lennon");
117+
System.out.println(year);
118+
pause();
69119

70120
System.out.println("Total number of artists without :artist/country attribute.");
71121
Integer res = Peer.query("[:find (count ?eid) . " +

0 commit comments

Comments
 (0)