Skip to content
New issue

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

Why does pg.Cursor still use callbacks? #2545

Closed
Bluenix2 opened this issue May 14, 2021 · 2 comments · Fixed by #2554
Closed

Why does pg.Cursor still use callbacks? #2545

Bluenix2 opened this issue May 14, 2021 · 2 comments · Fixed by #2554
Labels

Comments

@Bluenix2
Copy link
Contributor

Looking at the the pg.Cursor API documentation it appears to be using callbacks, is there a reason that there hasn't been a switch to the Promises API introduced in ES6?

Other parts of the package shows the usage of promises. As can be seen here.

@sehrope
Copy link
Contributor

sehrope commented May 14, 2021

All of that code predates Promises by many years and nobody has gotten around to adding it. It's common for anybody using the Cursor API in modern applications to add their own Promise wrapper. Ex: https://github.com/sehrope/postgres-with-nodejs-code/blob/85fd7acf5b4e1be5a124bbf39c68bbc2e5591489/src/00026-memory-usage-with-cursor.js#L5-L15

I think it'd be fine to add it directly to the Cursor.read(...) function. It could mirror the query API and check if the second parameter is not defined, and if so, return the result as a Promise. The close function is a bit trickier as right now the callback is not required so changing it to return a Promise (when there's no callback) could lead to a dangling Promise in existing code.

@Bluenix2
Copy link
Contributor Author

Is there a reason that Cursor doesn't use ES6 classes or can I make that switch as well?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants