企业🤖AI Agent构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
[TOC] > [参考](https://github.com/go-xorm/cmd) ## 安装 ``` //xorm 工具 go get github.com/go-xorm/cmd/xorm ``` ## 概述 • 对于 sqlite 支持,您需要通过 go 生成 -标记 sqlite3 生成,因为此驱动程序会询问 cgo。 ## 接口说明 ``` -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 has provide 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 ``` ## 使用 ### Reverse 把数据表转为go 结构体 ``` cd $GOPATH/src/github.com/go-xorm/cmd/xorm sqlite: xorm reverse sqite3 test.db templates/goxorm mysql: xorm reverse mysql root:12345678@[ip:port]/xorm_test?charset=utf8 templates/goxorm mymysql: xorm reverse mymysql xorm_test2/root/ templates/goxorm postgres: xorm reverse postgres "dbname=xorm_test sslmode=disable" templates/goxorm mssql: xorm reverse mssql "server=test;user id=testid;password=testpwd;database=testdb" templates/goxorm ``` ## 自定义输出模版 默认模版输出 表明与字段名都为 下划线转大小写如 `im_msg -> imMsg`,如果想修改为下划线的大写 templates/goxorm/struct.go.tpl 把所有的`Mapper`转为`UpperTitle`