<commit_before>package feedloggr2

import (
	"github.com/jinzhu/gorm"
	rss "github.com/jteeuwen/go-pkg-rss"
	_ "github.com/mattn/go-sqlite3"
)

type Datastore interface {
	GetItems(feed_url string) ([]*FeedItem, error)

	ProcessChannels(feed *rss.Feed, channels []*rss.Channel)
	ProcessItems(feed *rss.Feed, ch *rss.Channel, items []*rss.Item)
}

type DB struct {
	*gorm.DB
}

func OpenSqliteDB(args ...interface{}) (*DB, error) {
	// TODO: get rid of gorm
	db, e := gorm.Open("sqlite3", args...)
	if e != nil {
		return nil, e
	}
	db.AutoMigrate(&FeedItem{})
	return &DB{&db}, nil
}

func (db *DB) SaveItems(items []*FeedItem) {
	tx := db.Begin()
	tx.LogMode(false) // Don't show errors when UNIQUE fails

	for _, i := range items {
		tx.Create(i)
	}

	tx.Commit()
}

func (db *DB) GetItems(feed_url string) []*FeedItem {
	var items []*FeedItem
	// TODO: fix the feed url thing
	db.Order("date desc, title").Where(
		"feed = ? AND date(date) = date(?)", feed_url, Now(),
	).Find(&items)
	return items
}<commit_msg>Sort feed items by title first, then date.<commit_after>package feedloggr2

import (
	"github.com/jinzhu/gorm"
	rss "github.com/jteeuwen/go-pkg-rss"
	_ "github.com/mattn/go-sqlite3"
)

type Datastore interface {
	GetItems(feed_url string) ([]*FeedItem, error)

	ProcessChannels(feed *rss.Feed, channels []*rss.Channel)
	ProcessItems(feed *rss.Feed, ch *rss.Channel, items []*rss.Item)
}

type DB struct {
	*gorm.DB
}

func OpenSqliteDB(args ...interface{}) (*DB, error) {
	// TODO: get rid of gorm
	db, e := gorm.Open("sqlite3", args...)
	if e != nil {
		return nil, e
	}
	db.AutoMigrate(&FeedItem{})
	return &DB{&db}, nil
}

func (db *DB) SaveItems(items []*FeedItem) {
	tx := db.Begin()
	tx.LogMode(false) // Don't show errors when UNIQUE fails

	for _, i := range items {
		tx.Create(i)
	}

	tx.Commit()
}

func (db *DB) GetItems(feed_url string) []*FeedItem {
	var items []*FeedItem
	// TODO: fix the feed url thing
	db.Order("title, date desc").Where(
		"feed = ? AND date(date) = date(?)", feed_url, Now(),
	).Find(&items)
	return items
}
{'fraction_non_alphanumeric': 0.17387081107333657, 'fraction_numerical': 0.0029140359397765905, 'mean_word_length': 3.963855421686747, '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': '7499996', 'n_tokens_mistral': 825, 'n_tokens_neox': 809, 'n_words': 205}