Write to db