-
Notifications
You must be signed in to change notification settings - Fork 19
Backend Pattern Query
Ferris Tseng edited this page Jan 2, 2020
·
4 revisions
Query objects store complex SQL queries, data aggregation, and filtering methods. 1
app/queries
- The Query object should take a relation as it's argument, that should enable the caller to control the scope of the query.
- Query objects should be composable. 2
- Should return an
ActiveRecord::Relation
. 2
Note: In practice, it's difficult to achieve some of these desired qualities because Caseflow's data spans multiple databases.
Use the Service pattern if you are encapsulating complex logic that requires a read.
- 1: https://github.com/infinum/rails-handbook/blob/master/Design%20Patterns/Query%20Objects.md
- 2: https://medium.flatstack.com/query-object-in-ruby-on-rails-56ea434365f0
Pattern | Description |
---|---|
Service | Alternative for database logic that requires writes |