Skip to content

Commit

Permalink
DB: add delete functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
deathbybandaid committed May 15, 2019
1 parent a2e7378 commit 88f2ed2
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions sopel/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,26 @@ def set_nick_value(self, nick, key, value):
finally:
session.close()

def delete_nick_value(self, nick, key):
"""Deletes the value for a given key to be associated with the nick."""
nick = Identifier(nick)
nick_id = self.get_nick_id(nick)
session = self.ssession()
try:
result = session.query(NickValues) \
.filter(NickValues.nick_id == nick_id) \
.filter(NickValues.key == key) \
.one_or_none()
# NickValue exists, delete
if result:
session.delete(result)
session.commit()
except SQLAlchemyError:
session.rollback()
raise
finally:
session.close()

def get_nick_value(self, nick, key):
"""Retrieves the value for a given key associated with a nick."""
nick = Identifier(nick)
Expand Down Expand Up @@ -367,6 +387,25 @@ def set_channel_value(self, channel, key, value):
finally:
session.close()

def delete_channel_value(self, channel, key):
"""Deletes the value for a given key to be associated with the channel."""
channel = Identifier(channel).lower()
session = self.ssession()
try:
result = session.query(ChannelValues) \
.filter(ChannelValues.channel == channel)\
.filter(ChannelValues.key == key) \
.one_or_none()
# ChannelValue exists, update
if result:
session.delete(result)
session.commit()
except SQLAlchemyError:
session.rollback()
raise
finally:
session.close()

def get_channel_value(self, channel, key):
"""Retrieves the value for a given key associated with a channel."""
channel = Identifier(channel).lower()
Expand Down

0 comments on commit 88f2ed2

Please sign in to comment.