deno-sqlite icon indicating copy to clipboard operation
deno-sqlite copied to clipboard

Enable `fts` (full text search) for Deno-sqlite

Open dyedgreen opened this issue 3 years ago • 9 comments

I've just run into this too. I was trying to load the fts5 extension.

(Originally posted by @hobochild in https://github.com/dyedgreen/deno-sqlite/issues/100#issuecomment-792308703 )

Full text search seems like a common problem and it might make sense to enable full text search by default (since there is currently no way to import extensions at run-time). But I wanted to see how many others are interested in this functionality. (It it turns out to be too niche, it might make sense to ask people to compile their own WASM module with the extension enabled.)

For reference: SQLite full text search docs

dyedgreen avatar Mar 07 '21 17:03 dyedgreen

I'd like to see fts5 support by default. What about rtree (considering it is also available in the sqlite CLI)?

artisonian avatar Mar 09 '21 18:03 artisonian

Hm. I would be curious to test how much each feature effects the WASM binary size vs how much they are used to better understand the tradeoffs involved.

It might also be interesting to offer some more documentation on how to compile your own version if you have specific needs.

dyedgreen avatar Mar 09 '21 19:03 dyedgreen

This is anecdotal, but I ran deno info after enabling fts5 and rtree:

https://deno.land/x/[email protected]/build/sqlite.js (810.68KB)
file:///src/vendor/deno-sqlite/build/sqlite.js (1.03MB)

And fts5 alone:

file:///src/vendor/deno-sqlite/build/sqlite.js (1018.54KB)

artisonian avatar Mar 10 '21 02:03 artisonian

A thought on loading sqlite extensions: with Deno.dlopen it is possible to run code from a shared object. I’m not sure how much memory sharing SQLite extensions require; but if it’s sufficiently little (we can’t really easily expose the WASM memory to a so I believe), it might be possible to run arbitrary SQLite extensions.

dyedgreen avatar Sep 10 '21 08:09 dyedgreen

Having fts supported would be amazing. Are there any workarounds in the meantime?

iuioiua avatar Nov 14 '21 23:11 iuioiua

@ashersaupingomez

Having fts supported would be amazing. Are there any workarounds in the meantime?

You'd need to compile the WASM module yourself with the necessary build options enabled. https://www.sqlite.org/fts5.html should include all necessary information.

lusbuab avatar Nov 20 '21 19:11 lusbuab

Any update on this? I'm having no problem with a custom build with fts5 enabled but would prefer not to have the repo sitting in my project

mdkq avatar Mar 15 '22 04:03 mdkq

I've had some thoughts around using denos dll loader / a wash loader set-up to support loading custom extensions, but I don't have any specific progress on that yet.

dyedgreen avatar Mar 15 '22 21:03 dyedgreen

+1 for this feature. It is something I really need.

EtienneK avatar Jul 13 '22 11:07 EtienneK

It might also be interesting to offer some more documentation on how to compile your own version if you have specific needs.

I think this would be welcome at this point. It seems some people were able to enable fts without too much trouble. Perhaps @artisonian would be willing to publish his changes? I took a look at doing this myself but I'm quickly out of my depth.

A maintained fork or branch with commonly requested configurations could be one way to address this.

Thanks!

teleclimber avatar Oct 24 '22 19:10 teleclimber

@mdkq Can you share the commands you're using to build SQLite and use it with this library?

alexgleason avatar Aug 29 '23 20:08 alexgleason

@alexgleason You can fork this repo, make the changes to the config, and let Github actions build it for you. See the commits I made on my fork:

https://github.com/teleclimber/deno-sqlite

Then you can import it directly from Github:

import { DB } from "https://github.com/teleclimber/deno-sqlite/raw/master/mod.ts";

const db = new DB();

db.execute(`
CREATE VIRTUAL TABLE posts 
USING FTS5(title, body)
`);

//.. more FTS5 fun

Feel free to us mine to experiment with, but I make zero promises to keep it up to date right now (and it's already behind).

teleclimber avatar Aug 29 '23 23:08 teleclimber

@teleclimber Fantastic, thank you!!!

alexgleason avatar Aug 29 '23 23:08 alexgleason

Well, FTS works awesome with @teleclimber's fork. I'm even using it with Kysely query builder and it's wonderful.

@dyedgreen Would you be open to merging 05ce37da26742e6d3b80dc7b92e3b80cbd93689b? I can make a pull request.

alexgleason avatar Aug 30 '23 17:08 alexgleason

I think this is probably fine; I’d like to check if this extension is also enabled in nodes better sqlite but fts5 seems useful enough that we can enable it by default 😄

dyedgreen avatar Aug 31 '23 19:08 dyedgreen