wraps db stream in self-invoking function