absurd-sql icon indicating copy to clipboard operation
absurd-sql copied to clipboard

Where do I get sql-wasm.wasm ?

Open timwis opened this issue 2 years ago • 5 comments

Hi! Really excited by this project. I'm trying it out locally, using the directions in the readme, and my browser's making a request for /js/sql-wasm.wasm which throws a 404 as it doesn't exist. Not sure what's calling it, or where it's supposed to be. Any suggestions?

I see it as a static file in the example repo, but the readme doesn't mention it 🤔

timwis avatar Nov 07 '21 14:11 timwis

Hey @timwis I just downloaded the .wasm file from the examples folder.

https://github.com/jlongster/absurd-sql/blob/master/src/examples/sql-wasm.wasm

In my react application where I'm testing this library I put it in the public/wasm/bin folder and it works. When I initialize it with initSQLJs it looks like this

SQL = await initSqlJs({ locateFile: file => `/wasm/bin/${file}` });

adv1996 avatar Nov 08 '21 19:11 adv1996

Thanks, but:

  1. The documentation doesn't mention that as a installation step
  2. I can't see the source of it, so I don't know if it's specific to that example, or what it does in the first place
  3. Using it from the npm module would be preferable to 'vendoring' it (adding it to my source control)
  4. My browser was making requests for /js/sql-wasm.wasm, even though that my code said locateFile: file => file

timwis avatar Nov 15 '21 06:11 timwis

@timwis

As for 1., check https://github.com/jlongster/absurd-example-project, that file is there. As for 4., try to add /

locateFile: (file: string) => `/${file}`

steida avatar Nov 16 '21 21:11 steida

I just ran into this problem myself, which had been causing me quite a headache for several hours today. Didn't realize for a while that the problem was that my browser couldn't find sql-wasm.wasm, thought it was something wrong with my service worker setup for a while (apparently learning how to use service workers and absurd-sql for the first time might have been a bigger task than I anticipated :laughing:). If you check your node_modules and go into -> @jlongster -> sql.js -> dist folder, the file should be there! I just went ahead and copied that file to my build tool's directory that serves static assets (for me with vite and vite-plugin-pwa it's /public) and it seems to be working properly for me now! Hope that helps for anyone else who might have this issue

smithbm2316 avatar Jul 11 '22 00:07 smithbm2316

Overall, it's not a good practice to copy wasm file to your public dir, then you will lose ability to receive updates. It's better to import from lib. Here how you can do with CRA:

import sqlWasmUrl from "@jlongster/sql.js/dist/sql-wasm.wasm";

Or with vite:

import sqlWasmUrl from "@trong-orm/sql.js/dist/sql-wasm.wasm?url";

Also, this might help you https://trong-orm.netlify.app/core/usage https://trong-orm.netlify.app/backends/web (it's an abstraction layer, that makes it easier to use absurd-sql. There is also CRA and vite repo example)

quolpr avatar Jul 11 '22 06:07 quolpr