<commit_before>package model

import (
	"database/sql"

	"github.com/ViBiOh/funds/db"
)

// PerformanceByIsin retrieve Performance by isin
func PerformanceByIsin(isin string) (*Performance, error) {
	var (
		label string
		score float64
	)
	err := db.DB.QueryRow(`SELECT label, score FROM funds WHERE isin = $1`, isin).Scan(&label, &score)

	if err != nil {
		return nil, err
	}

	return &Performance{Isin: isin, Label: label, Score: score}, nil
}

// PerformanceWithScoreAbove retrieve Performance with score above a level
func PerformanceWithScoreAbove(minScore float64) ([]Performance, error) {
	rows, err := db.DB.Query(`SELECT isin, label, score FROM funds WHERE score >= $1`, minScore)

	if err != nil {
		return nil, err
	}

	var (
		performances []Performance
		isin         string
		label        string
		score        float64
	)

	for rows.Next() {
		if err := rows.Scan(&isin, &label, &score); err != nil {
			return nil, err
		}

		performances = append(performances, Performance{Isin: isin, Label: label, Score: score})
	}

	return performances, nil
}

// SavePerformance create or update given Performance
func SavePerformance(perf Performance, tx *sql.Tx) error {
	var err error
	var usedTx *sql.Tx

	defer func() {
		db.DeferTx(tx, usedTx, err)
	}()

	if usedTx, err = db.GetTx(tx); err != nil {
		return err
	}

	if _, err = PerformanceByIsin(perf.Isin); err != nil {
		err = createPerformance(perf, usedTx)
	} else {
		err = updatePerformance(perf, usedTx)
	}

	return err<commit_msg>Update performance_db.go<commit_after>package model

import (
	"database/sql"

	"github.com/ViBiOh/funds/db"
)

// PerformanceByIsin retrieve Performance by isin
func PerformanceByIsin(isin string) (*Performance, error) {
	var (
		label string
		score float64
	)
	err := db.DB.QueryRow(`SELECT label, score FROM funds WHERE isin = $1`, isin).Scan(&label, &score)

	if err != nil {
		return nil, err
	}

	return &Performance{Isin: isin, Label: label, Score: score}, nil
}

// PerformanceWithScoreAbove retrieve Performance with score above a level
func PerformanceWithScoreAbove(minScore float64) ([]Performance, error) {
	rows, err := db.DB.Query(`SELECT isin, label, score FROM funds WHERE score >= $1`, minScore)

	if err != nil {
		return nil, err
	}

	var (
		performances []Performance
		isin         string
		label        string
		score        float64
	)

	for rows.Next() {
		if err := rows.Scan(&isin, &label, &score); err != nil {
			return nil, err
		}

		performances = append(performances, Performance{Isin: isin, Label: label, Score: score})
	}

	return performances, nil
}

// SavePerformance create or update given Performance
func SavePerformance(perf Performance, tx *sql.Tx) error {
	var err error
	var usedTx *sql.Tx

	if usedTx, err = db.GetTx(tx); err != nil {
		return err
	}

	if usedTx != tx {
		defer func() {
			db.EndTx(usedTx, err)
		}()
	}

	if _, err = PerformanceByIsin(perf.Isin); err != nil {
		err = createPerformance(perf, usedTx)
	} else {
		err = updatePerformance(perf, usedTx)
	}

	return err
{'fraction_non_alphanumeric': 0.11807387862796834, 'fraction_numerical': 0.005277044854881266, 'mean_word_length': 3.6733436055469952, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '2096483', 'n_tokens_mistral': 1079, 'n_tokens_neox': 985, 'n_words': 308}