connects to db, writes rows, triggers updates/insertions