Query Object
- Definition
- An aggregate that represents a database query and allows it to be composed programmatically
How does it work?
An SQL query (or any other compound query) is represented by an aggregate object structure. It can be modified by calling methods on each of these objects. At any time its SQL equivalent can be produced by calling a method on the root object.
Examples
- SQLAlchemy (Python)
When should you use it?
- When you find yourself glueing pieces of sql query together a lot
Problems
- If the query object uses different names, or even a different conceptual framework, from the query language it is based on, the developer will need to learn this domain language and map concepts. This makes it harder to learn and debug.