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))
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)
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)
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}', '')
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
def add(self, item: TVal) -> None: revert.put(f'{self.__binding__}/{ogm.encode(item)}', '') ogm.update_node(self.__instance__)
def __setitem__(self, key: TKey, value: TVal) -> None: revert.put(f'{self.__binding__}/{ogm.encode(key)}', ogm.encode(value)) ogm.update_node(self.__instance__)
def __set__(self, instance: Node, value: TVal) -> None: revert.put(self._binding, ogm.encode(value))
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)
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))