Extract database connection to class