-
Notifications
You must be signed in to change notification settings - Fork 211
Expand file tree
/
Copy pathservice.sq
More file actions
134 lines (118 loc) · 2.83 KB
/
Copy pathservice.sq
File metadata and controls
134 lines (118 loc) · 2.83 KB
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
import kotlin.time.Instant;
import kotlin.Boolean;
import kotlin.Float;
import kotlin.Int;
-- Delete old tables db
DROP TABLE IF EXISTS items;
CREATE TABLE IF NOT EXISTS catchUpDbItem (
id INTEGER NOT NULL PRIMARY KEY,
title TEXT NOT NULL,
description TEXT,
timestamp INTEGER AS Instant,
scoreChar TEXT,
score INTEGER AS Int,
tag TEXT,
tagHintColor INTEGER AS Int,
author TEXT,
source TEXT,
itemClickUrl TEXT,
detailKey TEXT,
serviceId TEXT,
indexInResponse INTEGER AS Int,
contentType TEXT,
imagePreviewUrl TEXT,
-- Image info
imageUrl TEXT,
imageDetailUrl TEXT,
imageAnimatable INTEGER AS Boolean,
imageSourceUrl TEXT,
imageBestSizeX INTEGER AS Int,
imageBestSizeY INTEGER AS Int,
imageAspectRatio REAL AS Float,
imageImageId TEXT,
imageColor TEXT,
imageBlurHash TEXT,
-- Mark info
markText TEXT,
markTextPrefix TEXT,
-- By default, the icon used is a comment icon if this is null
markType TEXT,
markClickUrl TEXT,
markIconTintColor INTEGER AS Int,
markFormatTextAsCount INTEGER AS Boolean
);
CREATE TABLE IF NOT EXISTS remoteKeys (
serviceId TEXT NOT NULL PRIMARY KEY COLLATE NOCASE,
nextPageKey TEXT
);
CREATE TABLE IF NOT EXISTS opJournal (
timestamp INTEGER NOT NULL PRIMARY KEY,
serviceId TEXT NOT NULL,
operation TEXT NOT NULL
);
-- Remote key queries
insertRemoteKey:
INSERT OR REPLACE INTO remoteKeys (serviceId, nextPageKey) VALUES (?, ?);
remoteKeyByItem:
SELECT * FROM remoteKeys WHERE serviceId = ?;
deleteRemoteKeyByService:
DELETE FROM remoteKeys WHERE serviceId = ?;
-- service queries
-- TODO there's gotta be an easier way?
insert:
INSERT OR REPLACE INTO catchUpDbItem (
id,
title,
description,
timestamp,
scoreChar,
score,
tag,
tagHintColor,
author,
source,
itemClickUrl,
detailKey,
serviceId,
indexInResponse,
contentType,
imagePreviewUrl,
imageUrl,
imageDetailUrl,
imageAnimatable,
imageSourceUrl,
imageBestSizeX,
imageBestSizeY,
imageAspectRatio,
imageImageId,
imageColor,
imageBlurHash,
markText,
markTextPrefix,
markType,
markClickUrl,
markIconTintColor,
markFormatTextAsCount
) VALUES ?;
countItems:
SELECT count(*) AS Int FROM catchUpDbItem WHERE serviceId = ?;
getItem:
SELECT * FROM catchUpDbItem WHERE id = ?;
itemsByService:
SELECT *
FROM catchUpDbItem
WHERE catchUpDbItem.serviceId=?
ORDER BY indexInResponse ASC
-- Used for PagingSource<Int, CatchUpItem>
LIMIT ? OFFSET ?;
deleteItemsByService:
DELETE FROM catchUpDbItem WHERE serviceId = ?;
getNextIndexInService:
SELECT MAX(indexInResponse) + 1 FROM catchUpDbItem WHERE serviceId = ?;
-- Operations queries
lastOperation:
SELECT * FROM opJournal WHERE serviceId = ? ORDER BY timestamp DESC LIMIT 1;
putOperation:
INSERT INTO opJournal (timestamp, serviceId, operation) VALUES (?, ?, ?);
deleteOperationsByService:
DELETE FROM opJournal WHERE serviceId = ?;