简体   繁体   English

如何使用 flask 从 SQL 数据库创建组织结构图?

[英]How to create an organizational chart from SQL database with flask?

I have a SQL database like this:我有一个像这样的 SQL 数据库:

在此处输入图像描述

Basically this is a hierarchical database where you have managers (parent) and employees (children).基本上,这是一个分层数据库,其中有经理(父母)和员工(孩子)。

Currently I am working with flask which allows me to add/remove managers and employees and my idea is to have an html file which automatically reads from my SQL database and creates a tree like strucure (or an organizational chart) like this:目前我正在使用 flask,它允许我添加/删除经理和员工,我的想法是拥有一个 html 文件,该文件自动从我的 Z9778840A0100CB30C982876741B0B5A 中读取,并创建如下结构图:

在此处输入图像描述

I have figured out a way to create nested unordered lists which can be then turned into the chart by using the following library: https://github.com/caprica/jquery-orgchart我想出了一种创建嵌套无序列表的方法,然后可以使用以下库将其转换为图表: https://github.com/caprica/jquery-orgchart

However this works basically only when the database is static and does not change over time.但是,这基本上仅在数据库为 static 且不随时间变化时才有效。 I saw some solutions where they use json files but I have no clue of the middle step that leads from the SQL database to the json file.我看到了一些使用 json 文件的解决方案,但我不知道从 SQL 数据库到 json 文件的中间步骤。

Therefore, would you be able to propose an approach to solve this problem starting from the database?因此,您能否提出一种从数据库开始解决此问题的方法? Which solution do you recommend?您推荐哪种解决方案? Are there any tutorials / examples that I could follow?有没有我可以遵循的教程/示例?

Thanks in advance.提前致谢。

For SQL Server 2016 or later, you can extract data as JSON using T-SQL.对于 SQL Server 2016 或更高版本,您可以使用 T-SQL 将数据提取为 JSON。 An example using your pseudo-table:使用您的伪表的示例:

SELECT employee, employee_id, manager_id FROM employee_table FOR JSON PATH

The output of that query will be a single column with the table data formatted as JSON.该查询的 output 将是单列,表数据格式为 JSON。 You can read more about it here .你可以在这里阅读更多关于它的信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM