@@ -174,26 +174,96 @@ class EntriesRepo(
174174 }
175175
176176 private fun selectMaxUpdated (): Flow <String ?> {
177+ // selectMaxUpdated:
178+ // SELECT MAX(updated)
179+ // FROM Entry;
177180 return db.entryQueries.selectMaxUpdated().asFlow().mapToOneOrNull().map { it?.MAX }
178181 }
179182
180183 fun selectByFtsQuery (query : String ): Flow <List <SelectByQuery >> {
184+ // -- https://www.sqlite.org/fts5.html
185+ // -- > It is an error to add types
186+ // -- However, SQLDelight insists on typing every field but it will strip types from the real schema
187+ // CREATE VIRTUAL TABLE entry_search USING fts5(
188+ // id TEXT NOT NULL,
189+ // title TEXT,
190+ // summary TEXT,
191+ // content_text TEXT,
192+ // content=Entry,
193+ // tokenize='trigram'
194+ // );
195+ //
196+ // CREATE TRIGGER entry_fts_after_insert AFTER INSERT ON Entry BEGIN
197+ // INSERT
198+ // INTO entry_search(rowid, id, title, summary, content_text)
199+ // VALUES (new.rowid, new.id, new.title, new.summary, new.content_text);
200+ // END;
201+ //
202+ // CREATE TRIGGER entry_fts_after_delete AFTER DELETE ON Entry BEGIN
203+ // INSERT
204+ // INTO entry_search(entry_search, rowid, id, title, summary, content_text)
205+ // VALUES ('delete', old.rowid, old.id, old.title, old.summary, old.content_text);
206+ // END;
207+ //
208+ // CREATE TRIGGER entry_fts_after_update AFTER UPDATE ON Entry BEGIN
209+ // INSERT
210+ // INTO entry_search(entry_search, rowid, id, title, summary, content_text)
211+ // VALUES ('delete', old.rowid, old.id, old.title, old.summary, old.content_text);
212+ //
213+ // INSERT
214+ // INTO entry_search(rowid, id, title, summary, content_text)
215+ // VALUES (new.rowid, new.id, new.title, new.summary, new.content_text);
216+ // END;
217+ //
218+ // selectByQuery:
219+ // SELECT
220+ // e.id,
221+ // f.ext_show_preview_images,
222+ // e.ext_og_image_url,
223+ // e.ext_og_image_width,
224+ // e.ext_og_image_height,
225+ // e.title,
226+ // f.title AS feedTitle,
227+ // e.published,
228+ // e.summary,
229+ // e.ext_read,
230+ // f.ext_open_entries_in_browser,
231+ // e.links
232+ // FROM entry_search es
233+ // JOIN Entry e ON e.id = es.id
234+ // JOIN Feed f ON f.id = e.feed_id
235+ // WHERE es.title LIKE '%' || :query || '%'
236+ // OR es.summary LIKE '%' || :query || '%'
237+ // OR es.content_text LIKE '%' || :query || '%'
238+ // LIMIT 500;
181239 return db.entrySearchQueries.selectByQuery(query).asFlow().mapToList()
182240 }
183241
184242 suspend fun updateReadByFeedId (read : Boolean , feedId : String ) {
243+ // updateReadByFeedId:
244+ // UPDATE Entry
245+ // SET ext_read = :read, ext_read_synced = 0
246+ // WHERE ext_read != :read AND feed_id = :feedId;
185247 withContext(Dispatchers .IO ) {
186248 db.entryQueries.updateReadByFeedId(read, feedId)
187249 }
188250 }
189251
190252 suspend fun updateReadByBookmarked (read : Boolean , bookmarked : Boolean ) {
253+ // updateReadByBookmarked:
254+ // UPDATE Entry
255+ // SET ext_read = :read, ext_read_synced = 0
256+ // WHERE ext_read != :read AND ext_bookmarked = :bookmarked;
191257 withContext(Dispatchers .IO ) {
192258 db.entryQueries.updateReadByBookmarked(read = read, bookmarked = bookmarked)
193259 }
194260 }
195261
196262 suspend fun updateReadAndReadSynced (id : String , read : Boolean , readSynced : Boolean ) {
263+ // updateReadAndReadSynced:
264+ // UPDATE Entry
265+ // SET ext_read = ?, ext_read_synced = ?
266+ // WHERE id = ?;
197267 withContext(Dispatchers .IO ) {
198268 db.entryQueries.updateReadAndReadSynced(
199269 id = id,
@@ -208,6 +278,10 @@ class EntriesRepo(
208278 bookmarked : Boolean ,
209279 bookmarkedSynced : Boolean ,
210280 ) {
281+ // updateBookmarkedAndBookmaredSynced:
282+ // UPDATE Entry
283+ // SET ext_bookmarked = ?, ext_bookmarked_synced = ?
284+ // WHERE id = ?;
211285 withContext(Dispatchers .IO ) {
212286 db.entryQueries.updateBookmarkedAndBookmaredSynced(
213287 id = id,
@@ -253,6 +327,10 @@ class EntriesRepo(
253327
254328 db.entryQueries.transaction {
255329 unsyncedReadEntries.forEach {
330+ // updateReadSynced:
331+ // UPDATE Entry
332+ // SET ext_read_synced = ?
333+ // WHERE id = ?;
256334 db.entryQueries.updateReadSynced(true , it.id)
257335 }
258336 }
@@ -301,6 +379,10 @@ class EntriesRepo(
301379
302380 db.entryQueries.transaction {
303381 notSyncedBookmarkedEntries.forEach {
382+ // updateBookmarkedSynced:
383+ // UPDATE Entry
384+ // SET ext_bookmarked_synced = ?
385+ // WHERE id = ?;
304386 db.entryQueries.updateBookmarkedSynced(true , it.id)
305387 }
306388 }
0 commit comments