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

Allow define projection fields in read model queries #1481

Conversation

gonzalojaubert
Copy link
Contributor

@gonzalojaubert gonzalojaubert commented Oct 25, 2023

Add the select method to project which fields you want to get in your read model query:

@Command({
  authorize: 'all',
})
export class GetProductsCount {
  public constructor(readonly filters: Record<string, any>) {}

  public static async handle(): Promise<unknown> {
    const searcher = Booster.readModel(ProductReadModel)
            .filter({
              sku: { contains: 'toy' },
              or: [
                {
                  description: { contains: 'fancy' },
                },
                {
                  description: { contains: 'great' },
                },
              ],
            })
            .select(['sku', 'description'])
            .skipInstance(true)
    const result = await searcher.search()
    return { count: result.length }
  }
}

The searcher result using skipInstance will generate an array of objects with the sku and description fields of the ProductReadModel read model. If you don't use skipInstance the result will be an array of ProductReadModel instances.

Note: Using skipInstance will skip any Read Models migrations that need to be applied to the result. If you need to apply migrations to the result, don't use skipInstance.

@sweep-ai
Copy link
Contributor

sweep-ai bot commented Oct 25, 2023

Apply Sweep Rules to your PR?

  • Apply: All docstrings and comments should be up to date.
  • Apply: Do not include large chunks of commented-out code.
  • Apply: Ensure that error logs use traceback during exceptions.
  • Apply: Remove debug logs and print statements from production code.
  • Apply: All the business logic in the 'src' folder for each package should have the corresponding unit tests in the 'test' folder in the same package.
  • Apply: Avoid 'any' types when possible.
  • Apply: If there's a simpler way to express a type, it should be used.

@ghost
Copy link

ghost commented Oct 25, 2023

👇 Click on the image for a new way to code review

Review these changes using an interactive CodeSee Map

Legend

CodeSee Map legend

@gonzalogarciajaubert
Copy link
Collaborator

/integration sha=f759db3f44bbb758e31468a56d2c31972865b216

@github-actions
Copy link
Contributor

⌛ Integration tests are running...

Check their status here 👈

@github-actions
Copy link
Contributor

❌ Oh no! Integration tests have failed

@github-actions
Copy link
Contributor

⌛ Integration tests are running...

Check their status here 👈

@github-actions
Copy link
Contributor

✅ Integration tests have finished successfully!

@gonzalogarciajaubert gonzalogarciajaubert marked this pull request as draft October 26, 2023 13:52
@MarcAstr0
Copy link
Collaborator

/integration sha=ed4d1caa659a52b4745a5362cbe025848d193f75

Copy link
Contributor

⌛ Integration tests are running...

Check their status here 👈

Copy link
Contributor

✅ Integration tests have finished successfully!

Castro, Mario added 4 commits March 22, 2024 16:27
…on_fields_in_read_model_queries

# Conflicts:
#	common/config/rush/pnpm-lock.yaml
#	packages/framework-provider-local/src/services/read-model-registry.ts
@MarcAstr0
Copy link
Collaborator

/integration sha=fec44b84904d33b0a6617c5163dfd1b452d2adc0

Copy link
Contributor

⌛ Integration tests are running...

Check their status here 👈

Copy link
Contributor

✅ Integration tests have finished successfully!

@MarcAstr0 MarcAstr0 marked this pull request as ready for review April 15, 2024 14:19
Castro, Mario added 2 commits April 16, 2024 10:04
…on_fields_in_read_model_queries

# Conflicts:
#	common/config/rush/pnpm-lock.yaml
@NickSeagull NickSeagull removed their request for review May 21, 2024 09:21
@MarcAstr0
Copy link
Collaborator

/integration sha=afd9d2be3ee9124c77b9b696aac6a73927921454

Copy link
Contributor

⌛ Integration tests are running...

Check their status here 👈

Copy link
Contributor

✅ Integration tests have finished successfully!

Copy link
Contributor

@alvaroloes alvaroloes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What an great work @MarcAstr0 🥇 🥇🥇

if (part.endsWith('[]')) {
const arrayField = part.slice(0, -2)
if (!currentLevel[arrayField]) {
currentLevel[arrayField] = {}

Check warning

Code scanning / CodeQL

Prototype-polluting assignment Medium

This assignment may alter Object.prototype if a malicious '__proto__' string is injected from
library input
.
}
} else {
if (!currentLevel[part]) {
currentLevel[part] = {}

Check warning

Code scanning / CodeQL

Prototype-polluting assignment Medium

This assignment may alter Object.prototype if a malicious '__proto__' string is injected from
library input
.
@MarcAstr0
Copy link
Collaborator

/integration sha=8726201

Copy link
Contributor

⌛ Integration tests are running...

Check their status here 👈

Copy link
Contributor

✅ Integration tests have finished successfully!

@MarcAstr0 MarcAstr0 force-pushed the allow_define_projection_fields_in_read_model_queries branch from 8726201 to 34ddffa Compare May 28, 2024 12:02
@MarcAstr0 MarcAstr0 requested a review from alvaroloes May 28, 2024 13:26
@MarcAstr0
Copy link
Collaborator

/integration sha=c4b7ca6c3c63ec64f2c0da97a408b21c8cbb1655

Copy link
Contributor

⌛ Integration tests are running...

Check their status here 👈

Copy link
Contributor

✅ Integration tests have finished successfully!

@MarcAstr0
Copy link
Collaborator

/integration sha=e38a5b6

Copy link
Contributor

⌛ Integration tests are running...

Check their status here 👈

Copy link
Contributor

✅ Integration tests have finished successfully!

Copy link
Contributor

@alvaroloes alvaroloes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯 Thanks for all the clarifications

@MarcAstr0 MarcAstr0 merged commit f747847 into boostercloud:main May 30, 2024
6 checks passed
@MarcAstr0 MarcAstr0 mentioned this pull request Jun 5, 2024
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants