GRDB with custom SQLite build -> How to actually load an extension? #1761
Replies: 3 comments
-
Today, I've made some amount of progress. I've managed to load the extension, create a virtual table using it, insert some vectors and then search for them via the special However, this currently only works by modifying the GRDBCustom project and adding some files to the I'd appreciate anyone with more experience and knowledge about C and how to bundle these extensions into GRDB without having to touch the GRDBCustom project directly. I'm unsure how to do that. Xcode kind of needs to know about these files to build everything. Steps to Load
|
Beta Was this translation helpful? Give feedback.
-
I have been thinking about ways to load the extension without having to manually open and modify the The only problem is that this package includes its own implementation of What We Need
Exposing
|
Beta Was this translation helpful? Give feedback.
-
I think I have found a way to make this work. It still requires to make a small change in the To keep the "checkpoints" alive in the thread above, I have created a new repository with a fully working set up that uses the sqlite-vec SQLite extension: https://github.com/SwiftedMind/GRDBCustomSQLiteBuild The readme there contains a full step-by-step guide on how to set this up in any project. I hope my approach doesn't break anything, I'm not very experienced with C and stuff. But in my app, everything seems to be working. I'd love to hear if this would be possible to change in GRDB! What needs to change in the
|
Beta Was this translation helpful? Give feedback.
-
Update (April 26th 2025)
I think I have found a way to load extensions. For a fully working example, see my reply below .
This approach (and I believe any approach that uses SQLite extensions) does require some small changes to be made to the
GRDBCustom
project in GRDB. If that's possible and doesn't break anything, it would be awesome, I think.Original Post
Hey,
I've been trying to set up GRDB with a custom SQLite build so that I can load an SQLite extension that enables efficient vector search: https://github.com/asg017/sqlite-vec
I have found several threads trying to do this or a similar thing, but none actually concluded anything, as far as I can see. I'm not sure this is because it is still unclear how to do this, or if it is clear and I'm just not capable of understanding it 😅.
I'd love to get it working and provide clear instructions for others to reproduce because I think it would be awesome to have support for vector search directly in GRDB!
What I've Done So Far
I started a new project and followed the instructions in the "Custom SQLite Builds" guide, which worked well.
However, I did need to come up with another solution to make it possible for a local Swift package (living inside my app repo) to also access GRDB. So I created a script that compiles GRDB with the custom SQLite build into a
.xcframework
which I can then add to the package as binary target. That also worked! I can build and use GRDB in my Swift package.I have uploaded the example project, including a detailed list with all the steps I took to get it to work:
https://github.com/SwiftedMind/GRDBCustomExample
What's Missing
Where I am completely lost now is adding the sqlite-vec SQLite extension. It's just two files:
sqlite-vec.c
andsqlite-vec.h
but I have no idea how to include it in the SQLite build and then initialize it.I've tried adding it to the amalgamation, by modifying the
buildAmalgamation.sh
file:That does compile, but I have no way of loading the extension. This code
just tells me "Cannot find 'sqlite3_vec_init' in scope". Unfortunately, I have zero experience with Swift and C interactions and how to expose stuff to Swift, when it's part of this SQLite amalgamation.
I'd super appreciate any help with this. I've been trying for the past 3 days to find a way to load the extension, but nothing works and I think I'm lacking a lot of fundamental understanding. I'm basically poking around in the dark.
I'm not entirely sure if this is out-of-scope for GRDB (maybe it's more of a topic for SQLiteLib?) but I do think it would be amazing to have this support in GRDB, even if it involves some custom work.
Previous Related Threads
Beta Was this translation helpful? Give feedback.
All reactions