Files
async_sqlalchemy/utils/db/db_mtr_network_nodes.py
2025-05-27 12:40:07 +02:00

36 lines
1.3 KiB
Python

from utils.db.db import DbConnector
from models.model_mtr_network_nodes import MtrAdditionalNodesModel
from sqlalchemy import select
class MtrAdditionalNodeQuery:
def __init__(self):
db_con = DbConnector("spirent_mysql")
self.db = db_con.get_db()
async def get_all_nodes(self) -> list:
"""
Retrieve all entries from the mtr_network_nodes database table.
"""
async with self.db() as session:
return (await session.execute(select(MtrAdditionalNodesModel))).scalars().all()
async def get_all_nodes_for_testing(self) -> list:
"""
Retrieve all entries from the mtr_network_nodes database table, exclude rows used for storing parameters for
testing TAS servers.
"""
async with (self.db() as session):
stmt = select(MtrAdditionalNodesModel) \
.where(MtrAdditionalNodesModel.test_servers == False) \
.where(MtrAdditionalNodesModel.enabled == True)
return (await session.execute(stmt)).scalars().all()
async def get_node_by_id(self, node_id: int) -> MtrAdditionalNodesModel:
async with self.db() as session:
stmt = select(MtrAdditionalNodesModel).where(MtrAdditionalNodesModel.id == node_id)
return (await session.execute(stmt)).scalars().first()