|
@@ -14,6 +14,8 @@ class MyDataBase {
|
|
|
static Future<MyDataBase> get database async {
|
|
|
if(_instance == null){
|
|
|
_instance = MyDataBase();
|
|
|
+ String path = join((await Sqlite.getDatabasesPath()), 'data.db');
|
|
|
+ print('dbPath:${path}');
|
|
|
await _instance.init();
|
|
|
}
|
|
|
return _instance;
|
|
@@ -21,16 +23,37 @@ class MyDataBase {
|
|
|
|
|
|
Future init() async {
|
|
|
_database = await Sqlite.openDatabase(join((await Sqlite.getDatabasesPath()), 'data.db'));
|
|
|
- List<Map<String, dynamic>> result = await _database.rawQuery("CREATE TABLE IF NOT EXISTS $tableMembers(id INTEGER PRIMARY KEY, "
|
|
|
- "name TEXT, tel TEXT, birth TEXT, prov TEXT, city TEXT, area TEXT, addr TEXT, remark TEXT)");
|
|
|
+ List<Map<String, dynamic>> result = await _database.rawQuery("CREATE TABLE IF NOT EXISTS $tableMembers(id INTEGER PRIMARY KEY,"
|
|
|
+ "name TEXT, tel TEXT, birth TEXT, prov TEXT, city TEXT, area TEXT, addr TEXT, remark TEXT, services TEXT,"
|
|
|
+ "createtime DATETIME DEFAULT CURRENT_TIMESTAMP,"
|
|
|
+ "updatetime DATETIME DEFAULT CURRENT_TIMESTAMP);"
|
|
|
+ "CREATE TRIGGER [updatetime]"
|
|
|
+ "AFTER UPDATE"
|
|
|
+ "ON members"
|
|
|
+ "FOR EACH ROW"
|
|
|
+ "BEGIN"
|
|
|
+ "UPDATE members SET updatetime = CURRENT_TIMESTAMP WHERE id = old.id;"
|
|
|
+ "END;");
|
|
|
+ List<Map<String, dynamic>> services = await _database.rawQuery("CREATE TABLE IF NOT EXISTS $tableServices(id INTEGER PRIMARY KEY, "
|
|
|
+ "kind TEXT, cycle INTEGER, cycleUnit TEXT, remindDay INTEGER, remark TEXT, "
|
|
|
+ "createtime DATETIME DEFAULT CURRENT_TIMESTAMP, "
|
|
|
+ "updatetime DATETIME DEFAULT CURRENT_TIMESTAMP);"
|
|
|
+ "CREATE TRIGGER [updatetime]"
|
|
|
+ "AFTER UPDATE"
|
|
|
+ "ON members"
|
|
|
+ "FOR EACH ROW"
|
|
|
+ "BEGIN"
|
|
|
+ "UPDATE members SET updatetime = CURRENT_TIMESTAMP WHERE id = old.id;"
|
|
|
+ "END;");
|
|
|
}
|
|
|
|
|
|
Future<List<JXMemberModel>> queryAllMembers() async {
|
|
|
List<Map<String , dynamic>> data = await _database.query("$tableMembers");
|
|
|
- return data.map((e) =>
|
|
|
- JXMemberModel()..id = e['id']..name = e['name']..tel = e['tel']
|
|
|
- ).toList();
|
|
|
-
|
|
|
+ return data.map((e) => JXMemberModel()
|
|
|
+ ..id = e['id']
|
|
|
+ ..name = e['name']
|
|
|
+ ..tel = e['tel'])
|
|
|
+ .toList();
|
|
|
}
|
|
|
|
|
|
Future<void> saveMember(JXMemberModel jxMemberModel) async {
|
|
@@ -41,8 +64,25 @@ class MyDataBase {
|
|
|
);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- Future<void> saveService(JXMemberModel jxMemberModel, JXServiceModel jxServiceModel) {
|
|
|
-
|
|
|
+ /*服务*/
|
|
|
+ Future<List <JXServiceModel>> queryAllServices() async {
|
|
|
+ List<Map<String , dynamic>> data = await _database.query("$tableServices");
|
|
|
+ return data.map((e) => JXServiceModel()
|
|
|
+ ..id = e['id']
|
|
|
+ ..kind = e['kind']
|
|
|
+ ..cycle = e['cycle']
|
|
|
+ ..cycleUnit = e['cycleUnit']
|
|
|
+ ..remindDay = e['remindDay']
|
|
|
+ ..remark = e['remark'])
|
|
|
+ .toList();
|
|
|
+ }
|
|
|
+ /*添加新服务*/
|
|
|
+ Future<JXServiceModel> saveService(JXServiceModel jxServiceModel) async {
|
|
|
+ await _database.insert(
|
|
|
+ tableServices,
|
|
|
+ jxServiceModel.toMap(),
|
|
|
+ conflictAlgorithm: ConflictAlgorithm.replace,
|
|
|
+ );
|
|
|
+ return null;
|
|
|
}
|
|
|
}
|