1
0
mirror of https://github.com/h7x4/Jisho-Study-Tool.git synced 2024-12-22 13:57:29 +01:00

Rename some badly named pieces

- Saved and SavedLists are now referred to as Library and LibraryLists
- the sql searchword is now just called word
This commit is contained in:
Oystein Kristoffer Tveit 2022-06-05 22:07:30 +02:00
parent d2a3de4823
commit ea220e25f5
7 changed files with 40 additions and 40 deletions

View File

@ -1,32 +1,32 @@
CREATE TABLE "JST_SavedList" ( CREATE TABLE "JST_LibraryList" (
"name" TEXT PRIMARY KEY NOT NULL, "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" ( CREATE TABLE "JST_LibraryListEntry" (
"listName" TEXT NOT NULL REFERENCES "JST_SavedList"("name") ON DELETE CASCADE, "listName" TEXT NOT NULL REFERENCES "JST_LibraryList"("name") ON DELETE CASCADE,
"entryText" TEXT NOT NULL, "entryText" TEXT NOT NULL,
"isKanji" BOOLEAN NOT NULL DEFAULT 0, "isKanji" BOOLEAN NOT NULL DEFAULT 0,
"lastModified" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, "lastModified" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
"nextEntry" TEXT NOT NULL, "nextEntry" TEXT NOT NULL,
PRIMARY KEY ("listName", "entryText", "isKanji"), 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)) 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 -- CREATE VIEW "JST_LibraryListEntry_sortedByLists" AS
-- WITH RECURSIVE "JST_SavedListEntry_sorted"("next") AS ( -- WITH RECURSIVE "JST_LibraryListEntry_sorted"("next") AS (
-- -- Initial SELECT -- -- Initial SELECT
-- UNION ALL -- UNION ALL
-- SELECT * FROM "" -- SELECT * FROM ""
-- -- Recursive Select -- -- Recursive Select
-- ) -- )
-- SELECT * FROM "JST_SavedListEntry_sorted"; -- SELECT * FROM "JST_LibraryListEntry_sorted";
CREATE TABLE "JST_HistoryEntry" ( CREATE TABLE "JST_HistoryEntry" (
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT
@ -40,9 +40,9 @@ CREATE TABLE "JST_HistoryEntryKanji" (
CREATE TABLE "JST_HistoryEntryWord" ( CREATE TABLE "JST_HistoryEntryWord" (
"entryId" INTEGER NOT NULL REFERENCES "JST_HistoryEntry"("id") ON DELETE CASCADE, "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")), "language" CHAR(1) CHECK ("language" IN ("e", "j")),
PRIMARY KEY ("entryId", "searchword") PRIMARY KEY ("entryId", "word")
); );
CREATE TABLE "JST_HistoryEntryTimestamp" ( CREATE TABLE "JST_HistoryEntryTimestamp" (

View File

@ -3,7 +3,7 @@ import 'dart:io';
// Example file Structure: // Example file Structure:
// jisho_data_22.01.01_1 // jisho_data_22.01.01_1
// - history.json // - history.json
// - saved/ // - library/
// - lista.json // - lista.json
// - listb.json // - listb.json
@ -16,5 +16,5 @@ extension ArchiveFormat on Directory {
} }
File get historyFile => File(uri.resolve('history.json').path); 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);
} }

View File

@ -95,14 +95,14 @@ class TableNames {
/// Attributes: /// Attributes:
/// - entryId INTEGER /// - entryId INTEGER
/// - searchword TEXT /// - word TEXT
/// - language CHAR(1)? /// - language CHAR(1)?
static const String historyEntryWord = 'JST_HistoryEntryWord'; static const String historyEntryWord = 'JST_HistoryEntryWord';
/// Attributes: /// Attributes:
/// - name TEXT /// - name TEXT
/// - nextList TEXT /// - nextList TEXT
static const String savedList = 'JST_SavedList'; static const String libraryList = 'JST_LibraryList';
/// Attributes: /// Attributes:
/// - listName TEXT /// - listName TEXT
@ -110,7 +110,7 @@ class TableNames {
/// - isKanji BOOLEAN /// - isKanji BOOLEAN
/// - lastModified TIMESTAMP /// - lastModified TIMESTAMP
/// - nextEntry TEXT /// - nextEntry TEXT
static const String savedListEntry = 'JST_SavedListEntry'; static const String libraryListEntry = 'JST_LibraryListEntry';
/////////// ///////////
// VIEWS // // VIEWS //
@ -119,7 +119,7 @@ class TableNames {
/// Attributes: /// Attributes:
/// - entryId INTEGER /// - entryId INTEGER
/// - timestamp INTEGER /// - timestamp INTEGER
/// - searchword TEXT? /// - word TEXT?
/// - kanji CHAR(1)? /// - kanji CHAR(1)?
/// - language CHAR(1)? /// - language CHAR(1)?
static const String historyEntryOrderedByTimestamp = static const String historyEntryOrderedByTimestamp =

View File

@ -4,12 +4,12 @@ import 'dart:io';
import 'package:path_provider/path_provider.dart'; import 'package:path_provider/path_provider.dart';
import '../models/history/history_entry.dart'; import '../models/history/history_entry.dart';
import 'archive_format.dart';
import 'database.dart'; import 'database.dart';
Future<Directory> exportDirectory() async { Future<Directory> exportDirectory() async {
final basedir = (await getExternalStorageDirectory())!; final basedir = (await getExternalStorageDirectory())!;
// TODO: fix path final dir = basedir.exportDirectory;
final dir = Directory(basedir.uri.resolve('export').path);
dir.createSync(recursive: true); dir.createSync(recursive: true);
return dir; return dir;
} }
@ -17,12 +17,12 @@ Future<Directory> exportDirectory() async {
/// Returns the path to which the data was saved. /// Returns the path to which the data was saved.
Future<String> exportData() async { Future<String> exportData() async {
final dir = await exportDirectory(); final dir = await exportDirectory();
final savedDir = Directory.fromUri(dir.uri.resolve('saved')); final libraryDir = dir.libraryDir;
savedDir.createSync(); libraryDir.createSync();
await Future.wait([ await Future.wait([
exportHistoryTo(dir), exportHistoryTo(dir),
exportSavedListsTo(savedDir), exportLibraryListsTo(libraryDir),
]); ]);
return dir.path; return dir.path;
} }
@ -38,8 +38,8 @@ Future<void> exportHistoryTo(Directory dir) async {
file.writeAsStringSync(jsonEncode(jsonEntries)); file.writeAsStringSync(jsonEncode(jsonEntries));
} }
Future<void> exportSavedListsTo(Directory dir) async { Future<void> exportLibraryListsTo(Directory dir) async {
// TODO: // TODO:
// final query = db().query(TableNames.savedList); // final query = db().query(TableNames.libraryList);
print('TODO: implement exportSavedLists'); print('TODO: implement exportLibraryLists');
} }

View File

@ -7,7 +7,7 @@ import 'archive_format.dart';
Future<void> importData(Directory dir) async { Future<void> importData(Directory dir) async {
await Future.wait([ await Future.wait([
importHistoryFrom(dir.historyFile), importHistoryFrom(dir.historyFile),
importSavedListsFrom(dir.savedLists), importLibraryListsFrom(dir.libraryDir),
]); ]);
} }
@ -20,6 +20,6 @@ Future<void> importHistoryFrom(File file) async {
); );
} }
Future<void> importSavedListsFrom(Directory savedListsDir) async { Future<void> importLibraryListsFrom(Directory libraryListsDir) async {
print('TODO: Implement importSavedLists'); print('TODO: Implement importLibraryLists');
} }

View File

@ -34,13 +34,13 @@ class HistoryEntry {
/// ///
/// - entryId /// - entryId
/// - timestamp /// - timestamp
/// - searchword? /// - word?
/// - kanji? /// - kanji?
factory HistoryEntry.fromDBMap(Map<String, Object?> dbObject) => factory HistoryEntry.fromDBMap(Map<String, Object?> dbObject) =>
dbObject['searchword'] != null dbObject['word'] != null
? HistoryEntry.withWord( ? HistoryEntry.withWord(
id: dbObject['entryId']! as int, id: dbObject['entryId']! as int,
word: dbObject['searchword']! as String, word: dbObject['word']! as String,
lastTimestamp: DateTime.fromMillisecondsSinceEpoch( lastTimestamp: DateTime.fromMillisecondsSinceEpoch(
dbObject['timestamp']! as int, dbObject['timestamp']! as int,
), ),
@ -121,7 +121,7 @@ class HistoryEntry {
final existingEntry = await txn.query( final existingEntry = await txn.query(
TableNames.historyEntryWord, TableNames.historyEntryWord,
where: 'searchword = ?', where: 'word = ?',
whereArgs: [word], whereArgs: [word],
); );
@ -146,7 +146,7 @@ class HistoryEntry {
}); });
b.insert(TableNames.historyEntryWord, { b.insert(TableNames.historyEntryWord, {
'entryId': id, 'entryId': id,
'searchword': word, 'word': word,
'language': { 'language': {
null: null, null: null,
'japanese': 'j', 'japanese': 'j',
@ -210,7 +210,7 @@ class HistoryEntry {
) )
: await txn.query( : await txn.query(
TableNames.historyEntryWord, TableNames.historyEntryWord,
where: 'searchword = ?', where: 'word = ?',
whereArgs: [json['word']! as String], whereArgs: [json['word']! as String],
); );
@ -229,7 +229,7 @@ class HistoryEntry {
} else { } else {
b.insert(TableNames.historyEntryWord, { b.insert(TableNames.historyEntryWord, {
'entryId': id, 'entryId': id,
'searchword': json['word']! as String, 'word': json['word']! as String,
}); });
} }
} else { } else {
@ -286,7 +286,7 @@ class HistoryEntry {
) )
: await txn.query( : await txn.query(
TableNames.historyEntryWord, TableNames.historyEntryWord,
where: 'searchword = ?', where: 'word = ?',
whereArgs: [jsonObject['word']! as String], whereArgs: [jsonObject['word']! as String],
); );
@ -305,7 +305,7 @@ class HistoryEntry {
} else { } else {
b.insert(TableNames.historyEntryWord, { b.insert(TableNames.historyEntryWord, {
'entryId': id, 'entryId': id,
'searchword': jsonObject['word']! as String, 'word': jsonObject['word']! as String,
}); });
} }
} else { } else {

View File

@ -75,9 +75,9 @@ class _HomeState extends State<Home> {
), ),
_Page( _Page(
content: Container(), content: Container(),
titleBar: const Text('Saved'), titleBar: const Text('Library'),
item: const BottomNavigationBarItem( item: const BottomNavigationBarItem(
label: 'Saved', label: 'Library',
icon: Icon(Icons.bookmark), icon: Icon(Icons.bookmark),
), ),
), ),