2022-06-05 02:41:11 +02:00
|
|
|
|
2022-06-05 22:07:30 +02:00
|
|
|
CREATE TABLE "JST_LibraryList" (
|
2022-06-05 02:41:11 +02:00
|
|
|
"name" TEXT PRIMARY KEY NOT NULL,
|
2022-06-05 22:07:30 +02:00
|
|
|
"nextList" TEXT REFERENCES "JST_LibraryList"("name")
|
2022-06-05 02:41:11 +02:00
|
|
|
);
|
|
|
|
|
2022-06-05 22:07:30 +02:00
|
|
|
CREATE INDEX "JST_LibraryList_byNextList" ON "JST_LibraryList"("nextList");
|
2022-06-05 02:41:11 +02:00
|
|
|
|
2022-06-05 22:07:30 +02:00
|
|
|
CREATE TABLE "JST_LibraryListEntry" (
|
|
|
|
"listName" TEXT NOT NULL REFERENCES "JST_LibraryList"("name") ON DELETE CASCADE,
|
2022-06-05 02:41:11 +02:00
|
|
|
"entryText" TEXT NOT NULL,
|
|
|
|
"isKanji" BOOLEAN NOT NULL DEFAULT 0,
|
|
|
|
"lastModified" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
|
|
"nextEntry" TEXT NOT NULL,
|
|
|
|
PRIMARY KEY ("listName", "entryText", "isKanji"),
|
2022-06-05 22:07:30 +02:00
|
|
|
FOREIGN KEY ("listName", "nextEntry") REFERENCES "JST_LibraryListEntry"("listName", "entryText"),
|
2022-06-05 02:41:11 +02:00
|
|
|
CHECK ((NOT "isKanji") OR ("nextEntry" <> 0))
|
|
|
|
);
|
|
|
|
|
2022-06-05 22:07:30 +02:00
|
|
|
CREATE INDEX "JST_LibraryListEntry_byListName" ON "JST_LibraryListEntry"("listName");
|
2022-06-05 02:41:11 +02:00
|
|
|
|
2022-06-05 22:07:30 +02:00
|
|
|
-- CREATE VIEW "JST_LibraryListEntry_sortedByLists" AS
|
|
|
|
-- WITH RECURSIVE "JST_LibraryListEntry_sorted"("next") AS (
|
2022-06-05 02:41:11 +02:00
|
|
|
-- -- Initial SELECT
|
|
|
|
-- UNION ALL
|
|
|
|
-- SELECT * FROM ""
|
|
|
|
-- -- Recursive Select
|
|
|
|
-- )
|
2022-06-05 22:07:30 +02:00
|
|
|
-- SELECT * FROM "JST_LibraryListEntry_sorted";
|
2022-06-05 02:41:11 +02:00
|
|
|
|
|
|
|
CREATE TABLE "JST_HistoryEntry" (
|
|
|
|
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT
|
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE "JST_HistoryEntryKanji" (
|
|
|
|
"entryId" INTEGER NOT NULL REFERENCES "JST_HistoryEntry"("id") ON DELETE CASCADE,
|
|
|
|
"kanji" CHAR(1) NOT NULL,
|
|
|
|
PRIMARY KEY ("entryId", "kanji")
|
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE "JST_HistoryEntryWord" (
|
|
|
|
"entryId" INTEGER NOT NULL REFERENCES "JST_HistoryEntry"("id") ON DELETE CASCADE,
|
2022-06-05 22:07:30 +02:00
|
|
|
"word" TEXT NOT NULL,
|
2022-06-05 02:41:11 +02:00
|
|
|
"language" CHAR(1) CHECK ("language" IN ("e", "j")),
|
2022-06-05 22:07:30 +02:00
|
|
|
PRIMARY KEY ("entryId", "word")
|
2022-06-05 02:41:11 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE "JST_HistoryEntryTimestamp" (
|
|
|
|
"entryId" INTEGER NOT NULL REFERENCES "JST_HistoryEntry"("id") ON DELETE CASCADE,
|
|
|
|
-- Here, I'm using INTEGER insted of TIMESTAMP or DATETIME, because it seems to be
|
|
|
|
-- the easiest way to deal with global and local timeconversion between dart and
|
|
|
|
-- SQLite.
|
|
|
|
"timestamp" INTEGER NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
|
|
PRIMARY KEY ("entryId", "timestamp")
|
|
|
|
);
|
|
|
|
|
|
|
|
CREATE INDEX "JST_HistoryEntryTimestamp_byTimestamp" ON "JST_HistoryEntryTimestamp"("timestamp");
|
|
|
|
|
|
|
|
CREATE VIEW "JST_HistoryEntry_orderedByTimestamp" AS
|
|
|
|
SELECT * FROM "JST_HistoryEntryTimestamp"
|
|
|
|
LEFT JOIN "JST_HistoryEntryWord" USING ("entryId")
|
|
|
|
LEFT JOIN "JST_HistoryEntryKanji" USING ("entryId")
|
|
|
|
GROUP BY "entryId"
|
|
|
|
ORDER BY MAX("timestamp") DESC;
|