Skip to content

michaelschnyder/loopback-querybuilder

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 

Repository files navigation

Loopback QueryBuilder

This is a small litte sample project that shows how to use System.Linq.ExpressionVisitor to convert expressions in anything you desire. In my case, I wanted to convert expressions on a Queryable to be used on a rather strange Rest-Style backend called Lookpback.io. Their specification is partially specified on their Online documentation. But it seems that their format is heavily inspired by SailsJs/Waterline and MongoDb. See sources for more details.

Sample

var builder = new LoopbackQueryBuilder<Car>();

var query = builder.Where(car => car.Id = 2);
// Result: { "where": { "id": 2 } }

var query = builder.Where(car => car.Id = 2 && car.Name == "Audi");
// Result: { "where": { "and": [ { "id": 2 }, { "name": "Audi" } ] } }

var query = builder.Where(car => car.Name.Contains("au"));
// Result: { "where": { "name": { "like": "%di%" } } }

var query = builder.Where(car => car.Name.Contains("foo") && car.Name == "bla");
// Result: { "where": { "and": [ { "name": { "like": "%foo%" } }, { "name": "bla" } ] } }

var query = builder.Where(car => car.Name.IsPerfect == true);
// Result: { "where": { "isPerfect": true } }

Supported Operations

Please note that the aim is not so fully support all possible combinations

Operators

The following operations are supported and covered by tests.

  • Equality (==): Implemented for string, int and bool
  • Contains (x.Contains()): Implemented for string)

Combination

  • And (&&) for string, int and bool Equality-Expressions, including Contains()

Pagination

Both Skip() and Take() are implemented and will issue additional query parameters.

Example:

var query = builder.Where(car => car.Name.Contains("au")).Skip(10).Take(50);
// Result: { "where": { "name": { "like": "%di%" } }, "skip": 10, "take": 50 }

Any other operations, combinations or parameters are currently not supported.

Additional Sources

About

Loopback QueryBuilder

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages