Skip to content
Jean-Baptiste Musso edited this page Oct 28, 2013 · 1 revision

Model

Instance methods

model.save(callback)

Saves current model in the graph database. Will create a vertex if new, or update one if already existing (currently only checks for an existing or missing _id property).

model.update(callback)

Usually called by save()

update() ignores properties not defined the schema definition and will not change their values. There currently is no option to modify this behavior.

model.insert(callback)

Usually called by save()

Static methods

Model.find(grexQuery, asModel, callback)

Executes a Gremlin query, and return data as model instances or as raw data. Note that asModel is optional and defaults to true.

Model.findOne(property, callback)

Find a model by a given property name. Will only return the first of all found vertices.

User.findOne({name: "John"}, function(error, model) {
  // Check for error, and do something with model
});

Gremlin:

g.V("name", "John")[0]

Model.findById(id, callback)

Find a model by vertex id.

User.findById(4, function(error, model) {
  // ..
});

Gremlin:

g.v(4)

Model.delete(id, callback)

Delete a model by vertex id.

User.delete(4, function(error, result) {
  // ..
});

Gremlin:

g.removeVertex(g.v(id))