Usmonov akramjonning mobil ilovalarni ishlab chiqish kursidan tayyorlagan
Download 141.99 Kb.
|
1 2
Bog'liqmobil ilovalani ishlab chiqish
//Save User
saveData(IncomeExpensesModel user) async { return await _repository.insertData('mydb', user.toMap()); } //Read All Users readAllData() async { return await _repository.readData('mydb'); } //Edit User updateData(IncomeExpensesModel user) async { return await _repository.updateData('mydb', user.toMap()); } deleteData(userId) async { return await _repository.deleteDataById('mydb', userId); } } Bu kod esa bizga kerak bo’luvchi so’rovlar uchun methodlar bu bizning ishimizni osonlashtiradi, ya’ni har safar bir hil kod yozish o’rniga faqatgina methodni chaqiramiz. import 'package:my_simple_store/data/data_providers/database_connection.dart'; import 'package:sqflite/sqflite.dart'; class Repository { late DatabaseConnection _databaseConnection; Repository(){ _databaseConnection = DatabaseConnection(); } static Database? _database; Future if (_database != null) { return _database; } else { _database = await _databaseConnection.setDatabase(); return _database; } } //Insert User insertData(table, data) async { var connection = await database; return await connection?.insert(table, data); } //Read All Record readData(table) async { var connection = await database; return await connection?.query(table); } //Read a Single Record By ID readDataById(table, itemId) async { var connection = await database; return await connection?.query(table, where: 'id=?', whereArgs: [itemId]); } //Update User updateData(table, data) async { var connection = await database; return await connection ?.update(table, data, where: 'id=?', whereArgs: [data['id']]); } //Delete User deleteDataById(table, itemId) async { var connection = await database; return await connection?.rawDelete("delete from $table where id=$itemId"); } }
Download 141.99 Kb. Do'stlaringiz bilan baham: |
1 2
Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling
ma'muriyatiga murojaat qiling