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: