Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Group operation #14

Open
10 tasks
stombre opened this issue Sep 5, 2020 · 0 comments
Open
10 tasks

Group operation #14

stombre opened this issue Sep 5, 2020 · 0 comments
Labels
enhancement New feature or request

Comments

@stombre
Copy link
Contributor

stombre commented Sep 5, 2020

Average, sum...

Search for an API;

const result = await Invoices.query()
  .groupBy(Invoices.userId)
  .define('totalDebt').asSumOf(Invoices.amount)
  .define('nbInvoicse').asCountOf(Invoices)
  .find();

Hard scenario, how to do two stage grouping pipeline?

const result = await Invoices.query()
  .stage((query, Invoices) => {
    query.groupBy(query.year(Invoices.createdAt)).as('year')
      .groupBy(query.month(invoicse.createdAt)).as('month')
      .define('averageDebt').asAverageOf(Invoices.amount);
  })
  .stage((query, InvoicesAggregatedByMonthAndYear) => {
    query.groupBy(query.year(InvoicesAggregatedByMonthAndYear.year))
      .define('averageDebt').asAverageOf(InvoicesAggregatedByMonthAndYear.averageDebt))
  });

Need to introduce field defined on Model? sub field;

const result = await Invoices.query()
  .groupBy(Invoices.FIELDS.userId)
  .define('totalDebt').asSumOf(Invoices.FIELDS.amount)
  .define('nbInvoicse').asCountOf(Invoices)
  .find();
  • query.groupBy: Apply a groupBy operation
  • query.define: Create a property in the result. When define something? it's not a model instance anymore? alternate operation than find? apply? generate? fetch?
  • query.stage; multiple group by (support for mongoDb aggregate)
  • define.asSumOf
  • define.asAverageOf
  • define.asCountOf
  • define.asMaxOf
  • define.asMinOf

How to have access to this in every context?

  • query.year (apply a year on a date?)

  • query.month (apply a month on a date?)

  • query.day (apply a day on a date?)

  • query.define

  • DEFINE.as

  • Schema.FIELDS

  • DEFINE.asSumOf

  • DEFINE.asAverageOf

  • DEFINE.asCountOf

  • DEFINE.asMaxOf

  • DEFINE.asMinOf

  • query.groupBy

  • query.stage

@stombre stombre added the enhancement New feature or request label Sep 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant