Skip to content
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

SQLite extensions #2

Open
spaciandd opened this issue Mar 20, 2022 · 13 comments
Open

SQLite extensions #2

spaciandd opened this issue Mar 20, 2022 · 13 comments

Comments

@spaciandd
Copy link

I need to load stats extension. Is there any way ?

@spaciandd spaciandd changed the title How to dynamic loadable extensions ? How to load dynamic loadable extensions ? Mar 20, 2022
@jvail
Copy link
Owner

jvail commented Mar 20, 2022

Hi, I am afraid no. It needs to be included during compilation. Also I am not sure about the quality of this extension: It is not an official sqlite extension. But I'd guess with some research you could implement it in plain SQL e.g. https://stackoverflow.com/questions/1123576/how-to-find-nth-percentile-with-sqlite

P.S.
I have just seen that sql.js has included the extension-functions.c. So I guess then I could give it a try and add the file from the repo you suggested.

PPS
I think this looks quite interesting: https://github.com/nalgeon/sqlean

@spaciandd
Copy link
Author

Hi, thanks for reply, do you have any plans to add loadExtension api ?

@jvail
Copy link
Owner

jvail commented Mar 20, 2022

Hi, thanks for reply, do you have any plans to add loadExtension api ?

I think - at least to my current understanding - this is impossible because WebAssembly has no way to load/link other wasm files dynamically.

jvail added a commit that referenced this issue Mar 21, 2022
@jvail
Copy link
Owner

jvail commented Mar 21, 2022

@spaciandd Please checkout the new version. I'll pin this issue and rename it so I can reuse it for other extensions.

@jvail jvail pinned this issue Mar 21, 2022
@jvail jvail changed the title How to load dynamic loadable extensions ? SQLite extensions Mar 21, 2022
@Fsystem
Copy link

Fsystem commented May 19, 2024

Is it possible to add the fuzzy, regexp, and text extensions from the sqlean.js library? I need these extensions for performing certain queries.
Or, once I've obtained an ArrayBuffer by using db.save, is it possible to reopen it within sqlean.js and make use of these extended functions?

@jvail
Copy link
Owner

jvail commented May 20, 2024

Is it possible to add the fuzzy, regexp, and text extensions from the sqlean.js library? I need these extensions for performing certain queries.

Sure, should not be too difficult. Could you prepare a PR? - no changes to dist/* please. If you look at the changes for the stats extension it is pretty much the same:

  • Maybe update the sqlean submodule to the latest release tag
  • Add extensions to Makefile
  • Load when a database is created/opened in src/spl.js
  • Add a simple test (at least to test/node.js) to see if the extension is working

If you could prepare a PR (mustn't be perfect) then I will merge it (maybe with a bit of refactoring/cleaning).

@Fsystem
Copy link

Fsystem commented May 21, 2024

I will give it a try.

@Fsystem
Copy link

Fsystem commented May 26, 2024

I attempted to perform a build on Debian, but encountered errors that I am unable to resolve.
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.50 (047b82506d6b471873300a5e4d1e690420b582d0)
clang version 18.0.0 (https://github.com/llvm/llvm-project 14028ec0a62210d68a4dd7a046ac79c8c3b7727e)
Target: wasm32-unknown-emscripten
Thread model: posix
image

@jvail
Copy link
Owner

jvail commented May 26, 2024

Could you make draft PR and share the changes you made?

@Fsystem
Copy link

Fsystem commented May 26, 2024

In fact, I haven't started making any changes yet; I'm just compiling the latest current version of the spl.js code.

@jvail
Copy link
Owner

jvail commented May 27, 2024

Did you initialize the git submodules - especially sqlean? Except that I can see that something seems to be wrong with the stats extension I can not really give you a hint were the problem might be.

@Fsystem
Copy link

Fsystem commented May 28, 2024

Did you initialize the git submodules - especially sqlean? Except that I can see that something seems to be wrong with the stats extension I can not really give you a hint were the problem might be.

I have already run git submodule init.
Today, I discovered the custom function capability of sqlite-wasm, which enables you to write custom functions in JavaScript and subsequently call these functions directly within SQL statements.
https://sqlite.org/wasm/doc/trunk/api-c-style.md#sqlite3_create_function
Is this functionality achievable with Spl.js?
This way, I can utilize custom functions as a substitute for the regexp and text extension.

@jvail
Copy link
Owner

jvail commented May 31, 2024

/wasm/doc/trunk/api-c-style.md#sqlite3_create_function Is this functionality achievable with Spl.js? This way, I can utilize custom functions as a substitute for the regexp and text extension.

Theoretically yes, but it is not implemented. Here is a related issue #28 But I think just including the extensions from sqlean would be far easier and more efficient in this case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants