Giter VIP home page Giter VIP logo

mysql_generate's Introduction

mysql_generate

mysql_generate包是根据数据库生成基础model和数据库脚本的工具

如何使用

安装生成可执行文件

  • cd ~/lib/database/mysql_generate
  • go install

使用工具

第一种方式

  • cd mysql_generate
  • go build main.go生成当前环境的可执行文件
  • 将可执行文件放到GOROOT的bin文件夹下
  • cd ~/model && mysql_generate -a address -d user:password@database -t table

第二种方式

  • cd mysql_generate
  • go build main.go生成当前环境的可执行文件
  • 将可执行文件放到GOROOT的bin文件夹下
  • 在model.go 的init()上注释(注意//后面没有空格) //go:generate mysql_generate -a address -d database -t table
  • cd ~/model
  • go generate

生成规则

在model目录下,生成数据库表名对应.go文件,里面包含对数据库的基本Get,Search,Create,Update方法,同时在doc下,生成 对应表的DDL,如果有变动会生成增量语句。

模型文件包含方法如下:

  • CreateXX() 创建数据
  • UpdateXX() 更新数据
  • GetXX() 获取单条数据,指定的列字段将不会被返回
  • GetXXWithFields() 获取单条数据,并返回指定的列字段
  • SearchXX() 获取列表数据,指定的列字段将不会被返回,最大返回1000条
  • SearchXXWithFields() 获取列表数据,并返回指定的列字段,最大返回1000条
  • SearchXXWithFieldsLimit() 获取列表数据,并返回指定的列字段,可指定offset,limit,若limit大于1000,则返回1000

备注

  • 修改字段名,生的语句需要注意,工具自动生成会有两条先删后加脚本
  • 需要在运用项目的model目录下运行服务
  • -t参数若不输入,则默认生成全表
  • -e参数若不输入,则默认linux环境

mysql_generate's People

Contributors

lights-t avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.