All Projects → sliveryou → grom

sliveryou / grom

Licence: MIT license
A powerful command line tool for converting mysql table fields to golang model structure.

Programming Languages

go
31211 projects - #10 most used programming language
shell
77523 projects
Makefile
30231 projects

Projects that are alternatives of or similar to grom

Go Web
Modern Web Application with Golang
Stars: ✭ 138 (+213.64%)
Mutual labels:  gorm
Golang Project Structure
Golang Skeleton with fully version managed
Stars: ✭ 103 (+134.09%)
Mutual labels:  gorm
go-pangu
rest api web server based on go(High availability, high security, high performance)
Stars: ✭ 45 (+2.27%)
Mutual labels:  gorm
Cmall Go
golang写的电子商城的API接口
Stars: ✭ 167 (+279.55%)
Mutual labels:  gorm
Grails Data Mapping
GORM - Groovy Object Mapping
Stars: ✭ 194 (+340.91%)
Mutual labels:  gorm
Goweibo
Go Weibo App
Stars: ✭ 243 (+452.27%)
Mutual labels:  gorm
Gin bbs
Gin BBS App
Stars: ✭ 123 (+179.55%)
Mutual labels:  gorm
dproxy
简易的网络代理工具,带有IP白名单限制管,带有简洁的UI管理界面,提供丰富的API接口,可方便的与各个系统集成,可编译为单文件运行
Stars: ✭ 25 (-43.18%)
Mutual labels:  xorm
Fuckdb
From database generate go struct,help you fuck db fields
Stars: ✭ 195 (+343.18%)
Mutual labels:  gorm
opentracing-gorm
OpenTracing instrumentation for GORM.
Stars: ✭ 46 (+4.55%)
Mutual labels:  gorm
Goilerplate
Clean Boilerplate of Go, Domain-Driven Design, Clean Architecture, Gin and GORM.
Stars: ✭ 173 (+293.18%)
Mutual labels:  gorm
Go Mocket
Go GORM & SQL mocking library
Stars: ✭ 190 (+331.82%)
Mutual labels:  gorm
golang-example-app
Example application
Stars: ✭ 138 (+213.64%)
Mutual labels:  gorm
Gosql
golang orm and sql builder
Stars: ✭ 141 (+220.45%)
Mutual labels:  gorm
gorm-mongodb
GORM for MongoDB
Stars: ✭ 58 (+31.82%)
Mutual labels:  gorm
Gorm Paginator
gorm pagination extension
Stars: ✭ 136 (+209.09%)
Mutual labels:  gorm
Gorm Bulk Insert
implement BulkInsert using gorm, just pass a Slice of Struct. Simple and compatible.
Stars: ✭ 241 (+447.73%)
Mutual labels:  gorm
go-orm-code-helper
🔥🔥🔥go-orm-code-helper is a goland plugin, it aims to make gorm code getting more simple
Stars: ✭ 22 (-50%)
Mutual labels:  gorm
simple-mpesa
A simple example of how MPESA works. Works with all 3 types of customers i.e. Agents, Merchants and Subscribers. Allows you to configure a tariff and apply it to transactions. The project follows DDD principles.
Stars: ✭ 31 (-29.55%)
Mutual labels:  gorm
BEW-2.5-Strongly-Typed-Languages
💪 Learn and implement the design patterns and best practices that make Go a top choice at high-velocity startups like Lyft, Heroku, Docker, Medium, and more!
Stars: ✭ 14 (-68.18%)
Mutual labels:  gorm

grom

English简体中文

Github License Go Doc Go Report Github Latest Release Github Latest Tag Github Stars

Grom is a powerful command line tool that can convert mysql table fields to golang model structure. Its full name is golang relational object mapping (GROM).

Installation

Download package by using:

$ go get -u github.com/sliveryou/grom

To build from source code, you need Go environment (1.14 or newer) and use the following commands:

$ git clone https://github.com/sliveryou/grom.git
$ cd grom
$ sh scripts/install.sh

Or download a pre-compiled binary from the release page.

Grom CLI

$ grom -h
Get golang model structure by mysql information schema

Usage:
  grom [command]

Examples:
  grom generate -n ./grom.json
  grom convert -n ./grom.json

Available Commands:
  convert     Convert mysql table fields to golang model structure
  generate    Generate grom configuration file
  help        Help about any command
  version     Show the grom version information

Flags:
  -h, --help   help for grom

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

$ grom generate -h
Generate grom configuration file like this:
{
    "host": "localhost",
    "port": 3306,
    "user": "user",
    "password": "password",
    "database": "database",
    "table": "table",
    "package_name": "package_name",
    "struct_name": "struct_name",
    "enable_initialism": true,
    "enable_field_comment": true,
    "enable_sql_null": false,
    "enable_guregu_null": false,
    "enable_json_tag": true,
    "enable_xml_tag": false,
    "enable_gorm_tag": false,
    "enable_xorm_tag": false,
    "enable_beego_tag": false,
    "enable_gorose_tag": false,
    "enable_gorm_v2_tag": true
}

Usage:
  grom generate [flags]

Examples:
  grom generate -n ./grom.json

Flags:
  -h, --help          help for generate
  -n, --name string   the name of the generated grom configuration file (default "grom.json")

$ grom convert -h
Convert mysql table fields to golang model structure by information_schema.columns and information_schema.statistics

Usage:
  grom convert [flags]

Examples:
  grom convert -n ./grom.json
  grom convert -H localhost -P 3306 -u user -p password -d database -t table -e INITIALISM,FIELD_COMMENT,JSON_TAG,GORM_V2_TAG --package PACKAGE_NAME --struct STRUCT_NAME

Flags:
  -d, --database string   the database of mysql
  -e, --enable strings    enable services (must in [INITIALISM,FIELD_COMMENT,SQL_NULL,GUREGU_NULL,JSON_TAG,XML_TAG,GORM_TAG,XORM_TAG,BEEGO_TAG,GOROSE_TAG,GORM_V2_TAG])
  -h, --help              help for convert
  -H, --host string       the host of mysql
  -n, --name string       the name of the grom configuration file
  -o, --output string     the name of the file used to store the grom output
      --package string    the package name of the converted model structure
  -p, --password string   the password of mysql
  -P, --port int          the port of mysql
      --struct string     the struct name of the converted model structure
  -t, --table string      the table of mysql
  -u, --user string       the user of mysql

$ grom version -h
Show the grom version information, such as project name, project version, go version, git commit id, build time, etc

Usage:
  grom version [flags]

Flags:
  -h, --help   help for version

Supported Generated Types And Tags

Types:

Tags:

Supported Tag Generation Rules

Tag PrimaryKey AutoIncrement ColumnName Type IsNullable Indexes Uniques Default Comment ForeignKey
json × × × × × × × × ×
xml × × × × × × × × ×
gorm v1 ×
xorm ×
beego orm × × ×
gorose × × × × × × × × ×
gorm v2 ×

Supported Function Generation Rules

Tag TableName TableIndex TableUnique
json × × ×
xml × × ×
gorm v1 × ×
xorm × ×
beego orm
gorose × ×
gorm v2 × ×

Usage Example

  1. Create the table named api by following sql:
CREATE TABLE `api` (
    `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '接口id',
    `path` varchar(255) NULL DEFAULT NULL COMMENT '接口路径',
    `description` varchar(255) NULL DEFAULT NULL COMMENT '接口描述',
    `group` varchar(255) NULL DEFAULT NULL COMMENT '接口属组',
    `method` varchar(255) NULL DEFAULT 'POST' COMMENT '接口方法',
    `create_time` bigint(20) NULL DEFAULT NULL COMMENT '创建时间',
    `update_time` bigint(20) NULL DEFAULT NULL COMMENT '更新时间',
    PRIMARY KEY (`id`),
    UNIQUE INDEX `path_method`(`path`, `method`),
    INDEX `group`(`group`)
) ENGINE = InnoDB AUTO_INCREMENT = 1;
  1. Generate the grom configuration file and edit it:
$ grom generate -n grom.json 
$ vim grom.json
{
    "host": "localhost",
    "port": 3306,
    "user": "user",
    "password": "password",
    "database": "database",
    "table": "api",
    "package_name": "model",
    "struct_name": "API",
    "enable_initialism": true,
    "enable_field_comment": true,
    "enable_sql_null": false,
    "enable_guregu_null": false,
    "enable_json_tag": true,
    "enable_xml_tag": false,
    "enable_gorm_tag": false,
    "enable_xorm_tag": false,
    "enable_beego_tag": false,
    "enable_gorose_tag": false,
    "enable_gorm_v2_tag": true
}
$ grom convert -n grom.json -o output.go

You can also fill in the parameters on the command line without generating a configuration file:

$ grom convert -H localhost -P 3306 -u user -p password -d database -t api -e INITIALISM,FIELD_COMMENT,JSON_TAG,GORM_V2_TAG

Then you will get the generated code:

package model

type API struct {
    ID          int    `json:"id" gorm:"primaryKey;column:id;type:int(11) auto_increment;comment:接口id"`                           // 接口id
    Path        string `json:"path" gorm:"column:path;type:varchar(255);uniqueIndex:path_method;comment:接口路径"`                  // 接口路径
    Description string `json:"description" gorm:"column:description;type:varchar(255);comment:接口描述"`                            // 接口描述
    Group       string `json:"group" gorm:"column:group;type:varchar(255);index:group;comment:接口属组"`                            // 接口属组
    Method      string `json:"method" gorm:"column:method;type:varchar(255);uniqueIndex:path_method;default:POST;comment:接口方法"` // 接口方法
    CreateTime  int64  `json:"create_time" gorm:"column:create_time;type:bigint(20);comment:创建时间"`                              // 创建时间
    UpdateTime  int64  `json:"update_time" gorm:"column:update_time;type:bigint(20);comment:更新时间"`                              // 更新时间
}

// TableName returns the table name of the API model
func (a *API) TableName() string {
    return "api"
}
  1. Enjoy yourself!
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].