예제 #1
0
def update_node(obj: Optional[Node]) -> None:
    if obj is None:
        return
    now = datetime.datetime.now()
    uid = object.__getattribute__(obj, '__uid__')
    object.__setattr__(obj, '__updated_at__', now)
    revert.put(f'{config.base}/objects/{uid}/updated_at', encode(now))
예제 #2
0
def register_node(obj: Node, uid: str) -> None:
    now = datetime.datetime.now()
    revert.put(f'{config.base}/objects/{uid}/created_at', encode(now))
    revert.put(f'{config.base}/objects/{uid}/updated_at', encode(now))
    object.__setattr__(obj, '__created_at__', now)
    object.__setattr__(obj, '__updated_at__', now)
    node_cache[uid] = obj
    intent_entity_created.announce(obj)
예제 #3
0
def db_connected(directory: str) -> None:
    with revert.transaction(message='schema change'):
        for cls in node_classes.values():
            mro = ','.join([
                parent.class_reference() for parent in cls.mro()
                if issubclass(parent, Node)
            ])
            revert.put(f'{config.base}/classes/{cls.class_reference()}/mro',
                       mro)
예제 #4
0
 def __init__(self, *, parent: Node, child: Node) -> None:
     actual_cls = self.__class__.class_reference()
     for cls in self.__class__.mro():
         if issubclass(cls, Edge):
             revert.count_up_or_set(
                 f'{config.base}/child_relations/{encode(parent)}/{cls.class_reference()}/{encode(child)}'
             )
             revert.count_up_or_set(
                 f'{config.base}/parent_relations/{encode(child)}/{cls.class_reference()}/{encode(parent)}'
             )
             revert.put(
                 f'{config.base}/child_edges/{encode(parent)}/{encode(child)}/{cls.class_reference()}/{actual_cls}',
                 '')
             revert.put(
                 f'{config.base}/parent_edges/{encode(child)}/{encode(parent)}/{cls.class_reference()}/{actual_cls}',
                 '')
예제 #5
0
 def __new__(cls, *args, **kwargs):
     if cls == Node:
         raise TypeError('Cannot create objects of abstract Node class')
     obj = object.__new__(cls)
     class_reference = obj.__class__.class_reference()
     uid = str(uuid.uuid4())
     object.__setattr__(obj, '__uid__', uid)
     object.__setattr__(obj, '__class_reference__', class_reference)
     revert.put(f'{config.base}/objects/{uid}/class_reference',
                class_reference)
     revert.put(f'{config.base}/objects/{uid}/uid', str(uid))
     for cls in obj.__class__.mro():
         if issubclass(cls, Node):
             Set(__binding__=
                 f'{config.base}/classes/{cls.class_reference()}/objects'
                 ).add(obj)
     ogm.register_node(obj, uid)
     return obj
예제 #6
0
 def add(self, item: TVal) -> None:
     revert.put(f'{self.__binding__}/{ogm.encode(item)}', '')
     ogm.update_node(self.__instance__)
예제 #7
0
 def __setitem__(self, key: TKey, value: TVal) -> None:
     revert.put(f'{self.__binding__}/{ogm.encode(key)}', ogm.encode(value))
     ogm.update_node(self.__instance__)
예제 #8
0
 def __set__(self, instance: Node, value: TVal) -> None:
     revert.put(self._binding, ogm.encode(value))
예제 #9
0
 def __set__(self, instance: Node, value: TVal) -> None:
     revert.put(ogm.get_node_binding(instance, self._attr_name),
                ogm.encode(value))
     ogm.update_node(instance)
예제 #10
0
def test_make_transactions():
    for i in range(5):
        with revert.transaction('transaction 1'):
            revert.put('x', str(i))
            revert.put('x/y', str(i))
            revert.put('y', str(i))
            revert.put('z', str(i))
            revert.put('x/y/z', str(i))
            revert.put('z/x', str(i))