组件分享之后端组件——从 postgres 数据库模式生成DOT描述工具dbdot

dbdot是一个用于从postgres数据库模式生成DOT描述的工具,适用于数据库设计可视化。它支持通过命令行参数指定数据库连接详情,并能过滤生成特定表格的架构图。例如,可以生成全部表的架构图或者只包含特定表的白名单图。生成的DOT文件可以进一步转换为PNG等图形格式查看。
摘要由CSDN通过智能技术生成

组件分享之后端组件——从 postgres 数据库模式生成DOT描述工具dbdot

背景

近期正在探索前端、后端、系统端各类常用组件与工具,对其一些常见的组件进行再次整理一下,形成标准化组件专题,后续该专题将包含各类语言中的一些常用组件。欢迎大家进行持续关注。

组件基本信息

内容

本节我们分享一个从 postgres 数据库模式生成DOT描述。工具dbdot
它是一个二进制文件,可以直接进行安装使用,具体安装包可以在这里进行获取到。

具体使用如下:

$ ./dbdot -dbname=pgguide -user=kewluser                                                                                                       [16:33:31]
digraph  {

    node[label=<<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0"><TR><TD colspan="2">products</TD></TR>[<TR><TD>id</TD><TD>integer</TD></TR> <TR><TD>title</TD><TD>character varying</TD></TR> <TR><TD>price</TD><TD>numeric</TD></TR> <TR><TD>created_at</TD><TD>timestamp with time zone</TD></TR> <TR><TD>deleted_at</TD><TD>timestamp with time zone</TD></TR> <TR><TD>tags</TD><TD>ARRAY</TD></TR>]</TABLE>>,shape=plaintext] n1;
    node[label=<<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0"><TR><TD colspan="2">purchase_items</TD></TR>[<TR><TD>id</TD><TD>integer</TD></TR> <TR><TD>purchase_id</TD><TD>integer</TD></TR> <TR><TD>product_id</TD><TD>integer</TD></TR> <TR><TD>price</TD><TD>numeric</TD></TR> <TR><TD>quantity</TD><TD>integer</TD></TR> <TR><TD>state</TD><TD>character varying</TD></TR>]</TABLE>>,shape=plaintext] n2;
    node[label=<<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0"><TR><TD colspan="2">users</TD></TR>[<TR><TD>id</TD><TD>integer</TD></TR> <TR><TD>email</TD><TD>character varying</TD></TR> <TR><TD>password</TD><TD>character varying</TD></TR> <TR><TD>details</TD><TD>USER-DEFINED</TD></TR> <TR><TD>created_at</TD><TD>timestamp with time zone</TD></TR> <TR><TD>deleted_at</TD><TD>timestamp with time zone</TD></TR>]</TABLE>>,shape=plaintext] n3;
    node[label=<<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0"><TR><TD colspan="2">purchases</TD></TR>[<TR><TD>id</TD><TD>integer</TD></TR> <TR><TD>created_at</TD><TD>timestamp with time zone</TD></TR> <TR><TD>name</TD><TD>character varying</TD></TR> <TR><TD>address</TD><TD>character varying</TD></TR> <TR><TD>state</TD><TD>character varying</TD></TR> <TR><TD>zipcode</TD><TD>integer</TD></TR> <TR><TD>user_id</TD><TD>integer</TD></TR>]</TABLE>>,shape=plaintext] n4;
    n2->n1;
    n2->n4;
    n4->n3;

}

生成模式图

./dbdot -dbname=pgguide -user=kewluser > test.dot && dot -Tpng test.dot -o outfile.png && open outfile.png
image.png

将表列入白名单并为其生成架构图

./dbdot -dbname=pgguide -user=kewluser > test.dot --whitelist=purchase_items,purchases && dot -Tpng test.dot -o outfile-whitelisted.png && open outfile-whitelisted.png
image.png

具体使用方式可以参考如下:

-W    ask for password
  -dbname string
        dbname for which you want to generate dot file
  -host string
        database host (default "localhost")
  -port uint
        database port (default 5432)
  -schema string
        schema name (default "public")
  -sslmode
        enable sslmode for postgres db connection
  -user string
        username of postgres db
  -whitelist string
        comma separated list of tables you want to generate dot file for
本文声明:
88x31.png
知识共享许可协议
本作品由 cn華少 采用 知识共享署名-非商业性使用 4.0 国际许可协议 进行许可。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

CN華少

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值