diff options
| author | 2019-04-24 12:07:30 +0100 | |
|---|---|---|
| committer | 2019-04-24 12:07:30 +0100 | |
| commit | dc102f258d75493b11735fdd69e25f92be186c1f (patch) | |
| tree | 8f696eab637c5d741b8903774179570bec85deb6 /src/Database.py | |
| parent | Add UNIQUE constraint for `alias` on `servers` table (diff) | |
Add Database.servers.get_by_alias, move IRCBot.get_server to
IRCBot.get_server_by_id, add IRCBot.get_server_by_alias and change
!connect/!disconnect to take aliases instead of IDs
Diffstat (limited to 'src/Database.py')
| -rw-r--r-- | src/Database.py | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/src/Database.py b/src/Database.py index f1563ac0..67fe4a6f 100644 --- a/src/Database.py +++ b/src/Database.py @@ -24,7 +24,7 @@ class Servers(Table): def get_all(self): return self.database.execute_fetchall( "SELECT server_id, alias FROM servers") - def get(self, id: int) -> typing.Tuple[int, typing.Optional[str], str, + def get(self, id: int)-> typing.Tuple[int, typing.Optional[str], str, int, typing.Optional[str], bool, bool, typing.Optional[str], str, typing.Optional[str], typing.Optional[str]]: return self.database.execute_fetchone( @@ -32,6 +32,13 @@ class Servers(Table): ipv4, bindhost, nickname, username, realname FROM servers WHERE server_id=?""", [id]) + def get_by_alias(self, alias: str) -> typing.Optional[int]: + value = self.database.execute_fetchone( + "SELECT server_id FROM servers WHERE alias=? COLLATE NOCASE", + [alias]) + if value: + return value[0] + return value class Channels(Table): def add(self, server_id: int, name: str): |
