<commit_before>'''
Abstraction of TinyDB table for storing config
'''
from tinydb import Query


class KeyValueTable:
    """Wrapper around a TinyDB table.

    """

    def __init__(self, tdb, name='_default'):
        self.table = tdb.table(name)
        self.setting = Query()

    def get(self, key):
        """Get the value of named setting or None if it doesn't exist.

        """
        result = self.table.get(self.setting.key == key)
        if result:
            return result['value']
        return None

    def set(self, key, value):
        """Insert or update named setting with given value.

        """
        if self.table.contains(self.setting.key == key):
            self.table.update({'value': value}, self.setting.key == key)
        else:
            self.table.insert({'key': key, 'value': value})

    def __getitem__(self, key):
        return self.get(key)

    def __setitem__(self, key, value):
        return self.set(key, value)<commit_msg>Use upsert to reduce chance of duplicates<commit_after>'''
Abstraction of TinyDB table for storing config
'''
from tinydb import Query


class KeyValueTable:
    """Wrapper around a TinyDB table.

    """
    setting = Query()

    def __init__(self, tdb, name='_default'):
        self.table = tdb.table(name)

    def get(self, key):
        """Get the value of named setting or None if it doesn't exist.

        """
        result = self.table.get(self.setting.key == key)
        if result:
            return result['value']
        return None

    def set(self, key, value):
        """Insert or update named setting with given value.

        """
        self.table.upsert({
            'key': key,
            'value': value
        }, self.setting.key == key)

    def __getitem__(self, key):
        return self.get(key)

    def __setitem__(self, key, value):
        return self.set(key, value)
{'fraction_non_alphanumeric': 0.12195121951219512, 'fraction_numerical': 0.0, 'mean_word_length': 2.236706689536878, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6464193', 'n_tokens_mistral': 563, 'n_tokens_neox': 533, 'n_words': 174}