Use singular form in the sq file

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

@ -1,4 +1,4 @@
CREATE TABLE news_resources (
CREATE TABLE news_resource (
id TEXT NOT NULL PRIMARY KEY,
title TEXT NOT NULL,
content TEXT NOT NULL,
@ -9,7 +9,7 @@ CREATE TABLE news_resources (
);
getNewsResources:
SELECT * FROM news_resources
SELECT * FROM news_resource
WHERE
CASE WHEN :useFilterNewsIds
THEN id IN (:filterNewsIds)
@ -27,7 +27,7 @@ WHERE
ORDER BY publish_date DESC;
getNewsResourceIds:
SELECT id FROM news_resources
SELECT id FROM news_resource
WHERE
CASE WHEN :useFilterNewsIds
THEN id IN (:filterNewsIds)
@ -45,11 +45,11 @@ WHERE
ORDER BY publish_date DESC;
insertOrIgnoreNewsResources:
INSERT OR IGNORE INTO news_resources (id, title, content, url, header_image_url, publish_date, type)
INSERT OR IGNORE INTO news_resource (id, title, content, url, header_image_url, publish_date, type)
VALUES (?, ?, ?, ?, ?, ?, ?);
upsertNewsResources:
INSERT INTO news_resources (id, title, content, url, header_image_url, publish_date, type)
INSERT INTO news_resource (id, title, content, url, header_image_url, publish_date, type)
VALUES (?, ?, ?, ?, ?, ?, ?)
ON CONFLICT(id) DO UPDATE SET
title = excluded.title,
@ -64,5 +64,5 @@ INSERT OR IGNORE INTO news_resources_topics (news_resource_id, topic_id)
VALUES (?, ?);
deleteNewsResources:
DELETE FROM news_resources
DELETE FROM news_resource
WHERE id IN (:ids);

@ -0,0 +1,28 @@
CREATE VIRTUAL TABLE news_resource_fts
USING FTS4(
tokenizer = porter,
content = news_resources,
news_resource_id TEXT NOT NULL,
title TEXT NOT NULL,
content TEXT NOT NULL,
);
-- Triggers to keep the FTS index up to date.
CREATE TRIGGER news_resource_ai AFTER INSERT ON news_resource BEGIN
INSERT INTO news_resource_fts (rowid, news_resource_id, title, content) VALUES (new.rowid, new.id, new.title, new.content);
END;
CREATE TRIGGER news_resource_ad AFTER DELETE ON news_resource BEGIN
INSERT INTO news_resource_fts (news_resource_fts, rowid, news_resource_id, title, content) VALUES ('delete', old.rowid, old.id, old.title, old.content);
END;
CREATE TRIGGER news_resource_au AFTER UPDATE ON news_resource BEGIN
INSERT INTO news_resource_fts (news_resource_fts, rowid, news_resource_id, title, content) VALUES ('delete', old.rowid, old.id, old.title, old.content);
INSERT INTO news_resource_fts (rowid, news_resource_id, title, content) VALUES (new.rowid, new.id, new.title, new.content);
END;
insertAll:
INSERT INTO news_resource_fts (news_resource_id, title, content) SELECT id, title, content FROM news_resource;
searchAllNewsResources:
SELECT news_resource_id FROM news_resource_fts WHERE news_resource_fts MATCH :query;
getCount:
SELECT count(*) FROM news_resource_fts;

@ -0,0 +1,11 @@
CREATE TABLE IF NOT EXISTS news_resource_topic (
news_resource_id TEXT NOT NULL,
topic_id TEXT NOT NULL,
PRIMARY KEY(news_resource_id, topic_id),
FOREIGN KEY(news_resource_id) REFERENCES news_resource(id) ON DELETE CASCADE,
FOREIGN KEY(topic_id) REFERENCES topic(id) ON DELETE CASCADE
);
CREATE INDEX IF NOT EXISTS index_news_resource_topic_news_resource_id ON news_resource_topic(news_resource_id);
CREATE INDEX IF NOT EXISTS index_news_resource_topic_topic_id ON news_resource_topic(topic_id);

@ -0,0 +1,11 @@
CREATE TABLE IF NOT EXISTS news_resources_topics (
news_resource_id TEXT NOT NULL,
topic_id TEXT NOT NULL,
PRIMARY KEY (news_resource_id, topic_id),
FOREIGN KEY (news_resource_id) REFERENCES news_resource(id) ON DELETE CASCADE,
FOREIGN KEY (topic_id) REFERENCES topic(id) ON DELETE CASCADE
);
CREATE INDEX idx_news_resource_id ON news_resource_topic(news_resource_id);
CREATE INDEX idx_topic_id ON news_resource_topic(topic_id);

@ -1,11 +0,0 @@
CREATE TABLE IF NOT EXISTS news_resources_topics (
news_resource_id TEXT NOT NULL,
topic_id TEXT NOT NULL,
PRIMARY KEY(news_resource_id, topic_id),
FOREIGN KEY(news_resource_id) REFERENCES news_resources(id) ON DELETE CASCADE,
FOREIGN KEY(topic_id) REFERENCES topics(id) ON DELETE CASCADE
);
CREATE INDEX IF NOT EXISTS index_news_resources_topics_news_resource_id ON news_resources_topics(news_resource_id);
CREATE INDEX IF NOT EXISTS index_news_resources_topics_topic_id ON news_resources_topics(topic_id);

@ -1,28 +0,0 @@
CREATE VIRTUAL TABLE news_resources_fts
USING FTS4(
tokenizer = porter,
content = news_resources,
news_resource_id TEXT NOT NULL,
title TEXT NOT NULL,
content TEXT NOT NULL,
);
-- Triggers to keep the FTS index up to date.
CREATE TRIGGER news_resources_ai AFTER INSERT ON news_resources BEGIN
INSERT INTO news_resources_fts (rowid, news_resource_id, title, content) VALUES (new.rowid, new.id, new.title, new.content);
END;
CREATE TRIGGER news_resources_ad AFTER DELETE 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);
END;
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;

@ -1,11 +0,0 @@
CREATE TABLE IF NOT EXISTS news_resources_topics (
news_resource_id TEXT NOT NULL,
topic_id TEXT NOT NULL,
PRIMARY KEY (news_resource_id, topic_id),
FOREIGN KEY (news_resource_id) REFERENCES news_resources(id) ON DELETE CASCADE,
FOREIGN KEY (topic_id) REFERENCES topics(id) ON DELETE CASCADE
);
CREATE INDEX idx_news_resource_id ON news_resources_topics(news_resource_id);
CREATE INDEX idx_topic_id ON news_resources_topics(topic_id);

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

@ -1,4 +1,4 @@
CREATE TABLE topics (
CREATE TABLE topic (
id TEXT PRIMARY KEY NOT NULL,
name TEXT NOT NULL,
short_description TEXT NOT NULL,
@ -8,20 +8,20 @@ CREATE TABLE topics (
);
getTopicEntity:
SELECT * FROM topics WHERE id = :topicId;
SELECT * FROM topic WHERE id = :topicId;
getTopicEntities:
SELECT * FROM topics;
SELECT * FROM topic;
getOneOffTopicEntities:
SELECT * FROM topics;
SELECT * FROM topic;
insertOrIgnoreTopics:
INSERT OR IGNORE INTO topics(id, name, short_description, long_description, url, image_url)
INSERT OR IGNORE INTO topic(id, name, short_description, long_description, url, image_url)
VALUES (?, ?, ?, ?, ?, ?);
upsertTopics:
INSERT INTO topics(id, name, short_description, long_description, url, image_url)
INSERT INTO topic(id, name, short_description, long_description, url, image_url)
VALUES (?, ?, ?, ?, ?, ?)
ON CONFLICT(id) DO UPDATE SET
name = excluded.name,
@ -31,4 +31,4 @@ url = excluded.url,
image_url = excluded.image_url;
deleteTopics:
DELETE FROM topics WHERE id IN (:ids);
DELETE FROM topic WHERE id IN (:ids);

@ -1,4 +1,4 @@
CREATE VIRTUAL TABLE IF NOT EXISTS topics_fts
CREATE VIRTUAL TABLE IF NOT EXISTS topic_fts
USING FTS4(
topic_id TEXT,
name TEXT,
@ -6,20 +6,20 @@ USING FTS4(
long_description TEXT
);
CREATE TRIGGER IF NOT EXISTS topics_ai AFTER INSERT ON topics
CREATE TRIGGER IF NOT EXISTS topic_ai AFTER INSERT ON topic
BEGIN
INSERT INTO topics_fts (topic_id, name, short_description, long_description)
INSERT INTO topic_fts (topic_id, name, short_description, long_description)
VALUES (new.id, new.name, new.short_description, new.long_description);
END;
CREATE TRIGGER IF NOT EXISTS topics_ad AFTER DELETE ON topics
CREATE TRIGGER IF NOT EXISTS topic_ad AFTER DELETE ON topic
BEGIN
DELETE FROM topics_fts WHERE topic_id = old.id;
DELETE FROM topic_fts WHERE topic_id = old.id;
END;
CREATE TRIGGER IF NOT EXISTS topics_au AFTER UPDATE ON topics
CREATE TRIGGER IF NOT EXISTS topic_au AFTER UPDATE ON topic
BEGIN
UPDATE topics_fts SET
UPDATE topic_fts SET
name = new.name,
short_description = new.short_description,
long_description = new.long_description
@ -27,7 +27,7 @@ BEGIN
END;
insertAll:
INSERT INTO topics_fts (topic_id, name, short_description, long_description)
INSERT INTO topic_fts (topic_id, name, short_description, long_description)
VALUES (?, ?, ?, ?)
ON CONFLICT(topic_id) DO UPDATE SET
name = excluded.name,
@ -35,7 +35,7 @@ short_description = excluded.short_description,
long_description = excluded.long_description;
searchAllTopics:
SELECT topic_id FROM topics_fts WHERE topics_fts MATCH :query;
SELECT topic_id FROM topic_fts WHERE topic_fts MATCH :query;
getCount:
SELECT count(*) FROM topics_fts;
SELECT count(*) FROM topic_fts;

Loading…
Cancel
Save