Beispiel #1
0
func CreateDatabaseConnection() *hood.Hood {
	username, _ := configuration.GetString(config.CONFIG_DB_USER)
	password, _ := configuration.GetString(config.CONFIG_DB_PASSWORD)
	scheme, _ := configuration.GetString(config.CONFIG_DB_SCHEME)
	connectionString := fmt.Sprintf("%v/%v/%v", scheme, username, password)

	hd, err := hood.Open("mymysql", connectionString)
	if err != nil {
		log.Error("DatabaseHelper", "CreateDatabaseConnection", "Unable to connect to database scheme '%s' with supplied credentials '%s'.\nError: %s", scheme, username, err.Error())
		return nil
	}

	return hd
}
Beispiel #2
0
func initializeDatabase() {
	log.Verbose("main", "initializeDatabase", "Creating database connection")

	username, _ := configuration.GetString(config.CONFIG_DB_USER)
	password, _ := configuration.GetString(config.CONFIG_DB_PASSWORD)
	scheme, _ := configuration.GetString(config.CONFIG_DB_SCHEME)
	connectionString := fmt.Sprintf("%v/%v/%v", scheme, username, password)

	hd, err := hood.Open("mymysql", connectionString)
	if err != nil {
		log.Error("main", "initializeDatabase", "Unable to connect to database scheme '%s' with supplied credentials '%s'", scheme, username)
		panic("Unable to connect to database")
	}
	hd.Log = DEBUG_SQL

	mainDatabase = hd

	log.Info("main", "initializeDatabase", "Database connection initialized: %s", connectionString)
}