前言

Visor(http://www.visor.com.cn)   是一个基于HTML5 Canvas 开发的IDE 框架和设计开发平台,有关Visor的设计架构和技术应用,在以后的文章里会逐渐跟大家分享,今天主要是分享一下它的数据库设计功能和SQL生成功能。在众多的软件项目里面,权限管理基本上都是必备的,看到有网友甚至为权限管理单独做了一套框架,目的都是为了很快的应用到不同的项目里面,减少开发的成本。本人也做过很多类似的工作,不论多好的框架都只能解决80%的用户,总有20%的用户会让你花80%的精力重复做过的事情,下边就说说在Visor 中如何完成数据库设计,并且通过模板生成数据库DDL SQL 和实体对象。

1. 建模设计,在Visor 里面,现在提供三种设计器,流程设计,ER设计和JPA实体设计,只有ER设计里面完成的ER图可以生成数据库需要的DDL SQL。

2. 设计模板

在文档菜单里面可以下载建模生成的数据表对象关系数据文件,数据文件是JSON格式的,然后用你熟悉的模板语言去生成想要的SQL代码和实体代码,在项目有严格规范的情况下,可以生成更多的对象,如DAO,Service,resultful api 等。可以说一劳永逸。 在Visor里面,默认使用的是Jsrender ,而且已经提供了生成ORACLE,SQL Server 和MYSQL 对应的DDL的模板。完成建模以后,点击相应的模板,可以下载对应数据库的DDL SQL文件. 里面会包含唯一索引和非空约束, 如果你要在数据库里面建立更多的约束和索引,这还需要手动完成。但是这些对象是否要创建在数据库里都还有争议。

{
  "tables": [
    {
      "name": "Users",
      "text": "Users",
      "auditable": false,
      "prefix": "",
      "abbreviation": "",
      "annotation": "",
      "cachable": false,
      "namespace": "",
      "strategy": "seqence",
      "sequenceName": "",
      "owner": "",
      "fields": [
        {
          "name": "id",
          "text": "id",
          "abbreviation": "",
          "datatype": "number",
          ,
          "ispk": true,
          "isfk": false,
          "reftable": "",
          "refield": "",
          "nullable": false,
          "unique": true,
          "annotation": "",
          "defaultvalue": "",
          ,
          ,

        },
        {
          "name": "name",
          "text": "name",
          "abbreviation": "",
          "datatype": "varchar",
          ,
          "ispk": false,
          "isfk": false,
          "reftable": "",
          "refield": "",
          "nullable": true,
          "unique": false,
          "annotation": "",
          "defaultvalue": "",
          ,
          ,

        },
        {
          "name": "email",
          "text": "email",
          "abbreviation": "",
          "datatype": "varchar",
          ,
          "ispk": false,
          "isfk": false,
          "reftable": "",
          "refield": "",
          "nullable": true,
          "unique": false,
          "annotation": "",
          "defaultvalue": "",
          ,
          ,

        },
        {
          "name": "password",
          "text": "password",
          "abbreviation": "",
          "datatype": "varchar",
          ,
          "ispk": false,
          "isfk": false,
          "reftable": "",
          "refield": "",
          "nullable": true,
          "unique": false,
          "annotation": "",
          "defaultvalue": "",
          ,
          ,

        },
        {
          "name": "active",
          "text": "active",
          "abbreviation": "",
          "datatype": "boolean",
          ,
          "ispk": false,
          "isfk": false,
          "reftable": "",
          "refield": "",
          "nullable": true,
          "unique": false,
          "annotation": "",
          "defaultvalue": "",
          ,
          ,

        }
      ],
      "pks": [
        {
          "name": "id",
          "text": "id",
          "abbreviation": "",
          "datatype": "number",
          ,
          "ispk": true,
          "isfk": false,
          "reftable": "",
          "refield": "",
          "nullable": false,
          "unique": true,
          "annotation": "",
          "defaultvalue": "",
          ,
          ,

        }
      ]
    },
    {
      "name": "Roles",
      "text": "Roles",
      "auditable": false,
      "prefix": "",
      "abbreviation": "",
      "annotation": "",
      "cachable": false,
      "namespace": "",
      "strategy": "seqence",
      "sequenceName": "",
      "owner": "",
      "fields": [
        {
          "name": "id",
          "text": "id",
          "abbreviation": "",
          "datatype": "number",
          ,
          "ispk": true,
          "isfk": false,
          "reftable": "",
          "refield": "",
          "nullable": false,
          "unique": true,
          "annotation": "",
          "defaultvalue": "",
          ,
          ,

        },
        {
          "name": "name",
          "text": "name",
          "abbreviation": "",
          "datatype": "varchar",
          ,
          "ispk": false,
          "isfk": false,
          "reftable": "",
          "refield": "",
          "nullable": true,
          "unique": false,
          "annotation": "",
          "defaultvalue": "",
          ,
          ,

        },
        {
          "name": "description",
          "text": "description",
          "abbreviation": "",
          "datatype": "varchar",
          ,
          "ispk": false,
          "isfk": false,
          "reftable": "",
          "refield": "",
          "nullable": true,
          "unique": false,
          "annotation": "",
          "defaultvalue": "",
          ,
          ,

        }
      ],
      "pks": [
        {
          "name": "id",
          "text": "id",
          "abbreviation": "",
          "datatype": "number",
          ,
          "ispk": true,
          "isfk": false,
          "reftable": "",
          "refield": "",
          "nullable": false,
          "unique": true,
          "annotation": "",
          "defaultvalue": "",
          ,
          ,

        }
      ]
    },
    {
      "name": "User_Role",
      "text": "User_Role",
      "auditable": false,
      "prefix": "",
      "abbreviation": "",
      "annotation": "",
      "cachable": false,
      "namespace": "",
      "strategy": "seqence",
      "sequenceName": "",
      "owner": "",
      "fields": [
        {
          "name": "User_id",
          "text": "id",
          "abbreviation": "",
          "datatype": "number",
          ,
          "ispk": true,
          "isfk": true,
          "reftable": "Users",
          "refield": "id",
          "nullable": false,
          "unique": true,
          "annotation": "",
          "defaultvalue": "",
          ,
          ,

        },
        {
          "name": "Role_id",
          "text": "id",
          "abbreviation": "",
          "datatype": "number",
          ,
          "ispk": true,
          "isfk": true,
          "reftable": "Roles",
          "refield": "id",
          "nullable": false,
          "unique": true,
          "annotation": "",
          "defaultvalue": "",
          ,
          ,

        }
      ],
      "pks": [
        {
          "name": "User_id",
          "text": "id",
          "abbreviation": "",
          "datatype": "number",
          ,
          "ispk": true,
          "isfk": true,
          "reftable": "Users",
          "refield": "id",
          "nullable": false,
          "unique": true,
          "annotation": "",
          "defaultvalue": "",
          ,
          ,

        },
        {
          "name": "Role_id",
          "text": "id",
          "abbreviation": "",
          "datatype": "number",
          ,
          "ispk": true,
          "isfk": true,
          "reftable": "Roles",
          "refield": "id",
          "nullable": false,
          "unique": true,
          "annotation": "",
          "defaultvalue": "",
          ,
          ,

        }
      ]
    },
    {
      "name": "privileges",
      "text": "table1",
      "auditable": false,
      "prefix": "",
      "abbreviation": "",
      "annotation": "",
      "cachable": false,
      "namespace": "",
      "strategy": "seqence",
      "sequenceName": "",
      "owner": "",
      "fields": [
        {
          "name": "id",
          "text": "id",
          "abbreviation": "",
          "datatype": "varchar",
          ,
          "ispk": true,
          "isfk": false,
          "reftable": "",
          "refield": "",
          "nullable": false,
          "unique": true,
          "annotation": "",
          "defaultvalue": "",
          ,
          ,

        },
        {
          "name": "name",
          "text": "name",
          "abbreviation": "",
          "datatype": "varchar",
          ,
          "ispk": false,
          "isfk": false,
          "reftable": "",
          "refield": "",
          "nullable": true,
          "unique": false,
          "annotation": "",
          "defaultvalue": "",
          ,
          ,

        },
        {
          "name": "description",
          "text": "description",
          "abbreviation": "",
          "datatype": "varchar",
          ,
          "ispk": false,
          "isfk": false,
          "reftable": "",
          "refield": "",
          "nullable": true,
          "unique": false,
          "annotation": "",
          "defaultvalue": "",
          ,
          ,

        }
      ],
      "pks": [
        {
          "name": "id",
          "text": "id",
          "abbreviation": "",
          "datatype": "varchar",
          ,
          "ispk": true,
          "isfk": false,
          "reftable": "",
          "refield": "",
          "nullable": false,
          "unique": true,
          "annotation": "",
          "defaultvalue": "",
          ,
          ,

        }
      ]
    },
    {
      "name": "Role_Privilege",
      "text": "table1",
      "auditable": false,
      "prefix": "",
      "abbreviation": "",
      "annotation": "",
      "cachable": false,
      "namespace": "",
      "strategy": "seqence",
      "sequenceName": "",
      "owner": "",
      "fields": [
        {
          "name": "Roles_id",
          "text": "id",
          "abbreviation": "",
          "datatype": "number",
          ,
          "ispk": true,
          "isfk": true,
          "reftable": "Roles",
          "refield": "id",
          "nullable": false,
          "unique": true,
          "annotation": "",
          "defaultvalue": "",
          ,
          ,

        },
        {
          "name": "privilege_id",
          "text": "id",
          "abbreviation": "",
          "datatype": "varchar",
          ,
          "ispk": true,
          "isfk": true,
          "reftable": "privilege",
          "refield": "id",
          "nullable": false,
          "unique": true,
          "annotation": "",
          "defaultvalue": "",
          ,
          ,

        }
      ],
      "pks": [
        {
          "name": "Roles_id",
          "text": "id",
          "abbreviation": "",
          "datatype": "number",
          ,
          "ispk": true,
          "isfk": true,
          "reftable": "Roles",
          "refield": "id",
          "nullable": false,
          "unique": true,
          "annotation": "",
          "defaultvalue": "",
          ,
          ,

        },
        {
          "name": "privilege_id",
          "text": "id",
          "abbreviation": "",
          "datatype": "varchar",
          ,
          "ispk": true,
          "isfk": true,
          "reftable": "privilege",
          "refield": "id",
          "nullable": false,
          "unique": true,
          "annotation": "",
          "defaultvalue": "",
          ,
          ,

        }
      ]
    }
  ],
  "connections": [
    {
      "name": "R1",
      "identifying": true,
      "nullable": false,
      "source_owner": "",
      "source_prefix": "",
      "source": "Users",
      "target_owner": "",
      "target_prefix": "",
      "target": "User_Role",
      "elements": [
        {
          "key": "id",
          "value": "User_id"
        }
      ]
    },
    {
      "name": "R2",
      "identifying": true,
      "nullable": false,
      "source_owner": "",
      "source_prefix": "",
      "source": "Roles",
      "target_owner": "",
      "target_prefix": "",
      "target": "User_Role",
      "elements": [
        {
          "key": "id",
          "value": "Role_id"
        }
      ]
    },
    {
      "name": "R3",
      "identifying": true,
      "nullable": false,
      "source_owner": "",
      "source_prefix": "",
      "source": "Roles",
      "target_owner": "",
      "target_prefix": "",
      "target": "Role_Privilege",
      "elements": [
        {
          "key": "id",
          "value": "Roles_id"
        }
      ]
    },
    {
      "name": "R4",
      "identifying": true,
      "nullable": false,
      "source_owner": "",
      "source_prefix": "",
      "source": "privileges",
      "target_owner": "",
      "target_prefix": "",
      "target": "Role_Privilege",
      "elements": [
        {
          "key": "id",
          "value": "privilege_id"
        }
      ]
    }
  ],
  "option": {
    "datetime": "2015-05-25T04:32:51.916Z"
  }
}

3. 完善建模设计和模板

项目需求会不停的改变,不同项目也有可能会应用不同的技术和语言。而我们要做的只是完善建模和制作新的模板。 而那些重复的工作,就让Visor 替你去完成吧。

Visor 应用之一 通过ER 设计生成数据库脚本和实体对象的更多相关文章

  1. 在EA中用ER图生成数据库

    ER图 E-R图也称实体-联系图(Entity Relationship Diagram).提供了表示实体类型.属性和联系的方法.用来描写叙述现实世界的概念模型. 实体就是看的见摸得着或者能被人感知接 ...

  2. powerdesigner 生成数据库脚本

    PowerDesigner导出所有SQL脚本 操作:Database=>Generate Database PowerDesigner怎么导出建表sql脚本 1 按照数据库类型,切换数据库. D ...

  3. ABP增加记录EFCore 生成数据库脚本日志到新的txt文件

    由于EFCore并没直接生成脚本到txt文件,故而自己画了点时间把实现记录下来,方便给大家参考. 0.安装Microsoft.Extensions.Logging.Debug,我这里是2.1.1版本. ...

  4. IDEA快速生成数据库表的实体类

    IDEA连接数据库 IDEA右边侧栏有个DataSource,可以通过这个来连接数据库,我们先成功连接数据库 点击进入后填写数据库进行连接,注意记得一定要去Test Connection 确保正常连接 ...

  5. idea生成springboot jpa的实体对象

    在idea的database里面添加上数据库 File-->Project Structure Modules--->点击加号----->选择JPA  选择确认之后再主面板上就会出现 ...

  6. PowerDesigner生成SQL脚本时,对象带有双引号的问题解决

    在pdm查看脚本时,发现表名和字段名带有双引号: 1.create table"cfg_user_card_account"  ( 2.  "user_card_acco ...

  7. MyBatis数据库字段和实体对象属性名不一致的解决方案

    数据库和对象的属性名不一致是很常见的问题,这个时候依从表字段到对象属性名的按名称匹配映射已经搞不定这个了,下面是几种解决方案. 1. 开启驼峰转换 如果数据库中的字段名与对象只是简单的不一致的话,比如 ...

  8. NHibernate中,查询SqlServer数据库多个实体对象

    关于datetime类型使用:  Oracle:  "and tb.EffectiveDate >= to_date(?,'yyyy-mm')" Sql:  "an ...

  9. NetCore使用使用Scaffold-DbContext命令生成数据库表实体类

    一.为了模拟项目,本处创建了一个NetCore的Web项目.打算在Models文件夹下生成数据库表的实体类. 二.在程序包管理控制台,输入“Scaffold-DbContext "Serve ...

随机推荐

  1. centos 带S权限的二进制

    早上写的一个用find查找带S权限的,感觉不记一下可惜了. [root@iZ28wg1kditZ ~]# find / -type f -exec ls -al {} \;|awk 'BEGIN {p ...

  2. NE Upgrade python script. Need to write a Tkinter GUI for it

    # -*- coding: utf-8 -*-#from ftplib import FTP __authour__='CC' import osimport telnetlibimport time ...

  3. hihoCoder 1430 : A Boring Problem(一琐繁题)

    hihoCoder #1430 : A Boring Problem(一琐繁题) 时间限制:1000ms 单点时限:1000ms 内存限制:256MB Description - 题目描述 As a ...

  4. 百度-official

    1.请描述html5新增的一些标签,描述这些标签的用法和语义 2.css属性position的属性值有哪些,描述它们的作用 3.常见的浏览器端的存储技术有哪些,以及它们的优缺点 4.程序定义如下: v ...

  5. 学习UFT11.5历程(一)

    博主三年来测试都是功能测试 看了虫师的文章,感觉是要学点东西.所以,听从虫师的话,不被眼花瞭乱的测试技术打扰,先学习UFT,再学习python. 再不学习感觉要被淘汰了...... 也不想有谈工资的时 ...

  6. jupyter nb + scite 混合搭建成我的最爱IDE

    jupyter nb + scite 混合搭建成我的最爱IDE 自从体验过jupyter notebook之后, 就深深地爱上了你, jupyter. jupyter这个名字也很古怪的. 它应该是ju ...

  7. c#winform程序退出的方法

    一共有4种方式: 1.this.Close();  只是关闭当前窗口,若不是主窗体,无法退出程序,另外若有托管线程(非主线程),也无法干净的退出: 2.Application.Exit();强制所有消 ...

  8. Hangfire项目使用

    基本介绍: hangfire 主要用于根据设置时间来执行任务,间隔几分钟执行一次,每天几点钟执行一次,如此执行任务. 方法: backgroundjob.enqueue(()=>"要执 ...

  9. 红包demo

    嘿嘿,红包demo import random dic={} lis=['KeLan','MonKey','Dexter','Superman','Iron Man','Robin'] def red ...

  10. ctags使用细节

    在src code目录中运行下面的命令(我自己使用的命令):    $ctags --langmap=c++:.h --languages=c++,c,perl,verilog -R 其中,指定cta ...