save events into the database