Ejemplo n.º 1
0
class Index(object):
    
    def __init__(self, dbcon, collection, iname):
        self.dbcon = dbcon
        self.collection = collection
        self.queries = IndexQueries(self.dbcon, collection.name(), iname)
        
        self.iname = iname

        self.__init_table()        
        
        
    def name(self):
        return self.iname
        
        
    def find(self, value):
        
        value_json = json.dumps(value)
        
        uuids = self.queries.find_index(value_json)
        
        results = FindResult(self.collection, uuids)
        
        return results
        
    def findone(self, value):
        
        value_json = json.dumps(value)
        
        uuids = self.queries.find_index(value_json)
        
        if len(uuids) == 0:
            return None
            
        uuid = uuids[0]
        
        return self.collection.load(uuid)
        
    
    def link(self, value, uuid):        
        value_json = json.dumps(value)
        
        self.queries.update_index(uuid, value_json)
        
        
    def unlink(self, uuid):
        self.queries.delete_index(uuid)
        
        
    def __init_table(self):
        # create table if necessary
        if not self.queries.table_exists():
            self.queries.create_table()
Ejemplo n.º 2
0
    def __init__(self, dbcon, collection, iname):
        self.dbcon = dbcon
        self.collection = collection
        self.queries = IndexQueries(self.dbcon, collection.name(), iname)
        
        self.iname = iname

        self.__init_table()