DEV Community

Cover image for Soul, SQLite REST server is realtime now.
Vahid Al
Vahid Al

Posted on

Soul, SQLite REST server is realtime now.

Hi Folks, It's been an amazing journey since I first published Soul on HN and now I added a really major feature that Soul lacked, Realtime changes via Websockets.
For those who are not familiar with Soul, it basically takes a SQLite database file and run a CRUD API on it, so you can have a minimal backend with no code.

Now thanks to this new feature, users can subscribe to changes in a table and whenever a Create, Update or Delete operation happens, Soul will send the realtime data to subscribers.

If you need some examples on how to work with websockets in Soul, you can find a bunch of examples here: https://github.com/thevahidal/soul/blob/main/docs/ws-examples.md

Please let me know what you think of this new feature and also submit any issues you faced so we can fix them as soon as possible.

Also if you have ideas to make Soul a better tool, please send me your ideas, it'll help me a lot.

Here's a small example of how realtime works in Soul:

 # Install Soul
npm install -g soul-cli 

# Install websocket client to test Soul realtime
npm i -g wscat

 # Download sample sqlite database
wget https://raw.githubusercontent.com/lerocha/chinook-database/master/ChinookDatabase/DataSources/Chinook_Sqlite.sqlite

# Run Soul
soul -d ./Chinook_Sqlite.sqlite -p 8000

# Subscribe to Employee table realtime changes
wscat -c ws://localhost:8000/ws/tables/Employee
Enter fullscreen mode Exit fullscreen mode

Then to test it, in a new terminal, insert a new row in the table Employee:
to test it, in a new terminal, insert a new row in the table Employee:

curl --request POST \
  --url http://localhost:8000/api/tables/Employee/rows \
  --header 'Content-Type: application/json' \
  --data '{
    "fields": {
        "FirstName": "Damien",
        "LastName": "Rice"
    }
}'
Enter fullscreen mode Exit fullscreen mode

Checkout wscat terminal, it should respond with the following message:

{
  "type": "INSERT",
  "data": {
    "pk": 10,
    "FirstName": "Damien",
    "LastName": "Rice"
  }
}
Enter fullscreen mode Exit fullscreen mode

You can test the same thing with Update and Delete operations too.

Once again thanks for the support and I'll see you in the next one!

Repo: https://github.com/thevahidal/soul
HN: https://news.ycombinator.com/item?id=33484693

Top comments (0)