add db path
This commit is contained in:
@@ -1,12 +1,16 @@
|
||||
import sqlite3
|
||||
import os
|
||||
|
||||
class DBApplications:
|
||||
def __init__(self):
|
||||
self.db_path = 'instance/dev.db'
|
||||
# Allow DB path override via env, default to /app/instance/dev.db inside container
|
||||
default_path = os.getenv("DB_PATH", "instance/dev.db")
|
||||
self.db_path = os.path.abspath(default_path)
|
||||
os.makedirs(os.path.dirname(self.db_path), exist_ok=True)
|
||||
self.create_table()
|
||||
|
||||
def create_table(self):
|
||||
with sqlite3.connect(self.db_path) as conn:
|
||||
with sqlite3.connect(self.db_path, check_same_thread=False) as conn:
|
||||
cursor = conn.cursor()
|
||||
cursor.execute("""
|
||||
CREATE TABLE IF NOT EXISTS applications (
|
||||
@@ -23,7 +27,7 @@ class DBApplications:
|
||||
|
||||
def insert_application(self, user_id, name, access_code: str) -> bool:
|
||||
try:
|
||||
with sqlite3.connect(self.db_path) as conn:
|
||||
with sqlite3.connect(self.db_path, check_same_thread=False) as conn:
|
||||
cursor = conn.cursor()
|
||||
cursor.execute("""
|
||||
INSERT INTO applications (user_id, name, access_code)
|
||||
@@ -35,7 +39,7 @@ class DBApplications:
|
||||
return False
|
||||
|
||||
def get_application_by_id(self, id):
|
||||
with sqlite3.connect(self.db_path) as conn:
|
||||
with sqlite3.connect(self.db_path, check_same_thread=False) as conn:
|
||||
cursor = conn.cursor()
|
||||
cursor.execute("""
|
||||
SELECT * FROM applications
|
||||
@@ -55,7 +59,7 @@ class DBApplications:
|
||||
return None
|
||||
|
||||
def get_applications(self, user_id):
|
||||
with sqlite3.connect(self.db_path) as conn:
|
||||
with sqlite3.connect(self.db_path, check_same_thread=False) as conn:
|
||||
cursor = conn.cursor()
|
||||
cursor.execute("""
|
||||
SELECT * FROM applications
|
||||
@@ -79,7 +83,7 @@ class DBApplications:
|
||||
return all_rows
|
||||
|
||||
def delete(self, id):
|
||||
with sqlite3.connect(self.db_path) as conn:
|
||||
with sqlite3.connect(self.db_path, check_same_thread=False) as conn:
|
||||
cursor = conn.cursor()
|
||||
cursor.execute("""
|
||||
DELETE FROM applications WHERE id = ?
|
||||
|
||||
@@ -1,12 +1,16 @@
|
||||
import sqlite3
|
||||
import os
|
||||
|
||||
class Users:
|
||||
def __init__(self):
|
||||
self.db_path = 'instance/dev.db'
|
||||
# Allow DB path override via env, default to /app/instance/dev.db inside container
|
||||
default_path = os.getenv("DB_PATH", "instance/dev.db")
|
||||
self.db_path = os.path.abspath(default_path)
|
||||
os.makedirs(os.path.dirname(self.db_path), exist_ok=True)
|
||||
self.create_table()
|
||||
|
||||
def create_table(self):
|
||||
with sqlite3.connect(self.db_path) as conn:
|
||||
with sqlite3.connect(self.db_path, check_same_thread=False) as conn:
|
||||
cursor = conn.cursor()
|
||||
cursor.execute("""
|
||||
CREATE TABLE IF NOT EXISTS users (
|
||||
@@ -22,7 +26,7 @@ class Users:
|
||||
|
||||
def insert_user(self, email, password: str) -> bool:
|
||||
try:
|
||||
with sqlite3.connect(self.db_path) as conn:
|
||||
with sqlite3.connect(self.db_path, check_same_thread=False) as conn:
|
||||
cursor = conn.cursor()
|
||||
cursor.execute("""
|
||||
INSERT INTO users (email, password)
|
||||
@@ -34,7 +38,7 @@ class Users:
|
||||
return False
|
||||
|
||||
def get_user_by_id(self, id):
|
||||
with sqlite3.connect(self.db_path) as conn:
|
||||
with sqlite3.connect(self.db_path, check_same_thread=False) as conn:
|
||||
cursor = conn.cursor()
|
||||
cursor.execute("""
|
||||
SELECT * FROM users
|
||||
@@ -53,7 +57,7 @@ class Users:
|
||||
return None
|
||||
|
||||
def get_user_by_email(self, email):
|
||||
with sqlite3.connect(self.db_path) as conn:
|
||||
with sqlite3.connect(self.db_path, check_same_thread=False) as conn:
|
||||
cursor = conn.cursor()
|
||||
cursor.execute("""
|
||||
SELECT * FROM users
|
||||
|
||||
@@ -47,8 +47,10 @@ services:
|
||||
API_BASE_URL: https://${SOLARDB_API_HOST}
|
||||
# If your entry file differs, uncomment and set it:
|
||||
# FLET_ENTRY: client/main.py
|
||||
USERS_DB_PATH: /app/instance/dev.db
|
||||
volumes:
|
||||
- solardb_uploads:/app/uploads
|
||||
- solardb_ui_data:/app/instance
|
||||
expose:
|
||||
- "5555"
|
||||
depends_on:
|
||||
|
||||
Reference in New Issue
Block a user