```
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)
```go
1. type User struct {
Id int64 //可以定义成Id
Name string
Age int
Author string
Published int
}
2 . type User struct {
Id int64 `xorm:"'id' "` //在xorm标签上面加一个'id'
Name string
Age int
Author string
Published int
}
```
试一下
#4
更多评论