假设我定义了类型Fetch[A]
,它封装了一个查询来从数据库中获取类型A
的数据。 (它可能会为MySQL
创建一个SQL查询,但这是实现细节。
假设我还有一些函数可以创建Fetch[A]
来获取博客数据:
type BlogPosts = Seq[BlogPost]
def recentPosts(blogId : BlogId): Fetch[BlogPosts] = ...
def featuredPosts(blogId : BlogId): Fetch[BlogPosts] = ...
def popularPosts(blogId : BlogId): Fetch[BlogPosts] = ...
现在我需要一起获取所有recent
,featured
和popular
个帖子。我想从上面的三个查询中创建单个查询。
def threePosts(recent : Fetch[BlogPosts],
featured : Fetch[BlogPosts],
popular : Fetch[BlogPosts]): Fetch[(BlogPosts, BlogPosts, BlogPosts)]
有意义吗?它可行吗?
P.S。很抱歉,我不知道SQL
因此我无法提供原始recent
,featured
和popular
查询以及生成的查询的具体示例。
P.P.S Slick
不是这样做的吗?