# doyto-query
**Repository Path**: doytowin/doyto-query
## Basic Information
- **Project Name**: doyto-query
- **Description**: Java版OQM框架
- **Primary Language**: Java
- **License**: Apache-2.0
- **Default Branch**: main
- **Homepage**: https://query.docs.doyto.win/
- **GVP Project**: No
## Statistics
- **Stars**: 10
- **Forks**: 4
- **Created**: 2019-07-27
- **Last Updated**: 2024-11-13
## Categories & Tags
**Categories**: database-dev
**Tags**: None
## 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 Usage
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;
}
```
Invoke the [`DataAccess#query(Q)`](https://github.com/doytowin/doyto-query/blob/main/doyto-query-api/src/main/java/win/doyto/query/core/DataAccess.java) method in `UserService`:
```java
@Service
public class UserService extends AbstractCrudService {
public List findValidGmailUsers() {
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);
}
}
```
And a controller to support RESTful API:
```java
@RestController
@RequestMapping("user")
public class UserController extends AbstractEIQController {
}
```
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://oss.sonatype.org/content/repositories/snapshots/win/doyto/doyto-query-api/) | [![api-release-img]](https://search.maven.org/artifact/win.doyto/doyto-query-api/) |
| doyto-query-geo | [![geo-snapshots-img]](https://oss.sonatype.org/content/repositories/snapshots/win/doyto/doyto-query-geo/) | [![geo-release-img]](https://search.maven.org/artifact/win.doyto/doyto-query-geo/) |
| doyto-query-common | [![common-snapshots-img]](https://oss.sonatype.org/content/repositories/snapshots/win/doyto/doyto-query-common/) | [![common-release-img]](https://search.maven.org/artifact/win.doyto/doyto-query-common/) |
| doyto-query-sql | [![sql-snapshots-img]](https://oss.sonatype.org/content/repositories/snapshots/win/doyto/doyto-query-sql/) | [![sql-release-img]](https://search.maven.org/artifact/win.doyto/doyto-query-sql/) |
| doyto-query-jdbc | [![jdbc-snapshots-img]](https://oss.sonatype.org/content/repositories/snapshots/win/doyto/doyto-query-jdbc/) | [![jdbc-release-img]](https://search.maven.org/artifact/win.doyto/doyto-query-jdbc/) |
| doyto-query-web-common | [![web-common-snapshots-img]](https://oss.sonatype.org/content/repositories/snapshots/win/doyto/doyto-query-web-common/) | [![web-common-release-img]](https://search.maven.org/artifact/win.doyto/doyto-query-web-common/) |
| doyto-query-web | [![web-snapshots-img]](https://oss.sonatype.org/content/repositories/snapshots/win/doyto/doyto-query-web/) | [![web-release-img]](https://search.maven.org/artifact/win.doyto/doyto-query-web/) |
| doyto-query-dialect | [![dialect-snapshots-img]](https://oss.sonatype.org/content/repositories/snapshots/win/doyto/doyto-query-dialect/) | [![dialect-release-img]](https://search.maven.org/artifact/win.doyto/doyto-query-dialect/) |
## Supported Databases
- MySQL
- Oracle
- SQL Server
- PostgreSQL
- SQLite
- HSQLDB
- MongoDB
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