Пример #1
0
    def get_all_datasource_names(
            cls, db, datasource_type: str) -> List[utils.DatasourceName]:
        """Returns a list of all tables or views in database.

        :param db: Database instance
        :param datasource_type: Datasource_type can be 'table' or 'view'
        :return: List of all datasources in database or schema
        """
        # TODO: Fix circular import caused by importing Database
        schemas = db.get_all_schema_names(
            cache=db.schema_cache_enabled,
            cache_timeout=db.schema_cache_timeout,
            force=True,
        )
        all_datasources: List[utils.DatasourceName] = []
        for schema in schemas:
            if datasource_type == "table":
                all_datasources += db.get_all_table_names_in_schema(
                    schema=schema,
                    force=True,
                    cache=db.table_cache_enabled,
                    cache_timeout=db.table_cache_timeout,
                )
            elif datasource_type == "view":
                all_datasources += db.get_all_view_names_in_schema(
                    schema=schema,
                    force=True,
                    cache=db.table_cache_enabled,
                    cache_timeout=db.table_cache_timeout,
                )
            else:
                raise Exception(
                    f"Unsupported datasource_type: {datasource_type}")
        return all_datasources
Пример #2
0
    def get_all_datasource_names(cls, db, datasource_type: str) \
            -> List[utils.DatasourceName]:
        """Returns a list of all tables or views in database.

        :param db: Database instance
        :param datasource_type: Datasource_type can be 'table' or 'view'
        :return: List of all datasources in database or schema
        """
        schemas = db.get_all_schema_names(
            cache=db.schema_cache_enabled,
            cache_timeout=db.schema_cache_timeout,
            force=True)
        all_datasources: List[utils.DatasourceName] = []
        for schema in schemas:
            if datasource_type == 'table':
                all_datasources += db.get_all_table_names_in_schema(
                    schema=schema,
                    force=True,
                    cache=db.table_cache_enabled,
                    cache_timeout=db.table_cache_timeout)
            elif datasource_type == 'view':
                all_datasources += db.get_all_view_names_in_schema(
                    schema=schema,
                    force=True,
                    cache=db.table_cache_enabled,
                    cache_timeout=db.table_cache_timeout)
            else:
                raise Exception(
                    f'Unsupported datasource_type: {datasource_type}')
        return all_datasources