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,
"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" (

View File

@ -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);
}

View File

@ -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 =

View File

@ -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<Directory> 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<Directory> exportDirectory() async {
/// Returns the path to which the data was saved.
Future<String> 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<void> exportHistoryTo(Directory dir) async {
file.writeAsStringSync(jsonEncode(jsonEntries));
}
Future<void> exportSavedListsTo(Directory dir) async {
Future<void> 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');
}

View File

@ -7,7 +7,7 @@ import 'archive_format.dart';
Future<void> importData(Directory dir) async {
await Future.wait([
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 {
print('TODO: Implement importSavedLists');
Future<void> importLibraryListsFrom(Directory libraryListsDir) async {
print('TODO: Implement importLibraryLists');
}

View File

@ -34,13 +34,13 @@ class HistoryEntry {
///
/// - entryId
/// - timestamp
/// - searchword?
/// - word?
/// - kanji?
factory HistoryEntry.fromDBMap(Map<String, Object?> 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 {

View File

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