Coder Social home page Coder Social logo

jangocheng / dbstruct Goto Github PK

View Code? Open in Web Editor NEW

This project forked from licoy/dbstruct

0.0 1.0 0.0 18 KB

dbstruct是一款将数据库表一键转换为Golang Struct的应用程序,支持自定义Tag和多种命名格式配置。

License: MIT License

Go 100.00%

dbstruct's Introduction

介绍

dbstruct是一款将数据库表一键转换为Golang Struct的应用程序,支持自定义Tag和多种命名格式配置。

参数列表

dsn              string   //数据库链接
tables           []string //自定义表
tagJson          bool     //json tag
tagOrm           bool     //orm tag
fieldNameFmt     FmtMode  //字段名称格式
structNameFmt    FmtMode  //结构名格式
fileNameFmt      FmtMode  //文件名格式
genTableName     string   //TableName方法名,
genTableNameFunc bool     //是否生成TableName方法
modelPath        string   //model保存的路径,若singleFile==true,则填写model.go的完整路径,默认为当前路径
singleFile       bool     //是否合成一个单文件
packageName      string   //包名
tags             []*Tag   //自定义Tag列表

使用方法

安装依赖

go get github.com/Licoy/dbstruct

使用

err := dbstruct.NewDBStruct().
    Dsn("root:root@tcp(127.0.0.1:3306)/dbname?charset=utf8").
    StructNameFmt(dbstruct.FmtUnderlineToStartUpHump).
    FieldNameFmt(dbstruct.FmtUnderlineToStartUpHump).
    FileNameFmt(dbstruct.FmtUnderline).
    //SingleFile(true).
    GenTableNameFunc(true).
    GenTableName("TableName").
    TagJson(true).
    PackageName("model").
    TagOrm(true).
    AppendTag(dbstruct.NewTag("xml", dbstruct.FmtDefault)).
    Generate()
if err != nil {
    fmt.Println(err)
}

生成结果示例

package model

type Mart struct {
	Id         int64 `xml:"id" json:"id" orm:"id" `
	ActId      int64 `xml:"act_id" json:"act_id" orm:"act_id" `
	Created    int64 `xml:"created" json:"created" orm:"created" `
	TemplateId int   `xml:"template_id" json:"template_id" orm:"template_id" `
	Number     int   `xml:"number" json:"number" orm:"number" `
	Price      int   `xml:"price" json:"price" orm:"price" `
	Day        int   `xml:"day" json:"day" orm:"day" `
}

func (m *Mart) MyTableName() string {
	return "mart"
}

授权

MIT

dbstruct's People

Contributors

licoy 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.