Generic interface to query a database.

database, java, jpa, mongodb, nosql, spring-data, sql


Querity-logo Querity

Build Bugs Vulnerabilities Coverage Quality Gate Status Twitter

Generic interface to query a database.


The aim of this project is to provide a simple generic interface, supporting fluent Java and REST APIs, to query databases in Java applications.

The modules implement the support for different databases and frameworks.

Why you should use Querity?

learn once, use everywhere

zero logic needed apart building a generic Query object

switch database without rewriting the logic of your application

ready to use REST API which implements filtering, sorting and pagination, to be consumed by your UI components

expose the same REST API in all your projects

Getting Started


  • Java 8+


All releases are published to the Maven Central repository ( see here).

Available modules:

  • querity-spring-data-jpa: supports Spring Data JPA
  • querity-spring-data-mongodb: supports Spring Data MongoDB
  • querity-spring-web: supports JSON serialization and deserialization of Querity objects in Spring Web MVC

All modules are "Spring Boot starters", you just need to add the dependency to your Spring Boot project and start using it, no other configuration needed.




implementation "net.brunomendola.querity:querity-spring-data-jpa:${querityVersion}"


import static net.brunomendola.querity.api.Querity.*;
import static net.brunomendola.querity.api.Operator.*;
import static net.brunomendola.querity.api.Sort.Direction.*;

public class MyService {

  Querity querity;

  public Result<Person> getPeople() {
    Query query = Querity.query()
        // customize filters, pagination, sorting...
                filterBy("lastName", EQUALS, "Skywalker"),
                filterBy("firstName", EQUALS, "Luke")
        .sort(sortBy("lastName"), sortBy("birthDate", DESC))
        .pagination(1, 10)
    List<Person> items = querity.findAll(Person.class, query);
    Long totalCount = querity.count(Person.class, query.getFilter());
    return new Result<>(items, totalCount);

  record Result<T>(List<T> items, Long totalCount) {

In the above example, the findAll method returns the first of n pages with max 10 elements of all people NOT named Luke Skywalker, sorted by last name and then birthdate descending.
The count method returns the total filtered items count excluding pagination (the record keyword is implemented from Java 14).

Note the static imports to improve the readability.


Read the full documentation here.

Access to SNAPSHOT builds

Commits to the main branch are automatically built and deployed to OSSRH SNAPSHOTs Maven repository.

To use the SNAPSHOTs in your project, add the SNAPSHOTs repository as follows.

Of course using SNAPSHOTs is not recommended, but if you feel brave you can do it to test new not-yet-released features.




repositories {
  maven {
    url ""
    mavenContent { snapshotsOnly() }

Browse the repository here to find the latest SNAPSHOT version.


Running tests

Run with Maven (wrapper):

./mvnw test

or just run them with your favourite IDE.

Test dataset

The test dataset is generated with Mockaroo.

If you want to make changes, you don't need to do it manually, please find the schema here.


Contributors names and contact info

PRs are welcome!

Version History

See Releases.


This project is licensed under the Apache 2.0 License - see the LICENSE file for details