Skip to content
This repository has been archived by the owner on Apr 2, 2024. It is now read-only.
/ ormat Public archive
generated from things-labs/cicd-go-template

Deprecated(move to ens/cmd/ormat): database/sql to golang struct. 一个数据库/SQL转struct模型的生成工具,生成gorm的模型.

License

Notifications You must be signed in to change notification settings

things-go/ormat

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ormat

database/sql to golang struct, and generate enum annotation from comment to proto file.

GoDoc Go.Dev reference codecov Action Status Go Report Card Licence Tag

Features

Usage

Installation

Use go get.

    go get github.com/things-go/ormat/cmd/ormat

or

    go install github.com/things-go/ormat/cmd/ormat@latest

Example.

NOTE:

  • database filed comment [@jsontag: realjsontag] will overwrite the filed json tags.
  • database filed comment [@affix] will append ,string to the filed json tags.
// SysUser 用户表
type SysUser struct {
	Id        int64     `gorm:"column:id;type:bigint;autoIncrement;not null;primaryKey,priority:1" json:"id,omitempty"`
	Username  string    `gorm:"column:username;type:varchar(64);not null;primaryKey,priority:2;uniqueIndex:uk_username" json:"username,omitempty"`
	Password  string    `gorm:"column:password;type:varchar(255);not null" json:"password,omitempty"`
	Nickname  string    `gorm:"column:nickname;type:varchar(64);not null" json:"nickname,omitempty"`
	Phone     string    `gorm:"column:phone;type:varchar(16);not null" json:"phone,omitempty"`
	Avatar    string    `gorm:"column:avatar;type:varchar(255);not null" json:"avatar,omitempty"`
	Sex       int8      `gorm:"column:sex;type:tinyint;not null;default:3" json:"sex,omitempty"`
	Email     string    `gorm:"column:email;type:varchar(32);not null" json:"email,omitempty"`
	Status    string    `gorm:"column:status;type:varchar(1);not null;default:1" json:"status,omitempty"`
	Remark    string    `gorm:"column:remark;type:varchar(255);not null" json:"remark,omitempty"`
	Creator   string    `gorm:"column:creator;type:varchar(32);not null" json:"creator,omitempty"`
	Updator   string    `gorm:"column:updator;type:varchar(32);not null" json:"updator,omitempty"`
	CreatedAt time.Time `gorm:"column:created_at;type:datetime(3);not null" json:"created_at,omitempty"`
	UpdatedAt time.Time `gorm:"column:updated_at;type:datetime(3);not null" json:"updated_at,omitempty"`
}

// TableName implement schema.Tabler interface
func (*SysUser) TableName() string {
	return "sys_user"
}

Help

$ ./ormat --help

database/sql to golang struct

Usage:
  ormat [command]

Available Commands:
  build       Generate model from sql
  completion  Generate the autocompletion script for the specified shell
  gen         Generate model from database
  help        Help about any command
  sql         Generate sql file
  upgrade     Upgrade ormat

Flags:
  -h, --help           help for ormat
  -l, --level string   log level(debug,info,warn,error) (default "info")
  -v, --version        version for ormat

Use "ormat [command] --help" for more information about a command.

Build

goreleaser release --snapshot  --rm-dist

References

JetBrains OS licenses

ormat had been being developed with GoLand under the free JetBrains Open Source license(s) granted by JetBrains s.r.o., hence I would like to express my thanks here.

License

This project is under MIT License. See the LICENSE file for the full license text.

About

Deprecated(move to ens/cmd/ormat): database/sql to golang struct. 一个数据库/SQL转struct模型的生成工具,生成gorm的模型.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages