123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- import 'package:path/path.dart';
- import 'package:sqflite/sqflite.dart' as Sqlite;
- import 'package:sqflite/sqflite.dart';
- import 'package:taskservice/Model/JXMemberModel.dart';
- import 'package:taskservice/Model/JXServiceModel.dart';
- class MyDataBase {
- static MyDataBase _instance;
- Database _database;
- String tableMembers = 'members';
- String tableServices = 'services';
- static Future<MyDataBase> get database async {
- if(_instance == null){
- _instance = MyDataBase();
- await _instance.init();
- }
- return _instance;
- }
- 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)");
- }
- 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();
- }
- Future<void> saveMember(JXMemberModel jxMemberModel) async {
- await _database.insert(
- tableMembers,
- jxMemberModel.toMap(),
- conflictAlgorithm: ConflictAlgorithm.replace,
- );
- }
- Future<void> saveService(JXMemberModel jxMemberModel, JXServiceModel jxServiceModel) {
- }
- }
|