Skip to content

Native Queries and Traversals

eduardoejp edited this page May 24, 2012 · 2 revisions

(use 'clj-orient.query)

Native Queries

Another way to do queries in OrientDB is with native queries, which can be accessed at native-query, e.g.:

(native-query :user
  {:country \"USA\",
   :age [:$>= 20]
   :last-name [:$not= \"Smith\"]})

native-query can also take a function instead, which will have to use the Java API's methods to filter the documents. For your comfort, though, I'd recommend you stick with native-query instead.

API Traversals

Not a SQL fan? You can still do traversals by using the traverse function. It takes a vector of fields (e.g. [:in :out :pets]), a target (which can be a seq of CljODoc objects or ORecordIDs or a mixture of those), a predicate (which will take a CljODoc as it's first argument and a function as the second) and an optional limit as an integer.

For the predicate, the function it is passed takes 1 argument (a keyword) and returns the corresponding context variable.

Example:

(traverse [:in :out :pets] [(clj-orient.core/orid [12 824])]
  (fn [d ctx] (< (ctx :depth) 5)))

traverse will return a lazy-seq of CljODoc objects.

Clone this wiki locally