https://gohouse.github.io/gorose
Gorose, a mini database ORM for golang, which inspired by the famous php framwork laravle's eloquent. It will be friendly for php developers and python or ruby developers.
Currently provides five major database drivers:
- mysql : https://github.com/go-sql-driver/mysql
- sqlite3 : https://github.com/mattn/go-sqlite3
- postgres : https://github.com/lib/pq
- oracle : https://github.com/mattn/go-oci8
- mssql : https://github.com/denisenkom/go-mssqldb
// select * from users where id=1 limit 1
db.Table("users").Where("id",1).First()
// select id as uid,name,age from users where id=1 order by id desc limit 10
db.Table("users").Where("id",1).Fields("id as uid,name,age").Order("id desc").Limit(10).Get()
// query string
db.Query("select * from user limit 10")
db.Execute("update users set name='fizzday' where id=?", 1)
- Chain Operation
- Connection Pool
- Golang 1.6+
- Glide (optional, dependencies management for golang)
- standard:
go get -u github.com/gohouse/gorose
- or for Glide:
glide get github.com/gohouse/gorose
package main
import (
"github.com/gohouse/gorose" //import Gorose
_ "github.com/go-sql-driver/mysql" //import DB driver
"fmt"
)
// DB Config.(Recommend to use configuration file to import)
var DbConfig = map[string]interface{}{
// Default database configuration
"Default": "mysql_dev",
// (Connection pool) Max open connections, default value 0 means unlimit.
"SetMaxOpenConns": 300,
// (Connection pool) Max idle connections, default value is 1.
"SetMaxIdleConns": 10,
// Define the database configuration character "mysql_dev".
"Connections":map[string]map[string]string{
"mysql_dev": map[string]string{
"host": "192.168.200.248",
"username": "gcore",
"password": "gcore",
"port": "3306",
"database": "test",
"charset": "utf8",
"protocol": "tcp",
"prefix": "", // Table prefix
"driver": "mysql", // Database driver(mysql,sqlite,postgres,oracle,mssql)
},
},
}
func main() {
connection, err := gorose.Open(DbConfig)
if err != nil {
fmt.Println(err)
return
}
// close DB
defer connection.Close()
db := connection.GetInstance()
res,err := db.Table("users").First()
if err != nil {
fmt.Println(err)
return
}
fmt.Println(res)
}
For more usage, please read the Documentation.
MIT
0.9.0
- new seperate db instance
0.8.2
- improve config format, new config format support file config like json/toml etc.
0.8.1
- improve multi connection and nulti transation
0.8.0
- add connection pool
- adjust dir for open source standard
- add glide version control
- translate for english and chinese docment