docs icon indicating copy to clipboard operation
docs copied to clipboard

API JS - r.connect and r.close

Open neumino opened this issue 11 years ago • 2 comments

See http://pastebin.com/GGqiqbKu

We should actually write a whole example on how to connect, bind listeners for errors, run a query, close the connection.

neumino avatar Jul 22 '14 21:07 neumino

We should probably write about using/disposer -- https://github.com/petkaantonov/bluebird/blob/master/API.md#promiseusingpromisedisposer-promise-promisedisposer-promise--function-handler---promise

I have to tests a few things, but I should be able to provide some snippets.

neumino avatar Jul 22 '14 22:07 neumino

Just pasting a snippet I used (with bind).

r.connect({}).bind({}).then(function(conn) {
    this.conn = conn;
    return query.run(this.conn);
}).then(function(result) {
    // do things with result
}).error(function(err) {
    // handle error
}).finally(function() {
    if (this.conn) {
        this.conn.close();
    }
})

neumino avatar Aug 06 '14 17:08 neumino