Skip to content

Instantly share code, notes, and snippets.

@ericgrandt
Created April 17, 2019 18:50
Show Gist options
  • Save ericgrandt/88a40ab6402dc9ac274b45a1f233505e to your computer and use it in GitHub Desktop.
Save ericgrandt/88a40ab6402dc9ac274b45a1f233505e to your computer and use it in GitHub Desktop.
newNote(Note note) async {
final db = await database;
var res = await db.insert('note', note.toJson());
return res;
}
getNotes() async {
final db = await database;
var res = await db.query('note');
List<Note> notes = res.isNotEmpty ? res.map((note) => Note.fromJson(note)).toList() : [];
return notes;
}
getNote(int id) async {
final db = await database;
var res = await db.query('note', where: 'id = ?', whereArgs: [id]);
return res.isNotEmpty ? Note.fromJson(res.first) : null;
}
updateNote(Note note) async {
final db = await database;
var res = await db.update('note', note.toJson(), where: 'id = ?', whereArgs: [note.id]);
return res;
}
deleteNote(int id) async {
final db = await database;
db.delete('note', where: 'id = ?', whereArgs: [id]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment