64 lines
1.3 KiB
Dart
64 lines
1.3 KiB
Dart
import 'package:journaler/db.dart';
|
|
|
|
class Note {
|
|
final String date;
|
|
String content;
|
|
|
|
Note({required this.date, required this.content});
|
|
}
|
|
|
|
class Scratch {
|
|
final String date;
|
|
String content;
|
|
|
|
Scratch({required this.date, required this.content});
|
|
}
|
|
|
|
Future<Note?> getLatestNote() async {
|
|
final note = await DB.db.rawQuery(
|
|
'SELECT content, date FROM notes ORDER BY date DESC LIMIT 1',
|
|
);
|
|
if (note.isEmpty) {
|
|
return null;
|
|
}
|
|
return Note(
|
|
date: note[0]['date'] as String,
|
|
content: note[0]['content'] as String,
|
|
);
|
|
}
|
|
|
|
Future<void> createNote(String content) async {
|
|
if (content.isEmpty) {
|
|
return;
|
|
}
|
|
await DB.db.insert('notes', {'content': content});
|
|
}
|
|
|
|
Future<void> updateNote(Note note) async {
|
|
await DB.db.update(
|
|
'notes',
|
|
{'content': note.content},
|
|
where: 'date = ?',
|
|
whereArgs: [note.date],
|
|
);
|
|
}
|
|
|
|
Future<Scratch?> getLatestScratch() async {
|
|
final scratch = await DB.db.rawQuery(
|
|
'SELECT content, date FROM scratches ORDER BY date DESC LIMIT 1',
|
|
);
|
|
|
|
if (scratch.isEmpty) {
|
|
return null;
|
|
} else {
|
|
return Scratch(
|
|
date: scratch[0]['date'] as String,
|
|
content: scratch[0]['content'] as String,
|
|
);
|
|
}
|
|
}
|
|
|
|
Future<void> createScratch(String content) async {
|
|
await DB.db.insert('scratches', {'content': content});
|
|
}
|