```
package main
import (
_ "github.com/mattn/go-sqlite3"
"log"
"xorm.io/xorm"
)
type User struct {
ID int64
Name string
Age int
Author string
Published int
}
var x *xorm.Engine
func main() {
x, err := xorm.NewEngine("sqlite3", "test.db")
err = x.Sync2(new(User))
if err != nil {
log.Fatalf("Fail to sync database: %v\n", err)
}
}
```
运行后查看数据库表
![Screenshot_1.jpg](https://static.studygolang.com/210316/db84d7a50d6bb7802c4b2d01e7763e65.jpg)
![image.png](https://static.studygolang.com/210319/598dbc15822ebe16ec3f6922d54b75b9.png)
https://gobook.io/read/gitea.com/xorm/manual-zh-CN/chapter-01/1.engine.html 更多有关 xorm 知识请参阅官方文档
#9
更多评论