examples/find/find.go
2020-02-26 23:12:13 +08:00

52 lines
708 B
Go

package main
import (
"fmt"
"os"
"time"
_ "github.com/mattn/go-sqlite3"
"xorm.io/xorm"
)
// User describes a user
type User struct {
Id int64
Name string
Created time.Time `xorm:"created"`
Updated time.Time `xorm:"updated"`
}
func main() {
f := "conversion.db"
os.Remove(f)
orm, err := xorm.NewEngine("sqlite3", f)
if err != nil {
fmt.Println(err)
return
}
orm.ShowSQL(true)
err = orm.CreateTables(&User{})
if err != nil {
fmt.Println(err)
return
}
_, err = orm.Insert(&User{Id: 1, Name: "xlw"})
if err != nil {
fmt.Println(err)
return
}
users := make([]User, 0)
err = orm.Find(&users)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(users)
}