Exemplo n.º 1
0
 def adjust_channel_value(self, channel, key, value):
     """Adjusts the value for a given key to be associated with the channel."""
     channel = Identifier(channel).lower()
     result = self.execute(
         'SELECT value FROM channel_values WHERE channel = ? AND key = ?',
         [channel, key]).fetchone()
     if result is not None:
         result = result[0]
     current_value = _deserialize(result)
     value = current_value + value
     value = json.dumps(value, ensure_ascii=False)
     self.execute('INSERT OR REPLACE INTO channel_values VALUES (?, ?, ?)',
                  [channel, key, value])
Exemplo n.º 2
0
 def adjust_nick_value(self, nick, key, value):
     """Adjusts the value for a given key to be associated with the nick."""
     nick = Identifier(nick)
     result = self.execute(
         'SELECT value FROM nicknames JOIN nick_values '
         'ON nicknames.nick_id = nick_values.nick_id '
         'WHERE slug = ? AND key = ?', [nick.lower(), key]).fetchone()
     if result is not None:
         result = result[0]
     current_value = _deserialize(result)
     value = current_value + value
     value = json.dumps(value, ensure_ascii=False)
     nick_id = self.get_nick_id(nick)
     self.execute('INSERT OR REPLACE INTO nick_values VALUES (?, ?, ?)',
                  [nick_id, key, value])
Exemplo n.º 3
0
 def get_plugin_value(self, plugin, key, namespace='default'):
     """Retrieves the value for a given key associated with a plugin."""
     plugin = plugin.lower()
     session = self.ssession()
     try:
         result = session.query(PluginValues) \
             .filter(PluginValues.plugin == plugin)\
             .filter(PluginValues.namespace == namespace)\
             .filter(PluginValues.key == key) \
             .one_or_none()
         if result is not None:
             result = result.value
         return _deserialize(result)
     except SQLAlchemyError:
         session.rollback()
         raise
     finally:
         session.close()
Exemplo n.º 4
0
 def get_server_value(self, server, key, namespace='default'):
     """Retrieves the value for a given key associated with a server."""
     server = server.lower()
     session = self.ssession()
     try:
         result = session.query(ServerValues) \
             .filter(ServerValues.server == server)\
             .filter(ServerValues.namespace == namespace)\
             .filter(ServerValues.key == key) \
             .one_or_none()
         if result is not None:
             result = result.value
         return _deserialize(result)
     except SQLAlchemyError:
         session.rollback()
         raise
     finally:
         session.close()
Exemplo n.º 5
0
 def get_channel_value(self, channel, key, namespace='default'):
     """Retrieves the value for a given key associated with a channel."""
     channel = Identifier(channel).lower()
     session = self.ssession()
     try:
         result = session.query(ChannelValues) \
             .filter(ChannelValues.channel == channel)\
             .filter(ChannelValues.namespace == namespace)\
             .filter(ChannelValues.key == key) \
             .one_or_none()
         if result is not None:
             result = result.value
         return _deserialize(result)
     except SQLAlchemyError:
         session.rollback()
         raise
     finally:
         session.close()
Exemplo n.º 6
0
 def get_nick_value(self, nick, key, namespace='default'):
     """Retrieves the value for a given key associated with a nick."""
     nick = Identifier(nick)
     session = self.ssession()
     try:
         result = session.query(NickValues) \
             .filter(Nicknames.nick_id == NickValues.nick_id) \
             .filter(Nicknames.slug == nick.lower()) \
             .filter(NickValues.namespace == namespace)\
             .filter(NickValues.key == key) \
             .one_or_none()
         if result is not None:
             result = result.value
         return _deserialize(result)
     except SQLAlchemyError:
         session.rollback()
         raise
     finally:
         session.close()