Golang Xorm reverse automatically generate database entity files

Source: Internet
Author: User
Tags mssql

First of all, install the necessary things

Xorm

go get github.com/go-xorm/cmd/xorm

Install the driver version and choose the one you need

go get github.com/go-sql-driver/mysql  //Mysqlgo get github.com/ziutek/mymysql/godrv  //MyMysqlgo get github.com/lib/pq  //Postgresgo get github.com/mattn/go-sqlite3  //SQLitego get github.com/denisenkom/go-mssqldb  //MSSQL

Second, the configuration%gopath%/bin environment variable

Third, test xorm cmd is installed successfully

xorm help reverse

The xorm reverse command parameters are as follows

D:\MyConfiguration\xxx>xorm help reverseusage: xorm reverse [-s] driverName datasourceName tmplPath [generatedPath] [tableFilterReg]according database's tables and columns to generate codes for Go, C++ and etc.    -s                Generated one go file for every table    driverName        Database driver name, now supported four: mysql mymysql sqlite3 postgres    datasourceName    Database connection uri, for detail infomation please visit driver's project page    tmplPath          Template dir for generated. the default templates dir hasprovide 1 template    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

Note that the Templates/goxorm in the following directive refers to the%gopath%/src\github.com\go-xorm\cmd\xorm\templates\goxorm
If the CD switch to the%gopath%/src\github.com\go-xorm\cmd\xorm directory, you can use the following instructions, otherwise tmplpath please fill in the full path.
Reference case: MSSQL

sqlite: xorm reverse sqite3 test.db templates/goxormmysql: xorm reverse mysql root:@/xorm_test?charset=utf8 templates/goxormmymysql: xorm reverse mymysql xorm_test2/root/ templates/goxormpostgres: xorm reverse postgres "dbname=xorm_test sslmode=disable" templates/goxormmssql: xorm reverse mssql "server=127.0.0.1;user id=testid;password=testpwd;database=testdb" templates/goxorm

Case: MSSQL
Method One: It is recommended to specify Generatedpath (example C:\temp below) so that the generated code is easy to find.

xorm reverse mssql "server=127.0.0.1;user id=sa;password=123456;database=shifenzheng" %GOPATH%\Src\github.com\go-xorm\cmd\xorm\templates\goxorm  C:\temp

Mode two: CD first switch to Xorm/cmd/xorm folder and then execute

cd %GOPATH%/Src\github.com\go-xorm\cmd\xormxorm reverse mssql "server=127.0.0.1;user id=sa;password=123456;database=shifenzheng" templates\goxorm  C:\temp



Post-generated code:

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.