Exemplo n.º 1
0
    def put(self, key, value, synchronous=False):
        ''' Put the supplied value at the given key.

        :param key: The key to store the value at
        :param value: The value to store at the key
        :param synchronous: True to make the put to disk synchronous, False to buffer
        :throws DatabaseException: If an error has occurred
        '''
        options = LDB.leveldb_writeoptions_create()

        try:
            error = new_native_string()
            LDB.leveldb_writeoptions_set_sync(options, synchronous)
            LDB.leveldb_put(self.database, options, key, len(key), value, len(value), get_reference_to(error))
            self.handle_error(error)
        finally:
            if options: LDB.leveldb_writeoptions_destroy(options)