Factor db connection code out into separate file