Skip to content

Commit 455820b

Browse files
committed
QueryRequest examples with different shapes
1 parent 27c98fd commit 455820b

2 files changed

Lines changed: 45 additions & 5 deletions

File tree

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<dependencies>
55
<dependency>
66
<groupId>com.datomic</groupId>
7-
<artifactId>datomic-free</artifactId>
7+
<artifactId>datomic-pro</artifactId>
88
<version>0.9.5153</version>
99
<exclusions>
1010
<exclusion>

src/java/datomic/samples/Query.java

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import datomic.*;
44

5+
import java.util.List;
56
import java.util.Scanner;
67
import java.util.Collection;
78

@@ -414,17 +415,56 @@ public static void main(String[] args) {
414415
System.out.println(results);
415416
pause();
416417

417-
System.out.println("Building a QueryRequest.");
418-
QueryRequest queryRequest = QueryRequest.create("[:find ?release-name " +
418+
System.out.println("Using a QueryRequest to return a relation");
419+
QueryRequest queryRequest = QueryRequest.create("[:find ?artist-name ?release-name " +
419420
" :in $ ?artist-name " +
420421
" :where [?artist :artist/name ?artist-name] " +
421422
" [?release :release/artists ?artist] " +
422423
" [?release :release/name ?release-name]]",
423424
db, "John Lennon");
424-
results = Peer.query(queryRequest);
425-
System.out.println(results);
425+
Collection<List<String>> queryResultRelation = Peer.query(queryRequest);
426+
427+
System.out.println(queryResultRelation);
428+
pause();
429+
430+
System.out.println("Using a QueryRequest to return a collection");
431+
queryRequest = QueryRequest.create("[:find [?release-name ...]" +
432+
" :in $ ?artist-name " +
433+
" :where [?artist :artist/name ?artist-name] " +
434+
" [?release :release/artists ?artist] " +
435+
" [?release :release/name ?release-name]]",
436+
db, "John Lennon");
437+
Collection<String> queryResultCollection = Peer.query(queryRequest);
438+
439+
System.out.println(queryResultCollection);
440+
pause();
441+
442+
System.out.println("Using a QueryRequest to return a single tuple");
443+
queryRequest = QueryRequest.create("[:find [?year ?month ?day]" +
444+
" :in $ ?name" +
445+
" :where [?artist :artist/name ?name] " +
446+
" [?artist :artist/startDay ?day] " +
447+
" [?artist :artist/startMonth ?month] " +
448+
" [?artist :artist/startYear ?year]]",
449+
db, "John Lennon");
450+
List<Long> queryResultSingleTuple = Peer.query(queryRequest);
451+
452+
System.out.println(queryResultSingleTuple);
426453
pause();
427454

455+
456+
System.out.println("Using a QueryRequest to return a single scalar");
457+
queryRequest = QueryRequest.create("[:find ?year . " +
458+
" :in $ ?name " +
459+
" :where [?artist :artist/name ?name] " +
460+
" [?artist :artist/startYear ?year]]",
461+
db, "John Lennon");
462+
Long queryResultSingleScalar = Peer.query(queryRequest);
463+
464+
System.out.println(queryResultSingleScalar);
465+
pause();
466+
467+
428468
System.out.println("Timeout a long running query.");
429469
queryRequest = QueryRequest.create("[:find ?track-name " +
430470
" :in $ ?artist-name " +

0 commit comments

Comments
 (0)