We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
When executing queries with this library like so: db.query('select * from users').then(res => res.rows[0]);
db.query('select * from users').then(res => res.rows[0]);
I very often just want to get the first row from the result, and it's tedious to retype the .then(res => res.rows[0]) every time.
.then(res => res.rows[0])
It would be great to add some convenience methods like firstRow() or allRows() that would save a lot of typing. For example:
db.query('select * from users').firstRow() db.query('select * from users').allRows() db.query('select * from users')
db.query('select * from users').firstRow()
db.query('select * from users').allRows()
db.query('select * from users')
Omitting the methods would maintain the current functionality.
Let me know if you think this is a worthwhile addition.
The text was updated successfully, but these errors were encountered:
query returns a promise, so you could include those on the configurable promise implementation for pools:
query
class QueryPromise extends Promise { firstRow() { return this.then(result => result.rows[0]); } allRows() { return this.then(result => result.rows); } } const db = new pg.Pool({ …, Promise: QueryPromise, });
#1518 adds the same functionality to clients.
Sorry, something went wrong.
No branches or pull requests
When executing queries with this library like so:
db.query('select * from users').then(res => res.rows[0]);
I very often just want to get the first row from the result, and it's tedious to retype the
.then(res => res.rows[0])
every time.It would be great to add some convenience methods like firstRow() or allRows() that would save a lot of typing. For example:
db.query('select * from users').firstRow()
db.query('select * from users').allRows()
db.query('select * from users')
Omitting the methods would maintain the current functionality.
Let me know if you think this is a worthwhile addition.
The text was updated successfully, but these errors were encountered: