grist-core icon indicating copy to clipboard operation
grist-core copied to clipboard

(Automatically) (re)load external changes to SQLite database

Open mpsijm opened this issue 1 year ago • 2 comments

I was experimenting a bit with accessing a .grist SQLite database via the sqlite3 program. Super awesome that it's possible to change data externally like this! However, I needed to restart Grist in order for the changes to become visible.

My setup:

  • Arch Linux
  • grist-electron v0.2.8, installed from AUR
  • One table with some data columns and some formula columns

To reproduce:

  • sqlite3 *.grist
  • INSERT INTO <table> (<data columns...>) VALUES (<values...>);

Initially, nothing happens in Grist. However, after restarting Grist, the new row is shown. For this new row, the formula columns initially remain empty, but are updated within a few seconds, so that's really nice! However, it would be cool if Grist could reload external changes without a restart, either automatically or by adding a "reload database" button somewhere. Moving back to home and reopening the file didn't do the trick.

mpsijm avatar Jan 31 '24 13:01 mpsijm

There is an API endpoint to force the document to reload: /api/docs/:docId/force-reload

I haven't tested it myself, but I think if you edit the file with sqlite3 and hit that endpoint (e.g., with curl), it will reload the document in the browser for any users currently looking at it

I don't know if this will cause any other side effects, though. I think that endpoint is undocumented. I only know about it because I've seen it discussed in other Github issues

wunter8 avatar Jan 31 '24 18:01 wunter8

Thanks for the pointer! I tried POSTing to that endpoint with an empty body, as suggested by @paulfitz here, ~~but unfortunately, that did not refresh the page in my Electron app. The OP of that thread suggest that this does work with the "Self-Managed Core" setup, which I will test later, since that's how I'd intend to use this anyway :slightly_smiling_face:~~ EDIT: never mind, I used the wrong document ID in my API call, and this actually works! :smile:

Armed with a new search query "Grist force-reload", I also found this thread, which suggests clicking a skull icon in the settings page of the document, but I don't see this setting (potentially because I'm running from Electron).

EDIT: So, I now have something that works for me, but perhaps it would be nice to also have some way to force reload the Electron app from the UI. If you think that this doesn't belong on Grist's roadmap, feel free to close this issue, because my question has been answered :slightly_smiling_face:

mpsijm avatar Jan 31 '24 20:01 mpsijm