diff --git a/lib/data/app_database.dart b/lib/data/app_database.dart index 1ebd8cc..ca07fe5 100644 --- a/lib/data/app_database.dart +++ b/lib/data/app_database.dart @@ -18,7 +18,8 @@ class Categories extends Table { BoolColumn get isDeleted => boolean().named('is_deleted').withDefault(const Constant(false))(); IntColumn get colorValue => integer().nullable().named('color_value')(); - IntColumn get iconCodePoint => integer().nullable().named('icon_code_point')(); + IntColumn get iconCodePoint => + integer().nullable().named('icon_code_point')(); BoolColumn get isDirty => boolean().named('is_dirty').withDefault(const Constant(true))(); DateTimeColumn get updatedAt => dateTime().named('updated_at')(); @@ -40,11 +41,11 @@ class Notes extends Table { BoolColumn get isDeleted => boolean().named('is_deleted').withDefault(const Constant(false))(); TextColumn get categoryId => text().nullable().named('category_id')(); - BoolColumn get isDirty => + BoolColumn get isDirty => boolean().named('is_dirty').withDefault(const Constant(true))(); - @override - Set get primaryKey => {id}; + @override + Set get primaryKey => {id}; } @DriftDatabase(tables: [Notes, Categories]) @@ -72,12 +73,13 @@ class AppDatabase extends _$AppDatabase { await customStatement('UPDATE categories SET icon_code_point = NULL'); } if (from < 4) { - final List activeNotes = await (select(notes) - ..where((n) => n.isDeleted.equals(false)) - ..orderBy([ - (note) => OrderingTerm(expression: note.sortIndex), - ])) - .get(); + final List activeNotes = + await (select(notes) + ..where((n) => n.isDeleted.equals(false)) + ..orderBy([ + (note) => OrderingTerm(expression: note.sortIndex), + ])) + .get(); final List rebalancedPositions = rebalanceNotePositions( activeNotes.length, @@ -134,24 +136,25 @@ class AppDatabase extends _$AppDatabase { Future insertNoteAtTop(NotesCompanion note) { return transaction(() async { - final DbNote? topNote = await (select(notes) - ..where((n) => n.isDeleted.equals(false)) - ..orderBy([ - (note) => OrderingTerm( - expression: note.sortIndex, - mode: OrderingMode.desc, - ), - ]) - ..limit(1)) - .getSingleOrNull(); + final DbNote? topNote = + await (select(notes) + ..where((n) => n.isDeleted.equals(false)) + ..orderBy([ + (note) => OrderingTerm( + expression: note.sortIndex, + mode: OrderingMode.desc, + ), + ]) + ..limit(1)) + .getSingleOrNull(); final int nextSortIndex = topNote == null ? 0 : topNote.sortIndex + notePositionStep; - await into(notes).insert( - note.copyWith(sortIndex: Value(nextSortIndex)), - ); + await into( + notes, + ).insert(note.copyWith(sortIndex: Value(nextSortIndex))); return nextSortIndex; }); } @@ -206,17 +209,20 @@ class AppDatabase extends _$AppDatabase { required int newIndex, }) { return transaction(() async { - final List orderedNotes = await (select(notes) - ..where((n) => n.isDeleted.equals(false)) - ..orderBy([ - (note) => OrderingTerm( - expression: note.sortIndex, - mode: OrderingMode.desc, - ), - ])) - .get(); + final List orderedNotes = + await (select(notes) + ..where((n) => n.isDeleted.equals(false)) + ..orderBy([ + (note) => OrderingTerm( + expression: note.sortIndex, + mode: OrderingMode.desc, + ), + ])) + .get(); - final int currentIndex = orderedNotes.indexWhere((DbNote row) => row.id == id); + final int currentIndex = orderedNotes.indexWhere( + (DbNote row) => row.id == id, + ); if (currentIndex == -1) { return; } @@ -277,22 +283,23 @@ class AppDatabase extends _$AppDatabase { } Future> getDeletedNotes() { - // A note is considered deleted (in the trash) when `is_deleted` is true - // and at least one of `title` or `body` is not empty. Previously the - // query required both title AND body to be non-empty which excluded - // notes that had an empty body (common) from appearing in the trash. - return (select(notes) - ..where( - (n) => n.isDeleted.equals(true) & - (n.title.isNotValue('') | n.body.isNotValue('')), - ) - ..orderBy([ - (note) => OrderingTerm( - expression: note.sortIndex, - mode: OrderingMode.desc, - ), - ])) - .get(); + // A note is considered deleted (in the trash) when `is_deleted` is true + // and at least one of `title` or `body` is not empty. Previously the + // query required both title AND body to be non-empty which excluded + // notes that had an empty body (common) from appearing in the trash. + return (select(notes) + ..where( + (n) => + n.isDeleted.equals(true) & + (n.title.isNotValue('') | n.body.isNotValue('')), + ) + ..orderBy([ + (note) => OrderingTerm( + expression: note.sortIndex, + mode: OrderingMode.desc, + ), + ])) + .get(); } Future> getCategoriesChangedSince(DateTime since) { diff --git a/lib/data/note_positioning.dart b/lib/data/note_positioning.dart index 69c517b..3ba7198 100644 --- a/lib/data/note_positioning.dart +++ b/lib/data/note_positioning.dart @@ -43,4 +43,4 @@ List rebalanceNotePositions(int itemCount) { itemCount, (int index) => (itemCount - 1 - index) * notePositionStep, ); -} \ No newline at end of file +} diff --git a/lib/data/note_repository.dart b/lib/data/note_repository.dart index 7181803..845228b 100644 --- a/lib/data/note_repository.dart +++ b/lib/data/note_repository.dart @@ -59,9 +59,9 @@ class NoteRepository { Future createCategory(Category category) async { debugPrint('createCategory called with: ${category.name}'); - final DbCategory? existingCategory = await ( - _database.select(_database.categories)..where((c) => c.id.equals(category.id)) - ).getSingleOrNull(); + final DbCategory? existingCategory = await (_database.select( + _database.categories, + )..where((c) => c.id.equals(category.id))).getSingleOrNull(); final int effectiveServerVersion = math.max( category.serverVersion, existingCategory?.serverVersion ?? category.serverVersion, diff --git a/test/note_positioning_test.dart b/test/note_positioning_test.dart index 79beffc..a3b1c25 100644 --- a/test/note_positioning_test.dart +++ b/test/note_positioning_test.dart @@ -14,10 +14,7 @@ void main() { midpointNotePosition(higherPosition: 20000, lowerPosition: 10000), 15000, ); - expect( - midpointNotePosition(higherPosition: 2, lowerPosition: 1), - isNull, - ); + expect(midpointNotePosition(higherPosition: 2, lowerPosition: 1), isNull); expect(rebalanceNotePositions(3), [20000, 10000, 0]); }); -} \ No newline at end of file +}