Skip to content

Wildcards in aggregate namespace? #30

@chris-hinds

Description

@chris-hinds

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: [] },
    });

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions