Skip to content
Snippets Groups Projects
  • Jason Fried's avatar
    Column Family Support · 2a66e20c
    Jason Fried authored
    Add support for Column Families in a runtime safe way.
    Add unittests to test functionality
    Insure all unittests are passing.
    Cleaned up unittests to not use a fixed directory in tmp, but use tempfile
    2a66e20c
merge_operators.py 723 B
import struct as py_struct
from rocksdb.interfaces import AssociativeMergeOperator

class UintAddOperator(AssociativeMergeOperator):
    def merge(self, key, existing_value, value):
        if existing_value:
            s = py_struct.unpack('Q', existing_value)[0] + py_struct.unpack('Q', value)[0]
            return (True, py_struct.pack('Q', s))
        return (True, value)

    def name(self):
        return b'uint64add'

class StringAppendOperator(AssociativeMergeOperator):
    def merge(self, key, existing_value, value):
        if existing_value:
            s = existing_value + b',' + value
            return (True, s)
        return (True, value)

    def name(self):
        return b'StringAppendOperator'