jvail / spl.js

SpatiaLite for browser & node
GNU General Public License v3.0
164 stars 17 forks source link

SQLite extensions #2

Open spaciandd opened 2 years ago

spaciandd commented 2 years ago

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

jvail commented 2 years ago

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 commented 2 years ago

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

jvail commented 2 years ago

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 commented 2 years ago

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

Fsystem commented 1 month ago

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 commented 1 month ago

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:

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

Fsystem commented 1 month ago

I will give it a try.

Fsystem commented 1 month ago

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 commented 1 month ago

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

Fsystem commented 1 month ago

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

jvail commented 1 month ago

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 commented 1 month ago

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 commented 1 month ago

/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 https://github.com/jvail/spl.js/issues/28 But I think just including the extensions from sqlean would be far easier and more efficient in this case.