Gorm is a complete ORM for Go. Kwiscale/Gorm is a simple wrapper to be able to implement database in framework.
In your main package, simply import and initialize database connection.
package main
import (
"gopkg.in/kwiscale/framework.v1"
"gopkg.in/kwiscale/orm.v1"
_ "gopkg.in/kwiscale/orm.v1/dialects/sqlite"
)
// User is a simple orm.Model
type User struct {
orm.Model
Name string
Age int
}
func init() {
orm.Initialize("sqlite", "./test.db")
db := orm.Get()
defer db.Close()
// Create table, update if needed
db.AutoMigrate(&User{})
}
Then, you may insert, delete, find, and so on.
user := User{
Name: "Foo",
Age: 42,
}
db := orm.Get()
defer db.Close()
db.Create(&user)
// find a user and set it on
// "res" structure
res:=User{}
db.First(&res, &User{Name:"Foo"})
To get more information on requests, see Gorm documentation