Created
June 8, 2020 17:46
-
-
Save shivanchalaeologic/459fc3c039aaea09eb6db55b1026617b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:sembast/sembast.dart'; | |
import 'package:sembast_demo/db/data_base.dart'; | |
import 'package:sembast_demo/model/books_model.dart'; | |
class BooksDao { | |
static const String folderName = "Books"; | |
final _booksFolder = intMapStoreFactory.store(folderName); | |
Future<Database> get _db async => await AppDatabase.instance.database; | |
Future insertBooks(Books books) async { | |
await _booksFolder.add(await _db, books.toJson()); | |
} | |
Future updateBooks(Books books) async { | |
final finder = Finder(filter: Filter.byKey(books.rollNo)); | |
await _booksFolder.update(await _db, books.toJson(), finder: finder); | |
} | |
Future delete(Books books) async { | |
final finder = Finder(filter: Filter.byKey(books.rollNo)); | |
await _booksFolder.delete(await _db, finder: finder); | |
} | |
Future<List<Books>> getAllBooks() async { | |
final recordSnapshot = await _booksFolder.find(await _db); | |
return recordSnapshot.map((snapshot) { | |
final books = Books.fromJson(snapshot.value); | |
return books; | |
}).toList(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment