upsert method

Future<DtoBlocklistRecord> upsert(
  1. DtoBlocklistRecord record
)

Creates or updates the provided record in the database.

Implementation

Future<DtoBlocklistRecord> upsert(DtoBlocklistRecord record) async {
  _cache[record.userId] = record;

  final result = await safe((db) async {
    final DtoBlocklistRecord stored = _BlocklistDb.fromDb(
      await db
          .into(db.blocklist)
          .insertReturning(record.toDb(), mode: InsertMode.insertOrReplace),
    );

    return stored;
  }, tag: 'blocklist.upsert(record)');

  _cache.remove(record.userId);

  return result ?? record;
}