add a function: write to database