Git Product home page Git Product logo

dbtogo's Introduction

数据库表 -> go结构体

安装 go 1.17+

go install github.com/kzkzzzz/dbtogo@main
Usage:
dbtogo [flags]

Flags:
-d, --dsn string      dsn链接
-h, --help            help for dbtogo
-o, --output string   文件输出目录, 未指定则只打印到终端
-s, --source string   数据源(支持:mysql), 默认mysql (default "mysql")
-t, --table strings   表名, 多个逗号隔开

在当前目录生成文件

dbtogo -o . --dsn="remote:remote123@tcp(127.0.0.1:3306)/db" -t user,order

user.go

package main

type User struct {
	Id        int    `json:"id"`         // Id
	Phone     string `json:"phone"`      // 手机
	Username  string `json:"username"`   // 用户名
	Avatar    string `json:"avatar"`     // 头像
	CreatedAt int    `json:"created_at"` // CreatedAt
	UpdatedAt int    `json:"updated_at"` // UpdatedAt
}

func (u *User) TableName() string {
	return "user"
}

order.go

package main

type Order struct {
	Id        int   `json:"id"`         // Id
	OrderId   int64 `json:"order_id"`   // 订单id
	UserId    int   `json:"user_id"`    // 用户id
	CreatedAt int   `json:"created_at"` // 创建时间
}

func (o *Order) TableName() string {
	return "order"
}

dbtogo's People

Contributors

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