-
Notifications
You must be signed in to change notification settings - Fork 0
/
sql_stmts.go
95 lines (84 loc) · 2.71 KB
/
sql_stmts.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package skimmer
var (
// SQLCreateTables provides the statements that are use to create our tables
// It has two percent s, first is feed list name, second is datetime scheme
// was generated.
SQLCreateTables = `-- This is the scheme used for %s's SQLite 3 database
-- %s
CREATE TABLE IF NOT EXISTS channels (
link PRIMARY KEY,
title TEXT,
description TEXT,
feed_link TEXT,
links JSON,
updated DATETIME,
published DATETIME,
authors JSON,
language TEXT,
copyright TEXT,
generator TEXT,
categories JSON,
feed_type TEXT,
feed_version TEXT
);
CREATE TABLE IF NOT EXISTS items (
link PRIMARY KEY,
title TEXT,
description TEXT,
enclosures JSON DEFAULT '',
authors JSON,
updated DATETIME,
published DATETIME,
label TEXT,
tags JSON DEFAULT '',
channel TEXT,
retrieved DATETIME DEFAULT CURRENT_TIMESTAMP,
status TEXT DEFAULT '',
dc_ext JSON
);
`
// SQLResetChannels clear the channels talbe
SQLResetChannels = `DELETE FROM channels;`
// Update the channels in the skimmer file
SQLUpdateChannel = `REPLACE INTO channels (
link, title, description, feed_link, links,
updated, published,
authors, language, copyright, generator,
categories, feed_type, feed_version
) VALUES (
?, ?, ?, ?, ?,
?, ?,
?, ?, ?, ?,
?, ?, ?
);`
// Update a feed item in the items table
SQLUpdateItem = `INSERT INTO items (
link, title, description, enclosures, updated, published, label, authors, dc_ext, tags)
VALUES (
?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10
) ON CONFLICT (link) DO
UPDATE SET title = ?2, description = ?3, enclosures = ?4, updated = ?5,
published = ?6, label = ?7, tags = ?10;`
// Return link and title for Urls formatted output
SQLChannelsAsUrls = `SELECT link, title FROM channels ORDER BY link;`
// SQLItemCount returns a list of items in the items table
SQLItemCount = `SELECT COUNT(*) FROM items;`
// SQLItemStats returns a list of rows with totals per status
SQLItemStats = `SELECT IIF(status = '', 'unread', status) AS status, COUNT(*) FROM items GROUP BY status ORDER BY status`
// SQLDisplayItems returns a list of items in decending chronological order.
SQLDisplayItems = `SELECT link, title, description, enclosures,
updated, published, label, tags
FROM items
WHERE (description != "" OR title != "") AND status = ?
ORDER BY published DESC, updated DESC;`
SQLMarkItem = `UPDATE items SET status = ? WHERE link = ?;`
SQLTagItem = `UPDATE items SET tags = ? WHERE link = ?;`
// SQLPruneItems will prune our items table for all items that have easier
// a updated or publication date early than the timestamp provided.
SQLPruneItems = `DELETE FROM items
WHERE ((updated IS NULL AND published IS NULL) OR
(updated == '' AND published == '')
OR (updated < ? AND published < ?))
AND status = '';
`
)