3 ms·
Hmm... would it be possible, using Promises, to create a sorta-shim, you give it a SQL query and a callback function. The shim does asynchronously all the stuf
by mschuster91 11y ago
Hmm... would it be possible, using Promises, to create a sorta-shim, you give it a SQL query and a callback function.
The shim does asynchronously all the stuff a DB engine does (most people are going to use "SELECT cola,colb,colc FROM x WHERE foo=bar and baz=quux ORDER BY cola ASC GROUP BY colb" and nothing more complex anyway), then tracks all the stuff it needs to do in its own promise tracker. Once all is done, it assembles the returned row(s), stores them and calls the callback.
The biggest problem I see is locking as all the crap is async so you'd need some sort of locking and query ordering to maintain data consistency.
- tracker1 11y agoIf you don't really need true locking pessimism it's more possible... There are actual SQL engines in JS though. Using a single queue to run queries through would be relatively easy to do... a stage 1 analysis of what collections you need to query could then push the query into one of several queues for pipeline requests. It would be interesting, but I don't mind IndexDB (or localStorage for that matter) enough to really bother with it.