v2.0.-1 of newsriver
[rss-reader.git] / src / lib / db.ts
1 import Database from 'better-sqlite3';
2
3 const DB = 'feeds.db';
4
5 export const writer = new Database(DB, {
6   verbose: console.log
7 });
8 export const reader = new Database(DB, {
9   readonly: true,
10   verbose: console.log
11 });
12
13 export const query = {
14   addFeed: writer.prepare('insert into feedlist (id, title, link) values (?, ?, ?)'),
15   getFeedList: reader.prepare('select * from feedlist'),
16   getFeedInfo: reader.prepare('select * from feedlist where id = ?'),
17   getFeedItemInfo: reader.prepare('select * from feed_items where id = ? and feed_id = ?'),
18   addFeedItem: writer.prepare('insert into feed_items (id, feed_id, guid, title, link, pub_date, content) values (?, ?, ?, ?, ?, ?, ?)'),
19   getFeedsFor: reader.prepare('select id, feed_id, guid, title, link, pub_date,read_at from feed_items where feed_id = ? and pub_date > ? order by pub_date desc'),
20   readItem: writer.prepare('update feed_items set read_at = ? where id = ? and read_at = 0'),
21   getUnreadCountForAll: reader.prepare('select count(id) as unread, feed_id from feed_items where read_at = 0 group by feed_id')
22 };