upsert method

Future<void> upsert(
  1. ChatId id,
  2. ChatMessage message
)

Creates or updates the provided message in the database.

Implementation

Future<void> upsert(ChatId id, ChatMessage message) async {
  _cache[id] = message;
  _controllers[id]?.add(message);

  await safe((db) async {
    await db
        .into(db.drafts)
        .insertReturning(message.toDb(), mode: InsertMode.insertOrReplace);
  }, tag: 'draft.upsert($id, message)');

  _cache.remove(id);
}