-
Notifications
You must be signed in to change notification settings - Fork 2
Home
Documentation is in progress. If you want to speed-up the process - star this repo and this will inspire to invest more time here.
Ever wondered how to build dynamic queries with Entity Framework or any other ORM? QueryNinja is a answer to your problem. It's a framework that allows to build and execute dynamic queries.
QueryNinja is definitely suitable for low and mid loaded projects.
Latest versions has benchmarks that allows to approximate extra time per each request.
Main intention to save developers time needed to provide dynamically configured filters for table requests.
Extra attention should be paid in case QueryNinja used within high-load application where performance is a key.
Check out Quick Start for general introduction.
Also, you can take a look at example application HERE
More details you can found in specific extension documentation.
Sources:
- AspNetCore - allows to get IQuery from Query String.
Targets:
- Queryable - allows to apply IQuery on IQueryable interface.
- EnityFramework - extends Queryable target with EF-specific features.
QueryNinja developed around flexible core. More on that in the Extensibility.
QueryNinja consists of three main parts:
- Core - contains definitions of the IQuery and basic Query components (parts of the query)
- Sources - can create instances of IQuery implementation
- Targets - can convert IQuery to the actual request (to SqlServer, ElasticSearch, etc.).
Is a collection of QueryComponents.
On a high level Sources and Targets connected via IQuery.
As mentioned above, Source produce IQuery and Target consumes it.
Same as IQuery
but additionaly allows to configure projection of the original Entity.
For example, client-side can select properties they really need for this request.
Minimal unit that describes a part of query.
Currently there are two kinds of QueryComponents: Filters and Ordering Rules.
Allows to filter data in Target. Developers can create own implementation of IFilter and use them in QueryNinja. More on that in the Extensibility.
Talking about Extensibility, there is a specific kind of Filters that have the most simplified way to create and use. Default filter is a kind of filter where we apply some Operation on Property using Value. For example: Display students that are younger (Operation Less) than 18 (Value) years (Property Age).
CollectionFilter provides basic operations over collections:
-
Contains
allow to verify presence of Value inside a collection property. -
IsEmpty
allow to check whether collection property contains 0 elements.
ComparisonFilter provides simple arythmetic comparison operations over types that have this operations defined:
-
Equals
- use Equals method -
NotEquals
- negate result of Equals method -
Greater
- use operator -
GreaterOrEquals
- use operator -
Less
- use operator -
LessOrEquals
- use operator
ArrayEntryFilter provides operations that allow to check property entry in the passed array:
-
In
- checks that array contains desired property.
Allows to define ordering rules based on the property and order direction.
ISelector is interface that allows to specify a projection for orignal query. Main scenarious of usage is definition of required properties on the client-side. Currently, behavior of ISelector descendants can't be configured.
Selector defines a selection of a single property, while keeping the path to that property the same.
For example, property Student.Id will stay Student.Id and Student.University.Name will stay Student.University.Name.
Rename selector allow to put desired property by the specified path.
For example, Student.Id can become Student.Identifier and Student.University.Name can become Student.UniversityName.
Query component extension is a concept that allows Extensibility.
In general, IQueryComponentExtension knows how to use specific IQueryComponent Type inside Source or Target.
Source is a concept that describe a source of the IQuery interface implementations.
Main idea is build additional level of abstraction, so the IQuery can come from anywhere.
AspNetCore source allows to get IQuery interface inside contoller action methods.
Currently, only [FromQuery]
Binding is supported.
More details in AspNetCore Source Documentation
Target is another concept that describe a way IQuery interface can be interpreted. The idea here is to have ability to use same IQuery without knowing what exact data source is under the hood.
IQueryable is most popular interface used in vast majority of ORM's.
Using Queryable Target enables you to use filters and ordering rules for:
Extensions are packages that are not related to Core QueryNinja functionality but acting as a supplementary package to smooth QueryNinja usage experience.
Extension for Swagger allows to generate more or less proper OpenApi documentation for IQuery-type parameters.
Details about conribution available in latest Contribution Guide