Skip to content

Latest commit

History

16 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

gorb

Gorb is a package built upon Gorp and strongly inspired by Nap. It allows load balancing in a round robin style between master and replica databases.

Read queries are executed by replica.
Write queries are executed by the master. Use .MasterCanRead(true) to perform WRITE queries with the master and READ queries with the master and replica.

Gorp documentation

Usage

funcmain() {
dsns:="root:root@tcp(master:3306)/masterpwd;"dsns+="root:root@tcp(replica:3306)/replicapwd"b, err:=gorb.NewBalancer("mysql", gorp.MySQLDialect{"InnoDB", "utf8mb4"}	, dsns)
iferr!=nil{
panic(err)
}
err=b.Ping()
iferr!=nil{
panic(err)
}
// Master is used only for write queries, this is the default valueb.MasterCanRead(false) // Master is used for write and read queriesb.MasterCanRead(true)
count, err:=b.SelectInt("SELECT COUNT(*) FROM mytable")
iferr!=nil{
panic(err)
}
fmt.Println(count)
}

License

Gorb is licensed under the MIT License.

About

Gorb allows load balancing in a round robin style between master and slave databases.

Topics

Resources

Stars

14 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages