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

Enhance AbstractRepository with Custom Query Scopes #237

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

shmuel-torii
Copy link

This pull request introduces enhancement to the AbstractRepository class, empowering subclasses to add custom "scopes" to the repository's queries. The changes include the addition of a new method called startQueryBuilder, which can be overridden in subclasses to apply additional query constraints specific to their needs.

With this modification, subclasses can now override the startQueryBuilder method to add their own scopes, such as:

protected startQueryBuilder(queryBuilder: Knex): Knex.QueryBuilder {
  return queryBuilder(this.tableName).where('tenantId', 'xyz');
}

By overriding startQueryBuilder, subclasses can inject additional conditions into the query, tailored to their specific requirements. For example, the above implementation adds a scope that filters records based on a tenantId of 'xyz'.

Please review and merge this pull request if the changes align with the project's goals. These modifications provide greater flexibility and extensibility to the AbstractRepository class, allowing subclasses to introduce custom query scopes and enhance the functionality of the repository.

@shmuel-torii shmuel-torii changed the title Introduce the startQueryBuilder method Enhance AbstractRepository with Custom Query Scopes May 27, 2023
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.

None yet

1 participant