def get_account_id(s: sqlalchemy.orm.session.Session,
name: str,
server: Server) -> int:
"""Get an account id, creating the account if needed.
Note that player names are not case sensitive, so names are stored with
their canonical capitalisation but we always compare the lowercase version.
"""
player_id = get_player_id(s, name)
acc = s.query(Account.id).filter(
func.lower(Account.name) == name.lower(),
Account.server == server).one_or_none()
if acc:
return acc[0]
else:
acc = Account(name=name, server=server, player_id=player_id)
s.add(acc)
s.commit()
return acc.id
评论列表
文章目录