1
This commit was merged in pull request #1.
This commit is contained in:
@@ -1,3 +1,3 @@
|
||||
import redis
|
||||
|
||||
pool = redis.ConnectionPool(host='localhost', port=6379, decode_responses=True)
|
||||
pool = redis.ConnectionPool(host='localhost', port=6379, decode_responses=True)
|
||||
|
||||
@@ -1,22 +1,28 @@
|
||||
import os
|
||||
import sys
|
||||
from functools import cache
|
||||
from pathlib import Path
|
||||
import redis
|
||||
from sqlalchemy import create_engine
|
||||
from sqlalchemy.orm import Session
|
||||
from config.main import config
|
||||
|
||||
RedisPool = redis.ConnectionPool.from_url(config.REDIS_URL)
|
||||
BACKEND_DIR = Path(__file__).resolve().parents[1]
|
||||
|
||||
|
||||
def get_redis_client():
|
||||
return redis.Redis(connection_pool=RedisPool)
|
||||
|
||||
|
||||
def get_redis():
|
||||
with redis.Redis(connection_pool=RedisPool) as redis_conn:
|
||||
with get_redis_client() as redis_conn:
|
||||
yield redis_conn
|
||||
|
||||
|
||||
@cache
|
||||
def get_db_engine(version='0'):
|
||||
try:
|
||||
os.chdir(os.path.dirname(sys.argv[0]))
|
||||
except Exception:
|
||||
pass
|
||||
return create_engine(f'sqlite:///{os.path.join("./", "dataFiles", f"dcalc_{version}.db")}')
|
||||
db_path = BACKEND_DIR / 'dataFiles' / f'dcalc_{version}.db'
|
||||
return create_engine(f'sqlite:///{db_path}', connect_args={'check_same_thread': False})
|
||||
|
||||
|
||||
def get_db():
|
||||
with Session(get_db_engine()) as session:
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
# import os
|
||||
# import sys
|
||||
from sqlalchemy import Column, Integer, Text, Float
|
||||
from sqlalchemy import create_engine
|
||||
from sqlalchemy.orm import Session, declarative_base
|
||||
from sqlalchemy.orm import declarative_base
|
||||
|
||||
Base = declarative_base()
|
||||
metadata = Base.metadata
|
||||
|
||||
Reference in New Issue
Block a user