WebAssembly + Emscripten SQLite VFS for web browsers, powered by IndexedDB.
Checkout the live demo: https://gilzoide.github.io/idbvfs/
- Web browser applications that use SQLite directly from WebAssembly-compiled code, for example apps built using C/C++ game engines
- Web browser applications that use SQLite from JavaScript, like users of sqlite3.wasm or sql.js
- This project implements only the SQLite VFS that uses IndexedDB for persistence. You must compile and link SQLite with your app yourself. This project is supposed to be statically linked to your WebAssembly applications.
- This VFS does not implement any file locking mechanism. Just make sure there's a single database connection to each file and you should be fine.
TL;DR: call idbvfs_register
before opening your SQLite databases and that's it!
// 1. Include `idbvfs.h`
#include <idbvfs.h>
// 2. Somewhere in your app's initialization, register idbvfs.
// Pass `1` to make idbvfs the default VFS for new connections.
int result = idbvfs_register(1);
if (restult != SQLITE_OK) {
// handle errors if necessary...
}
// 3. Just use SQLite normally
sqlite3 *db;
int result = sqlite3_open_v2(
"mydb", &db,
SQLITE_OPEN_CREATE | SQLITE_OPEN_READWRITE,
IDBVFS_NAME
);
// The above is the same as below, if idbvfs is the default VFS
// int result = sqlite3_open("mydb", &db);
# 1. Import `idbvfs` as a subdirectory
# This will build idbvfs as a static library
add_subdirectory(path/to/idbvfs)
# 2. Link your library/executable to the `idbvfs` library
# This will also add the necessary includes for `idbvfs.h`
# as well as link the IDBFS library
target_link_libraries(my-wasm-app PUBLIC idbvfs)
# 1. Compile idbvfs using CMake, from the project root
# This will output a static library at `build/libidbvfs.a`
emcmake cmake . -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build
# 2. Link your app with `build/libidbvfs.a`.
# Don't forget to add `-lidbfs.js` link option or idbvfs will not work!
emcc -o my-wasm-app my-wasm-app.o \
-lidbfs.js \
-Lidbvfs/build -lidbvfs