def _parse_uri(self, parameter): """Parse the configured URI or URI's for the given parameter :param parameter: the parameter to extract from the URI :type parameter: str """ results = [] uri = config.Database().uri if type(uri) is dict: for key, value in uri.items(): results.append({key: getattr(URI(value), parameter)}) else: results = getattr(URI(uri), parameter) return results
def _patch_sqlite_uris(self): """Patch the URIs for SQLite configured databases """ def patch(uri): """Closure to patch the URI """ if uri.scheme == 'sqlite' and sqlite_version_info >= (3, 6, 19): if uri.options.setdefault('foreign_keys', '1') == '0': uri.options['foreign_keys'] = '1' return str(uri) uri = config.Database().uri if type(uri) is dict: for database in uri: patched_uri = patch(URI(uri[database])) if patched_uri is not None: config.Database().uri[database] = patched_uri else: patched_uri = patch(URI(uri)) if patched_uri is not None: config.Database().uri = patched_uri
def database(self): """Return the database name we are using """ return URI(config.Database().uri).database
def host(self): """Return the hostname this database is using """ return URI(config.Database().uri).host
def backend(self): """Return the type of backend this databse is using """ return URI(config.Database().uri).scheme