# Gorose ORM
[](https://godoc.org/github.com/gohouse/gorose)
[](https://goreportcard.com/report/github.com/gohouse/gorose)
[](https://gitter.im/gorose/wechat)
<a target="_blank" href="https://jq.qq.com/?_wv=1027&k=5JJOG9E">
<img border="0" src="http://pub.idqqimg.com/wpa/images/group.png" alt="gorose-orm" title="gorose-orm"></a>
### source Code
[github.com/gohouse/gorose](https://github.com/gohouse/gorose)
### What is Gorose?
Gorose, a mini database ORM for golang, which inspired by the famous php framwork laravel'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>
### Quick Preview(概覽)
```go
type users struct {
Name string
Age int `orm:"age"`
}
// select * from users where id=1 limit 1
var user users // 單條數據
var users []users // 多條數據
// struct模式
db.Table(&user).Select()
db.Table(&users).Where("id",1).Limit(10).Select()
// 也可以使用非struct兼容模式
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(&user).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)
```
### Features(特點)
- Chain Operation (鏈式操作)
- Connection Pool (連接池)
- struct/string compatible (兼容支持struct和string)
- read/write separation cluster (讀寫分離集群)
- 大量數據分片處理
- 一鍵事務
- 擴展開發更友好(非侵入式 自由添加配置解析器, 驅動解析器)
### Installation
- standard:
```go
go get -u github.com/gohouse/gorose
```
### Base Usage
```go
package main
import (
"github.com/gohouse/gorose"
_ "github.com/gohouse/gorose/driver/mysql"
"fmt"
)
type Users struct {
Name string
Age int `orm:"age"`
}
// DB Config.(Recommend to use configuration file to import)
var dbConfig1 = &gorose.DbConfigSingle {
Driver: "mysql", // 驅動: mysql/sqlite/oracle/mssql/postgres
EnableQueryLog: true, // 是否開啟sql日志
SetMaxOpenConns: 0, // (連接池)最大打開的連接數,默認值為0表示不限制
SetMaxIdleConns: 0, // (連接池)閑置的連接數
Prefix: "", // 表前綴
Dsn: "root:root@tcp(localhost:3306)/test?charset=utf8", // 數據庫鏈接
}
func main() {
connection, err := gorose.Open(dbConfig1)
if err != nil {
fmt.Println(err)
return
}
db := connection.NewSession()
// 查詢一條數據
var user Users
err2 := db.Table(&user).Select()
if err2 != nil {
fmt.Println(err2)
return
}
fmt.Println(db.LastSql)
fmt.Println(user)
// 查詢多條數據
var users []Users
err3 := db.Table(&users).Limit(3).Select()
if err3 != nil {
fmt.Println(err3)
return
}
fmt.Println(db.LastSql)
fmt.Println(users)
}
```
For more usage, please read the Documentation.
### 查看版本號
```go
fmt.Println(gorose.VERSION)
fmt.Println(gorose.VERSION_NO)
```
### Contribution
- [Issues](https://github.com/gohouse/gorose/issues)
- [Pull requests](https://github.com/gohouse/gorose/pulls)
### Contributors
- `fizzday` : Initiator(發起人)
- `wuyumin` : pursuing the open source standard(推行開源標準規劃)
- `holdno` : official website builder(官方網站搭建)
- `LazyNeo` : bug fix and improve source code(bug修復和改進源碼)
- `dmhome` : improve source code(改進源碼)
### 更新說明
- 目錄調整: 更加符合協作開發的目錄
- 架構調整: 開放式架構, 驅動, 解析器, 構造器, 全部分離, 自由定義
- 支持struct
- 讀寫分離集群支持
### release notes
> 1.0.0
- 全新開發式自由架構,自由擴展驅動,配置文件, struct支持, 讀寫分離集群支持
> 0.9.2
- new connection pack for supporting multi connection
> 0.9.1
- replace the insert result lastInsertId with rowsAffected as default
> 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
### License
MIT