Add functions in the sq file

pull/1323/head
lihenggui 2 years ago
parent bbc9a537dc
commit 9bf5033c05

@ -17,3 +17,12 @@ CREATE TRIGGER news_resources_au AFTER UPDATE ON news_resources BEGIN
INSERT INTO news_resources_fts (news_resources_fts, rowid, news_resource_id, title, content) VALUES ('delete', old.rowid, old.id, old.title, old.content);
INSERT INTO news_resources_fts (rowid, news_resource_id, title, content) VALUES (new.rowid, new.id, new.title, new.content);
END;
insertAll:
INSERT INTO news_resources_fts (news_resource_id, title, content) SELECT id, title, content FROM news_resources;
searchAllNewsResources:
SELECT news_resource_id FROM news_resources_fts WHERE news_resources_fts MATCH :query;
getCount:
SELECT count(*) FROM news_resources_fts;

@ -3,3 +3,12 @@ CREATE TABLE recent_search_queries (
query TEXT NOT NULL,
queried_date INTEGER DEFAULT CURRENT_TIMESTAMP
);
getRecentSearchQueryEntities:
SELECT * FROM recent_search_queries ORDER BY queried_date DESC LIMIT :limit;
insertOrReplaceRecentSearchQuery:
INSERT OR REPLACE INTO recent_search_queries (query) VALUES (:query);
clearRecentSearchQueries:
DELETE FROM recent_search_queries;

@ -6,3 +6,29 @@ CREATE TABLE topics (
url TEXT NOT NULL DEFAULT '',
image_url TEXT NOT NULL DEFAULT ''
);
getTopicEntity:
SELECT * FROM topics WHERE id = :topicId;
getTopicEntities:
SELECT * FROM topics;
getOneOffTopicEntities:
SELECT * FROM topics;
insertOrIgnoreTopics:
INSERT OR IGNORE INTO topics(id, name, short_description, long_description, url, image_url)
VALUES (?, ?, ?, ?, ?, ?);
upsertTopics:
INSERT INTO topics(id, name, short_description, long_description, url, image_url)
VALUES (?, ?, ?, ?, ?, ?)
ON CONFLICT(id) DO UPDATE SET
name = excluded.name,
short_description = excluded.short_description,
long_description = excluded.long_description,
url = excluded.url,
image_url = excluded.image_url;
deleteTopics:
DELETE FROM topics WHERE id IN (:ids);

@ -25,3 +25,17 @@ BEGIN
long_description = new.long_description
WHERE topic_id = new.id;
END;
insertAll:
INSERT INTO topics_fts (topic_id, name, short_description, long_description)
VALUES (?, ?, ?, ?)
ON CONFLICT(topic_id) DO UPDATE SET
name = excluded.name,
short_description = excluded.short_description,
long_description = excluded.long_description;
searchAllTopics:
SELECT topic_id FROM topics_fts WHERE topics_fts MATCH :query;
getCount:
SELECT count(*) FROM topics_fts;

Loading…
Cancel
Save