Back to Sequelize

Class Promise

static/v2/api/promise/index.html

latest3.9 KB
Original Source

Class Promise

View code A slightly modified version of bluebird promises. This means that, on top of the methods below, you can also call all the methods listed on the link below.

The main difference is that sequelize promises allows you to attach a listener that will be called with the generated SQL, each time a query is run.

The sequelize promise class works seamlessly with other A+/thenable libraries, with one exception. If you want to propagate SQL events across then, all calls etc., you must use sequelize promises exclusively.

Mixes:


on(evt, fct)

View code Listen for events, event emitter style. Mostly for backwards compat. with EventEmitter

Deprecated

Params:

NameTypeDescription
evtString
fctFunction

emit(type, value(s)*)

View code Emit an event from the emitter Deprecated

Params:

NameTypeDescription
typestringThe type of event
value(s)*anyAll other arguments will be passed to the event listeners

success(onSuccess) -> this

View code Listen for success events.

promise.success(function (result) {
 //...
});

Deprecated

Params:

NameTypeDescription
onSuccessfunction

Aliases: ok


error(onError) -> this

View code Listen for error events

promise.error(function (err) {
 //...
});

Deprecated

Params:

NameTypeDescription
onErrorfunction

Aliases: fail, failure


done(onDone) -> this

View code Listen for both success and error events.

promise.done(function (err, result) {
 //...
});

Deprecated done(fct) is deprecated, done() is regular promise syntax to explicitly signal the end of a promise chain and will not be deprecated

Params:

NameTypeDescription
onDonefunction

Aliases: complete


sql(onSQL) -> this

View code Attach a function that is called every time the function that created this emitter executes a query.

Params:

NameTypeDescription
onSQLfunction

proxy(promise, [options]) -> this

View code Proxy every event of this promise to another one.

Deprecated

Params:

NameTypeDescription
promiseSequelizePromiseThe promise that should receive the events.
[options]Object
[options.events]ArrayAn array of the events to proxy. Defaults to sql, error and success

This document is automatically generated based on source code comments. Please do not edit it directly, as your changes will be ignored. Please write on IRC, open an issue or a create a pull request if you feel something can be improved. For help on how to write source code documentation see JSDoc and dox