boxdot / gurk-rs

Signal Messenger client for terminal
GNU Affero General Public License v3.0
493 stars 37 forks source link

Replace json storage #209

Open boxdot opened 1 year ago

boxdot commented 1 year ago

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.

kiil commented 1 year ago

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?

boxdot commented 1 year ago

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.

kiil commented 1 year ago

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 :)