<commit_before>package model

import (
    "database/sql"
)

type DatabaseWordSource struct {
    db *DB
}

func RandomWord(source *DatabaseWordSource) (*Word, error) {
    rows, err := source.db.Query("SELECT * FROM words ORDER BY random() LIMIT 1")

    if err != nil {
        return nil, err
    }

    var word *Word = new(Word)
    rows.Next()
    err = rows.scan(&Word.Id, &Word.Word)

    return word, err
}

func AllWords(source *DatabaseWordSource) ([]Word, error) {
    rows, err := source.db.Query("SELECT * FROM words")

    if err != nil {
        return nil, err
    }

    var words []Word

    for rows.Next() {
        var word *Word = new(Word)
        err = rows.Scan(&word.Id, &word.Word)
        if err != nil {
            return nil, err<commit_msg>constructor for db word source<commit_after>package model

import (
    "database/sql"
)

type DatabaseWordSource struct {
    db *DB
}

func NewDatabaseWordSource(db) *DatabaseWordSource {
    source := new(DatabaseWordSource)
    source.db = db
    return source
}

func RandomWord(source *DatabaseWordSource) (*Word, error) {
    rows, err := source.db.Query("SELECT * FROM words ORDER BY random() LIMIT 1")

    if err != nil {
        return nil, err
    }

    var word *Word = new(Word)
    rows.Next()
    err = rows.scan(&Word.Id, &Word.Word)

    return word, err
}

func AllWords(source *DatabaseWordSource) ([]Word, error) {
    rows, err := source.db.Query("SELECT * FROM words")

    if err != nil {
        return nil, err
    }

    var words []Word

    for rows.Next() {
        var word *Word = new(Word)
        err = rows.Scan(&word.Id, &word.Word)
        if err != nil {
            return nil, err
{'fraction_non_alphanumeric': 0.1257378984651712, 'fraction_numerical': 0.0011806375442739079, 'mean_word_length': 2.4591836734693877, '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': '5861133', 'n_tokens_mistral': 549, 'n_tokens_neox': 532, 'n_words': 162}