style: Format code for consistency and readability across database and note positioning files
This commit is contained in:
@@ -18,7 +18,8 @@ class Categories extends Table {
|
|||||||
BoolColumn get isDeleted =>
|
BoolColumn get isDeleted =>
|
||||||
boolean().named('is_deleted').withDefault(const Constant(false))();
|
boolean().named('is_deleted').withDefault(const Constant(false))();
|
||||||
IntColumn get colorValue => integer().nullable().named('color_value')();
|
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 =>
|
BoolColumn get isDirty =>
|
||||||
boolean().named('is_dirty').withDefault(const Constant(true))();
|
boolean().named('is_dirty').withDefault(const Constant(true))();
|
||||||
DateTimeColumn get updatedAt => dateTime().named('updated_at')();
|
DateTimeColumn get updatedAt => dateTime().named('updated_at')();
|
||||||
@@ -72,7 +73,8 @@ class AppDatabase extends _$AppDatabase {
|
|||||||
await customStatement('UPDATE categories SET icon_code_point = NULL');
|
await customStatement('UPDATE categories SET icon_code_point = NULL');
|
||||||
}
|
}
|
||||||
if (from < 4) {
|
if (from < 4) {
|
||||||
final List<DbNote> activeNotes = await (select(notes)
|
final List<DbNote> activeNotes =
|
||||||
|
await (select(notes)
|
||||||
..where((n) => n.isDeleted.equals(false))
|
..where((n) => n.isDeleted.equals(false))
|
||||||
..orderBy([
|
..orderBy([
|
||||||
(note) => OrderingTerm(expression: note.sortIndex),
|
(note) => OrderingTerm(expression: note.sortIndex),
|
||||||
@@ -134,7 +136,8 @@ class AppDatabase extends _$AppDatabase {
|
|||||||
|
|
||||||
Future<int> insertNoteAtTop(NotesCompanion note) {
|
Future<int> insertNoteAtTop(NotesCompanion note) {
|
||||||
return transaction(() async {
|
return transaction(() async {
|
||||||
final DbNote? topNote = await (select(notes)
|
final DbNote? topNote =
|
||||||
|
await (select(notes)
|
||||||
..where((n) => n.isDeleted.equals(false))
|
..where((n) => n.isDeleted.equals(false))
|
||||||
..orderBy([
|
..orderBy([
|
||||||
(note) => OrderingTerm(
|
(note) => OrderingTerm(
|
||||||
@@ -149,9 +152,9 @@ class AppDatabase extends _$AppDatabase {
|
|||||||
? 0
|
? 0
|
||||||
: topNote.sortIndex + notePositionStep;
|
: topNote.sortIndex + notePositionStep;
|
||||||
|
|
||||||
await into(notes).insert(
|
await into(
|
||||||
note.copyWith(sortIndex: Value<int>(nextSortIndex)),
|
notes,
|
||||||
);
|
).insert(note.copyWith(sortIndex: Value<int>(nextSortIndex)));
|
||||||
return nextSortIndex;
|
return nextSortIndex;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -206,7 +209,8 @@ class AppDatabase extends _$AppDatabase {
|
|||||||
required int newIndex,
|
required int newIndex,
|
||||||
}) {
|
}) {
|
||||||
return transaction(() async {
|
return transaction(() async {
|
||||||
final List<DbNote> orderedNotes = await (select(notes)
|
final List<DbNote> orderedNotes =
|
||||||
|
await (select(notes)
|
||||||
..where((n) => n.isDeleted.equals(false))
|
..where((n) => n.isDeleted.equals(false))
|
||||||
..orderBy([
|
..orderBy([
|
||||||
(note) => OrderingTerm(
|
(note) => OrderingTerm(
|
||||||
@@ -216,7 +220,9 @@ class AppDatabase extends _$AppDatabase {
|
|||||||
]))
|
]))
|
||||||
.get();
|
.get();
|
||||||
|
|
||||||
final int currentIndex = orderedNotes.indexWhere((DbNote row) => row.id == id);
|
final int currentIndex = orderedNotes.indexWhere(
|
||||||
|
(DbNote row) => row.id == id,
|
||||||
|
);
|
||||||
if (currentIndex == -1) {
|
if (currentIndex == -1) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -283,7 +289,8 @@ class AppDatabase extends _$AppDatabase {
|
|||||||
// notes that had an empty body (common) from appearing in the trash.
|
// notes that had an empty body (common) from appearing in the trash.
|
||||||
return (select(notes)
|
return (select(notes)
|
||||||
..where(
|
..where(
|
||||||
(n) => n.isDeleted.equals(true) &
|
(n) =>
|
||||||
|
n.isDeleted.equals(true) &
|
||||||
(n.title.isNotValue('') | n.body.isNotValue('')),
|
(n.title.isNotValue('') | n.body.isNotValue('')),
|
||||||
)
|
)
|
||||||
..orderBy([
|
..orderBy([
|
||||||
|
|||||||
@@ -59,9 +59,9 @@ class NoteRepository {
|
|||||||
Future<void> createCategory(Category category) async {
|
Future<void> createCategory(Category category) async {
|
||||||
debugPrint('createCategory called with: ${category.name}');
|
debugPrint('createCategory called with: ${category.name}');
|
||||||
|
|
||||||
final DbCategory? existingCategory = await (
|
final DbCategory? existingCategory = await (_database.select(
|
||||||
_database.select(_database.categories)..where((c) => c.id.equals(category.id))
|
_database.categories,
|
||||||
).getSingleOrNull();
|
)..where((c) => c.id.equals(category.id))).getSingleOrNull();
|
||||||
final int effectiveServerVersion = math.max(
|
final int effectiveServerVersion = math.max(
|
||||||
category.serverVersion,
|
category.serverVersion,
|
||||||
existingCategory?.serverVersion ?? category.serverVersion,
|
existingCategory?.serverVersion ?? category.serverVersion,
|
||||||
|
|||||||
@@ -14,10 +14,7 @@ void main() {
|
|||||||
midpointNotePosition(higherPosition: 20000, lowerPosition: 10000),
|
midpointNotePosition(higherPosition: 20000, lowerPosition: 10000),
|
||||||
15000,
|
15000,
|
||||||
);
|
);
|
||||||
expect(
|
expect(midpointNotePosition(higherPosition: 2, lowerPosition: 1), isNull);
|
||||||
midpointNotePosition(higherPosition: 2, lowerPosition: 1),
|
|
||||||
isNull,
|
|
||||||
);
|
|
||||||
expect(rebalanceNotePositions(3), <int>[20000, 10000, 0]);
|
expect(rebalanceNotePositions(3), <int>[20000, 10000, 0]);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user