承接 mhd-jalilvand/php-dbml-parser 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

mhd-jalilvand/php-dbml-parser

Composer 安装命令:

composer require mhd-jalilvand/php-dbml-parser

包简介

PHP Parser for database markup language (dbml)

README 文档

README

Parse database markup language (DBML)

You can use Diagram.io to visually design your database diagram and write down the codes in a file and parse it using this script to parse it.

Installation & sample codes

composer require mhd-jalilvand/php-dbml-parser
cp  vendor/mhd-jalilvand/php-dbml-parser/example.php example.php
cp  vendor/mhd-jalilvand/php-dbml-parser/tests -r tests
php  example.php
phpunit tests/ParserTest.php

Usage

tests/test.dbml contains a sample database schema as:

table posts {
  id int [pk, increment]
  title varchar [not null]
}

table comments {
  id int [pk,increment]
  comment varchar 
  post_id int [not null,ref: > posts.id]
}
table tags{
  id int [pk, increment, not null]
  title varchar [not null]
}

table post_tags{
  id int [pk]
  post_id int
  tag_id int
}




Ref: "tags"."id" < "post_tags"."tag_id"

Ref: "posts"."id" < "post_tags"."post_id"

Example code:

<?php
require 'vendor/autoload.php';
use DbmlParser\Parser;
$parser = new Parser('tests/test.dbml');
foreach($parser->tables as $table){
  echo $table->name.':'.PHP_EOL;
  foreach($table->columns as $column){
    echo "\t".json_encode($column).PHP_EOL;
  }
}
echo 'Relations:'.PHP_EOL;
foreach($parser->relations as $relation){
  echo $relation->table->name.'.'.$relation->column->name;
  echo ' '.$relation->type.' ';
  echo $relation->foreign_table->name.'.'.$relation->foreign_column->name.PHP_EOL;
}

Results:

posts:
        {"name":"id","type":"int","PK":true,"NotNull":null,"Increment":true,"comment":null}
        {"name":"title","type":"varchar","PK":null,"NotNull":true,"Increment":null,"comment":null}
comments:
        {"name":"id","type":"int","PK":true,"NotNull":null,"Increment":true,"comment":null}
        {"name":"comment","type":"varchar","PK":null,"NotNull":null,"Increment":null,"comment":null}
        {"name":"post_id","type":"int","PK":null,"NotNull":null,"Increment":null,"comment":null}
tags:
        {"name":"id","type":"int","PK":true,"NotNull":true,"Increment":null,"comment":null}
        {"name":"title","type":"varchar","PK":null,"NotNull":true,"Increment":null,"comment":null}
post_tags:
        {"name":"id","type":"int","PK":true,"NotNull":null,"Increment":null,"comment":null}
        {"name":"post_id","type":"int","PK":null,"NotNull":null,"Increment":null,"comment":null}
        {"name":"tag_id","type":"int","PK":null,"NotNull":null,"Increment":null,"comment":null}
Relations:
tags.id < post_tags.tag_id
posts.id < post_tags.post_id
comments.post_id > posts.id

统计信息

  • 总下载量: 29
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 2
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-02-09

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固