From ea220e25f5fcdc805cfe8f4be508dd034a79ea2f Mon Sep 17 00:00:00 2001 From: h7x4 Date: Sun, 5 Jun 2022 22:07:30 +0200 Subject: [PATCH] Rename some badly named pieces - Saved and SavedLists are now referred to as Library and LibraryLists - the sql searchword is now just called word --- assets/migrations/0001_initial.sql | 24 ++++++++++++------------ lib/data/archive_format.dart | 4 ++-- lib/data/database.dart | 8 ++++---- lib/data/export.dart | 16 ++++++++-------- lib/data/import.dart | 6 +++--- lib/models/history/history_entry.dart | 18 +++++++++--------- lib/screens/home.dart | 4 ++-- 7 files changed, 40 insertions(+), 40 deletions(-) diff --git a/assets/migrations/0001_initial.sql b/assets/migrations/0001_initial.sql index f3e1554..e400754 100644 --- a/assets/migrations/0001_initial.sql +++ b/assets/migrations/0001_initial.sql @@ -1,32 +1,32 @@ -CREATE TABLE "JST_SavedList" ( +CREATE TABLE "JST_LibraryList" ( "name" TEXT PRIMARY KEY NOT NULL, - "nextList" TEXT REFERENCES "JST_SavedList"("name") + "nextList" TEXT REFERENCES "JST_LibraryList"("name") ); -CREATE INDEX "JST_SavedList_byNextList" ON "JST_SavedList"("nextList"); +CREATE INDEX "JST_LibraryList_byNextList" ON "JST_LibraryList"("nextList"); -CREATE TABLE "JST_SavedListEntry" ( - "listName" TEXT NOT NULL REFERENCES "JST_SavedList"("name") ON DELETE CASCADE, +CREATE TABLE "JST_LibraryListEntry" ( + "listName" TEXT NOT NULL REFERENCES "JST_LibraryList"("name") ON DELETE CASCADE, "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"), - FOREIGN KEY ("listName", "nextEntry") REFERENCES "JST_SavedListEntry"("listName", "entryText"), + FOREIGN KEY ("listName", "nextEntry") REFERENCES "JST_LibraryListEntry"("listName", "entryText"), CHECK ((NOT "isKanji") OR ("nextEntry" <> 0)) ); -CREATE INDEX "JST_SavedListEntry_byListName" ON "JST_SavedListEntry"("listName"); +CREATE INDEX "JST_LibraryListEntry_byListName" ON "JST_LibraryListEntry"("listName"); --- CREATE VIEW "JST_SavedListEntry_sortedByLists" AS --- WITH RECURSIVE "JST_SavedListEntry_sorted"("next") AS ( +-- CREATE VIEW "JST_LibraryListEntry_sortedByLists" AS +-- WITH RECURSIVE "JST_LibraryListEntry_sorted"("next") AS ( -- -- Initial SELECT -- UNION ALL -- SELECT * FROM "" -- -- Recursive Select -- ) --- SELECT * FROM "JST_SavedListEntry_sorted"; +-- SELECT * FROM "JST_LibraryListEntry_sorted"; CREATE TABLE "JST_HistoryEntry" ( "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT @@ -40,9 +40,9 @@ CREATE TABLE "JST_HistoryEntryKanji" ( CREATE TABLE "JST_HistoryEntryWord" ( "entryId" INTEGER NOT NULL REFERENCES "JST_HistoryEntry"("id") ON DELETE CASCADE, - "searchword" TEXT NOT NULL, + "word" TEXT NOT NULL, "language" CHAR(1) CHECK ("language" IN ("e", "j")), - PRIMARY KEY ("entryId", "searchword") + PRIMARY KEY ("entryId", "word") ); CREATE TABLE "JST_HistoryEntryTimestamp" ( diff --git a/lib/data/archive_format.dart b/lib/data/archive_format.dart index 8eacfa5..825026f 100644 --- a/lib/data/archive_format.dart +++ b/lib/data/archive_format.dart @@ -3,7 +3,7 @@ import 'dart:io'; // Example file Structure: // jisho_data_22.01.01_1 // - history.json -// - saved/ +// - library/ // - lista.json // - listb.json @@ -16,5 +16,5 @@ extension ArchiveFormat on Directory { } File get historyFile => File(uri.resolve('history.json').path); - Directory get savedLists => Directory(uri.resolve('savedLists').path); + Directory get libraryDir => Directory(uri.resolve('library').path); } diff --git a/lib/data/database.dart b/lib/data/database.dart index ce5076b..234deab 100644 --- a/lib/data/database.dart +++ b/lib/data/database.dart @@ -95,14 +95,14 @@ class TableNames { /// Attributes: /// - entryId INTEGER - /// - searchword TEXT + /// - word TEXT /// - language CHAR(1)? static const String historyEntryWord = 'JST_HistoryEntryWord'; /// Attributes: /// - name TEXT /// - nextList TEXT - static const String savedList = 'JST_SavedList'; + static const String libraryList = 'JST_LibraryList'; /// Attributes: /// - listName TEXT @@ -110,7 +110,7 @@ class TableNames { /// - isKanji BOOLEAN /// - lastModified TIMESTAMP /// - nextEntry TEXT - static const String savedListEntry = 'JST_SavedListEntry'; + static const String libraryListEntry = 'JST_LibraryListEntry'; /////////// // VIEWS // @@ -119,7 +119,7 @@ class TableNames { /// Attributes: /// - entryId INTEGER /// - timestamp INTEGER - /// - searchword TEXT? + /// - word TEXT? /// - kanji CHAR(1)? /// - language CHAR(1)? static const String historyEntryOrderedByTimestamp = diff --git a/lib/data/export.dart b/lib/data/export.dart index bca452b..462a320 100644 --- a/lib/data/export.dart +++ b/lib/data/export.dart @@ -4,12 +4,12 @@ import 'dart:io'; import 'package:path_provider/path_provider.dart'; import '../models/history/history_entry.dart'; +import 'archive_format.dart'; import 'database.dart'; Future exportDirectory() async { final basedir = (await getExternalStorageDirectory())!; - // TODO: fix path - final dir = Directory(basedir.uri.resolve('export').path); + final dir = basedir.exportDirectory; dir.createSync(recursive: true); return dir; } @@ -17,12 +17,12 @@ Future exportDirectory() async { /// Returns the path to which the data was saved. Future exportData() async { final dir = await exportDirectory(); - final savedDir = Directory.fromUri(dir.uri.resolve('saved')); - savedDir.createSync(); + final libraryDir = dir.libraryDir; + libraryDir.createSync(); await Future.wait([ exportHistoryTo(dir), - exportSavedListsTo(savedDir), + exportLibraryListsTo(libraryDir), ]); return dir.path; } @@ -38,8 +38,8 @@ Future exportHistoryTo(Directory dir) async { file.writeAsStringSync(jsonEncode(jsonEntries)); } -Future exportSavedListsTo(Directory dir) async { +Future exportLibraryListsTo(Directory dir) async { // TODO: - // final query = db().query(TableNames.savedList); - print('TODO: implement exportSavedLists'); + // final query = db().query(TableNames.libraryList); + print('TODO: implement exportLibraryLists'); } diff --git a/lib/data/import.dart b/lib/data/import.dart index 201cf38..badec94 100644 --- a/lib/data/import.dart +++ b/lib/data/import.dart @@ -7,7 +7,7 @@ import 'archive_format.dart'; Future importData(Directory dir) async { await Future.wait([ importHistoryFrom(dir.historyFile), - importSavedListsFrom(dir.savedLists), + importLibraryListsFrom(dir.libraryDir), ]); } @@ -20,6 +20,6 @@ Future importHistoryFrom(File file) async { ); } -Future importSavedListsFrom(Directory savedListsDir) async { - print('TODO: Implement importSavedLists'); +Future importLibraryListsFrom(Directory libraryListsDir) async { + print('TODO: Implement importLibraryLists'); } diff --git a/lib/models/history/history_entry.dart b/lib/models/history/history_entry.dart index 96cd53f..94f0296 100644 --- a/lib/models/history/history_entry.dart +++ b/lib/models/history/history_entry.dart @@ -34,13 +34,13 @@ class HistoryEntry { /// /// - entryId /// - timestamp - /// - searchword? + /// - word? /// - kanji? factory HistoryEntry.fromDBMap(Map dbObject) => - dbObject['searchword'] != null + dbObject['word'] != null ? HistoryEntry.withWord( id: dbObject['entryId']! as int, - word: dbObject['searchword']! as String, + word: dbObject['word']! as String, lastTimestamp: DateTime.fromMillisecondsSinceEpoch( dbObject['timestamp']! as int, ), @@ -121,7 +121,7 @@ class HistoryEntry { final existingEntry = await txn.query( TableNames.historyEntryWord, - where: 'searchword = ?', + where: 'word = ?', whereArgs: [word], ); @@ -146,7 +146,7 @@ class HistoryEntry { }); b.insert(TableNames.historyEntryWord, { 'entryId': id, - 'searchword': word, + 'word': word, 'language': { null: null, 'japanese': 'j', @@ -210,7 +210,7 @@ class HistoryEntry { ) : await txn.query( TableNames.historyEntryWord, - where: 'searchword = ?', + where: 'word = ?', whereArgs: [json['word']! as String], ); @@ -229,7 +229,7 @@ class HistoryEntry { } else { b.insert(TableNames.historyEntryWord, { 'entryId': id, - 'searchword': json['word']! as String, + 'word': json['word']! as String, }); } } else { @@ -286,7 +286,7 @@ class HistoryEntry { ) : await txn.query( TableNames.historyEntryWord, - where: 'searchword = ?', + where: 'word = ?', whereArgs: [jsonObject['word']! as String], ); @@ -305,7 +305,7 @@ class HistoryEntry { } else { b.insert(TableNames.historyEntryWord, { 'entryId': id, - 'searchword': jsonObject['word']! as String, + 'word': jsonObject['word']! as String, }); } } else { diff --git a/lib/screens/home.dart b/lib/screens/home.dart index 427a184..b20099f 100644 --- a/lib/screens/home.dart +++ b/lib/screens/home.dart @@ -75,9 +75,9 @@ class _HomeState extends State { ), _Page( content: Container(), - titleBar: const Text('Saved'), + titleBar: const Text('Library'), item: const BottomNavigationBarItem( - label: 'Saved', + label: 'Library', icon: Icon(Icons.bookmark), ), ),