https://github.com/doytowin/doyto-query
DoytoQuery - A Dynamic Query Language Implemented in Java for Database Access
https://github.com/doytowin/doyto-query
crud ddd java oqm orm sql
Last synced: 5 months ago
JSON representation
DoytoQuery - A Dynamic Query Language Implemented in Java for Database Access
- Host: GitHub
- URL: https://github.com/doytowin/doyto-query
- Owner: doytowin
- License: apache-2.0
- Created: 2019-05-12T07:51:34.000Z (about 7 years ago)
- Default Branch: main
- Last Pushed: 2025-07-21T09:52:47.000Z (11 months ago)
- Last Synced: 2025-07-23T17:49:30.933Z (11 months ago)
- Topics: crud, ddd, java, oqm, orm, sql
- Language: Java
- Homepage: https://www.doyto.win
- Size: 3.93 MB
- Stars: 41
- Watchers: 1
- Forks: 6
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
- awesome-java - DoytoQuery
README
[](https://www.apache.org/licenses/LICENSE-2.0.html)
[](https://sonarcloud.io/dashboard?id=win.doyto%3Adoyto-query)
[](https://sonarcloud.io/component_measures?id=win.doyto%3Adoyto-query&metric=ncloc)
[](https://sonarcloud.io/component_measures?id=win.doyto%3Adoyto-query&metric=coverage)
DoytoQuery - A Dynamic Query Language Implemented in Java for CRUD
---
## Introduction
DoytoQuery implements a dynamic query language which generates query statements from objects.
Entity/view objects are used to generate table names and columns,
while query/having objects are used to dynamically generate query conditions.
Each field defined in the query object is used to represent a query condition.
When executing query, the query condition corresponding to the assigned field will be combined into the query clause,
thereby completing the dynamic construction of SQL statements with entity/view objects.
Refer to the [docs](https://query.docs.doyto.win/) for more details.
## Quick Start
1. Initialize the project on Spring Initializer with the following 4 dependencies:
* Lombok
* Spring Web
* Validation
* \[A database driver]
2. Add DoytoQuery dependencies in pom.xml:
```xml
win.doyto
doyto-query-jdbc
2.1.0
win.doyto
doyto-query-web
2.1.0
win.doyto
doyto-query-dialect
2.1.0
```
3. Define entity and query objects for a table:
```java
@Getter
@Setter
@Entity(name = "user")
public class UserEntity extends AbstractPersistable {
private String username;
private Integer age;
private Boolean valid;
}
@Getter
@Setter
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
public class UserQuery extends PageQuery {
private String username;
private Integer ageGe;
private Integer ageLt;
private Boolean valid;
}
```
Invoking the method [`DataAccess#query(Q)`](https://github.com/doytowin/doyto-query/blob/main/doyto-query-api/src/main/java/win/doyto/query/core/DataAccess.java) in `UserService`:
```java
@Service
public class UserService extends AbstractCrudService {
public List findValidAdultUsers() {
UserQuery userQuery = UserQuery.builder().ageGe(20).valid(true).pageSize(10).build();
// Executed SQL: SELECT username, email, valid, id FROM t_user WHERE age >= ? AND valid = ? LIMIT 10 OFFSET 0
// Parameters : 20(java.lang.Integer), true(java.lang.Boolean)
return dataAccess.query(userQuery);
}
}
```
Define a controller to support RESTful API:
```java
@RestController
@RequestMapping("user")
public class UserController extends AbstractEIQController {
}
```
Set the log level of `logging.level.org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping` to `trace`,
and after starting the Spring Boot application, you can see in the console that the RESTful interface is ready for `/user/`:
```
s.w.s.m.m.a.RequestMappingHandlerMapping :
w.d.q.d.m.u.UserController:
{PUT [/user/{id}]}: update(Persistable)
{DELETE [/user/{id}]}: remove(Serializable)
{GET [/user/{id}]}: get(Serializable)
{DELETE [/user/]}: delete(DoytoQuery)
{PATCH [/user/]}: patch(Object,DoytoQuery)
{GET [/user/]}: page(DoytoQuery)
{POST [/user/]}: create(List)
{PATCH [/user/{id}]}: patch(Object)
```
Refer to the [demo](https://github.com/doytowin/doyto-query-demo) for more details.
## Architecture for 0.3.x and newer

## Versions
| Module | Snapshot | Release |
|------------------------|----------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------|
| doyto-query-api | [![api-snapshots-img]](https://central.sonatype.com/service/rest/repository/browse/maven-snapshots/win/doyto/doyto-query-api/) | [![api-release-img]](https://central.sonatype.com/artifact/win.doyto/doyto-query-api) |
| doyto-query-geo | [![geo-snapshots-img]](https://central.sonatype.com/service/rest/repository/browse/maven-snapshots/win/doyto/doyto-query-geo/) | [![geo-release-img]](https://central.sonatype.com/artifact/win.doyto/doyto-query-geo) |
| doyto-query-common | [![common-snapshots-img]](https://central.sonatype.com/service/rest/repository/browse/maven-snapshots/win/doyto/doyto-query-common/) | [![common-release-img]](https://central.sonatype.com/artifact/win.doyto/doyto-query-common) |
| doyto-query-sql | [![sql-snapshots-img]](https://central.sonatype.com/service/rest/repository/browse/maven-snapshots/win/doyto/doyto-query-sql/) | [![sql-release-img]](https://central.sonatype.com/artifact/win.doyto/doyto-query-sql) |
| doyto-query-jdbc | [![jdbc-snapshots-img]](https://central.sonatype.com/service/rest/repository/browse/maven-snapshots/win/doyto/doyto-query-jdbc/) | [![jdbc-release-img]](https://central.sonatype.com/artifact/win.doyto/doyto-query-jdbc) |
| doyto-query-web-common | [![web-common-snapshots-img]](https://central.sonatype.com/service/rest/repository/browse/maven-snapshots/win/doyto/doyto-query-web-common/) | [![web-common-release-img]](https://central.sonatype.com/artifact/win.doyto/doyto-query-web-common) |
| doyto-query-web | [![web-snapshots-img]](https://central.sonatype.com/service/rest/repository/browse/maven-snapshots/win/doyto/doyto-query-web/) | [![web-release-img]](https://central.sonatype.com/artifact/win.doyto/doyto-query-web) |
| doyto-query-dialect | [![dialect-snapshots-img]](https://central.sonatype.com/service/rest/repository/browse/maven-snapshots/win/doyto/doyto-query-dialect/) | [![dialect-release-img]](https://central.sonatype.com/artifact/win.doyto/doyto-query-dialect) |
## Supported Databases
- MySQL
- Oracle
- SQL Server
- PostgreSQL
- SQLite
- HSQLDB
License
-------
This project is under the [Apache Licence v2](https://www.apache.org/licenses/LICENSE-2.0).
[geo-snapshots-img]: https://img.shields.io/nexus/s/win.doyto/doyto-query-geo?color=blue&server=https%3A%2F%2Foss.sonatype.org
[geo-release-img]: https://img.shields.io/maven-central/v/win.doyto/doyto-query-geo?color=brightgreen
[api-snapshots-img]: https://img.shields.io/nexus/s/win.doyto/doyto-query-api?color=blue&server=https%3A%2F%2Foss.sonatype.org
[api-release-img]: https://img.shields.io/maven-central/v/win.doyto/doyto-query-api?color=brightgreen
[common-snapshots-img]: https://img.shields.io/nexus/s/win.doyto/doyto-query-common?color=blue&server=https%3A%2F%2Foss.sonatype.org
[common-release-img]: https://img.shields.io/maven-central/v/win.doyto/doyto-query-common?color=brightgreen
[sql-snapshots-img]: https://img.shields.io/nexus/s/win.doyto/doyto-query-sql?color=blue&server=https%3A%2F%2Foss.sonatype.org
[sql-release-img]: https://img.shields.io/maven-central/v/win.doyto/doyto-query-sql?color=brightgreen
[jdbc-snapshots-img]: https://img.shields.io/nexus/s/win.doyto/doyto-query-jdbc?color=blue&server=https%3A%2F%2Foss.sonatype.org
[jdbc-release-img]: https://img.shields.io/maven-central/v/win.doyto/doyto-query-jdbc?color=brightgreen
[web-common-snapshots-img]: https://img.shields.io/nexus/s/win.doyto/doyto-query-web-common?color=blue&server=https%3A%2F%2Foss.sonatype.org
[web-common-release-img]: https://img.shields.io/maven-central/v/win.doyto/doyto-query-web-common?color=brightgreen
[web-snapshots-img]: https://img.shields.io/nexus/s/win.doyto/doyto-query-web?color=blue&server=https%3A%2F%2Foss.sonatype.org
[web-release-img]: https://img.shields.io/maven-central/v/win.doyto/doyto-query-web?color=brightgreen
[dialect-snapshots-img]: https://img.shields.io/nexus/s/win.doyto/doyto-query-dialect?color=blue&server=https%3A%2F%2Foss.sonatype.org
[dialect-release-img]: https://img.shields.io/maven-central/v/win.doyto/doyto-query-dialect?color=brightgreen