Within the context of a personal play project for learning more about DDD patterns, I am missing a Specification object for my filters.
Looking around for examples, it seems that everything (like LinQ) is oriented towards SQL databases. However with many NoSQL databases most queries, even just a "select * from table" requires a predefined view. Nevertheless, if the repository is mapping a web service even the type of queries is much more rigid.
Are there variations of the Specification pattern taking into account the limitations of non SQL databases? I have the feeling that this would require the use of inheritance and static declarations to support different type of persistence backends.
How should I combine "sorting" and "filtering" in my repositories? As an example consider the repository for a list of Order items.
(Query)findAllSortedByDate;
(Query)findAllSortedByName;
(Query)findAllSortedByQuantity;
So these are different type of sorting when displayed by a table. Since I might handle large results, I never considered sorting or filtering in my views or view models. Initially I thought about a Proyection class that selects the right query from a repository according the user actions. However this does not work well if I want to combine different sort strategies along different filters.
Obviously I need some type of "specification" object, but I am not sure if:
- Should I use them for my repositories, making them smarter? Or should I use them for my view models?
- How can properly restrict my specification objects for a good polyglot persistence?
Originally I thought about performing any query with a Repository acting as a collection-like interface but now I am noticing that a view model may also behave as "stateful" collection-like interface while the former are "stateless" collection-like interfaces.
- Overall should I try to keep any type of sorting/filtering inside my repositories? It seems that doing so, might add unnecessary complexity if all the query results can be loaded into memory.
UPDATE: To spice up this question, consider also that although NoSQL views can be filtered and sorted, a full text search might need an external indexing engine such as Lucene or SQLite-FTS providing only the unique identity of the Entities for a query that must be sorted and filtered again.