read method

Future<DtoChatMember?> read(
  1. ChatId chatId,
  2. UserId userId
)

Returns the DtoChatMember stored in the database by the provided chatId and userId, if any.

Implementation

Future<DtoChatMember?> read(ChatId chatId, UserId userId) async {
  return await safe<DtoChatMember?>(
    (db) async {
      final stmt = db.select(db.chatMembers).join([
        innerJoin(db.users, db.users.id.equalsExp(db.chatMembers.userId)),
      ]);

      stmt.where(
        db.chatMembers.chatId.equals(chatId.val) &
            db.chatMembers.userId.equals(userId.val),
      );

      final row = await stmt.getSingleOrNull();

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

      return _ChatMemberDb.fromDb(
        row.readTable(db.chatMembers),
        row.readTable(db.users),
      );
    },
    tag: 'chat_member.read($chatId, $userId)',
    exclusive: false,
  );
}