Use sqlite db file (#257)

* Use file for sqlite db

* Use squeak as relative path parent for sqlite db file
This commit is contained in:
Jonathan Zernik 2020-09-26 01:30:47 -07:00 committed by GitHub
parent 5f482bf9be
commit b8dfac1e75
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 7 deletions

View file

@ -2,7 +2,7 @@
network=simnet
price=1000
max_squeaks_per_address_per_hour=5
database=postgresql
database=sqlite
sqk_dir=
enable_sync=false

View file

@ -14,7 +14,7 @@ function mine_blocks {
cd itests
docker-compose down --volumes
# docker-compose build
docker-compose build
docker-compose up -d
# Initialize the blockchain with miner rewards going to the test client.

View file

@ -17,11 +17,14 @@ def get_postgres_connection_string(user, password, host, database):
)
def get_sqlite_engine():
def get_sqlite_engine(squeak_dir, network):
return create_engine(
get_sqlite_connection_string()
get_sqlite_connection_string(squeak_dir, network)
)
def get_sqlite_connection_string():
return "sqlite:///squeakdb.db".format()
def get_sqlite_connection_string(squeak_dir, network):
return "sqlite:////{}/{}.db".format(
squeak_dir,
network,
)

View file

@ -4,6 +4,8 @@ import sys
import threading
from configparser import ConfigParser
from pathlib import Path
from squeak.params import SelectParams
from squeakserver.admin.squeak_admin_server_handler import SqueakAdminServerHandler
@ -79,6 +81,7 @@ def load_admin_handler(lightning_client, squeak_node):
def load_db(config, network):
database = load_database(config)
logger.info("database: " + database)
if database == "postgresql":
engine = get_postgres_engine(
config["postgresql"]["user"],
@ -88,7 +91,8 @@ def load_db(config, network):
)
return SqueakDb(engine, schema=network)
elif database == "sqlite":
engine = get_sqlite_engine()
Path("/squeak").mkdir(parents=True, exist_ok=True)
engine = get_sqlite_engine("squeak", network)
return SqueakDb(engine)