From 9924860181a47d3e9aa61ba44f84731cc653fd44 Mon Sep 17 00:00:00 2001 From: Hyperling Date: Wed, 12 Feb 2025 08:22:16 -0700 Subject: [PATCH] Create the beginning of a DB backup system. --- lib/models/database_backup.dart | 57 +++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 lib/models/database_backup.dart diff --git a/lib/models/database_backup.dart b/lib/models/database_backup.dart new file mode 100644 index 0000000..dae3553 --- /dev/null +++ b/lib/models/database_backup.dart @@ -0,0 +1,57 @@ +// Local +import '/models/expense.dart'; +import '/models/income.dart'; +import '/models/asset.dart'; +import '/db.dart'; + +/// TODO: +/// - Test the JSON data to ensure it's formed properly. +/// - Enable the functions for income and assets once they are implemented. +/// - Create a method (factory?) to load JSON data and delete/insert the data. + +class DatabaseBackup { + List expenseTable = []; + List incomeTable = []; + List assetTable = []; + + void loadTables() async { + expenseTable = await DatabaseHelper.instance.getExpenses(); + //incomeTable = await DatabaseHelper.instance.getIncomes(); + //assetTable = await DatabaseHelper.instance.getAssets(); + } + + Map toMap() { + loadTables(); // TODO: Do we somehow need to wait for this to finish? + return { + 'expense_table': [ + for (Expense e in expenseTable) + { + 'id': e.id, + 'name': e.name, + 'cost': e.amount, + 'frequency': e.frequency.title, + 'description': e.description, + }, + ], + 'income_table': [ + for (Income i in incomeTable) + { + 'id': i.id, + 'name': i.name, + 'revenue': i.amount, + 'frequency': i.frequency.title, + 'description': i.description, + }, + ], + 'asset_table': [ + for (Asset a in assetTable) + { + 'id': a.id, + 'name': a.name, + 'amount': a.amount, + 'description': a.description, + }, + ], + }; + } +}