|
2 | 2 |
|
3 | 3 | import datomic.*; |
4 | 4 |
|
| 5 | +import java.util.List; |
5 | 6 | import java.util.Scanner; |
6 | 7 | import java.util.Collection; |
7 | 8 |
|
@@ -414,17 +415,56 @@ public static void main(String[] args) { |
414 | 415 | System.out.println(results); |
415 | 416 | pause(); |
416 | 417 |
|
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 " + |
419 | 420 | " :in $ ?artist-name " + |
420 | 421 | " :where [?artist :artist/name ?artist-name] " + |
421 | 422 | " [?release :release/artists ?artist] " + |
422 | 423 | " [?release :release/name ?release-name]]", |
423 | 424 | 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); |
426 | 453 | pause(); |
427 | 454 |
|
| 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 | + |
428 | 468 | System.out.println("Timeout a long running query."); |
429 | 469 | queryRequest = QueryRequest.create("[:find ?track-name " + |
430 | 470 | " :in $ ?artist-name " + |
|
0 commit comments