fix(persistence): change mode insert or replace to upsert
This commit is contained in:
@@ -42,10 +42,9 @@ class ChannelDao extends DatabaseAccessor<MoorChatDatabase>
|
||||
|
||||
/// Updates all the channels using the new [channelList] data
|
||||
Future<void> updateChannels(List<ChannelModel> channelList) => batch(
|
||||
(it) => it.insertAll(
|
||||
(it) => it.insertAllOnConflictUpdate(
|
||||
channels,
|
||||
channelList.map((c) => c.toEntity()).toList(),
|
||||
mode: InsertMode.insertOrReplace,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -45,13 +45,12 @@ class ChannelQueryDao extends DatabaseAccessor<MoorChatDatabase>
|
||||
}
|
||||
|
||||
await batch((it) {
|
||||
it.insertAll(
|
||||
it.insertAllOnConflictUpdate(
|
||||
channelQueries,
|
||||
cids
|
||||
.map((cid) =>
|
||||
ChannelQueryEntity(queryHash: hash, channelCid: cid))
|
||||
.toList(),
|
||||
mode: InsertMode.insertOrReplace,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -26,7 +26,7 @@ class ConnectionEventDao extends DatabaseAccessor<MoorChatDatabase>
|
||||
/// Update stored connection event with latest data
|
||||
Future<int> updateConnectionEvent(Event event) => transaction(() async {
|
||||
final connectionInfo = await select(connectionEvents).getSingleOrNull();
|
||||
return into(connectionEvents).insert(
|
||||
return into(connectionEvents).insertOnConflictUpdate(
|
||||
ConnectionEventEntity(
|
||||
id: 1,
|
||||
type: event.type,
|
||||
@@ -38,7 +38,6 @@ class ConnectionEventDao extends DatabaseAccessor<MoorChatDatabase>
|
||||
unreadChannels:
|
||||
event.unreadChannels ?? connectionInfo?.unreadChannels,
|
||||
),
|
||||
mode: InsertMode.insertOrReplace,
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
@@ -32,10 +32,9 @@ class MemberDao extends DatabaseAccessor<MoorChatDatabase>
|
||||
/// Updates all the members using the new [memberList] data
|
||||
Future<void> updateMembers(String cid, List<Member> memberList) async =>
|
||||
batch(
|
||||
(it) => it.insertAll(
|
||||
(it) => it.insertAllOnConflictUpdate(
|
||||
members,
|
||||
memberList.map((m) => m.toEntity(cid: cid)).toList(),
|
||||
mode: InsertMode.insertOrReplace,
|
||||
),
|
||||
);
|
||||
|
||||
|
||||
@@ -171,10 +171,9 @@ class MessageDao extends DatabaseAccessor<MoorChatDatabase>
|
||||
/// the new [messageList] data
|
||||
Future<void> updateMessages(String cid, List<Message> messageList) => batch(
|
||||
(batch) {
|
||||
batch.insertAll(
|
||||
batch.insertAllOnConflictUpdate(
|
||||
messages,
|
||||
messageList.map((it) => it.toEntity(cid: cid)).toList(),
|
||||
mode: InsertMode.insertOrReplace,
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
@@ -170,10 +170,9 @@ class PinnedMessageDao extends DatabaseAccessor<MoorChatDatabase>
|
||||
/// the new [messageList] data
|
||||
Future<void> updateMessages(String cid, List<Message> messageList) => batch(
|
||||
(batch) {
|
||||
batch.insertAll(
|
||||
batch.insertAllOnConflictUpdate(
|
||||
pinnedMessages,
|
||||
messageList.map((it) => it.toPinnedEntity(cid: cid)).toList(),
|
||||
mode: InsertMode.insertOrReplace,
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
@@ -42,10 +42,9 @@ class ReactionDao extends DatabaseAccessor<MoorChatDatabase>
|
||||
|
||||
/// Updates the reactions data with the new [reactionList] data
|
||||
Future<void> updateReactions(List<Reaction> reactionList) => batch((it) {
|
||||
it.insertAll(
|
||||
it.insertAllOnConflictUpdate(
|
||||
reactions,
|
||||
reactionList.map((r) => r.toEntity()).toList(),
|
||||
mode: InsertMode.insertOrReplace,
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
@@ -30,10 +30,9 @@ class ReadDao extends DatabaseAccessor<MoorChatDatabase> with _$ReadDaoMixin {
|
||||
/// Updates the read data of a particular channel with
|
||||
/// the new [readList] data
|
||||
Future<void> updateReads(String cid, List<Read> readList) => batch(
|
||||
(it) => it.insertAll(
|
||||
(it) => it.insertAllOnConflictUpdate(
|
||||
reads,
|
||||
readList.map((r) => r.toEntity(cid: cid)).toList(),
|
||||
mode: InsertMode.insertOrReplace,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -14,10 +14,9 @@ class UserDao extends DatabaseAccessor<MoorChatDatabase> with _$UserDaoMixin {
|
||||
|
||||
/// Updates the users data with the new [userList] data
|
||||
Future<void> updateUsers(List<User> userList) => batch(
|
||||
(it) => it.insertAll(
|
||||
(it) => it.insertAllOnConflictUpdate(
|
||||
users,
|
||||
userList.map((u) => u.toEntity()).toList(),
|
||||
mode: InsertMode.insertOrReplace,
|
||||
),
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user