Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Golang struct generator similar to mysql terminal

License

NotificationsYou must be signed in to change notification settings

suncle1993/genstruct

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

75 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Golang struct generator from mysql schema

asciicast

命令行版本

安装:

go get github.com/suncle1993/genstruct

使用方法:

genstruct -h 127.0.0.1 -u root -P 123456 -p 3306
  • -h defaultlocalhost
  • -u defaultroot
  • -p default3306

线上版本

接口版本

curl --location --request GET'https://genstructapi.herokuapp.com/api/struct/generate' \--header'Content-Type: application/json' \--data-raw'{    "tags": ["db", "json"],    "table": "create table user_mine_info( id bigint(20) NOT NULL AUTO_INCREMENT, uid bigint(20) NOT NULL DEFAULT'\''0'\'' COMMENT'\''用户uid'\'', mined_cnt bigint(20) NOT NULL COMMENT'\''剩余挖矿次数'\'', un_exchange_diamond bigint(20) NOT NULL COMMENT'\''未兑换为挖矿次数的钻石'\'', created_at bigint(20) NOT NULL COMMENT'\''创建时间'\'', updated_at bigint(20) NOT NULL COMMENT'\''更新时间'\'', PRIMARY KEY (id), UNIQUE KEY uk_uid (uid) USING BTREE) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COMMENT ='\''用户挖矿剩余次数记录'\'';"}'

示例

建表数据

CREATETABLEuser_mine_info(  idbigint(20)NOT NULL AUTO_INCREMENT,   UIDbigint(20)NOT NULL DEFAULT'0' COMMENT'用户uid',   mined_cntbigint(20)NOT NULL COMMENT'剩余挖矿次数',   un_exchange_diamondbigint(20)NOT NULL COMMENT'未兑换为挖矿次数的钻石',   created_atbigint(20)NOT NULL COMMENT'创建时间',   updated_atbigint(20)NOT NULL COMMENT'更新时间',PRIMARY KEY (id),   UNIQUE KEY uk_uid (UID) USING BTREE) ENGINE= InnoDB DEFAULT CHARSET= utf8mb4 COMMENT='用户挖矿剩余次数记录';

生成的模型:

package user_mine_info// UserMineInfo 用户挖矿剩余次数记录typeUserMineInfostruct {IDint64`db:"id" json:"id" `UIDint64`db:"uid" json:"uid" `// 用户uidMinedCntint64`db:"mined_cnt" json:"mined_cnt" `// 剩余挖矿次数UnExchangeDiamondint64`db:"un_exchange_diamond" json:"un_exchange_diamond" `// 未兑换为挖矿次数的钻石CreatedAtint64`db:"created_at" json:"created_at" `// 创建时间UpdatedAtint64`db:"updated_at" json:"updated_at" `// 更新时间}// TableName ...func (u*UserMineInfo)TableName()string {return"user_mine_info"// TODO: 如果分表需要修改}// PK ...func (u*UserMineInfo)PK()string {return"id"}// Schema ...func (u*UserMineInfo)Schema()string {return`(  id bigint NOT NULL AUTO_INCREMENT,  uid bigint NOT NULL DEFAULT '0' COMMENT '用户uid',  mined_cnt bigint NOT NULL COMMENT '剩余挖矿次数',  un_exchange_diamond bigint NOT NULL COMMENT '未兑换为挖矿次数的钻石',  created_at bigint NOT NULL COMMENT '创建时间',  updated_at bigint NOT NULL COMMENT '更新时间',  PRIMARY KEY (id),  UNIQUE KEY uk_uid (uid) USING BTREE) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='用户挖矿剩余次数记录'`}

About

Golang struct generator similar to mysql terminal

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go97.0%
  • Makefile3.0%

[8]ページ先頭

©2009-2025 Movatter.jp