question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

using connection.query(...).stream() with promise wrapper

See original GitHub issue

why can’t I use connection.query(...).stream() with promise wrapper? (you get error: TypeError: connection.query(…).stream is not a function)

I’d quite like to be able to do: let q = await connection.query(someSQL); as well as

const s1 = connection.query(veryBiqSqlResult).stream();
s1.on('result', async function(row) {...})

in the same script, but atm I need promise api for the first and standard api for the second…

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:14 (5 by maintainers)

github_iconTop GitHub Comments

4reactions
sidorarescommented, Mar 25, 2019

maybe we need to wait for async generators to land: http://node.green/#ESNEXT-candidate--stage-3--Asynchronous-Iterators-for-await-of-loops

for await (const row of connection.query(veryBiqSqlResult).stream()) {
  console.log(row);
}

( not sure if I can mix buffering .query() => Promise version with non-buffering detecting that .stream() is added, maybe we need another name: `for await (const row of connection.queryStream(veryBiqSqlResult)) {})

You can access non-promise api from wrapper as connection.connection - see https://github.com/sidorares/node-mysql2/blob/97a88530db72c656c16f071a710701ad2830b38d/promise.js#L55

const [rows] = await connection.query(smallSqlResult);
await new Promise((accept, reject) => {
  const s1 = connection.connection.query(veryBiqSqlResult);
  s1.on('result', function(row) {...})
  s1.on('end', accept);
  s1.on('error', reject);
})
1reaction
marnixhohcommented, Oct 2, 2021

@eyalroth I have no idea… I think the docs are a little unclear on this. In case you’re interested, I have asked a somewhat similar question here: https://github.com/mysqljs/mysql/issues/2523

Read more comments on GitHub >

github_iconTop Results From Across the Web

Node MySQL 2 | node-mysql2
Node MySQL 2 ; History and Why MySQL2; Installation ; First Query; Using Prepared Statements ; Using connection pools; Using Promise Wrapper ;...
Read more >
promise-mysql - npm
Promise -mysql is a wrapper for mysqljs/mysql that wraps function calls with Bluebird promises. API. mysql.createConnection(connectionOptions).
Read more >
ERR_STREAM_WRITE_AFTER_...
util. promisify wraps a function that expects an (err, data) callback, converting it into an async function that returns a promise instead. ...
Read more >
Query Stream with MariaDB Connector/Node.js (Promise API)
Unlike most of the other Promise API functions, the queryStream() function does not return a Promise object, and therefore the value returned from...
Read more >
Creating Snowflakes SDK wrapper for NodeJS API - Medium
Now connection.connect will create connection as per the below code private method. private connectSnowflake = async (req: any): Promise<any> ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found