YohGo database manages the database connection of an application so that the database connection is wrapped in a configurable container that can be utilised in various packages that require a connection to a database.
- Go (1.5+)
- MySQL (4.1+)
- Lightweight and fast
- Native Go implementation
- Currently only supports
mysql
andgorm mysql
Simply install the package to your $GOPATH with the go tool from shell:
$ go get github.com/yohgo/database
Make sure Git is installed on your machine and in your system's PATH
.
YohGo Database is a Go database container that. You only need to import the YohGo database package of choice and can use the full database/sql
API then.
Example of using the gorm
package:
import (
"github.com/yohgo/database/gorm"
)
// Configure database connection
database, err := gorm.NewDatabase("DB_USER", "DB_PASS", "DB_HOST", "DB_PORT", "DB_NAME")
// Check if connection failed
if err != nil {
log.Fatal("Failed to connect to database")
}
// Always ensure to close the connection
defer database.Close()
Example of using the mysql
package:
import (
"github.com/yohgo/database/mysql"
)
// Configure database connection
database, err := mysql.NewDatabase("DB_USER", "DB_PASS", "DB_HOST", "DB_PORT", "DB_NAME")
// Check if connection failed
if err != nil {
log.Fatal("Failed to connect to database")
}
// Always ensure to close the connection
defer database.Close()