read method

Future<ChatId?> read(
  1. UserId id
)

Returns the ChatId stored in the database by the provided id, if any.

Implementation

Future<ChatId?> read(UserId id) async {
  final ChatId? existing = _cache[id];
  if (existing != null) {
    return existing;
  }

  return await safe<ChatId?>((db) async {
    try {
      final stmt = db.select(db.monologs)
        ..where((u) => u.userId.equals(id.val));
      final MonologRow? row = await stmt.getSingleOrNull();

      if (row == null) {
        return null;
      }

      return _MonologDb.fromDb(row);
    } on DriftRemoteException {
      // Upsert may fail during E2E tests due to rapid database resetting and
      // creating.
      return null;
    }
  }, tag: 'monolog.read($id)');
}