Query execution

Ogre cannot do everything for you. Specifically, it does not figure out the types of Java objects that are returned from some arbitrary query and convert them automatically into Clojure objects. So, with that in mind, Ogre includes several functions that execute the pipeline and then do conversions into specific Clojure data structures.

count!

q/count! returns the number of objects currently in the pipeline.

(q/query (g/find-by-id 1)
         q/-->
         q/count!)
;= 3

into-lazy-seq!

Gets the objects and returns them inside a lazy sequence. ``` clojure (type (q/query (g/find-by-id 1) q/--> q/into-lazy-seq!)) ;= clojure.lang.Cons

(first (q/query (g/find-by-id 1) q/--> q/into-lazy-seq!)) ;= # ```

into-list!

Gets the objects and sticks them inside of a list.

(q/query (g/find-by-id 1)
         q/-->
         q/into-list!)
;= (#<TinkerVertex v[3]> #<TinkerVertex v[4]> #<TinkerVertex v[2]>)

into-vec!

Gets the objects and sticks them inside of a vector.

(q/query (g/find-by-id 1)
         q/-->
         q/into-vec!)
;= [#<TinkerVertex v[2]> #<TinkerVertex v[4]> #<TinkerVertex v[3]>]

into-set!

Gets the objects and sticks them inside of a set.

(q/query (g/find-by-id 1)
         q/-->         
         q/into-set!)
;= #{#<TinkerVertex v[2]> #<TinkerVertex v[3]> #<TinkerVertex v[4]>}

first-of!

Gets the first object of the returned list.

(q/query (g/find-by-id 1)
         q/first-of!)
;= #<TinkerVertex v[1]>

first-into-vec!

Gets the first object of the returned list and puts it into a vector.

(q/query (g/find-by-id 1)
         (q/property :name)
         q/path
         q/into-vec!)
;= [#<ArrayList [v[1], marko]>]         

(q/query (g/find-by-id 1)
         (q/property :name)
         q/path
         q/first-into-vec!)
;= [#<TinkerVertex v[1]> "marko"]

first-into-set!

Gets the first object of the returned list and puts it into a set.

(q/query (g/find-by-id 1)
         q/-->
         q/id
         q/gather
         q/first-into-set!)
;= #{"2" "3" "4"}         

gather collects all objects up to that step; see reduce-like functions for more examples.

first-into-map!

Gets the first object of the returned list and puts it into a set.

(q/query (g/find-by-id 1)
          q/map
          q/first-into-map!)
;= {:name "marko", :age 29}

all-into-vecs!

Gets the list of returned objects and maps vec across all of the objects.

(q/query (g/find-by-id 1)
         q/-->
         (q/path (q/prop :age)
                 (q/prop :name))
         q/all-into-vecs!)
;= ([29 "vadas"] [29 "josh"] [29 "lop"])

all-into-sets!

Gets the list of returned objects and maps set across all of the objects.

(q/query (g/find-by-id 1)
         q/-->
         (q/path (q/prop :age)
                 (q/prop :name))
         q/all-into-sets!)
;= (#{"vadas" 29} #{"josh" 29} #{"lop" 29})

all-into-maps!

Gets the list of returned objects and maps set across all of the objects.

(q/query (g/find-by-id 1)
         q/<->
         q/<->
         q/map
         q/all-into-maps!)
;= ({:name "marko", :age 29} 
;=  {:name "marko", :age 29} 
;=  {:name "ripple", :lang "java"} 
;=  {:name "lop", :lang "java"} 
;=  {:name "marko", :age 29} 
;=  {:name "josh", :age 32} 
;=  {:name "peter", :age 35})         

Reduce-like functions are next

You should read about reduce-like functions next.

Tell Us What You Think!

Please take a moment to tell us what you think about this guide on Twitter or the Titanium mailing list.

Let us know what was unclear or what has not been covered. Reader feedback is key to making the documentation better. If we know people are reading the documentation, we'll be much more inclined to make the documentation that much better. Please speak up!