talaia-labs / rust-teos

The Eye of Satoshi - Lightning Watchtower
https://talaia-labs.github.io/talaia.watch/
MIT License
136 stars 63 forks source link

Use `sqlx` inplace of `rusqlite` #242

Open mariocynicys opened 1 year ago

mariocynicys commented 1 year ago

This PR replaces the rusqlite SQLite engine with sqlx.

sqlx is an asynchronous versatile sql engine that supports both SQLite & PostgreSQL.

Due to the asynchronous-only nature of sqlx, every method that interacted with the DB had to be asynchronous as well. This ripple effect propagated to nearly all the methods of the tower components. Also to the lightning::chain::Listen trait, thus a new AsyncListen trait was introduced to replace it.

The sqlite driver is enabled with the sqlite feature, and the postgresql driver with the postgres feature. By default, both of them are enabled, meaning that the tower program can run on top of either a sqlite or postgresql db.

To enable postgres-only driver: cargo build --no-default-features --features postgres (replace postgres with sqlite for sqlite-only build)

Fixes #32

mariocynicys commented 1 year ago

To test the tower with postgresql DB, this docker compose script might be handy:

version: '3.1'

services:

  db:
    image: postgres
    restart: always
    ports:
      - 5432:5432
    environment:
      POSTGRES_PASSWORD: pass
      POSTGRES_USER: user
      POSTGRES_DB: teos