def insert(self, role: Role, alias: str = None, is_primary: int = 0):
""" Inserts a new role into the table.
If the alias is not specified, the role name will be used instead
"""
if not role: # pragma: no cover
return
if alias is None:
alias = role.name
server = role.server
if self.sql_type is SQLType.sqlite:
return await self._insert_lite(role, server, alias, is_primary)
else: # pragma: no cover
self.cursor.execute(
self.query(
'''INSERT INTO roles VALUES (%(role)s, %(alias)s, %(server)s, %(primary)s)
ON CONFLICT(role, server_id)
DO UPDATE SET alias = %(alias)s'''),
{"role": role.id, "alias": alias, "server": server.id, "primary": is_primary})
self.connection.commit()
评论列表
文章目录