def fetch_schema()

in nl2sql/datasets/base.py [0:0]


    def fetch_schema(cls, name: str, dsn: AllowedDSN) -> BaseDatasetSchema:
        """
        Queries the dtabase to find out the schema for a given db name and DSN
        """
        logger.info(f"[{name}] : Fetching Schema ...")
        metadata = MetaData()
        metadata.reflect(
            bind=create_engine(dsn.unicode_string()),
            views=True,
        )
        db_schema: BaseDatasetSchema = {name: {}}
        if metadata.tables:
            for tablename, table in metadata.tables.items():
                tabledata = {}
                for column in table.columns:
                    tabledata[column.name] = str(column.type)
                if not tabledata:
                    msg = f"No columns found in {name}.{tablename}"
                    logger.critical(msg)
                    raise AttributeError(msg)
                db_schema[name][tablename] = tabledata
        if not db_schema[name]:
            msg = f"No tables found in {name}"
            logger.critical(msg)
            raise AttributeError(msg)
        logger.success(f"[{name}] : Schema Obtained Successfully")
        return db_schema