<commit_before>package models

import (
	"database/sql"
	"github.com/BrandonRomano/serf"
	db "github.com/carrot/burrow/db/postgres"
	"time"
)

type Topic struct {
	serf.Worker `json:"-"`
	Id          int64     `json:"id"`
	Name        string    `json:"name"`
	CreatedAt   time.Time `json:"created_at"`
	UpdatedAt   time.Time `json:"updated_at"`
}

func NewTopic() *Topic {
	topic := new(Topic)
	return topic.Prep()
}

func (t *Topic) Prep() *Topic {
	t.Worker = &serf.PqWorker{
		Database: db.Get(),
		Config: serf.Configuration{
			TableName: "topics",
			Fields: []serf.Field{
				serf.Field{
					Pointer:          &t.Id,
					Name:             "id",
					UniqueIdentifier: true,
					IsSet: func(pointer interface{}) bool {
						pointerInt := *pointer.(*int64)
						return pointerInt != 0
					},
				},
				serf.Field{
					Pointer:    &t.Name,
					Name:       "name",
					Insertable: true,
					Updatable:  true,
				},
				serf.Field{
					Pointer: &t.CreatedAt,
					Name:    "created_at",
				},
				serf.Field{
					Pointer: &t.UpdatedAt,
					Name:    "updated_at",
				},
			},
		},
	}
	return t
}

func AllTopics(limit int64, offset int64) ([]Topic, error) {
	// Query DB
	database := db.Get()
	rows, err := database.Query("SELECT * FROM topics ORDER BY created_at LIMIT $1 OFFSET $2", limit, offset)
	if err != nil {
		return nil, err
	}
	defer rows.Close()

	// Converting rows into []Topic
	var topics []Topic = []Topic{}
	for rows.Next() {<commit_msg>Shrink prep method to mostly one-liners<commit_after>package models

import (
	"database/sql"
	"github.com/BrandonRomano/serf"
	db "github.com/carrot/burrow/db/postgres"
	"time"
)

type Topic struct {
	serf.Worker `json:"-"`
	Id          int64     `json:"id"`
	Name        string    `json:"name"`
	CreatedAt   time.Time `json:"created_at"`
	UpdatedAt   time.Time `json:"updated_at"`
}

func NewTopic() *Topic {
	topic := new(Topic)
	return topic.Prep()
}

func (t *Topic) Prep() *Topic {
	t.Worker = &serf.PqWorker{
		Database: db.Get(),
		Config: serf.Configuration{
			TableName: "topics",
			Fields: []serf.Field{
				serf.Field{Pointer: &t.Id, Name: "id", UniqueIdentifier: true,
					IsSet: func(pointer interface{}) bool {
						pointerInt := *pointer.(*int64)
						return pointerInt != 0
					},
				},
				serf.Field{Pointer: &t.Name, Name: "name", Insertable: true, Updatable: true},
				serf.Field{Pointer: &t.CreatedAt, Name: "created_at"},
				serf.Field{Pointer: &t.UpdatedAt, Name: "updated_at"},
			},
		},
	}
	return t
}

func AllTopics(limit int64, offset int64) ([]Topic, error) {
	// Query DB
	database := db.Get()
	rows, err := database.Query("SELECT * FROM topics ORDER BY created_at LIMIT $1 OFFSET $2", limit, offset)
	if err != nil {
		return nil, err
	}
	defer rows.Close()

	// Converting rows into []Topic
	var topics []Topic = []Topic{}
	for rows.Next() {
{'fraction_non_alphanumeric': 0.15546218487394958, 'fraction_numerical': 0.007703081232492998, 'mean_word_length': 2.957063711911357, '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': '4462888', 'n_tokens_mistral': 1189, 'n_tokens_neox': 1030, 'n_words': 255}