gurk-rs icon indicating copy to clipboard operation
gurk-rs copied to clipboard

Replace json storage

Open boxdot opened this issue 2 years ago • 3 comments

Storing the data in a json file was just a quick'n'dirty hack to get started real fast. But now it is in use for a long time already. We should replace it by ~~sled~~ sqlite ASAP.

boxdot avatar Jan 20 '23 08:01 boxdot

I am currently using gurk in a way where I get the message content directly from a specific channel like so in nushell:

open ~/.local/share/gurk/gurk.data.json --raw | from json | get channels | get items | where name == ($handle) | get messages | flatten | get message | to text

Will there be some way to query sled directly also?

kiil avatar Jul 28 '23 10:07 kiil

Instead of using sled I implemented the storage in sqlite (for different reasons). The schema looks like this: https://github.com/boxdot/gurk-rs/blob/master/src/storage/migrations/001_init.sql. Some data is stored as blobs, but not the message text, so it should be quite easy to query them.

In case, you would like to try it out (on the master branch), add the following to the config:

[sqlite]
enabled = true

Migration of the data will run automatically, and convert json to sqlite on startup. Please backup your json file first. In case of some data loss.

boxdot avatar Jul 28 '23 12:07 boxdot

Thanks a lot. It just so happens the nushell can handle sqlite natively :)

I had to update my custom command like so:

def signal-messages [handle: string] {

let info = (
open ~/.local/share/gurk/gurk.sqlite | query db
"
SELECT channels.name, messages.message, messages.channel_id, channels.id 
FROM messages, channels
WHERE messages.channel_id = channels.id;
"
)

$info | where name == $handle | get message | to text

}

It is also a lot faster now :)

kiil avatar Jul 29 '23 07:07 kiil