async def create_system(conn, system_name: str, system_hid: str) -> System: logger.debug("Creating system (name={}, hid={})".format( system_name, system_hid)) row = await conn.fetchrow( "insert into systems (name, hid) values ($1, $2) returning *", system_name, system_hid) return System(**row) if row else None
async def get_system(conn, system_id: int) -> System: row = await conn.fetchrow("select * from systems where id = $1", system_id) return System(**row) if row else None
async def get_system_by_token(conn, token: str) -> Optional[System]: row = await conn.fetchrow("select * from systems where token = $1", token) return System(**row) if row else None
async def get_system_by_hid(conn, system_hid: str) -> System: row = await conn.fetchrow("select * from systems where hid = $1", system_hid) return System(**row) if row else None
async def get_system_by_account(conn, account_id: int) -> System: row = await conn.fetchrow( "select systems.* from systems, accounts where accounts.uid = $1 and accounts.system = systems.id", account_id) return System(**row) if row else None