Skip to content
/ gorose Public
forked from gohouse/gorose

Gorose(go orm), a mini database ORM for golang, which inspired by the famous php framwork laravle's eloquent. It will be friendly for php developer and python or ruby developer. Currently provides five major database drivers: mysql,sqlite3,postgres,oracle,mssql.

License

Notifications You must be signed in to change notification settings

wni0812/gorose

 
 

Repository files navigation

Gorose ORM

GoDoc Go Report Card Gitter gorose-orm

Official Website | (官方网站)

https://gohouse.github.io/gorose

Documentation

What is 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:

Quick Preview

// 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)

Features

  • Chain Operation
  • Connection Pool

Requirement

  • Golang 1.6+
  • Glide (optional, dependencies management for golang)

Installation

  • standard:
go get -u github.com/gohouse/gorose
glide get github.com/gohouse/gorose

Base Usage

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(db.LastSql)
	fmt.Println(res)
}

For more usage, please read the Documentation.

Contribution

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(改进源码)

release notes

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

About

Gorose(go orm), a mini database ORM for golang, which inspired by the famous php framwork laravle's eloquent. It will be friendly for php developer and python or ruby developer. Currently provides five major database drivers: mysql,sqlite3,postgres,oracle,mssql.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages

  • Go 100.0%