<commit_before>package db

import (
	"fmt"

	"github.com/jinzhu/gorm"
	_ "github.com/lib/pq"
)

// Gorm is goroutines friendly, so you can create a global variable
// to keep the connection and use it everywhere in your project
var DB *gorm.DB

func init() {
	var err error
	db, err := gorm.Open("postgres", "user=postgres password=<PASSWORD> dbname=social sslmode=disable")
	if err != nil {
		panic(fmt.Sprintf("Got error when connect database, the error is '%v'", err))
	}
	// By default, table name is plural of struct type, you can use struct type as table name with:
	db.SingularTable(true)
	db.LogMode(true)
	DB = &db
}<commit_msg>Social: connect to postgres with mustinit function<commit_after>package db

import (
	"fmt"
	"socialapi/config"

	"github.com/jinzhu/gorm"
	_ "github.com/lib/pq"
)

// Gorm is goroutines friendly, so you can create a global variable
// to keep the connection and use it everywhere in your project
var DB *gorm.DB

func MustInit(conf *config.Config) *gorm.DB {

	// host=localhost port=5432 dbname=mydb connect_timeout=10
	connString := fmt.Sprintf(
		"host=%s port=%d user=%s password=%s dbname=%s sslmode=disable",
		conf.Postgres.Host,
		conf.Postgres.Port,
		conf.Postgres.Username,
		conf.Postgres.Password,
		conf.Postgres.DBName,
	)

	db, err := gorm.Open("postgres", connString)
	if err != nil {
		panic(fmt.Sprintf("Got error when connect database, the error is '%v'", err))
	}
	// By default, table name is plural of struct type, you can use struct type as table name with:
	db.SingularTable(true)
	db.LogMode(true)
	DB = &db
	return &db
}
{'fraction_non_alphanumeric': 0.1192429022082019, 'fraction_numerical': 0.0037854889589905363, 'mean_word_length': 4.14935064935065, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, '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': '5799069', 'n_tokens_mistral': 567, 'n_tokens_neox': 545, 'n_words': 178}