entc/gen/template: allow disable DISTINCT in queries (#1371)

This commit is contained in:
Ariel Mashraki
2021-03-22 16:36:05 +02:00
committed by GitHub
parent afa3beca6b
commit cf8464cb28
96 changed files with 1032 additions and 21 deletions

View File

@@ -25,6 +25,7 @@ type PetQuery struct {
config
limit *int
offset *int
unique *bool
order []OrderFunc
fields []string
predicates []predicate.Pet
@@ -54,6 +55,13 @@ func (pq *PetQuery) Offset(offset int) *PetQuery {
return pq
}
// Unique configures the query builder to filter duplicate records on query.
// By default, unique is set to true, and can be disabled using this method.
func (pq *PetQuery) Unique(unique bool) *PetQuery {
pq.unique = &unique
return pq
}
// Order adds an order step to the query.
func (pq *PetQuery) Order(o ...OrderFunc) *PetQuery {
pq.order = append(pq.order, o...)
@@ -435,6 +443,9 @@ func (pq *PetQuery) querySpec() *sqlgraph.QuerySpec {
From: pq.sql,
Unique: true,
}
if unique := pq.unique; unique != nil {
_spec.Unique = *unique
}
if fields := pq.fields; len(fields) > 0 {
_spec.Node.Columns = make([]string, 0, len(fields))
_spec.Node.Columns = append(_spec.Node.Columns, pet.FieldID)

View File

@@ -26,6 +26,7 @@ type UserQuery struct {
config
limit *int
offset *int
unique *bool
order []OrderFunc
fields []string
predicates []predicate.User
@@ -54,6 +55,13 @@ func (uq *UserQuery) Offset(offset int) *UserQuery {
return uq
}
// Unique configures the query builder to filter duplicate records on query.
// By default, unique is set to true, and can be disabled using this method.
func (uq *UserQuery) Unique(unique bool) *UserQuery {
uq.unique = &unique
return uq
}
// Order adds an order step to the query.
func (uq *UserQuery) Order(o ...OrderFunc) *UserQuery {
uq.order = append(uq.order, o...)
@@ -428,6 +436,9 @@ func (uq *UserQuery) querySpec() *sqlgraph.QuerySpec {
From: uq.sql,
Unique: true,
}
if unique := uq.unique; unique != nil {
_spec.Unique = *unique
}
if fields := uq.fields; len(fields) > 0 {
_spec.Node.Columns = make([]string, 0, len(fields))
_spec.Node.Columns = append(_spec.Node.Columns, user.FieldID)