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 1db.Table("users").Where("id",1).First()
// select id as uid,name,age from users where id=1 order by id desc limit 10db.Table("users").Where("id",1).Fields("id as uid,name,age").Order("id desc").Limit(10).Get()
// query stringdb.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:
goget-ugithub.com/gohouse/gorose- or for Glide:
glidegetgithub.com/gohouse/gorosepackage 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)varDbConfig=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)
},
},
}
funcmain() {
connection, err:=gorose.Open(DbConfig)
iferr!=nil {
fmt.Println(err)
return
}
// close DBdeferconnection.Close()
db:=connection.GetInstance()
res,err:=db.Table("users").First()
iferr!=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
