1 Star 0 Fork 0

zlibin / xorm

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
singlemapping.go 927 Bytes
一键复制 编辑 原始数据 按行查看 历史
lunny 提交于 2017-08-27 15:50 . refactor query functions (#689)
package main
import (
"fmt"
"os"
"github.com/go-xorm/xorm"
_ "github.com/mattn/go-sqlite3"
)
// User describes a user
type User struct {
Id int64
Name string
}
// LoginInfo describes a login information
type LoginInfo struct {
Id int64
IP string
UserId int64
// timestamp should be updated by database, so only allow get from db
TimeStamp string `xorm:"<-"`
// assume
Nonuse int `xorm:"->"`
}
func main() {
f := "singleMapping.db"
os.Remove(f)
orm, err := xorm.NewEngine("sqlite3", f)
if err != nil {
fmt.Println(err)
return
}
orm.ShowSQL(true)
err = orm.CreateTables(&User{}, &LoginInfo{})
if err != nil {
fmt.Println(err)
return
}
_, err = orm.Insert(&User{1, "xlw"}, &LoginInfo{1, "127.0.0.1", 1, "", 23})
if err != nil {
fmt.Println(err)
return
}
info := LoginInfo{}
_, err = orm.ID(1).Get(&info)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(info)
}
1
https://gitee.com/pri_nsaa/xorm.git
git@gitee.com:pri_nsaa/xorm.git
pri_nsaa
xorm
xorm
v0.6.4

搜索帮助

53164aa7 5694891 3bd8fe86 5694891