Edit Page

.then()

Execute a Waterline query instance using promises.

.then(callback)

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

Usage

#
Argument Type Details
1 callback Function A function that runs if the query successfully completes

Takes the result of the query as its argument.
Callback
#
Argument Type Details
1 result Ref? The result from the database, if any. Exact data type depends on the query.

Example

#

To look up the user with the specified email address:

User.findOne({
  email: req.param('email')
})
.then(function (user){
  if (!user) { return res.notFound(); }
  return res.json(user);
})
.catch(function (err) { return res.serverError(err); });

Notes

#
  • Whenever possible, it is recommended that you use await instead of calling this method.
  • This is an alternative to .exec(). When combined with .catch(), it provides the same functionality.
  • The .then() function returns a promise to allow for chaining.
  • For more information, see the bluebird .then() api docs.

Is something missing?

If you notice something we've missed or could be improved on, please follow this link and submit a pull request to the sails repo. Once we merge it, the changes will be reflected on the website the next time it is deployed.

Reference

Reference