44 lines
948 B
Markdown
44 lines
948 B
Markdown
# ORM Query Builder
|
|
|
|
Fluent query builder on top of the ORM.
|
|
|
|
## Basic
|
|
|
|
```java
|
|
List<PlayerModel> top = api.orm().query(PlayerModel.class)
|
|
.where("level >= ?", 10)
|
|
.orderBy("level DESC")
|
|
.limit(10)
|
|
.list();
|
|
```
|
|
|
|
## Fluent Conditions
|
|
|
|
```java
|
|
import static com.andrewkydev.database.orm.Conditions.*;
|
|
|
|
List<PlayerModel> players = api.orm().query(PlayerModel.class)
|
|
.where(eq("status", "ACTIVE").and(gt("level", 10)))
|
|
.orderBy("level DESC")
|
|
.list();
|
|
```
|
|
|
|
## Joins + Group By + Having
|
|
|
|
```java
|
|
List<PlayerModel> rows = api.orm().query(PlayerModel.class)
|
|
.select("players.*")
|
|
.join("LEFT JOIN clans ON clans.id = players.clan_id")
|
|
.where("players.level >= ?", 10)
|
|
.groupBy("players.id")
|
|
.having("COUNT(clans.id) > ?", 0)
|
|
.orderBy("players.level DESC")
|
|
.limit(10, 0)
|
|
.list();
|
|
```
|
|
|
|
## Select Columns
|
|
|
|
If you select a subset of columns, only those are mapped.
|
|
Missing fields keep default values.
|