azure-cosmosdb-querybuilder-java

Java API for effectively building SQL Queries of Azure Cosmos DB

License

License

GroupId

GroupId

com.github.mohitgoyal91
ArtifactId

ArtifactId

cosmosdbquery-utils
Last Version

Last Version

1.6.10
Release Date

Release Date

Type

Type

jar
Description

Description

azure-cosmosdb-querybuilder-java
Java API for effectively building SQL Queries of Azure Cosmos DB
Project URL

Project URL

https://github.com/mohitgoyal91/azure-cosmosdb-querybuilder-java
Source Code Management

Source Code Management

https://github.com/mohitgoyal91/azure-cosmosdb-querybuilder-java

Download cosmosdbquery-utils

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.mohitgoyal91/cosmosdbquery-utils/ -->
<dependency>
    <groupId>com.github.mohitgoyal91</groupId>
    <artifactId>cosmosdbquery-utils</artifactId>
    <version>1.6.10</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.mohitgoyal91/cosmosdbquery-utils/
implementation 'com.github.mohitgoyal91:cosmosdbquery-utils:1.6.10'
// https://jarcasting.com/artifacts/com.github.mohitgoyal91/cosmosdbquery-utils/
implementation ("com.github.mohitgoyal91:cosmosdbquery-utils:1.6.10")
'com.github.mohitgoyal91:cosmosdbquery-utils:jar:1.6.10'
<dependency org="com.github.mohitgoyal91" name="cosmosdbquery-utils" rev="1.6.10">
  <artifact name="cosmosdbquery-utils" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.mohitgoyal91', module='cosmosdbquery-utils', version='1.6.10')
)
libraryDependencies += "com.github.mohitgoyal91" % "cosmosdbquery-utils" % "1.6.10"
[com.github.mohitgoyal91/cosmosdbquery-utils "1.6.10"]

Dependencies

compile (1)

Group / Artifact Type Version
org.json : json jar 20140107

test (2)

Group / Artifact Type Version
org.junit.jupiter : junit-jupiter-api jar 5.4.2
org.junit.jupiter : junit-jupiter-engine jar 5.4.2

Project Modules

There are no modules declared in this project.

Azure Cosmos DB SQL Query Generator

Maven Central Build Status Known Vulnerabilities Maintainability

This project provides a client, tools or utilities in Java that makes it easy to generate Azure CosmosDB SQL Queries effectively in an organised way.

Disclaimer

The implementation in this project is intended for reference purpose only.

Dependencies

Dependencies will be added automatically if Maven is used. Otherwise, please download the dependencies from the pom.xml file and add them to your build path.

For example, using maven, you can add the following dependency to your maven pom file:

<dependency>
  <groupId>com.github.mohitgoyal91</groupId>
  <artifactId>cosmosdbquery-utils</artifactId>
  <version>1.6.8</version>
</dependency>

Some Sample Queries

SELECT * FROM C

new SelectQuery().createQuery();

SELECT TOP 5 C.id AS ID, C.name AS NAME FROM C ORDER BY C._ts DESC

return new SelectQuery()
                .columns(new Columns("id", "name").as("ID", "NAME"))
                .orderBy("_ts", DESC)
                .limitResults(5)
                .createQuery();

SELECT C.id AS ID, C.name FROM C

List<String> columns = new ArrayList<>();
        columns.add("id"); columns.add("name");
        List<String> as = new ArrayList<>();
        as.add("ID");
        return new SelectQuery()
                .columns(new Columns(columns).as(as))
                .createQuery();

SELECT C.id FROM C WHERE ( ( C.name = 'Mohit' OR C.age <= 28) AND ( C.surname IN ( 'Goyal' , 'Sharma' ) ) ) OR ( ( ST_DISTANCE ( C.home.coordinates, {"type":"Point", "coordinates":[[48.858483, 2.294524]]}) <= 2000.0) OR (( C.monthlyIncome * 12 ) + C.savings >= 500.0) )

return new SelectQuery()
                .columns(new Columns("id"))
                .addRestrictions(
                        new RestrictionBuilder().eq("name", "Mohit")
                        .or().lte("age", 28),
                        new RestrictionBuilder().in("surname", "Goyal", "Sharma")
                )
                .orAddRestrictions(
                        new RestrictionBuilder().lte("home.coordinates",
                                new GeoSpatialObject(Constants.GeoSpatialTypes.POINT,
                                        new Coordinate(48.858483, 2.294524)), 2000.0)
                        .or(),
                        new RestrictionBuilder()
                        .gte(500.0, "( {} * {} ) + {} ", "monthlyIncome", 12, "savings")
                )
                .createQuery();

SELECT * FROM C WHERE ( C.id = '123' ) OR ( C.name IN (1, 'mohit' ) ) AND ( C.pid = 124) AND ( C.uuid = 123) ORDER BY C._ts DESC

List<Object> list = new ArrayList<>();
        list.add(1); list.add("mohit");
        return new SelectQuery()
                .id("123").or()
                .in("name", list)
                .eq("pid",124)
                .addRestrictions(new RestrictionBuilder().eq("uuid",123))
                .orderByTS(DESC)
                .createQuery();

SELECT * FROM C WHERE ( C.pid = 123) OR ( ( C.age >= 15) OR ( C.age < 29) )

return new SelectQuery()
                .eq("pid", 123)
                .or()
                .addRestrictions(
                        new RestrictionBuilder()
                                .gte("age", 15)
                                .or()
                                .lt("age", 29)
                )
                .createQuery();

SELECT MAX ( C.age) AS age, SUM ( C.life) AS life, MIN (udf.convertToInt( C.failure) ) AS failure, C.hello FROM C

return new SelectQuery()
                .columns(new Columns("hello"))
                .max("age", "age", null)
                .sum("life")
                .min("failure", "failure", "convertToInt")
                .createQuery();

Versions

Version
1.6.10
1.6.9
1.6.8
1.6.7
1.6.6
1.6.4
1.6.3
1.6.0
1.5.0
1.4.0
1.2
1.1.3