Giter Club home page Giter Club logo

sql2struct's Introduction

SQL2Struct

SQL2Struct是一款对golang开发者友好的chrome插件,根据在mysql中创建数据表的sql语句,自动生成golang中的struct,在golang开发者使用诸如gorm之类的框架时,可以很好的把mysql中的数据表与orm的结构体关联起来。

使用说明

  1. 下载扩展源码
git clone https://github.com/idoubi/sql2struct.git
  1. 安装扩展

Chrome浏览器地址栏输入chrome://extensions/进入扩展程序管理中心, 点击“加载已解压的扩展程序”,通过源码进行安装。

  1. 在mysql中获取生成数据表的sql语句
show create table system_user\G;
  1. 进入插件主页面,把上一步得到的sql语句粘贴至左侧的输入框

  2. 复制右侧生成的struct,粘贴至golang代码中即可

配置说明

目前只有三个配置项

  • gorm:开启此配置项,则生成struct的时候,每个字段都会包含类似gorm:column:"id"这样的信息。
  • sqlx:开启此配置项,则生成struct的时候,每个字段都会包含类似db:column:"id"这样的信息。
  • json:开启此配置项,则生成struct的时候,每个字段都会包含类似json:"id"这样的信息。
  • typeMap:此配置项定义mysql数据表字段类型与go字段类型的映射关系,在数据解析的时候会按照配置的映射关系进行结构体生成。

typeMap默认的映射关系为:

{
    "tinyint": "int64",
    "smallint": "int64",
    "int": "int64",
    "mediumint": "int64",
    "bigint": "int64",
    "float": "float64",
    "double": "float64",
    "decimal": "float64",
    "char": "string",
    "varchar": "string",
    "text": "string",
    "mediumtext": "string",
    "longtext": "string",
    "time": "time.Time",
    "date": "time.Time",
    "datetime": "time.Time",
    "timestramp": "int64",
    "enum": "string",
    "set": "string",
    "blob": "string"
}

Todolist

  • 支持更多的mysql类型与go类型的映射
  • 支持自定义要进行转换的字段配置
  • 正则表达式优化
  • 数据表名称复数形式与struct名称单数形式转换
  • 增加主键、索引转换支持

Contribution

欢迎fork代码、提issue或者是pull request

sql2struct's People

Contributors

alswl avatar idoubi avatar

Forkers

huadiji

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.