@Query('SELECT * FROM article ORDER BY publishedAt DESC') Stream> getAllArticles(); @Query('SELECT Author.*, _junction.articleId as articleId FROM ArticleAuthor AS _junction inner join Author ON (_junction.authorId = Author.id) WHERE _junction.articleId IN (:ids)') Future> getAuthorsFromArticles(List ids); Stream> getAllArticlesWithAuthors() { final stream = getAllArticles(); final controller = StreamController>.broadcast(); Future getInternalAuthors(List
articles) async { final ids = articles.map((it) => it.id).toList(); final authors = await getAuthorsFromArticles(ids); final result = articles.map((element) { final data = authors.firstWhere((it) => it.articleId == element.id); Author author; if (data != null) { author = Author(data.id, data.name, data.slug, data.avatar); } return ArticleWithAuthor( element, author ); }).toList(); controller.add(result); } stream.listen( (articles) async { getInternalAuthors(articles); }, onDone: () => controller.close() ); return controller.stream; }