Skip to content

Faster result processing using USE RESULT #3367

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

Open
infusion opened this issue Feb 3, 2025 · 2 comments
Open

Faster result processing using USE RESULT #3367

infusion opened this issue Feb 3, 2025 · 2 comments

Comments

@infusion
Copy link

infusion commented Feb 3, 2025

Hi,

thank you very much for the mysql2 library! I have a question that if not currently possible could be turned into a feature request. I want to process large streams of data from MySQL. The MySQL CLI client allows to add the -q option for avoiding buffering and PHP for example allows to add the result mode MYSQLI_USE_RESULT to stream the data. I only found a way to stream data using mysql2, but what I'm looking for is a way to run a query without buffering, optimally like so:

db = await mysql.createConnection({...})

for await (let row of db.query("SELECT * FROM t1")) {...} 

Is this already possible or is something in this direction already planned?

Thanks!
Robert

@sidorares
Copy link
Owner

you can read results without buffering right now like this:

    conn.query("SELECT * FROM table")
            .on('result', function (row) {
                 // use the data
            })

I do want to add async iterator api for the same functionality, see discussion here for example:
#822 (comment)

there are more issues discussing similar topic, feel free to link them @infusion if you find something that gives a better context

@nikhileshSakalabhaktula
Copy link

nikhileshSakalabhaktula commented Mar 8, 2025

Hi

I have huge amount of data like 2 lakhs of returned by a query. And it is wrking fine amd taking less time in every db querying tool but using mysql2 node driver it is taking more time to buffer and return the data that can be stored in js object. Can you help me here how to solve this.

The above streaming thing is not working with pool connection. It says .on is not a function

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

No branches or pull requests

4 participants