Skip to content

A simple query API to demonstrate usage of Manifold for AST transformations

License

Notifications You must be signed in to change notification settings

manifold-systems/manifold-simple-query

Repository files navigation

Manifold : Simple Query

A purely experimental project to write type-safe SQL-like queries directly against POJO entity types that can target any type of backend data source, whether it be Java Collections or SQL or what have you.

Query<Person> query = Person.query((p, q) -> q
  .where(p.age >= 18 && p.gender == male)
  .orderBy(p.name));

Execute queries like this:

Iterable<Person> result = query.run(dataSource);

Specify a 'select' clause using a type-safe tuple expression:

auto query = Person.query(p -> p
.select((p.name, DogYears: p.age * 7))
.from((s, q) -> q
  .where(p.gender == male && s.DogYears > 30)
  .orderBy(s.name)));

Access results as iterable tuple values mirroring the select clause.

auto result = query.run(data);

for(auto s : result) {
  System.out.println(s.name + " : " + s.DogYears);
}

The query API is very simple and not meant to be used for anything serious. This project primarily demonstrates usage of the ICompilerComponent SPI as a means to perform Java AST transformations. It also uses other Manifold features along the way, including extension methods, @val/@var properties, @Self, and others.

There are three modules comprising this project:

  1. manifold-simple-query-api - The API classes such as Query, Entity, Expression, etc.
  2. manifold-simple-query-ast-transformer - The ICompilerComponent implementation. Transforms query criteria expressed as normal POJO property references to a general-purpose Expression API that preserves the property reference type information. As such a wide range of data sources can be targeted e.g., POJO collections, database connections, web services, etc.
  3. manifold-simple-query-processor - Responsible for query execution. Extends Query with a run() method and defines a simple expression evaluator, which is used internally to filter, sort, etc. queried data sources. This implementation supports simple POJO collections.

The project layout is simple and light; not a lot of code.

About

A simple query API to demonstrate usage of Manifold for AST transformations

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages