-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make Query & NativeQuery implement the promise interface (#1047)
* Make Query & NativeQuery implement the promise interface * Fix test * Use older node API for checking listener length * Do not test for promises on node@v0.10.0
- Loading branch information
Showing
4 changed files
with
72 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
var helper = require(__dirname + '/../test-helper'); | ||
var pg = helper.pg; | ||
var semver = require('semver') | ||
|
||
if (semver.lt(process.version, '0.12.0')) { | ||
return console.log('promises are not supported in node < v0.10') | ||
} | ||
|
||
process.on('unhandledRejection', function(e) { | ||
console.error(e, e.stack) | ||
process.exit(1) | ||
}) | ||
|
||
pg.connect(helper.config, assert.success(function(client, done) { | ||
client.query('SELECT $1::text as name', ['foo']) | ||
.then(function(result) { | ||
assert.equal(result.rows[0].name, 'foo') | ||
return client | ||
}) | ||
.then(function(client) { | ||
client.query('ALKJSDF') | ||
.catch(function(e) { | ||
assert(e instanceof Error) | ||
}) | ||
}) | ||
|
||
client.query('SELECT 1 as num') | ||
.then(function(result) { | ||
assert.equal(result.rows[0].num, 1) | ||
done() | ||
pg.end() | ||
}) | ||
})) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters