简介
gorose(go orm), 一个小巧强悍的go语言数据库操作orm, 灵感来源于laravel的数据库操作orm, 也就是eloquent, php、python、ruby开发者, 都会喜欢上这个orm的操作方式, 主要是链式操作比较风骚
github
先睹为快
db.Table("tablename").First()
db.Table("tablename").Distinct().Where("id", ">", 5).Get()
db.Table("tablename").Fields("id, name, age, job").Group("job").Limit(10).Offset(20).Order("id desc").Get()
安装
- 安装 gorose
go get github.com/gohouse/gorose
配置和示例
- 多个数据库连接配置
import "github.com/gohouse/gorose"
var dbConfig = map[string]map[string]string {
"mysql": {
"host": "localhost",
"username": "root",
"password": "",
"port": "3306",
"database": "test",
"charset": "utf8",
"protocol": "tcp",
},
"mysql_dev": {
"host": "localhost",
"username": "root",
"password": "",
"port": "3306",
"database": "gorose",
"charset": "utf8",
"protocol": "tcp",
},
}
gorose.Open(dbConfig, "mysql")
var db gorose.Database
func main() {
res := db.Table("users").First()
fmt.Println(res)
}
- 简单的但数据库配置
gorose.Open(map[string]string {
"host": "localhost",
"username": "root",
"password": "",
"port":