Created
April 30, 2012 20:33
-
-
Save mhluongo/2562448 to your computer and use it in GitHub Desktop.
A quick hack for lazy-loaded nodes and relationships using neo4jrestclient (as of 12/2012).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class LazyBase(object): | |
""" | |
A mixin to make elements of the REST client lazy. | |
""" | |
def __init__(self, url, dic): | |
self._dont_update = True | |
super(LazyBase, self).__init__(url, create=False) | |
self._dic = dic.copy() | |
self._dont_update = False | |
def update(self, *args, **kwargs): | |
if not self._dont_update: | |
super(LazyBase, self).update(*args,**kwargs) | |
@classmethod | |
def from_dict(cls, dic): | |
return cls(dic['self'], dic) | |
class LazyNode(LazyBase, neo4j.Node): | |
id_url_template = 'node/%d' | |
class LazyRelationship(LazyBase, neo4j.Relationship): | |
id_url_template = 'relationship/%d' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment