fix(init): replace hardcoded database name with env.get_module_dbname()
- Replace all db.sqlorContext('hermes-web-cli') with dynamic dbname
- Use env.get_module_dbname() to get database name at runtime
This commit is contained in:
parent
d423a03a6d
commit
b950930156
@ -153,7 +153,9 @@ async def delete_service(userid: str, service_id: str) -> bool:
|
||||
})
|
||||
|
||||
# Also delete associated sessions
|
||||
async with db.sqlorContext('hermes-web-cli') as sor:
|
||||
env = ServerEnv()
|
||||
dbname = env.get_module_dbname()
|
||||
async with db.sqlorContext(dbname) as sor:
|
||||
await sor.sqlExe("""
|
||||
DELETE FROM sessions
|
||||
WHERE service_id = ${service_id}$ AND user_id = ${user_id}$
|
||||
@ -524,7 +526,9 @@ async def get_all_services(user_id: str) -> List[Dict]:
|
||||
try:
|
||||
# Query services table with user_id filter using sqlor-database-module
|
||||
db = DBPools()
|
||||
async with db.sqlorContext('hermes-web-cli') as sor:
|
||||
env = ServerEnv()
|
||||
dbname = env.get_module_dbname()
|
||||
async with db.sqlorContext(dbname) as sor:
|
||||
sql_template = SERVICES_CRUD['operations']['read_all']['sql_template']
|
||||
recs = await sor.sqlExe(sql_template, {'user_id': user_id})
|
||||
|
||||
@ -566,7 +570,9 @@ async def create_service(name: str, url: str, user_id: str, description: str = "
|
||||
|
||||
# Save to database using sqlor-database-module
|
||||
db = DBPools()
|
||||
async with db.sqlorContext('hermes-web-cli') as sor:
|
||||
env = ServerEnv()
|
||||
dbname = env.get_module_dbname()
|
||||
async with db.sqlorContext(dbname) as sor:
|
||||
sql_template = SERVICES_CRUD['operations']['create']['sql_template']
|
||||
await sor.sqlExe(sql_template, {
|
||||
'id': service_id,
|
||||
@ -606,7 +612,9 @@ async def delete_service(service_id: str, user_id: str) -> bool:
|
||||
|
||||
# Delete from database using sqlor-database-module
|
||||
db = DBPools()
|
||||
async with db.sqlorContext('hermes-web-cli') as sor:
|
||||
env = ServerEnv()
|
||||
dbname = env.get_module_dbname()
|
||||
async with db.sqlorContext(dbname) as sor:
|
||||
sql_template = SERVICES_CRUD['operations']['delete']['sql_template']
|
||||
await sor.sqlExe(sql_template, {
|
||||
'service_id': service_id,
|
||||
@ -614,7 +622,9 @@ async def delete_service(service_id: str, user_id: str) -> bool:
|
||||
})
|
||||
|
||||
# Also delete associated sessions
|
||||
async with db.sqlorContext('hermes-web-cli') as sor:
|
||||
env = ServerEnv()
|
||||
dbname = env.get_module_dbname()
|
||||
async with db.sqlorContext(dbname) as sor:
|
||||
await sor.sqlExe("""
|
||||
DELETE FROM sessions
|
||||
WHERE service_id = ${service_id}$ AND user_id = ${user_id}$
|
||||
@ -641,7 +651,9 @@ async def get_service_by_id(service_id: str, user_id: str) -> Optional[Dict]:
|
||||
try:
|
||||
# Query database directly with user_id filter for security
|
||||
db = DBPools()
|
||||
async with db.sqlorContext('hermes-web-cli') as sor:
|
||||
env = ServerEnv()
|
||||
dbname = env.get_module_dbname()
|
||||
async with db.sqlorContext(dbname) as sor:
|
||||
sql_template = SERVICES_CRUD['operations']['read_by_id']['sql_template']
|
||||
recs = await sor.sqlExe(sql_template, {
|
||||
'service_id': service_id,
|
||||
@ -675,7 +687,9 @@ async def test_service_connection(service_id: str) -> Tuple[bool, str]:
|
||||
try:
|
||||
# Get service configuration from database
|
||||
db = DBPools()
|
||||
async with db.sqlorContext('hermes-web-cli') as sor:
|
||||
env = ServerEnv()
|
||||
dbname = env.get_module_dbname()
|
||||
async with db.sqlorContext(dbname) as sor:
|
||||
sql_template = SERVICES_CRUD['operations']['read_by_id']['sql_template']
|
||||
recs = await sor.sqlExe(sql_template, {
|
||||
'service_id': service_id,
|
||||
@ -750,7 +764,9 @@ async def create_session(service_id: str, user_id: str, user_message: str = "")
|
||||
|
||||
# Create local session record in database
|
||||
db = DBPools()
|
||||
async with db.sqlorContext('hermes-web-cli') as sor:
|
||||
env = ServerEnv()
|
||||
dbname = env.get_module_dbname()
|
||||
async with db.sqlorContext(dbname) as sor:
|
||||
sql_template = SESSIONS_CRUD['operations']['create']['sql_template']
|
||||
await sor.sqlExe(sql_template, {
|
||||
'session_id': remote_session_id,
|
||||
@ -864,7 +880,9 @@ async def get_session_messages(session_id: str, user_id: str) -> List[Dict]:
|
||||
|
||||
# Update session last_active timestamp and message count in local database
|
||||
db = DBPools()
|
||||
async with db.sqlorContext('hermes-web-cli') as sor:
|
||||
env = ServerEnv()
|
||||
dbname = env.get_module_dbname()
|
||||
async with db.sqlorContext(dbname) as sor:
|
||||
await sor.sqlExe("""
|
||||
UPDATE sessions
|
||||
SET last_active = CURRENT_TIMESTAMP,
|
||||
@ -894,7 +912,9 @@ async def get_active_sessions(user_id: str) -> List[Dict]:
|
||||
try:
|
||||
# Query the sessions table for active sessions belonging to current user using sqlor-database-module
|
||||
db = DBPools()
|
||||
async with db.sqlorContext('hermes-web-cli') as sor:
|
||||
env = ServerEnv()
|
||||
dbname = env.get_module_dbname()
|
||||
async with db.sqlorContext(dbname) as sor:
|
||||
sql_template = SESSIONS_CRUD['operations']['read_active']['sql_template']
|
||||
recs = await sor.sqlExe(sql_template, {'user_id': user_id})
|
||||
|
||||
@ -927,7 +947,9 @@ async def get_recent_sessions(user_id: str, limit: int = 5) -> List[Dict]:
|
||||
try:
|
||||
# Query the sessions table for recent sessions belonging to current user using sqlor-database-module
|
||||
db = DBPools()
|
||||
async with db.sqlorContext('hermes-web-cli') as sor:
|
||||
env = ServerEnv()
|
||||
dbname = env.get_module_dbname()
|
||||
async with db.sqlorContext(dbname) as sor:
|
||||
sql_template = SESSIONS_CRUD['operations']['read_recent']['sql_template']
|
||||
recs = await sor.sqlExe(sql_template, {'user_id': user_id, 'limit': limit})
|
||||
|
||||
@ -960,7 +982,9 @@ async def get_session_by_id(session_id: str, user_id: str) -> Optional[Dict]:
|
||||
try:
|
||||
# Query database directly with user_id filter for security
|
||||
db = DBPools()
|
||||
async with db.sqlorContext('hermes-web-cli') as sor:
|
||||
env = ServerEnv()
|
||||
dbname = env.get_module_dbname()
|
||||
async with db.sqlorContext(dbname) as sor:
|
||||
sql_template = SESSIONS_CRUD['operations']['read_by_id']['sql_template']
|
||||
recs = await sor.sqlExe(sql_template, {
|
||||
'session_id': session_id,
|
||||
@ -1023,7 +1047,9 @@ async def get_setting(user_id: str) -> Dict:
|
||||
try:
|
||||
# Query user settings from database
|
||||
db = DBPools()
|
||||
async with db.sqlorContext('hermes-web-cli') as sor:
|
||||
env = ServerEnv()
|
||||
dbname = env.get_module_dbname()
|
||||
async with db.sqlorContext(dbname) as sor:
|
||||
sql_template = SETTINGS_CRUD['operations']['read']['sql_template']
|
||||
recs = await sor.sqlExe(sql_template, {'user_id': user_id})
|
||||
|
||||
@ -1071,7 +1097,9 @@ async def save_setting(section: str, key: str, value, user_id: str) -> bool:
|
||||
try:
|
||||
# Save to database using sqlor-database-module
|
||||
db = DBPools()
|
||||
async with db.sqlorContext('hermes-web-cli') as sor:
|
||||
env = ServerEnv()
|
||||
dbname = env.get_module_dbname()
|
||||
async with db.sqlorContext(dbname) as sor:
|
||||
sql_template = SETTINGS_CRUD['operations']['create_or_update']['sql_template']
|
||||
await sor.sqlExe(sql_template, {
|
||||
'user_id': user_id,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user