encapsulates database connection through factory method