Create the beginning of a DB backup system.

This commit is contained in:
Hyperling 2025-02-12 08:22:16 -07:00
parent 60363c29f2
commit 9924860181

View File

@ -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<Expense> expenseTable = [];
List<Income> incomeTable = [];
List<Asset> assetTable = [];
void loadTables() async {
expenseTable = await DatabaseHelper.instance.getExpenses();
//incomeTable = await DatabaseHelper.instance.getIncomes();
//assetTable = await DatabaseHelper.instance.getAssets();
}
Map<String, dynamic> 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,
},
],
};
}
}