Back to Sails

`.exec()`

docs/reference/waterline/queries/exec.md

12.12.20001.8 KB
Original Source

.exec()

Execute a Waterline query instance.

usage
.exec(function (err, result) {

})

As of Sails v1 and Node.js v8, you can take advantage of await instead of using this method.

Usage

ArgumentTypeDetails
1callback((function))The Node-style callback that will be called when the query completes, successfully or otherwise.
Callback
ArgumentTypeDetails
1err((Error?))The Error that occurred, or undefined if there were no errors.
2result((Ref?))The result from the database, if any. Exact data type depends on the query. If an error occurred (i.e. err is truthy), then this result argument should be ignored.

Example

javascript
Zookeeper.find().exec((err, zookeepers)=>{
  if (err) {
    return res.serverError(err);
  }

  // would you look at all those zookeepers?
  return res.json(zookeepers);
});
//
// (don't put code out here)

Notes

  • If you don't run .exec() or use promises, your query will not execute. For help using .exec() with model methods like .find(), read more about the chainable query object.
<docmeta name="displayName" value=".exec()"> <docmeta name="pageType" value="method">