• 【BI报表】Superset二开相关接口文档


    记录一下Superset二开相关接口信息,方便后面查询

    图表配置保存接口

    接口地址

    /superset/explore/?form_data=%7B%22slice_id%22%3A1%7D&slice_id=1&action=overwrite&slice_name=demo&save_to_dashboard_id=1

    源码文件地址

    根目录\superset\views\core.py

    源码及部分截图

    1. @has_access
    2. @event_logger.log_this
    3. @expose("/explore///", methods=["GET", "POST"])
    4. @expose("/explore/", methods=["GET", "POST"])
    5. @expose("/explore/p//", methods=["GET"])
    6. # pylint: disable=too-many-locals,too-many-branches,too-many-statements
    7. def explore(
    8. self,
    9. datasource_type: Optional[str] = None,
    10. datasource_id: Optional[int] = None,
    11. key: Optional[str] = None,
    12. ) -> FlaskResponse:
    13. initial_form_data = {}
    14. form_data_key = request.args.get("form_data_key")

    保存与更新

    1. if action == "saveas" and slice_add_perm:
    2. ChartDAO.save(slc)
    3. msg = _("Chart [{}] has been saved").format(slc.slice_name)
    4. flash(msg, "success")
    5. elif action == "overwrite" and slice_overwrite_perm:
    6. ChartDAO.overwrite(slc)
    7. msg = _("Chart [{}] has been overwritten").format(slc.slice_name)
    8. flash(msg, "success")

    添加数据集

    接口地址

    /api/v1/dataset/

    1. {database: 1, schema: "datacollect", table_name: "cgmx_out"}
    2. database: 1
    3. schema: "datacollect"
    4. table_name: "cgmx_out"

    源码文件地址

    根目录\superset\views\core.py

    源码及部分截图

    数据DAO

    源码文件地址

    \superset\dao\base.py

    源码及部分截图

    create
    1. @classmethod
    2. def create(cls, properties: Dict[str, Any], commit: bool = True) -> Model:
    3. """
    4. Generic for creating models
    5. :raises: DAOCreateFailedError
    6. """
    7. if cls.model_cls is None:
    8. raise DAOConfigError()
    9. model = cls.model_cls() # pylint: disable=not-callable
    10. for key, value in properties.items():
    11. setattr(model, key, value)
    12. try:
    13. db.session.add(model)
    14. if commit:
    15. db.session.commit()
    16. except SQLAlchemyError as ex: # pragma: no cover
    17. db.session.rollback()
    18. raise DAOCreateFailedError(exception=ex) from ex
    19. return model

    save
    1. @classmethod
    2. def save(cls, instance_model: Model, commit: bool = True) -> Model:
    3. """
    4. Generic for saving models
    5. :raises: DAOCreateFailedError
    6. """
    7. if cls.model_cls is None:
    8. raise DAOConfigError()
    9. if not isinstance(instance_model, cls.model_cls):
    10. raise DAOCreateFailedError(
    11. "the instance model is not a type of the model class"
    12. )
    13. try:
    14. db.session.add(instance_model)
    15. if commit:
    16. db.session.commit()
    17. except SQLAlchemyError as ex: # pragma: no cover
    18. db.session.rollback()
    19. raise DAOCreateFailedError(exception=ex) from ex
    20. return instance_model

    update
    1. @classmethod
    2. def update(
    3. cls, model: Model, properties: Dict[str, Any], commit: bool = True
    4. ) -> Model:
    5. """
    6. Generic update a model
    7. :raises: DAOCreateFailedError
    8. """
    9. for key, value in properties.items():
    10. setattr(model, key, value)
    11. try:
    12. db.session.merge(model)
    13. if commit:
    14. db.session.commit()
    15. except SQLAlchemyError as ex: # pragma: no cover
    16. db.session.rollback()
    17. raise DAOUpdateFailedError(exception=ex) from ex
    18. return model
    delete
    1. @classmethod
    2. def delete(cls, model: Model, commit: bool = True) -> Model:
    3. """
    4. Generic delete a model
    5. :raises: DAODeleteFailedError
    6. """
    7. try:
    8. db.session.delete(model)
    9. if commit:
    10. db.session.commit()
    11. except SQLAlchemyError as ex: # pragma: no cover
    12. db.session.rollback()
    13. raise DAODeleteFailedError(exception=ex) from ex
    14. return model

  • 相关阅读:
    学习笔记-Nginx
    GptFuck—开源Gpt4分享
    evm 代码分析
    Vue路由与nodejs下载安装及环境变量的配置
    基础算法:二分查找
    PEG/蛋白/抗体功能/修饰/偶联化铋纳米球 PEG/Protein/antibody-Bi nanosphere 的产品介绍
    函数和变量总结
    使用vue3+vite+elctron构建小项目介绍Electron进程间通信
    XML基础知识汇总
    AJAX学习笔记9 搜索联想自动补全
  • 原文地址:https://blog.csdn.net/wenchun001/article/details/133421437