Native messaging and local databases

Is it possible to use native messaging to write data from an extension to SQLite or another local database either instead of or in conjunction with indexedDB? Thank you.

You can send the data for new records to a native application, and that application can update a database. A lot of examples use Python, and there’s a Python doc page on how to connect to a SQLite database, but I didn’t study it in detail: https://docs.python.org/3/library/sqlite3.html. Maybe there’s something a little more ready-made out there for extension authors to use.

Thank you. I’m not sure what the definition is of a native application. I assume then that the database itself is not a native application. To do similar to what the article you kindly provided describes, seems to mean that an interpreter is needed to run the Python script. Is it possible to write something in C that can receive the data and write it to the database?

Perhaps, I’m just being ridiculous because I don’t quite understand how all of these pieces connect at the moment. I was looking for something that I could provide to the users that would not require them to install an interpreter of a scripting language. I guess I’m trying to use the extension code and the native application in a manner that replaces the server side/node.js/Electron packaging. Right now, the extension APIs and indexedDB provide all that is needed for my little application, but the user has to backup the database as a text file to disk. That works fairly well but extracting the data and joining it together into a single text file can, for very large amounts of data, temporarily take up a bit of RAM when that giant blob is assembled for download. I tried to stream it to disk as the pieces were extracted from the database but could not get it to work.

If I could make a native application that permitted the extension and database to communicate without requiring the user to install an interpreter (or whatever it should be termed), then that backing up step would be eliminated and there’d be no worry about the indexedDB database persisting. For my purposes, at least, this would function like a desktop application that stores data locally and happens to run in a normal browser along side the other open web pages. The user could have the choice of using only indexedDB and backing up manually or installing SQLite and using the native application.

But I may just be confused and this is unreasonable. Thank you.

Hi Gary, a database is just a file. To update an existing file, you need to send commands to a program that knows how to do that.

The idea of native messaging was developed in Chrome extensions, so researching how other extensions update local SQLite databases could lead to a program (or at least some code) you could use. But since you need a program that understands SQLite, there will definitely have to be a second download for users to install.

What if you don’t need to update an existing file, and you just want to save a new one. I use the Clippings extension, for example, and it prompts me to save a backup (.json file) about every two weeks. Not sure if that would suit your needs. I think it probably uses the downloads API. Upon re-reading your last reply, I think this has a bottleneck and you are looking for something more atomic than an entire file.

Thank you for the explanation. I’ll read more about it.

What you wrote gave me an idea, too, that even if writing to an external database for each individual change is not possible or feasible, perhaps, it will be possible to use this approach to just backup the indexedDB database to disk as a text file in a manner that can avoid having to generate a single giant blob that consumes a lot of RAM.