V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
peng49
V2EX  ›  程序员

PHP 生成数据库的 markdown 字段说明文档,支持 mysql,postgresql

  •  
  •   peng49 ·
    peng49 · 294 天前 · 621 次点击
    这是一个创建于 294 天前的主题,其中的信息可能已经有所发展或是发生改变。

    安装

    composer require peng49/db2markdown

    命令行使用

    php vendor/bin/db2markdown

    输入数据库的 地址(host), 端口(port) 用户名,密码,要导出的表,默认是*,生成所有表的文档,指定多个表明用逗号隔开,如: table1,table2

    $ php src/bin/db2markdown
    please enter the db(1 mysql,2 postgresql):
    please enter the host(localhost):
    please enter the port(3306): 3310
    please enter username(root):
    please enter password: password
    please enter database: acg
    please enter tables(default is *,match all table):
    
    admin_menu successful
    
    admin_operation_log successful
    
    admin_permissions successful
    
    ....
    
    E:\develop\db2markdown\db2markdown20230712091813.md is export success
    

    导出 PostgreSQL 结构

    $ php src/bin/db2markdown
    please enter the db(1 mysql,2 postgresql): 3
    please enter the db(1 mysql,2 postgresql): 2
    please enter the host(localhost):
    please enter the port(5432): 5432
    please enter username(root): odoo
    please enter password: password
    please enter database: gocron
    please enter table schema(public):
    please enter tables(default is *,match all table):
    
    task successful
    
    task_log successful
    
    host successful
    
    ......
    
    E:\develop\db2markdown\db2markdown20230712092030.md is export success
    

    代码中使用

    <?php
    require_once "vendor/autoload.php";
    
    /* @var $generator \DB2Markdown\Generator\Mysql */
    $generator = \DB2Markdown\Factory::getGenerator('mysql');
    
    //mysql
    $generator->setHost('localhost')
        ->setPort(3306)
        ->setDatabase('database')
        ->setUsername('username')
        ->setPassword('password')
        ->output("filename", "*");
    

    源码

    Github: https://github.com/peng49/db2markdown

    Packagist: https://packagist.org/packages/peng49/db2markdown

    2 条回复    2023-07-13 13:29:25 +08:00
    mrpzx001
        1
    mrpzx001  
       294 天前
    815979670
        2
    815979670  
       294 天前
    https://www.dbkuaizi.com/archives/97.html
    很久之前写过一个单文件版本的,但只支持 mysql 或 mariadb
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   945 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 23:28 · PVG 07:28 · LAX 16:28 · JFK 19:28
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.