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

Faster result processing using USE RESULT #3367

Open
infusion opened this issue Feb 3, 2025 · 1 comment
Open

Faster result processing using USE RESULT #3367

infusion opened this issue Feb 3, 2025 · 1 comment

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

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

3 participants