read and write to db