<commit_before>package db

import (
	"database/sql"
	_ "github.com/go-sql-driver/mysql"
	"github.com/open-falcon/hbs/g"
	"log"
)

var DB *sql.DB

func Init() {
	err := dbInit(g.Config().Database)

	if err != nil {
		log.Fatalf("open db fail: %v", err)
	}

	DB.SetMaxIdleConns(g.Config().MaxIdle)
}

func dbInit(dsn string) (err error) {
	if DB, err = sql.Open("mysql", dsn)
		err != nil {
		return
	}

	if err = DB.Ping()
		err != nil {
		return
	}

	return
}

// Convenient IoC for transaction processing
func inTx(txCallback func(tx *sql.Tx) error) (err error) {
	var tx *sql.Tx

	if tx, err = DB.Begin()
		err != nil {<commit_msg>[OWL-277] Fix ambiguous message while connecting to database<commit_after>package db

import (
	"database/sql"
	"fmt"
	_ "github.com/go-sql-driver/mysql"
	"github.com/open-falcon/hbs/g"
	"log"
)

var DB *sql.DB

func Init() {
	err := dbInit(g.Config().Database)

	if err != nil {
		log.Fatalln(err)
	}

	DB.SetMaxIdleConns(g.Config().MaxIdle)
}

func dbInit(dsn string) (err error) {
	if DB, err = sql.Open("mysql", dsn)
		err != nil {
		return fmt.Errorf("Open DB error: %v", err)
	}

	if err = DB.Ping()
		err != nil {
		return fmt.Errorf("Ping DB error: %v", err)
	}

	return
}

// Convenient IoC for transaction processing
func inTx(txCallback func(tx *sql.Tx) error) (err error) {
	var tx *sql.Tx

	if tx, err = DB.Begin()
		err != nil {
{'fraction_non_alphanumeric': 0.16290909090909092, 'fraction_numerical': 0.002181818181818182, 'mean_word_length': 3.3406940063091484, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6084483', 'n_tokens_mistral': 591, 'n_tokens_neox': 563, 'n_words': 142}