55import org .javawebstack .orm .SQLMapper ;
66import org .javawebstack .orm .connection .pool .PooledSQL ;
77import org .javawebstack .orm .exception .ORMQueryException ;
8- import org .javawebstack .orm .connection .SQL ;
98import org .javawebstack .orm .renderer .SQLQueryString ;
109
1110import java .sql .ResultSet ;
@@ -31,6 +30,8 @@ public class Query<T extends Model> {
3130 private QueryGroup <T > having ;
3231 private boolean applyAccessible = false ;
3332 private Object accessor ;
33+ private boolean distinct = false ;
34+ private String distinctColumn = null ;
3435
3536 public Query (Class <T > model ) {
3637 this (Repo .get (model ), model );
@@ -45,6 +46,14 @@ public boolean isWithDeleted() {
4546 return withDeleted ;
4647 }
4748
49+ public boolean isDistinct () {
50+ return distinct ;
51+ }
52+
53+ public String getDistinctColumn () {
54+ return distinctColumn ;
55+ }
56+
4857 public boolean shouldApplyAccessible () {
4958 return applyAccessible ;
5059 }
@@ -94,6 +103,24 @@ public Query<T> select(String... columns) {
94103 return this ;
95104 }
96105
106+ public Query <T > distinct () {
107+ this .distinct = true ;
108+ return this ;
109+ }
110+
111+ public Query <T > distinct (String column ) {
112+ this .distinct = true ;
113+ this .distinctColumn = column ;
114+ return this ;
115+ }
116+
117+ public Query <T > distinct (boolean distinct ) {
118+ this .distinct = distinct ;
119+ if (!distinct )
120+ this .distinctColumn = null ;
121+ return this ;
122+ }
123+
97124 public Query <T > and (Function <QueryGroup <T >, QueryGroup <T >> group ) {
98125 where .and (group );
99126 return this ;
0 commit comments