예제 #1
0
파일: leveldb.py 프로젝트: bashwork/common
    def get_key(self):
        ''' Get the current key at the iterator

        :returns: The current key at the iterator
        '''
        size = new_native_size()
        pointer = LDB.leveldb_iter_key(self.iterator, get_reference_to(size))
        return as_python_string(pointer, size)
예제 #2
0
파일: leveldb.py 프로젝트: bashwork/common
    def get(self, key, verify_checksum=False, fill_cache=True):
        ''' Delete the supplied value at the given key.

        :param key: The key to delete the value at
        :throws DatabaseException: If an error has occurred
        '''
        result  = None
        options = self.get_read_options(verify_checksum, fill_cache)

        try:
            error = new_native_string()
            size = new_native_size()
            value = LDB.leveldb_get(self.database, options, key, len(key),
                get_reference_to(size), get_reference_to(error))
            self.handle_error(error)
            return as_python_string(value, size)
        finally:
            if LDB and options:
                LDB.leveldb_readoptions_destroy(options)
예제 #3
0
파일: leveldb.py 프로젝트: bashwork/common
    def assert_no_error(self):
        ''' Check if there was an error after the last error.
        If there was, then throw an exception.

        :throws DatabaseException: If there was a problem with the iterator
        '''
        error = new_native_string()
        LDB.leveldb_iter_get_error(error, get_reference_to(error))
        message = as_python_string(error)
        if message:
            raise DatabaseException(message)
예제 #4
0
파일: leveldb.py 프로젝트: bashwork/common
    def destroy(self):
        ''' Completely blows away the underlying database. This process
        is not reversable.

        :throws DatabaseException: If an error has occurred
        '''
        options = self.get_open_options()

        try:
            error = new_native_string()
            LDB.leveldb_destroy_db(options, self.filename, get_reference_to(error))
            self.handle_error(error)
        finally:
            if LDB and options:
                LDB.leveldb_options_destroy(options)
            self.close()
예제 #5
0
파일: leveldb.py 프로젝트: bashwork/common
    def repair(self):
        ''' Attempt to repair a database after setting paranoid checks
        still results in an error.

        :throws DatabaseException: If an error has occurred
        '''
        options = self.get_open_options()

        try:
            error = new_native_string()
            LDB.leveldb_repair_db(options, self.filename, get_reference_to(error))
            self.handle_error(error)
        finally:
            if LDB and options:
                LDB.leveldb_options_destroy(options)
            self.close()
예제 #6
0
파일: leveldb.py 프로젝트: bashwork/common
    def delete(self, key, synchronous=False):
        ''' Delete the supplied value at the given key.

        :param key: The key to delete the value at
        :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_delete(self.database, options, key, len(key), get_reference_to(error))
            self.handle_error(error)
        finally:
            if options: LDB.leveldb_writeoptions_destroy(options)
예제 #7
0
파일: leveldb.py 프로젝트: bashwork/common
    def write(self, write_batch, synchronous=False):
        ''' Apply the write batch to the datbase.

        :param write_batch: The write batch to apply to the database.
        :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_write(self.database, options, write_batch, get_reference_to(error))
            self.handle_error(error)
        finally:
            if options: LDB.leveldb_writeoptions_destroy(options)
예제 #8
0
파일: leveldb.py 프로젝트: bashwork/common
    def open(self):
        ''' Creates the neccessary data structures and opens the
        underlying database. To tune the underlying options for the
        database read the following:

        http://docs.basho.com/riak/1.0.0/tutorials/choosing-a-backend/LevelDB/

        :throws DatabaseException: If an error has occurred
        '''
        options = self.get_open_options()

        try:
            error = new_native_string()
            self.database = LDB.leveldb_open(options, self.filename, get_reference_to(error))
            self.handle_error(error)
        finally:
            LDB.leveldb_options_destroy(options)