It took me some time to get litesync up and running. For later reference here is what I did:
LiteSync Installation on Ubuntu 20.04
LITESYNC_URL=http://litesync.io/download/litesync-free-linux-x86_64.tar.gz
mkdir ~/litesync \
&& cd ~/litesync \
&& wget -O - "${LITESYNC_URL}" | tar -xvzf - \
sudo ./install
Workaround for Ubuntu 20.04 libreadline issue
see http://litesync.io/forum/d/74-installation-on-ubuntu-20-04-fails-libreadline-so-6-not-found
(cd /usr/lib/x86_64-linux-gnu;\
test -f libreadline.so.6 || sudo ln -s libreadline.so.8.0 libreadline.so.6)
Python Setup
sudo apt-get -y install -y python3-pip
pip3 install --user litesync
Python Test Scripts
cat > test-server.py <<'EOF'
import litesync
import json
import time
conn = litesync.connect('file:server.db?node=primary&bind=tcp://0.0.0.0:1234')
# check if the db is ready
while True:
result = conn.cursor().execute("PRAGMA sync_status").fetchone()
status = json.loads(result[0])
if status["db_is_ready"]: break
time.sleep(0.250)
# report updates
def on_db_update(arg):
print("update received")
conn.create_function("update_notification", 1, on_db_update)
# create table with data
result = conn.cursor().execute("CREATE TABLE IF NOT EXISTS table1 (id INTEGER NOT NULL PRIMARY KEY,name TEXT NOT NULL)")
conn.cursor().execute("INSERT INTO table1 (id,name) VALUES (1,'Paul')")
conn.cursor().execute("INSERT INTO table1 (id,name) VALUES (2,'Wolodymyr')")
conn.commit()
# loop and print db status
while True:
result = conn.cursor().execute("PRAGMA sync_status").fetchone()
status = json.loads(result[0])
print(str(status))
time.sleep(3)
EOF
and
cat > test-app.py <<'EOF'
import litesync as sqlite3
import json
import time
conn = sqlite3.connect('file:app.db?node=secondary&connect=tcp://localhost:1234')
# check if the db is ready
while True:
result = conn.cursor().execute("PRAGMA sync_status").fetchone()
status = json.loads(result[0])
if status["db_is_ready"]: break
time.sleep(0.250)
c = conn.cursor()
c.execute("SELECT * FROM table1")
row = c.fetchone()
while row:
print("got a row:" + str(row))
row = c.fetchone()
conn.close()
EOF
Run Test
- In Shell 1:
python3 test-server.py
- In Shell 2:
python3 test-app.py