def perform_update(self): Logger.success("Delete old db") self._delete_old_db() Logger.success("Retrieving building view collection from persistence") buildings = list(BuildingView.get_collection().find({'building_name':{'$exists':True}})) Logger.success("Creating new db") db_connection = sqlite3.connect( self.db_path() ) sql_create = "CREATE TABLE lookup(" sql_create += "id INTEGER PRIMARY KEY," sql_create += "b_id VARCHAR(6)," sql_create += "building_name VARCHAR(100)," sql_create += "f_id VARCHAR(6)," sql_create += "floor_name VARCHAR(20)," sql_create += "r_id VARCHAR(10)," sql_create += "room_name VARCHAR(100))" db_connection.execute(sql_create) Logger.success("Begin transaction") index = 0 for building in buildings: for f_id,floor in enumerate(building['floors']): for room_id in floor['rooms']: sql_insert = 'INSERT INTO lookup VALUES({},"{}","{}","{}","{}","{}","{}")'.format( index, building['_id'], building['building_name'], floor['f_id'], floor['floor_name'], room_id, floor['rooms'][room_id]['room_name']) db_connection.execute(sql_insert) index +=1 db_connection.commit() Logger.success("End transaction") Logger.success("{0} entries".format(index))
def perform_update(self): Logger.success("Delete old db") self._delete_old_db() Logger.success("Retrieving building view collection from persistence") buildings = list(BuildingView.get_collection().find( {'building_name': { '$exists': True }})) Logger.success("Creating new db") db_connection = sqlite3.connect(self.db_path()) sql_create = "CREATE TABLE lookup(" sql_create += "id INTEGER PRIMARY KEY," sql_create += "b_id VARCHAR(6)," sql_create += "building_name VARCHAR(100)," sql_create += "f_id VARCHAR(6)," sql_create += "floor_name VARCHAR(20)," sql_create += "r_id VARCHAR(10)," sql_create += "room_name VARCHAR(100))" db_connection.execute(sql_create) Logger.success("Begin transaction") index = 0 for building in buildings: for f_id, floor in enumerate(building['floors']): for room_id in floor['rooms']: sql_insert = 'INSERT INTO lookup VALUES({},"{}","{}","{}","{}","{}","{}")'.format( index, building['_id'], building['building_name'], floor['f_id'], floor['floor_name'], room_id, floor['rooms'][room_id]['room_name']) db_connection.execute(sql_insert) index += 1 db_connection.commit() Logger.success("End transaction") Logger.success("{0} entries".format(index))
def prepare_buildings_collection(): app.buildings = BuildingView.get_collection() app.protocol = 'http' app.domain = request.headers['Host']