<commit_before>package utils

import (
	"database/sql"
	"fmt"
	_ "github.com/go-sql-driver/mysql"

	"github.com/techjanitor/pram-post/config"
)

var db *sql.DB

// NewDb initializes a connection to MySQL and tries to connect.
func NewDb() {
	var err error

	db, err = sql.Open("mysql", fmt.Sprintf("%s:%s@%s(%s)/%s",
		config.Settings.Database.User,
		config.Settings.Database.Password,
		config.Settings.Database.Proto,
		config.Settings.Database.Host,
		config.Settings.Database.Database,
	))
	if err != nil {
		panic(err)
	}

	err = db.Ping()
	if err != nil {
		panic(err)
	}

	db.SetMaxIdleConns(config.Settings.Database.MaxIdle)
	db.SetMaxOpenConns(config.Settings.Database.MaxConnections)
}

// GetDb returns a connection to MySQL
func GetDb() (*sql.DB, error) {
	return db, nil
}

// GetTransaction will return a transaction
func GetTransaction() (*sql.Tx, error) {
	tx, err := db.Begin()
	if err != nil {
		panic(err)
	}

	return tx, err
}

// Check a bool in the database
func GetBool(column, table, row string, id uint) (boolean bool) {
	var boolean bool

	// Check if thread is closed and get the total amount of posts
	err := db.QueryRow("SELECT ? FROM ? WHERE ? = ?", column, table, row, id).Scan(&boolean)
	if err != nil {
		return false
	}

	return

}

// Set a bool in the database
func SetBool(table, column, row string, boolean bool, id uint) (err error) {<commit_msg>db bool functions<commit_after>package utils

import (
	"database/sql"
	"fmt"
	_ "github.com/go-sql-driver/mysql"

	"github.com/techjanitor/pram-post/config"
)

var db *sql.DB

// NewDb initializes a connection to MySQL and tries to connect.
func NewDb() {
	var err error

	db, err = sql.Open("mysql", fmt.Sprintf("%s:%s@%s(%s)/%s",
		config.Settings.Database.User,
		config.Settings.Database.Password,
		config.Settings.Database.Proto,
		config.Settings.Database.Host,
		config.Settings.Database.Database,
	))
	if err != nil {
		panic(err)
	}

	err = db.Ping()
	if err != nil {
		panic(err)
	}

	db.SetMaxIdleConns(config.Settings.Database.MaxIdle)
	db.SetMaxOpenConns(config.Settings.Database.MaxConnections)
}

// GetDb returns a connection to MySQL
func GetDb() (*sql.DB, error) {
	return db, nil
}

// GetTransaction will return a transaction
func GetTransaction() (*sql.Tx, error) {
	tx, err := db.Begin()
	if err != nil {
		panic(err)
	}

	return tx, err
}

// Check a bool in the database
func GetBool(column, table, row string, id uint) (boolean bool) {

	// Check if thread is closed and get the total amount of posts
	err := db.QueryRow("SELECT ? FROM ? WHERE ? = ?", column, table, row, id).Scan(&boolean)
	if err != nil {
		return false
	}

	return

}

// Set a bool in the database
func SetBool(table, column, row string, boolean bool, id uint) (err error) {
{'fraction_non_alphanumeric': 0.13705583756345177, 'fraction_numerical': 0.0, 'mean_word_length': 3.7162393162393164, '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': '5950200', 'n_tokens_mistral': 994, 'n_tokens_neox': 959, 'n_words': 277}