-
Notifications
You must be signed in to change notification settings - Fork 28
Query API
desaperados edited this page Nov 25, 2013
·
2 revisions
The query API is used for generating Datomic queries, whether to send via an external client or via the persistence API. The two methods used to generate a query are .where
and .filter
, both of which are chainable.
To get query data and args for a query, call .data
on a Query
.
If you are using a persistence API, you can ask Query
to get the results of a Datomic query. Diametric::Query
is an Enumerable
. To get the results of a query, use Enumerable
methods such as .each
or .first
. Query
also provides a .all
method to run the query and get the results.
query = Diametric::Query.new(Person).where(:name => "Clinton Dreisbach")
query.data
# Datomic query:
# [:find ?e ?name ?email ?birthday ?iq ?website
# :from $ ?name
# :where [?e :person/name ?name]
# [?e :person/email ?email]
# [?e :person/birthday ?birthday]
# [?e :person/iq ?iq]
# [?e :person/website ?website]]
# Args:
# ["Clinton Dreisbach"]
#
# Returns as an array, [query, args].
query = Diametric::Query.new(Person).where(:name => "Clinton Dreisbach").filter(:>, :iq, 150)
query.data
# Datomic query:
# [:find ?e ?name ?email ?birthday ?iq ?website
# :from $ ?name
# :where [?e :person/name ?name]
# [?e :person/email ?email]
# [?e :person/birthday ?birthday]
# [?e :person/iq ?iq]
# [?e :person/website ?website]
# [> ?iq 150]
# Args:
# ["Clinton Dreisbach"]
#
# Returns as an array, [query, args].