-
Notifications
You must be signed in to change notification settings - Fork 121
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
[RFE] Custom sql.js build with newer SQLite and a few extensions #45
Comments
Not sure what your asking for in this issue, sql.js Math functions are in the 1.5 release that Sqliteviz uses. Simple test: |
@twoxfh the thing that it's not enough to have |
I tried it your branch. It didn't work. Firefox.
Chromium.
I plan to take a look at it the custom build when I have time. I have roughly these in mind.
|
Interesting, my local build worked, admittedly I did not properly remove the dependency and rebuild sqliteviz. @lana-k might have thoughts on static asset contributions. |
I updated my build directory, I noticed my buld of SQL-WASM doesnt appear to show the added extensions. I tried the queries and they worked though. Githack link |
@twoxfh Yes, that works. I don't mind static assets but it must be a script that does all the work in case when sql.js is updated (download sql.js, download extensions, change makefile, run |
Unfortunately building sql-js is painful and not really scriptable for future updates due to manually editing js files. I could upload the node_modules directory which would be easy. Also https://github.com/rhashimoto/wa-sqlite potentially might give better flexibility to manage customizations without building the wasm, possibly abort long queries due to it being async, and allows you to program vtab extensions in js. |
I briefly looked at
That practically means that we should stay with sql.js for the time being. |
I made some progress on the issue today. Here's the draft PR #62. Not too bad, and conceptually it's what I expected. But a lot of details are left to do. |
I haven't tested it yet, but looks nice not to maintain the API.js in sql-js and extensions file. |
The PR is merged, and I'm closing this issue. A note on |
(1) is indeed a valid concern. If I didn't write it I'd be reluctant to use it based solely on that. (2) is not so cut and dry. First, wa-sqlite provides both synchronous and asynchronous builds so if you don't need Asyncify then you don't have to include it. Second, if you do need to use an asynchronous resource (e.g. IndexedDB), the Asyncify penalties can be a small fraction of the cost of accessing the resource. This is the case for IndexedDB, for example - the time spent waiting for IDB events is typically far greater than the Asyncify overhead. I think your decision will usually be driven by the performance of your resource and not wa-sqlite itself. (3) I really question. wa-sqlite does not require the use of Atomics. You can use Atomics to avoid the Asyncify build if you're willing to jump through a lot of extra hoops (and give up browser compatibility), but it wouldn't surprise me if that turned out to be slower in the end. I would add some other potential issues for you to weigh:
|
First of all, thanks for detailed explanation. On Asyncify and/or Atomics. To be honest, I've only cursory understanding of the two, so I may be missing something. But still, currently there's only one new feature that might benefit from asynchronous interface to SQLite (as mentioned here #45 (comment)). It's cancelling of running queries -- #33. It's not that important of a feature (the database is in memory in the end and the memory is limited to what the browser allows a tab to allocate), but a nice to have one. Options there are:
My take is that (1) is good enough, and (3) is worth exploring. And as I mentioned in #45 (comment), future will show if there are more use cases that might benefit from it. |
For just aborting, I think there's another possibility. Since you're already compiling your own SQL.js artifacts, you can patch the SQLite source to call out to Javascript within query processing and conditionally return an error code. I mentioned this at the bottom of a reply to @twoxfh. If you want to avoid an Asyncify build, the Javascript call would have to be synchronous, which really restricts how you can signal the abort. But LocalStorage access is synchronous and state is shared by all Window contexts in the same origin so that would let you set a flag in one context to abort a running query in another context. So the only remaining hiccup with that is you would have to run SQLite in a Window context, like an invisible iframe, instead of a Worker since workers can't access LocalStorage. Advantages:
Disadvantages:
|
Use cases
Math functions
As a educational user of Sqliteviz,
In order to use SQLite to generate mathematical function series and graphs them,
I want to be able to call functions like
sin
,cos
etc.SQLite has math functions, but:Turns out there's another extension mechanism used in sql-js'
Makefile
to enable the mathematical function (which apparently was used before 3.35.0 2021-03-12 introducedSQLITE_ENABLE_MATH_FUNCTIONS
):The C file contains this description (and these could be useful in the auto-complete.):
A series can be generated by a recursive CTE without creating a table.
There's simpler way to do it, with
generate_series
table-valued function, but:It can be used like like:
Or
Generating matrix for Plotly surface plot
As a user of Sqliteviz,
In order to visualise 3D surface,
I want to be able to select the pivot/matrix table that Plotly 3D surface plot expects.
There's SQLite pivot_vtab virtual table extension (see building and running example in this SO answer).
It produces:
WASM build of SQLite
According to this issue sql-js/sql.js#342, loadable extension can also be pre-built. And here's SQLite's Statically Linking A Run-Time Loadable Extension.
The text was updated successfully, but these errors were encountered: