Skip to content

Expose details of result column #374

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

Open
charlielidbury opened this issue Mar 21, 2020 · 9 comments
Open

Expose details of result column #374

charlielidbury opened this issue Mar 21, 2020 · 9 comments
Assignees

Comments

@charlielidbury
Copy link

In connectors like better-sqlite3: sqlite3_column_name and the origins of columns are exposed via Statement.columns, this is useful for analysing a statement.

I've written a connector which uses the Statement.columns method to automatically replace forgein key references with getters, I would like to bring this to the browser via sql.js but that information isn't exposed in this API, or in any other wasm API.

Would you be interested in adding a method similar to better-sqlite3's prepared statements? It's quite a niche thing but most server-side connectors impliment it, so people must be using it.

I have looked a little bit at sql.js' source code and I think I'll be able to impliment it myself and make a pull request, but I've never worked on C and JS in tandem so it would be a learning curve, I just haven't gone on that curve yet in case you think it's a dumb idea and you'll never merge it.

Thanks for your time.

@lovasoa
Copy link
Member

lovasoa commented Mar 21, 2020

Hello,
This is a nice feature, and I would be happy to review your PR ! Don't hesitate to ask if you need help or pointers to get started.

@charlielidbury
Copy link
Author

Thank you! When I get some time I will start playing around with it.

@charlielidbury
Copy link
Author

Hello,
This is a nice feature, and I would be happy to review your PR ! Don't hesitate to ask if you need help or pointers to get started.

Hello, really sorry but I'm stuck at the first hurdle.

  • Ran npm run rebuild got an error (e=2) about not being able to find rm on path
  • Added C:\Program Files\Git\usr\bin to path to add rm
  • Found that if you add sh to path, make errors
  • Removed sh from path by renaming it (bodge!)
  • Now I'm stuck with the following error:
C:\Users\charl\Documents\GitHub\sql.js>make
mkdir -p cache
A subdirectory or file -p already exists.
Error occurred while processing: -p.
make: *** [cache/sqlite-amalgamation-3310100.zip] Error 1

I know this isn't a make support line but lots of the contributers to this project must have had make and git installed while working on this project, so figured you might have an easy fix to this!

Many thanks.

@lovasoa
Copy link
Member

lovasoa commented Jun 7, 2020

Hello @charlielidbury ! I don't know very much about windows, but I guess the easiest fix is to just not use it for this kind of work 😄 If you don't want to install linux, you can try WSL. It should come with all the tools you need.

@charlielidbury
Copy link
Author

charlielidbury commented Jun 7, 2020 via email

@lovasoa
Copy link
Member

lovasoa commented Jun 7, 2020

I personally don't use windows, but I've heard a lot of good things about WSL2. Hope you can make it work :)

@kaizhu256
Copy link
Member

I'm a windows user, who runs linux stuff under debian docker. don't know about wsl2, but was not impressed with wsl1 -- things would randomly crash under it.

i don't actually compile sqj.js or bother with emscripten tooling locally. just let github-ci do the heavy-lifting (takes 5 minutes) and then download it's artifacts.

@lovasoa
Copy link
Member

lovasoa commented Jun 7, 2020

I wouldn't recommend this workflow. The CI has to reinstall emscripten every time you launch it, and as you noticed, it takes several minutes. Setting up emscripten locally is a little bit painful, but it's a one-time job, which then lets you test your changes and iterate on them rapidly.

@charlielidbury
Copy link
Author

Hello, been sitting on this issue for a day now with no success.

When I add _sqlite3_column_count to exported_functions.json, it compiles just fine, then I can use cwrap to call it within api.js

If I add _sqlite3_column_origin_name to exported_functions.json, it errors with:

emcc --memory-init-file 0 -s RESERVED_FUNCTION_POINTERS=64 -s ALLOW_TABLE_GROWTH=1 -s EXPORTED_FUNCTIONS=@src/exported_functions.json -s EXTRA_EXPORTED_RUNTIME_METHODS=@src/exported_runtime_methods.json -s SINGLE_FILE=0 -s NODEJS_CATCH_EXIT=0 -s INLINING_LIMIT=50 -O3 -flto --llvm-lto 1 --closure 1 -s WASM=0 out/sqlite3.bc out/extension-functions.bc --pre-js src/api.js -o dist/sql-asm.js
emcc:WARNING: --llvm-lto ignored when using llvm backend
emcc: error: undefined exported function: "_sqlite3_column_origin_name" [-Wundefined] [-Werror]
make: *** [Makefile:95: dist/sql-asm.js] Error 1

Which makes it look like column_origin_name should have been exported somewhere but it doesn't. I had a look in sqlite3.c and it looks to be exporting sqlite3_column_origin_name, so I don't know what to do to make sqlite3_column_origin_nameaccessable withinapi.js`

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