Matheus Finatti
04/28/2023, 2:32 PMuserId <-> groupId
relationship and one to store members, which has a groupId
column.
I’m trying to flatMap
one query into the other, but if I insert a new group under that userId
it doesn’t trigger the chain.
small example:
suspend fun getGroups(userId: String): Flow<List<Groups>> =
userGroupQueries.getGroups(userId)
.asFlow()
.mapToList(coroutineContext)
.flatMapLatest { groupIds: List<String> ->
memberQueries.getAllGroupsMembers(groupIds)
.asFlow()
.mapToList(coroutineContext)
.mapLatest { members -> members.groupBy { it.groupId }}
}
UserGroup.sq
CREATE TABLE UserGroup(
userid TEXT NOT NULL,
groupid TEXT NOT NULL,
FOREIGN KEY (groupid) REFERENCES EGroup(id),
FOREIGN KEY (userid) REFERENCES User(id)
);
getGroups:
SELECT groupid FROM UserGroup WHERE userid = ?;
Member.sq
getAllFromGroupIds:
SELECT * FROM Member WHERE groupid IN ?;
I can try to provide a minimum reproducible example if necessary. Didn’t find anything like this on SO or on github so I wonder if I’m trying to do something sillyglureau
04/28/2023, 2:42 PMMatheus Finatti
04/28/2023, 2:46 PMGroup(id: String, members: List<Member>)
so maybe this whole ordeal is indeed unnecessaryglureau
04/28/2023, 3:01 PMMatheus Finatti
04/28/2023, 3:07 PM