xorm/examples/pool.go

47 lines
591 B
Go
Raw Normal View History

package main
import (
2014-01-07 09:33:27 +00:00
"fmt"
2014-01-25 02:31:07 +00:00
"os"
2014-01-07 09:33:27 +00:00
"github.com/lunny/xorm"
_ "github.com/mattn/go-sqlite3"
)
type User struct {
2014-01-07 09:33:27 +00:00
Id int64
Name string
}
func main() {
2014-01-07 09:33:27 +00:00
f := "pool.db"
os.Remove(f)
2014-01-25 02:31:07 +00:00
Orm, err := xorm.NewEngine("sqlite3", f)
2014-01-07 09:33:27 +00:00
if err != nil {
fmt.Println(err)
return
}
2014-01-25 02:31:07 +00:00
err = Orm.SetPool(xorm.NewSimpleConnectPool())
2014-01-07 09:33:27 +00:00
if err != nil {
fmt.Println(err)
return
}
2014-01-07 09:33:27 +00:00
Orm.ShowSQL = true
err = Orm.CreateTables(&User{})
if err != nil {
fmt.Println(err)
return
}
2014-01-07 09:33:27 +00:00
for i := 0; i < 10; i++ {
_, err = Orm.Get(&User{})
if err != nil {
fmt.Println(err)
break
}
2014-01-07 09:33:27 +00:00
}
}