different `where` but same return type for relational queries?

what's the best way to approach it when i have a fair few relational queries that have different where: clauses, but are otherwise the same (or extremely similar)?
public static async queryPostsByWantsItemId(itemId: number) {
  return await db.query.posts.findMany({
    /* different v */
    where: (post, { eq, and }) => exists(
      db.select({}).from(postItemsWants).limit(1).where(
        and(
          eq(postItemsWants.postId, post.id),
          eq(postItemsWants.itemId, itemId)
        )
      )
    ),
    /* different ^ */
    /* same v */
    limit: 50,
    orderBy: (post, { desc }) => [desc(post.createdAt)],
    columns: {
      id: true,
      description: true,
      createdAt: true,
      expiresAt: true,
    },
    with: {
      // ...
    }
    /* same ^ */
  });
}
Was this page helpful?