-
Notifications
You must be signed in to change notification settings - Fork 3
Open
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: [] },
});
arionaxiom
Metadata
Metadata
Assignees
Labels
No labels