<commit_before>package dbutils

import "database/sql"

type InterfaceScanner struct {
	Name  string
	Value interface{}
}

// InterfaceScanner implements the sql.Scan interface
func (s *InterfaceScanner) Scan(src interface{}) error {
	s.Value = src
	return nil
}

// Convert a row to a map. Expects rows.Next() to have been already called.
func ConvertRowToMap(r *sql.Rows) (map[string]interface{}, error) {
	result := make(map[string]interface{})

	cols, err := r.Columns()
	if err != nil {
		return result, err
	}

	vals := make([]interface{}, len(cols))
	for i := range vals {
		vals[i] = &InterfaceScanner{Name: cols[i]}
	}

	r.Scan(vals...)

	for i := range vals {
		scanner := *(vals[i].(*InterfaceScanner))
		result[scanner.Name] = scanner.Value
	}

	return result, nil
}
<commit_msg>Switching to map[string]string because github.com/go-sql-driver/mysql doesn't play nicely with interfaces.<commit_after>package dbutils

import (
	"database/sql"
	"fmt"
)

type InterfaceScanner struct {
	Name  string
	Value string
}

// InterfaceScanner implements the sql.Scan interface
func (s *InterfaceScanner) Scan(src interface{}) error {
	s.Value = fmt.Sprintf("%s", src)
	return nil
}

// Convert a row to a map. Expects rows.Next() to have been already called.
func ConvertRowToMap(r *sql.Rows) (map[string]string, error) {
	result := make(map[string]string)

	cols, err := r.Columns()
	if err != nil {
		return result, err
	}

	vals := make([]interface{}, len(cols))
	for i := range vals {
		vals[i] = &InterfaceScanner{Name: cols[i]}
	}

	r.Scan(vals...)

	for i := range vals {
		scanner := *(vals[i].(*InterfaceScanner))
		result[scanner.Name] = scanner.Value
	}

	return result, nil
}

{'fraction_non_alphanumeric': 0.14328004736530492, 'fraction_numerical': 0.0, 'mean_word_length': 4.13677811550152, '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': '440772', 'n_tokens_mistral': 597, 'n_tokens_neox': 569, 'n_words': 165}