Skip to content

Commit

Permalink
Merge DBs to use single store now
Browse files Browse the repository at this point in the history
  • Loading branch information
Rexeh committed Feb 2, 2024
1 parent 6f52d17 commit 72735fd
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
7 changes: 4 additions & 3 deletions joystick_diagrams/db/db_device_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from sqlite3 import connect

DB_DIR = "data"
DB_NAME = "devices.db"
DB_NAME = "joystick_diagrams.db"
TABLE_NAME = "devices"


Expand All @@ -13,12 +13,12 @@ def create_new_db_if_not_exist():
cur.execute(f"CREATE TABLE IF NOT EXISTS {TABLE_NAME}(guid TEXT PRIMARY KEY, template_path TEXT)")


def add_update_device_template_path(guid: str, template_path: str):
def add_update_device_template_path(guid: str, template_path: str) -> bool:
path = os.path.join(os.getcwd(), DB_DIR, DB_NAME)
connection = connect(path)
cur = connection.cursor()

cur.execute(f"SELECT * from {TABLE_NAME} WHERE guid = {guid}")
cur.execute("SELECT * from devices WHERE guid = ?", (guid,))
result = cur.fetchall()

if result:
Expand All @@ -32,6 +32,7 @@ def add_update_device_template_path(guid: str, template_path: str):
cur.execute(query, params)

connection.commit()
return True


def get_device_template_path(guid: str):
Expand Down
7 changes: 6 additions & 1 deletion joystick_diagrams/db/db_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@
Author: Robert Cox
"""

import logging

from joystick_diagrams.db import db_device_management, db_plugin_data, db_value_store

_logger = logging.getLogger(__name__)


def init():
def init() -> None:
_logger.info("Initialising datastores")
db_device_management.create_new_db_if_not_exist()
db_value_store.create_new_db_if_not_exist()
db_plugin_data.create_new_db_if_not_exist()
Expand Down
2 changes: 1 addition & 1 deletion joystick_diagrams/db/db_plugin_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from sqlite3 import connect

DB_DIR = "data"
DB_NAME = "plugins.db"
DB_NAME = "joystick_diagrams.db"
TABLE_NAME = "plugins"


Expand Down
2 changes: 1 addition & 1 deletion joystick_diagrams/db/db_value_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from sqlite3 import connect

DB_DIR = "data"
DB_NAME = "values.db"
DB_NAME = "joystick_diagrams.db"


def create_new_db_if_not_exist():
Expand Down

0 comments on commit 72735fd

Please sign in to comment.