iris-xorm开始
- Mysql: github.com/go-sql-driver/mysql
- MyMysql: github.com/ziutek/mymysql/godrv
- Postgres: github.com/lib/pq
- Tidb: github.com/pingcap/tidb
- SQLite: github.com/mattn/go-sqlite3
- MsSql: github.com/denisenkom/go-mssqldb
- Oracle: github.com/mattn/go-oci8 (experiment)
下面的示例,实现了xorm的初始化,同步表结构
基于Mysql驱动的数据库连接字符串:
[username[:password]@][protocol[(address)]]/dbname[?param1=value1&...¶mN=valueN]
package main
import (
"fmt"
"time"
_ "github.com/go-sql-driver/mysql"
"xorm.io/xorm"
)
type App struct {
Id int64 `xorm:"autoincr pk notnull 'id' comment('ID')"`
Code string `xorm:"varchar(200) notnull 'code' default('') index(code) comment('编码')"`
Name string `xorm:"varchar(200) notnull 'name' default('') index(name) comment('名称')"`
Status int `xorm:"int notnull 'status' default(1) comment('状态')"`
DelStatus int `xorm:"int notnull 'del_status' default(0) comment('删除状态')"`
CreateTime time.Time `xorm:"datetime notnull 'create_time' comment('创建时间')"`
UpdateTime time.Time `xorm:"datetime notnull 'update_time' comment('更新时间')"`
}
func main() {
engine, err := xorm.NewEngine("mysql", "root:password@tcp(localhost:3306)/easynet_cn_app?charset=utf8")
if err != nil {
fmt.Println(err)
return
}
engine.ShowSQL(true)
err = engine.Sync2(new(App))
if err != nil {
fmt.Println(err)
return
}
}
本文标题:iris-xorm开始
本文链接:https://www.haomeiwen.com/subject/rlmsfhtx.html
网友评论