write data to db