<commit_before>package model

import (
	"database/sql"
	"log"
	"strings"
	"time"

	"github.com/SlyMarbo/rss"
	_ "github.com/mattn/go-sqlite3"
)

const (
	sqlCreateFeed = `CREATE TABLE IF NOT EXISTS feed(
	id      INTEGER PRIMARY KEY,
	title   TEXT NOT NULL,
	url     TEXT NOT NULL,
	filters TEXT,
	UNIQUE (url, filters));`
	sqlCreatePost = `CREATE TABLE IF NOT EXISTS post(
	id      INTEGER PRIMARY KEY,
	feed    INTEGER,
	url     TEXT NOT NULL,
	title   TEXT NOT NULL,
	summary TEXT,
	content TEXT,
	read    INTEGER,
	date    DATETIME DEFAULT CURRENT_TIMESTAMP,
	FOREIGN KEY(feed) REFERENCES feed(id),
	UNIQUE (url) ON CONFLICT IGNORE
	);`
	sqlNewFeed        = `INSERT INTO feed(url, title, filters) VALUES(?, ?, ?);`
	sqlNewPost        = `INSERT INTO post(url, title, summary, content, read, feed) VALUES(?, ?, ?, ?, 0, ?);`
	sqlGetUnreadPosts = `SELECT post.id, post.url, post.title, post.summary, post.content, post.date, feed.title
	FROM post, feed WHERE read = 0 AND feed.id=post.feed ORDER BY post.date DESC;`
	sqlGetAllFeeds = `SELECT id, title, url, filters FROM feed;`
	sqlMarkAllRead = `UPDATE post SET read = 1 WHERE read = 0 AND id <= ?;`
)

type RedMeFeed struct {
	id      int64
	Filters []string
	Feed    *rss.Feed
}

type RedMePost struct {
	Id        int
	Item      *rss.Item
	FeedTitle string
	Date      string
}

func NewRedMeFeed(url string, filters []string) (*RedMeFeed, error) {
	feed := new(RedMeFeed)
	openedFeed, err := rss.Fetch(url)
	if err != nil {
		return nil, err
	}
	feed.Feed = openedFeed

	feed.Filters = filters
	return feed, nil
}

type RedMeDB struct {<commit_msg>fix the order of posts incoming at the same time<commit_after>package model

import (
	"database/sql"
	"log"
	"strings"
	"time"

	"github.com/SlyMarbo/rss"
	_ "github.com/mattn/go-sqlite3"
)

const (
	sqlCreateFeed = `CREATE TABLE IF NOT EXISTS feed(
	id      INTEGER PRIMARY KEY,
	title   TEXT NOT NULL,
	url     TEXT NOT NULL,
	filters TEXT,
	UNIQUE (url, filters));`
	sqlCreatePost = `CREATE TABLE IF NOT EXISTS post(
	id      INTEGER PRIMARY KEY,
	feed    INTEGER,
	url     TEXT NOT NULL,
	title   TEXT NOT NULL,
	summary TEXT,
	content TEXT,
	read    INTEGER,
	date    DATETIME DEFAULT CURRENT_TIMESTAMP,
	FOREIGN KEY(feed) REFERENCES feed(id),
	UNIQUE (url) ON CONFLICT IGNORE
	);`
	sqlNewFeed        = `INSERT INTO feed(url, title, filters) VALUES(?, ?, ?);`
	sqlNewPost        = `INSERT INTO post(url, title, summary, content, read, feed) VALUES(?, ?, ?, ?, 0, ?);`
	sqlGetUnreadPosts = `SELECT post.id, post.url, post.title, post.summary, post.content, post.date, feed.title
	FROM post, feed WHERE read = 0 AND feed.id=post.feed ORDER BY post.date DESC, post.id ASC;`
	sqlGetAllFeeds = `SELECT id, title, url, filters FROM feed;`
	sqlMarkAllRead = `UPDATE post SET read = 1 WHERE read = 0 AND id <= ?;`
)

type RedMeFeed struct {
	id      int64
	Filters []string
	Feed    *rss.Feed
}

type RedMePost struct {
	Id        int
	Item      *rss.Item
	FeedTitle string
	Date      string
}

func NewRedMeFeed(url string, filters []string) (*RedMeFeed, error) {
	feed := new(RedMeFeed)
	openedFeed, err := rss.Fetch(url)
	if err != nil {
		return nil, err
	}
	feed.Feed = openedFeed

	feed.Filters = filters
	return feed, nil
}

type RedMeDB struct {
{'fraction_non_alphanumeric': 0.11124769514443761, 'fraction_numerical': 0.0043023970497848806, 'mean_word_length': 3.3927125506072873, 'pattern_counts': {'":': 0, '<': 5, '<?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': '176656', 'n_tokens_mistral': 1222, 'n_tokens_neox': 1172, 'n_words': 371}