Adding SQLite Database Integration to an Obsidian Plugin

Hello everyone,

I’m developing an ObsidianMd plugin using a Node.js environment with TypeScript and React. Currently, I’m working on integrating a SQLite database to read data from a .sqlite file.

However, I’ve encountered an issue when trying to run the plugin within the Electron environment. I’m using the better-sqlite3 npm package. The error message I receive is:

Uncaught TypeError: Cannot read properties of undefined (reading 'indexOf')
    at Function.getFileName (plugin:my-plugin...)

I’ve found a similar issue described here: Github WiseLibs - Better-SQLite3 Issue #488, but I’m still struggling to understand the root cause or how to resolve it.

Has anyone here integrated SQLite with an ObsidianMd plugin or experienced similar issues?

I’m particularly interested in understanding if there are limitations or best practices when working with databases in Electron-based environments. Any advice or guidance on troubleshooting this would be greatly appreciated!

Thank you in advance for your help!

I succeeded in doing this recently using SQL.js.

DB loading and saving is done with app.vault.adapter.readBinary() and .writeBinary().

Have a read of the repo README for the other SQLite options I tried and why they didn’t work:

Database initialisation is like this: