英文:
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')
这里是查看所有表的输出,尽管以上尝试了各种方法指定只查看一个模式。
英文:
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("librarian")
library(librarian)
}
# librarian downloads, if not already downloaded, and reads in needed packages
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')
and here is the output of every table being viewed even with all the above attempts to specify just one schema.
答案1
得分: 1
survey_data <- dm_from_con(connection, schema = 'survey_data')
survey_data %>%
dm_draw(view_type = "all", rankdir = "RL")
英文:
survey_data <- dm_from_con(connection, schema = 'survey_data')
survey_data %>%
dm_draw(view_type = "all", rankdir = "RL")
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论