From 5132159206f1b9f2f2a780d597fa960b5b91e58e Mon Sep 17 00:00:00 2001 From: Avinash Sajjanshetty Date: Wed, 29 Nov 2023 17:54:53 +0530 Subject: [PATCH] Add sync write example --- examples/sync_write.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 examples/sync_write.py diff --git a/examples/sync_write.py b/examples/sync_write.py new file mode 100644 index 0000000..853aa83 --- /dev/null +++ b/examples/sync_write.py @@ -0,0 +1,18 @@ +""" +A short example showing how to create an embedded replica, make writes and then read them + +Set the LIBSQL_URL and LIBSQL_AUTH_TOKEN environment variables to point to a database. +""" +import os + +import libsql_experimental as libsql + +print(F"syncing with {os.getenv('LIBSQL_URL')}") +conn = libsql.connect("hello.db", sync_url=os.getenv("LIBSQL_URL"), + auth_token=os.getenv("LIBSQL_AUTH_TOKEN")) +conn.execute("CREATE TABLE IF NOT EXISTS users (id INTEGER);") +conn.execute("INSERT INTO users(id) VALUES (1);") +conn.commit() +conn.sync() + +print(conn.execute("select * from users").fetchall())