使用xorm的reverse指令创建model

编译xorm包

go get github.com/go-xorm/cmd/xorm
cd $GOPATH/src/github.com/go-xorm/cmd/xorm
go build //会自动下载依赖包

需要安装的依赖包:

go get github.com/go-sql-driver/mysql  //Mysql
go get github.com/ziutek/mymysql/godrv  //MyMysql
go get github.com/lib/pq  //Postgres
go get github.com/mattn/go-sqlite3  //SQLite
go get github.com/denisenkom/go-mssqldb  //MSSQL

命令格式

1、格式
xorm reverse <数据库驱动名称><数据库连接字符串><生成struct的模板文件所在路径>[model文件保存路径]

2、查看帮助 xorm help reverse

usage: xorm reverse [-s] driverName datasourceName tmplPath [generatedPath] [tableFilterReg]

according database's tables and columns to generate codes for Go, C++ and etc.

    将struct生成到一个go文件里
    -s                Generated one go file for every table
    数据库驱动名称,如mysql mymysql sqlite3 postgres
    driverName        Database driver name, now supported four: mysql mymysql sqlite3 postgres
    数据库连接字符串
    datasourceName    Database connection uri, for detail infomation please visit driver's project page
    生成struct的模板文件所在路径,可以修改
    tmplPath          Template dir for generated. the default templates dir has provide 1 template
    文件保存路径,默认是当前路径下的./models
    generatedPath     This parameter is optional, if blank, the default value is models, then will
                      generated all codes in models dir
    正则过滤不需要生成的表名
    tableFilterReg    Table name filter regexp

示例

xorm reverse mysql "root:123456@tcp(127.0.0.1:3306)/db_keduoduo?charset=utf8mb4" templates/goxorm

你可能感兴趣的:(使用xorm的reverse指令创建model)