Add methods for accessing Incomes and Assets in the database.
This commit is contained in:
parent
02f08093c9
commit
778b4e2f39
91
lib/db.dart
91
lib/db.dart
@ -9,6 +9,8 @@ import 'package:sqflite/sqflite.dart';
|
|||||||
|
|
||||||
// Local
|
// Local
|
||||||
import '/models/expense.dart';
|
import '/models/expense.dart';
|
||||||
|
import '/models/income.dart';
|
||||||
|
import '/models/asset.dart';
|
||||||
import '/models/tracked_item.dart';
|
import '/models/tracked_item.dart';
|
||||||
|
|
||||||
// Leaned on this example:
|
// Leaned on this example:
|
||||||
@ -118,9 +120,98 @@ class DatabaseHelper {
|
|||||||
|
|
||||||
/// Income Section
|
/// Income Section
|
||||||
///
|
///
|
||||||
|
Future<List<Income>> getIncomes() async {
|
||||||
|
Database db = await instance.db;
|
||||||
|
var incomes = await db.query("income", orderBy: "name");
|
||||||
|
List<Income> incomeList = incomes.isNotEmpty
|
||||||
|
? incomes.map((c) => Income.fromMap(c)).toList()
|
||||||
|
: [];
|
||||||
|
return incomeList;
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<int> addIncome(TrackedItem income) async {
|
||||||
|
Database db = await instance.db;
|
||||||
|
return await db.insert(
|
||||||
|
"income",
|
||||||
|
income.toMap(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<int> removeIncome(int id) async {
|
||||||
|
Database db = await instance.db;
|
||||||
|
return await db.delete(
|
||||||
|
"income",
|
||||||
|
where: "id = ?",
|
||||||
|
whereArgs: [id],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<int> updateIncome(TrackedItem income) async {
|
||||||
|
Database db = await instance.db;
|
||||||
|
return await db.update(
|
||||||
|
"income",
|
||||||
|
income.toMap(),
|
||||||
|
where: "id = ?",
|
||||||
|
whereArgs: [income.id],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<bool> checkIncomeNameExists(String name) async {
|
||||||
|
Database db = await instance.db;
|
||||||
|
var incomes = await db.query(
|
||||||
|
"income",
|
||||||
|
where: "name = ?",
|
||||||
|
whereArgs: [name],
|
||||||
|
);
|
||||||
|
return incomes.isNotEmpty;
|
||||||
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
/// Liquid Asset Section
|
/// Liquid Asset Section
|
||||||
|
Future<List<Asset>> getAssets() async {
|
||||||
|
Database db = await instance.db;
|
||||||
|
var assets = await db.query("asset", orderBy: "name");
|
||||||
|
List<Asset> assetList =
|
||||||
|
assets.isNotEmpty ? assets.map((c) => Asset.fromMap(c)).toList() : [];
|
||||||
|
return assetList;
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<int> addAsset(TrackedItem asset) async {
|
||||||
|
Database db = await instance.db;
|
||||||
|
return await db.insert(
|
||||||
|
"asset",
|
||||||
|
asset.toMap(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<int> removeAsset(int id) async {
|
||||||
|
Database db = await instance.db;
|
||||||
|
return await db.delete(
|
||||||
|
"asset",
|
||||||
|
where: "id = ?",
|
||||||
|
whereArgs: [id],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<int> updateAsset(TrackedItem asset) async {
|
||||||
|
Database db = await instance.db;
|
||||||
|
return await db.update(
|
||||||
|
"asset",
|
||||||
|
asset.toMap(),
|
||||||
|
where: "id = ?",
|
||||||
|
whereArgs: [asset.id],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<bool> checkAssetNameExists(String name) async {
|
||||||
|
Database db = await instance.db;
|
||||||
|
var assets = await db.query(
|
||||||
|
"asset",
|
||||||
|
where: "name = ?",
|
||||||
|
whereArgs: [name],
|
||||||
|
);
|
||||||
|
return assets.isNotEmpty;
|
||||||
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user