readAt method

Future<DtoChatItem?> readAt(
  1. PreciseDateTime at
)

Returns the DtoChatItem stored in the database by the provided at, if any.

Implementation

Future<DtoChatItem?> readAt(PreciseDateTime at) async {
  return await safe<DtoChatItem?>(
    (db) async {
      final stmt =
          db.select(db.chatItems)
            ..where(
              (u) =>
                  u.at.isSmallerOrEqual(Variable(at.microsecondsSinceEpoch)),
            )
            ..orderBy([(u) => OrderingTerm.desc(u.at)])
            ..limit(1);
      final ChatItemRow? row = await stmt.getSingleOrNull();

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

      return _ChatItemDb.fromDb(row);
    },
    tag: 'chat_item.readAt($at)',
    exclusive: false,
  );
}