Skip to content
MisterHoker edited this page Apr 19, 2021 · 11 revisions

General

Documentation is in progress. If you want to speed-up the process - star this repo and this will inspire to invest more time here.

What is QueryNinja?

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.

System Context Diagram

When you should use it?

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.

How to use it?

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.

What if I need smth that QueryNinja don't have?

QueryNinja developed around flexible core. More on that in the Extensibility.

Concept

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.).

Container Diagram

Core

IQuery

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.

IDynamicQuery

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.

IQueryComponent

Minimal unit that describes a part of query.
Currently there are two kinds of QueryComponents: Filters and Ordering Rules.

IFilter

Allows to filter data in Target. Developers can create own implementation of IFilter and use them in QueryNinja. More on that in the Extensibility.

IDefaultFilter

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

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

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

ArrayEntryFilter provides operations that allow to check property entry in the passed array:

  • In - checks that array contains desired property.

OrderingRule

Allows to define ordering rules based on the property and order direction.

ISelector

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

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.

RenameSelector

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.

IQueryComponentExtension

Query component extension is a concept that allows Extensibility.
In general, IQueryComponentExtension knows how to use specific IQueryComponent Type inside Source or Target.

Sources

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

AspNetCore source allows to get IQuery interface inside contoller action methods.
Currently, only [FromQuery] Binding is supported. More details in AspNetCore Source Documentation

Targets

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.

Queryable

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

Extensions are packages that are not related to Core QueryNinja functionality but acting as a supplementary package to smooth QueryNinja usage experience.

Swagger

Extension for Swagger allows to generate more or less proper OpenApi documentation for IQuery-type parameters.

Contribution

Details about conribution available in latest Contribution Guide