1 import Database from 'better-sqlite3';
2 import { cli } from './migrate';
5 export const writer = new Database(DB, {
9 export function down() {
10 writer.prepare('drop table feed_items').run();
11 writer.prepare('drop table feedlist').run();
12 writer.prepare('drop table accounts').run();
15 export function up() {
17 create table accounts (
22 login_code_expires number
28 create table feedlist (
39 create table feed_items (
47 read_at number default 0
51 writer.prepare(`create unique index idx_account_feed on feedlist (account_id, link)`).run();
60 link: 'http://scripting.com/rss.xml',
64 title: 'Hacker News Front Page',
65 link: 'https://hnrss.org/frontpage'
70 link: 'https://xangelo.ca/posts/index.xml'
74 writer.prepare('insert into feedlist (id, title, link) values (?,?,?), (?, ?, ?), (?,?,?)').run(
75 feeds[0].id, feeds[0].title, feeds[0].link,
76 feeds[1].id, feeds[1].title, feeds[1].link,
77 feeds[2].id, feeds[2].title, feeds[2].link
80 const insert = writer.prepare(`insert into feed_items (id, feed_id, guid, title, link, pub_date, content) values (?, ?, ?, ?, ?, ?, ?)`);
81 const rss = new RSSParser();
82 feeds.forEach(async feed => {
83 const data = await rss.parse(feed.link);
84 data.items.forEach(item => {
86 insert.run(id, feed.id, item.guid, item.title, item.link, item.pubDate, item.content);
90 const args = cli(process.argv);
91 if(args.dir === 'up') {
94 else if(args.dir === 'down') {
98 console.error('Invalid dir');