Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
Write a generator to produce paged series of your record for batching to sql:
https://developer.mozilla.org/en-US...*
Js doesn't support tail recursion, so you'll either need to flatten the recursion that way, or use the trampoline pattern.
https://blog.logrocket.com/using-tr... -
Sounds cool.
Take care of edge cases though, we wouldn't want it to have a fucked up exit condition. -
eval6804yFuck callbacks. Use mysql2/promise and use async await... That's like the best of both worlds (async but readable like sequential and no callback hell)
I'd never want to use JS without async await anymore. Just make sure to try catch where appropriate. -
@eval
I would agree with this strongly if I didn't truly prefer Observables to the async await Impl in js. -
A resursive callback function like that might cause a stack overflow if the number of recursions are too high.
Related Rants
Being new to NodeJS, I wanted to use the framework for a small script that involved connecting to a MySQL database and updating 1500+ records.
With NodeJS's preference towards functional programming over sequential, I wanted to do things the NodeJS way with callback functions instead how I'm used to doing it, using loops (and all the MySQL functions were async).
I couldn't update all the rows at once, so I wrote a callback function that calls back itself after the SQL statement is executed. A recursive callback function... am I doing this right?
question
nodejs
functional programming