Saturday, 22 May 2021

Room @Relation selection limit

In the following scenario:

public class ChatData {
    @Embedded public ChatEntity chat;
    @Relation(parentColumn = "chat_id", entityColumn = "chat_id", entity = MessageEntity.class) public List<MessageEntity> messages;
}

With DAO:

@Dao
public interface JoinDAO {
    @Transaction
    @Query("SELECT * FROM chat")
    List<ChatData> getChats();
}

How can I limit the selection of the MessageEntity List to only n rows, instead than all the rows in the database? Is it even possible?

In this case the MessageEntity List could be very big, hundreds MessageEntity for each ChatEntity. I'd like to get all the ChatEntity, but limit the selection to only 10 MessageEntity.



from Room @Relation selection limit

No comments:

Post a Comment