add function of writing data to db