A function doesn't need to be impure to communicate with a db. It can describe the actions without executing them, returning the actions to let some other impure process execute the effects.
The function itself hardly communicates with the db then, does it? In your example it's the impure process that does all the actual communicating.