TanStack / TanStack/db

SQL STRING_AGG function in groupBy

Open
#422 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
3.9k
Forks
266
Avg merge
1d 4h
Merged PRs (30d)
55

Description

new Query().from({ brand: brandsCollection })
      .innerJoin({ productBrand: productBrandsCollection }, ({ productBrand, brand }) => eq(productBrand.brandId, brand.id))
      .groupBy(({ productBrand }) => productBrand.productId)
      .select(({ brand, productBrand }) => ({
        id: productBrand.productId,
        brands: stringAgg(brand.name, ", ", { orderBy: { val: productBrand.order, order: "asc" | "desc" }}),
      }))

result

[
  { id: 1, brands: "coca, fanta" },
]

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the Query.groupBy entry point and the stringAgg usage shown in the issue, then trace how grouped selections are translated. Implement the requested ordered STRING_AGG behavior and verify that the example produces one row with the comma-separated brand names.

Written by the indexing model from the issue text.

Assessment

Tech stack
sql, typescript
Domain
databases
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.