get-convex / get-convex/aggregate

Wildcards in aggregate namespace?

Open
#30 0 comments 1 reaction 0 assignees View on GitHub
Dominant language
TypeScript
Stars
31
Forks
7
Avg merge
8h
Merged PRs (30d)
9

Description

Is there anyway to use a wildcard in an aggregate namespace when querying the data?

I have the following aggregates

```
export const transactionsAggregate = new TableAggregate<{
Namespace: [Id<"businesses">, Id<"customers">];
Key: [number];
DataModel: DataModel;
TableName: "transactions";
}>(components.transactionsAggregate, {
namespace: (doc) => [doc.businessId, doc.customerId],
sortKey: (doc) => [doc._creationTime],
});

export const transactionsAggregatePurchasesSpent = new TableAggregate<{
Namespace: [Id<"businesses">, Id<"customers">];
Key: [number];
DataModel: DataModel;
TableName: "transactions";
}>(components.transactionsAggregatePurchasesSpent, {
namespace: (doc) => [doc.businessId, doc.customerId],
sortKey: (doc) => [doc._creationTime],
sumValue: (doc) => doc.transactionValue,
});

export const transactionsAggregatePurchasesRewarded = new TableAggregate<{
Namespace: [Id<"businesses">, Id<"customers">];
Key: [number];
DataModel: DataModel;
TableName: "transactions";
}>(components.transactionsAggregatePurchasesRewarded, {
namespace: (doc) => [doc.businessId, doc.customerId],
sortKey: (doc) => [doc._creationTime],
sumValue: (doc) => doc.cashbackEarned!,
});

export const transactionsAggregateRedemptions = new TableAggregate<{
Namespace: [Id<"businesses">, Id<"customers">];
Key: [number];
DataModel: DataModel;
TableName: "transactions";
}>(components.transactionsAggregateRedemptions, {
namespace: (doc) => [doc.businessId, doc.customerId],
sortKey: (doc) => [doc._creationTime],
sumValue: (doc) => doc.transactionValue,
});
```

This namespace allows me to get the aggregates when scoped into a single customer fine, however how can a business query the aggregates for all of it's customers?

Something like this would be great. I don't believe I can move thre customerId to the sortKey either as then I a business wont be able to query based on the `_creationTime` as it would have to include the customerId as well

```
const transactionsCount = await transactionsAggregate.sum(ctx, {
namespace: [args.id, "*"],
bounds: { prefix: [] },
});
```

Contributor guide

Open the contributing guide

Research direction

The issue does not name implementation files or tests. Start by tracing the TableAggregate namespace definition and the sum query entry point, then determine how a business could aggregate across every customer while preserving _creationTime bounds. Done means a supported query pattern or a clear limitation, with coverage for business-wide and single-customer queries.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
databases
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.