如何使用 `dm` 包在 R 中查看来自Postgres数据库的特定ERD。

huangapple go评论70阅读模式
英文:

How to view specific ERD from Postgres database in R using `dm` package

问题

I understand your instructions. Here's the translated content:


我已经建立了一个带有几个单独实体关系图(ERD)的数据库。我可以在我的数据库GUI(dbeaver)中查看这些ERD,但我想在RStudio中查看特定模式的ERD。

我找到了dm包,其中有一个dm::dm_draw函数。问题是,当我调用dm::dm_draw函数到我的数据库连接时,它会在一个图像中绘制每个表和模式。我只想查看一个模式。我该如何在RStudio中调用和查看特定的ERD模式?

以下是我尝试将search_path设置为'survey_data'模式并将各种参数传递到'dm::dm_draw'函数中的方法。很抱歉,我无法提供此数据库的凭据,因此无法使此问题完全可再现。

if (!require(librarian)){
  install.packages("librarian")
  library(librarian)
}
# librarian下载所需的包,如果尚未下载,并将其读入
librarian::shelf(dm, tidyverse, DBI, RPostgres, DiagrammeR)


connection <- dbConnect(drv = dbDriver("Postgres"),
                        dbname = Sys.getenv("aws_dbname"),
                        host = Sys.getenv("aws_host"),
                        port = Sys.getenv("aws_port"),
                        user = Sys.getenv("aws_user"),
                        password = Sys.getenv("aws_password"),
                        options="-c search_path='survey_data'") 

dbExecute(connection,"set search_path = 'survey_data'")

survey_data <- dm_from_con(connection)

survey_data %>% 
  dm_draw(view_type = "all", graph_name = 'survey_data', focus = 'survey_data')

这里是查看所有表的输出,尽管以上尝试了各种方法指定只查看一个模式。
如何使用 `dm` 包在 R 中查看来自Postgres数据库的特定ERD。


英文:

I have built a database with a handful or schemas that have separate entity relationship diagrams (ERDs). I can view those ERDs in my database GUI (dbeaver) but I would like to view schema specific ERDs in RStudio.

I have found the dm package where there is a dm::dm_draw function. The problem is when I call the dm::dm_draw function to my database connection it draws every table and schema in one image. I want to view just one schema. How do I call in and view a specific ERD schema in RStudio?

Below is my attempt of setting the search_path to the 'survey_data' schema as well as passing various arguments into the 'dm::dm_draw' function. I am sorry for not making this fully reproducible but I am not able to provide credentials tot his database.

if (!require(librarian)){
  install.packages(&quot;librarian&quot;)
  library(librarian)
}
# librarian downloads, if not already downloaded, and reads in needed packages
librarian::shelf(dm, tidyverse, DBI, RPostgres, DiagrammeR)


connection &lt;- dbConnect(drv = dbDriver(&quot;Postgres&quot;),
                        dbname = Sys.getenv(&quot;aws_dbname&quot;),
                        host = Sys.getenv(&quot;aws_host&quot;),
                        port = Sys.getenv(&quot;aws_port&quot;),
                        user = Sys.getenv(&quot;aws_user&quot;),
                        password = Sys.getenv(&quot;aws_password&quot;),
                        options=&quot;-c search_path=&#39;survey_data&#39;&quot;) 

dbExecute(connection,&quot;set search_path = &#39;survey_data&#39;&quot;)


survey_data &lt;- dm_from_con(connection)

survey_data %&gt;% 
  dm_draw(view_type = &quot;all&quot;, graph_name = &#39;survey_data&#39;, focus = &#39;survey_data&#39;)



and here is the output of every table being viewed even with all the above attempts to specify just one schema.

如何使用 `dm` 包在 R 中查看来自Postgres数据库的特定ERD。

答案1

得分: 1


survey_data <- dm_from_con(connection, schema = 'survey_data')

survey_data %>% 
  dm_draw(view_type = "all", rankdir = "RL")

英文:

survey_data &lt;- dm_from_con(connection, schema = &#39;survey_data&#39;)

survey_data %&gt;% 
  dm_draw(view_type = &quot;all&quot;, rankdir = &quot;RL&quot;)

huangapple
  • 本文由 发表于 2023年4月19日 23:29:47
  • 转载请务必保留本文链接:https://go.coder-hub.com/76056321.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定