def add_device(): session = Session() new_device = Device("9422", "172.65.112.13", "3") session.add(new_device) session.commit() session.close() click.echo('device added')
from src.repositories.entity import Session from src.entities.user import User from src.entities.role import Role from src.repositories.role_repository import fetch_role from datetime import datetime from src.repositories.entity import init_db init_db() session = Session() try: role = session.query(Role).filter(Role.name == 'Admin').first() if not role: role = Role('Admin', 'This is the admin role') session.add(role) session.commit() user = session.query(User).filter( User.email == '*****@*****.**').first() if not user: role = fetch_role(session, 'Admin') cDate = datetime.now() user = User('test', '*****@*****.**', '123456', cDate, role) session.add(user) session.commit() session.close() except Exception as e: print(str(e))