Batch database writes in transactions