-
Notifications
You must be signed in to change notification settings - Fork 9
Vertices
Working with vertices is straightforward with Hermes and the functions
within hermes.vertex
.
hermes.vertex/create!
takes an element, and optionally a map of properties, and
creates a vertex within the graph.
(def example-1 (v/create!))
;;#<PersistStandardTitanVertex v[348]>
(def example-2 (v/create! {:a 1 :b 2}))
;;#<PersistStandardTitanVertex v[352]>
(v/prop-map example-2)
;;{:id 352, :a 1, :b 2}
hermes.vertex/get-by-id
takes an id and retrieves that vertex from
the graph.
(def example (v/create!))
;;#<PersistStandardTitanVertex v[364]>
(v/get-by-id (v/get-id example))
;;#<PersistStandardTitanVertex v[364]>
hermes.vertex/find-by-kv
takes a key and a value and
checks indices of that key for the given value. Returns a set of all
vertices that match the key/value pair. The indices need to be indexed
though (checkout out
types and groups
for how to set this up).
(v/create! {:indexed-a 1 :name "example 1"})
;;#<PersistStandardTitanVertex v[384]>
(v/create! {:indexed-a 1 :name "example 2"})
;;#<PersistStandardTitanVertex v[412]>
(v/find-by-kv :indexed-a 1)
;;#{#<PersistStandardTitanVertex v[412]> #<PersistStandardTitanVertex v[384]>}
hermes.upsert!
takes in a key and a map and does a upsert
like operation. It takes
the key and the value of the key from the map, finds all of the
vertices that match the pair, and merges the map into the properties
of the returned vertices. hermes.upsert!
returns a PersistentHashSet
of all the updated vertices.
(v/create! {:age 1 :name "Titan"})
;;#<PersistStandardTitanVertex v[432]>
(v/create! {:age 1 :name "Titan"})
;;#<PersistStandardTitanVertex v[444]>
(v/upsert! :age {:age 1 :type "Project"})
;;#{#<PersistStandardTitanVertex v[432]> #<PersistStandardTitanVertex v[444]>}
(map v/prop-map (v/upsert! :age {:age 1 :type "Project"}))
;;({:id 432, :age 1, :name "Zack", :type "Project"} {:id 444, :age 1, :name "Titan", :type "Project"})