entc/gen: rename <type>.Order to <type>.OrderOption (#3468)

Also, avoid generting predicate without op in case a field named: order_option
This commit is contained in:
Ariel Mashraki
2023-04-11 08:23:29 +03:00
committed by GitHub
parent 065cb9f9ff
commit da69615bd0
308 changed files with 2837 additions and 1561 deletions

View File

@@ -53,40 +53,40 @@ func ValidColumn(column string) bool {
return false
}
// Order defines the ordering method for the Node queries.
type Order func(*sql.Selector)
// OrderOption defines the ordering options for the Node queries.
type OrderOption func(*sql.Selector)
// ByID orders the results by the id field.
func ByID(opts ...sql.OrderTermOption) Order {
func ByID(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldID, opts...).ToFunc()
}
// ByValue orders the results by the value field.
func ByValue(opts ...sql.OrderTermOption) Order {
func ByValue(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldValue, opts...).ToFunc()
}
// ByParentID orders the results by the parent_id field.
func ByParentID(opts ...sql.OrderTermOption) Order {
func ByParentID(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldParentID, opts...).ToFunc()
}
// ByParentField orders the results by parent field.
func ByParentField(field string, opts ...sql.OrderTermOption) Order {
func ByParentField(field string, opts ...sql.OrderTermOption) OrderOption {
return func(s *sql.Selector) {
sqlgraph.OrderByNeighborTerms(s, newParentStep(), sql.OrderByField(field, opts...))
}
}
// ByChildrenCount orders the results by children count.
func ByChildrenCount(opts ...sql.OrderTermOption) Order {
func ByChildrenCount(opts ...sql.OrderTermOption) OrderOption {
return func(s *sql.Selector) {
sqlgraph.OrderByNeighborsCount(s, newChildrenStep(), opts...)
}
}
// ByChildren orders the results by children terms.
func ByChildren(term sql.OrderTerm, terms ...sql.OrderTerm) Order {
func ByChildren(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption {
return func(s *sql.Selector) {
sqlgraph.OrderByNeighborTerms(s, newChildrenStep(), append([]sql.OrderTerm{term}, terms...)...)
}

View File

@@ -23,7 +23,7 @@ import (
type NodeQuery struct {
config
ctx *QueryContext
order []node.Order
order []node.OrderOption
inters []Interceptor
predicates []predicate.Node
withParent *NodeQuery
@@ -59,7 +59,7 @@ func (nq *NodeQuery) Unique(unique bool) *NodeQuery {
}
// Order specifies how the records should be ordered.
func (nq *NodeQuery) Order(o ...node.Order) *NodeQuery {
func (nq *NodeQuery) Order(o ...node.OrderOption) *NodeQuery {
nq.order = append(nq.order, o...)
return nq
}
@@ -297,7 +297,7 @@ func (nq *NodeQuery) Clone() *NodeQuery {
return &NodeQuery{
config: nq.config,
ctx: nq.ctx.Clone(),
order: append([]node.Order{}, nq.order...),
order: append([]node.OrderOption{}, nq.order...),
inters: append([]Interceptor{}, nq.inters...),
predicates: append([]predicate.Node{}, nq.predicates...),
withParent: nq.withParent.Clone(),