Ejemplo n.º 1
0
class Session(object):
    """
    Session object that connects to the database.
    
    Keeps indices for retrieving models, by the model element_type field.
    A Post model class with element_type = "posts" can be accessed like:
    
    db = DBSession()
    db.posts.get(1)
    db.posts.index.get(key=value) 
    """
    
    @classmethod
    def bind(cls, engine_uri):
        cls.engine_uri = engine_uri
    
    def __init__(self):
        self.engine = create_engine(self.engine_uri)
        
        # Standard stuff
        self.indices  = IndexProxy(self.engine)
        self.vertices = VertexProxy(self.engine)
        self.edges    = EdgeProxy(self.engine)
        
        
        # Models
        model_indices = {}
        for name in Node._model_registry:
            model = Node._model_registry[name]
            index = self.indices.get_create(name, Node)
            model_indices[name] = index
        
        self.nodes    = NodeProxy(engine=self.engine, indices=model_indices)
Ejemplo n.º 2
0
 def __init__(self):
     self.engine = create_engine(self.engine_uri)
     
     # Standard stuff
     self.indices  = IndexProxy(self.engine)
     self.vertices = VertexProxy(self.engine)
     self.edges    = EdgeProxy(self.engine)
     
     
     # Models
     model_indices = {}
     for name in Node._model_registry:
         model = Node._model_registry[name]
         index = self.indices.get_create(name, Node)
         model_indices[name] = index
     
     self.nodes    = NodeProxy(engine=self.engine, indices=model_indices)