mirror of
https://github.com/ent/ent.git
synced 2026-05-24 09:31:56 +03:00
entc/gen: lazy compute storage-driver queries (#408)
This commit is contained in:
@@ -31,8 +31,9 @@ type CarQuery struct {
|
||||
// eager-loading edges.
|
||||
withOwner *UserQuery
|
||||
withFKs bool
|
||||
// intermediate query.
|
||||
sql *sql.Selector
|
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector
|
||||
path func(context.Context) (*sql.Selector, error)
|
||||
}
|
||||
|
||||
// Where adds a new predicate for the builder.
|
||||
@@ -62,12 +63,18 @@ func (cq *CarQuery) Order(o ...Order) *CarQuery {
|
||||
// QueryOwner chains the current query on the owner edge.
|
||||
func (cq *CarQuery) QueryOwner() *UserQuery {
|
||||
query := &UserQuery{config: cq.config}
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(car.Table, car.FieldID, cq.sqlQuery()),
|
||||
sqlgraph.To(user.Table, user.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2O, true, car.OwnerTable, car.OwnerColumn),
|
||||
)
|
||||
query.sql = sqlgraph.SetNeighbors(cq.driver.Dialect(), step)
|
||||
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
|
||||
if err := cq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(car.Table, car.FieldID, cq.sqlQuery()),
|
||||
sqlgraph.To(user.Table, user.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2O, true, car.OwnerTable, car.OwnerColumn),
|
||||
)
|
||||
fromU = sqlgraph.SetNeighbors(cq.driver.Dialect(), step)
|
||||
return fromU, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
@@ -167,6 +174,9 @@ func (cq *CarQuery) OnlyXID(ctx context.Context) int {
|
||||
|
||||
// All executes the query and returns a list of Cars.
|
||||
func (cq *CarQuery) All(ctx context.Context) ([]*Car, error) {
|
||||
if err := cq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return cq.sqlAll(ctx)
|
||||
}
|
||||
|
||||
@@ -199,6 +209,9 @@ func (cq *CarQuery) IDsX(ctx context.Context) []int {
|
||||
|
||||
// Count returns the count of the given query.
|
||||
func (cq *CarQuery) Count(ctx context.Context) (int, error) {
|
||||
if err := cq.prepareQuery(ctx); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return cq.sqlCount(ctx)
|
||||
}
|
||||
|
||||
@@ -213,6 +226,9 @@ func (cq *CarQuery) CountX(ctx context.Context) int {
|
||||
|
||||
// Exist returns true if the query has elements in the graph.
|
||||
func (cq *CarQuery) Exist(ctx context.Context) (bool, error) {
|
||||
if err := cq.prepareQuery(ctx); err != nil {
|
||||
return false, err
|
||||
}
|
||||
return cq.sqlExist(ctx)
|
||||
}
|
||||
|
||||
@@ -236,7 +252,8 @@ func (cq *CarQuery) Clone() *CarQuery {
|
||||
unique: append([]string{}, cq.unique...),
|
||||
predicates: append([]predicate.Car{}, cq.predicates...),
|
||||
// clone intermediate query.
|
||||
sql: cq.sql.Clone(),
|
||||
sql: cq.sql.Clone(),
|
||||
path: cq.path,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -256,7 +273,12 @@ func (cq *CarQuery) WithOwner(opts ...func(*UserQuery)) *CarQuery {
|
||||
func (cq *CarQuery) GroupBy(field string, fields ...string) *CarGroupBy {
|
||||
group := &CarGroupBy{config: cq.config}
|
||||
group.fields = append([]string{field}, fields...)
|
||||
group.sql = cq.sqlQuery()
|
||||
group.path = func(ctx context.Context) (prev *sql.Selector, err error) {
|
||||
if err := cq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return cq.sqlQuery(), nil
|
||||
}
|
||||
return group
|
||||
}
|
||||
|
||||
@@ -264,10 +286,27 @@ func (cq *CarQuery) GroupBy(field string, fields ...string) *CarGroupBy {
|
||||
func (cq *CarQuery) Select(field string, fields ...string) *CarSelect {
|
||||
selector := &CarSelect{config: cq.config}
|
||||
selector.fields = append([]string{field}, fields...)
|
||||
selector.sql = cq.sqlQuery()
|
||||
selector.path = func(ctx context.Context) (prev *sql.Selector, err error) {
|
||||
if err := cq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return cq.sqlQuery(), nil
|
||||
}
|
||||
return selector
|
||||
}
|
||||
|
||||
func (cq *CarQuery) prepareQuery(ctx context.Context) error {
|
||||
if cq.path != nil {
|
||||
prev, err := cq.path(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
cq.sql = prev
|
||||
}
|
||||
// Privacy and query checks go here.
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cq *CarQuery) sqlAll(ctx context.Context) ([]*Car, error) {
|
||||
var (
|
||||
nodes = []*Car{}
|
||||
@@ -414,8 +453,9 @@ type CarGroupBy struct {
|
||||
config
|
||||
fields []string
|
||||
fns []Aggregate
|
||||
// intermediate query.
|
||||
sql *sql.Selector
|
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector
|
||||
path func(context.Context) (*sql.Selector, error)
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the group-by query.
|
||||
@@ -426,6 +466,11 @@ func (cgb *CarGroupBy) Aggregate(fns ...Aggregate) *CarGroupBy {
|
||||
|
||||
// Scan applies the group-by query and scan the result into the given value.
|
||||
func (cgb *CarGroupBy) Scan(ctx context.Context, v interface{}) error {
|
||||
query, err := cgb.path(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
cgb.sql = query
|
||||
return cgb.sqlScan(ctx, v)
|
||||
}
|
||||
|
||||
@@ -544,12 +589,18 @@ func (cgb *CarGroupBy) sqlQuery() *sql.Selector {
|
||||
type CarSelect struct {
|
||||
config
|
||||
fields []string
|
||||
// intermediate queries.
|
||||
sql *sql.Selector
|
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector
|
||||
path func(context.Context) (*sql.Selector, error)
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scan the result into the given value.
|
||||
func (cs *CarSelect) Scan(ctx context.Context, v interface{}) error {
|
||||
query, err := cs.path(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
cs.sql = query
|
||||
return cs.sqlScan(ctx, v)
|
||||
}
|
||||
|
||||
|
||||
@@ -190,14 +190,16 @@ func (c *CarClient) GetX(ctx context.Context, id int) *Car {
|
||||
// QueryOwner queries the owner edge of a Car.
|
||||
func (c *CarClient) QueryOwner(ca *Car) *UserQuery {
|
||||
query := &UserQuery{config: c.config}
|
||||
id := ca.ID
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(car.Table, car.FieldID, id),
|
||||
sqlgraph.To(user.Table, user.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2O, true, car.OwnerTable, car.OwnerColumn),
|
||||
)
|
||||
query.sql = sqlgraph.Neighbors(ca.driver.Dialect(), step)
|
||||
|
||||
query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) {
|
||||
id := ca.ID
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(car.Table, car.FieldID, id),
|
||||
sqlgraph.To(user.Table, user.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2O, true, car.OwnerTable, car.OwnerColumn),
|
||||
)
|
||||
fromV = sqlgraph.Neighbors(ca.driver.Dialect(), step)
|
||||
return fromV, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
@@ -287,56 +289,64 @@ func (c *UserClient) GetX(ctx context.Context, id int) *User {
|
||||
// QueryParent queries the parent edge of a User.
|
||||
func (c *UserClient) QueryParent(u *User) *UserQuery {
|
||||
query := &UserQuery{config: c.config}
|
||||
id := u.ID
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(user.Table, user.FieldID, id),
|
||||
sqlgraph.To(user.Table, user.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, true, user.ParentTable, user.ParentColumn),
|
||||
)
|
||||
query.sql = sqlgraph.Neighbors(u.driver.Dialect(), step)
|
||||
|
||||
query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) {
|
||||
id := u.ID
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(user.Table, user.FieldID, id),
|
||||
sqlgraph.To(user.Table, user.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, true, user.ParentTable, user.ParentColumn),
|
||||
)
|
||||
fromV = sqlgraph.Neighbors(u.driver.Dialect(), step)
|
||||
return fromV, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// QueryChildren queries the children edge of a User.
|
||||
func (c *UserClient) QueryChildren(u *User) *UserQuery {
|
||||
query := &UserQuery{config: c.config}
|
||||
id := u.ID
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(user.Table, user.FieldID, id),
|
||||
sqlgraph.To(user.Table, user.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2M, false, user.ChildrenTable, user.ChildrenColumn),
|
||||
)
|
||||
query.sql = sqlgraph.Neighbors(u.driver.Dialect(), step)
|
||||
|
||||
query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) {
|
||||
id := u.ID
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(user.Table, user.FieldID, id),
|
||||
sqlgraph.To(user.Table, user.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2M, false, user.ChildrenTable, user.ChildrenColumn),
|
||||
)
|
||||
fromV = sqlgraph.Neighbors(u.driver.Dialect(), step)
|
||||
return fromV, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// QuerySpouse queries the spouse edge of a User.
|
||||
func (c *UserClient) QuerySpouse(u *User) *UserQuery {
|
||||
query := &UserQuery{config: c.config}
|
||||
id := u.ID
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(user.Table, user.FieldID, id),
|
||||
sqlgraph.To(user.Table, user.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2O, false, user.SpouseTable, user.SpouseColumn),
|
||||
)
|
||||
query.sql = sqlgraph.Neighbors(u.driver.Dialect(), step)
|
||||
|
||||
query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) {
|
||||
id := u.ID
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(user.Table, user.FieldID, id),
|
||||
sqlgraph.To(user.Table, user.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2O, false, user.SpouseTable, user.SpouseColumn),
|
||||
)
|
||||
fromV = sqlgraph.Neighbors(u.driver.Dialect(), step)
|
||||
return fromV, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// QueryCar queries the car edge of a User.
|
||||
func (c *UserClient) QueryCar(u *User) *CarQuery {
|
||||
query := &CarQuery{config: c.config}
|
||||
id := u.ID
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(user.Table, user.FieldID, id),
|
||||
sqlgraph.To(car.Table, car.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2O, false, user.CarTable, user.CarColumn),
|
||||
)
|
||||
query.sql = sqlgraph.Neighbors(u.driver.Dialect(), step)
|
||||
|
||||
query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) {
|
||||
id := u.ID
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(user.Table, user.FieldID, id),
|
||||
sqlgraph.To(car.Table, car.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2O, false, user.CarTable, user.CarColumn),
|
||||
)
|
||||
fromV = sqlgraph.Neighbors(u.driver.Dialect(), step)
|
||||
return fromV, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
|
||||
@@ -35,8 +35,9 @@ type UserQuery struct {
|
||||
withSpouse *UserQuery
|
||||
withCar *CarQuery
|
||||
withFKs bool
|
||||
// intermediate query.
|
||||
sql *sql.Selector
|
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector
|
||||
path func(context.Context) (*sql.Selector, error)
|
||||
}
|
||||
|
||||
// Where adds a new predicate for the builder.
|
||||
@@ -66,48 +67,72 @@ func (uq *UserQuery) Order(o ...Order) *UserQuery {
|
||||
// QueryParent chains the current query on the parent edge.
|
||||
func (uq *UserQuery) QueryParent() *UserQuery {
|
||||
query := &UserQuery{config: uq.config}
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(user.Table, user.FieldID, uq.sqlQuery()),
|
||||
sqlgraph.To(user.Table, user.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, true, user.ParentTable, user.ParentColumn),
|
||||
)
|
||||
query.sql = sqlgraph.SetNeighbors(uq.driver.Dialect(), step)
|
||||
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
|
||||
if err := uq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(user.Table, user.FieldID, uq.sqlQuery()),
|
||||
sqlgraph.To(user.Table, user.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, true, user.ParentTable, user.ParentColumn),
|
||||
)
|
||||
fromU = sqlgraph.SetNeighbors(uq.driver.Dialect(), step)
|
||||
return fromU, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// QueryChildren chains the current query on the children edge.
|
||||
func (uq *UserQuery) QueryChildren() *UserQuery {
|
||||
query := &UserQuery{config: uq.config}
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(user.Table, user.FieldID, uq.sqlQuery()),
|
||||
sqlgraph.To(user.Table, user.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2M, false, user.ChildrenTable, user.ChildrenColumn),
|
||||
)
|
||||
query.sql = sqlgraph.SetNeighbors(uq.driver.Dialect(), step)
|
||||
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
|
||||
if err := uq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(user.Table, user.FieldID, uq.sqlQuery()),
|
||||
sqlgraph.To(user.Table, user.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2M, false, user.ChildrenTable, user.ChildrenColumn),
|
||||
)
|
||||
fromU = sqlgraph.SetNeighbors(uq.driver.Dialect(), step)
|
||||
return fromU, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// QuerySpouse chains the current query on the spouse edge.
|
||||
func (uq *UserQuery) QuerySpouse() *UserQuery {
|
||||
query := &UserQuery{config: uq.config}
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(user.Table, user.FieldID, uq.sqlQuery()),
|
||||
sqlgraph.To(user.Table, user.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2O, false, user.SpouseTable, user.SpouseColumn),
|
||||
)
|
||||
query.sql = sqlgraph.SetNeighbors(uq.driver.Dialect(), step)
|
||||
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
|
||||
if err := uq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(user.Table, user.FieldID, uq.sqlQuery()),
|
||||
sqlgraph.To(user.Table, user.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2O, false, user.SpouseTable, user.SpouseColumn),
|
||||
)
|
||||
fromU = sqlgraph.SetNeighbors(uq.driver.Dialect(), step)
|
||||
return fromU, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// QueryCar chains the current query on the car edge.
|
||||
func (uq *UserQuery) QueryCar() *CarQuery {
|
||||
query := &CarQuery{config: uq.config}
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(user.Table, user.FieldID, uq.sqlQuery()),
|
||||
sqlgraph.To(car.Table, car.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2O, false, user.CarTable, user.CarColumn),
|
||||
)
|
||||
query.sql = sqlgraph.SetNeighbors(uq.driver.Dialect(), step)
|
||||
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
|
||||
if err := uq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(user.Table, user.FieldID, uq.sqlQuery()),
|
||||
sqlgraph.To(car.Table, car.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2O, false, user.CarTable, user.CarColumn),
|
||||
)
|
||||
fromU = sqlgraph.SetNeighbors(uq.driver.Dialect(), step)
|
||||
return fromU, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
@@ -207,6 +232,9 @@ func (uq *UserQuery) OnlyXID(ctx context.Context) int {
|
||||
|
||||
// All executes the query and returns a list of Users.
|
||||
func (uq *UserQuery) All(ctx context.Context) ([]*User, error) {
|
||||
if err := uq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return uq.sqlAll(ctx)
|
||||
}
|
||||
|
||||
@@ -239,6 +267,9 @@ func (uq *UserQuery) IDsX(ctx context.Context) []int {
|
||||
|
||||
// Count returns the count of the given query.
|
||||
func (uq *UserQuery) Count(ctx context.Context) (int, error) {
|
||||
if err := uq.prepareQuery(ctx); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return uq.sqlCount(ctx)
|
||||
}
|
||||
|
||||
@@ -253,6 +284,9 @@ func (uq *UserQuery) CountX(ctx context.Context) int {
|
||||
|
||||
// Exist returns true if the query has elements in the graph.
|
||||
func (uq *UserQuery) Exist(ctx context.Context) (bool, error) {
|
||||
if err := uq.prepareQuery(ctx); err != nil {
|
||||
return false, err
|
||||
}
|
||||
return uq.sqlExist(ctx)
|
||||
}
|
||||
|
||||
@@ -276,7 +310,8 @@ func (uq *UserQuery) Clone() *UserQuery {
|
||||
unique: append([]string{}, uq.unique...),
|
||||
predicates: append([]predicate.User{}, uq.predicates...),
|
||||
// clone intermediate query.
|
||||
sql: uq.sql.Clone(),
|
||||
sql: uq.sql.Clone(),
|
||||
path: uq.path,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -342,7 +377,12 @@ func (uq *UserQuery) WithCar(opts ...func(*CarQuery)) *UserQuery {
|
||||
func (uq *UserQuery) GroupBy(field string, fields ...string) *UserGroupBy {
|
||||
group := &UserGroupBy{config: uq.config}
|
||||
group.fields = append([]string{field}, fields...)
|
||||
group.sql = uq.sqlQuery()
|
||||
group.path = func(ctx context.Context) (prev *sql.Selector, err error) {
|
||||
if err := uq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return uq.sqlQuery(), nil
|
||||
}
|
||||
return group
|
||||
}
|
||||
|
||||
@@ -361,10 +401,27 @@ func (uq *UserQuery) GroupBy(field string, fields ...string) *UserGroupBy {
|
||||
func (uq *UserQuery) Select(field string, fields ...string) *UserSelect {
|
||||
selector := &UserSelect{config: uq.config}
|
||||
selector.fields = append([]string{field}, fields...)
|
||||
selector.sql = uq.sqlQuery()
|
||||
selector.path = func(ctx context.Context) (prev *sql.Selector, err error) {
|
||||
if err := uq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return uq.sqlQuery(), nil
|
||||
}
|
||||
return selector
|
||||
}
|
||||
|
||||
func (uq *UserQuery) prepareQuery(ctx context.Context) error {
|
||||
if uq.path != nil {
|
||||
prev, err := uq.path(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
uq.sql = prev
|
||||
}
|
||||
// Privacy and query checks go here.
|
||||
return nil
|
||||
}
|
||||
|
||||
func (uq *UserQuery) sqlAll(ctx context.Context) ([]*User, error) {
|
||||
var (
|
||||
nodes = []*User{}
|
||||
@@ -595,8 +652,9 @@ type UserGroupBy struct {
|
||||
config
|
||||
fields []string
|
||||
fns []Aggregate
|
||||
// intermediate query.
|
||||
sql *sql.Selector
|
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector
|
||||
path func(context.Context) (*sql.Selector, error)
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the group-by query.
|
||||
@@ -607,6 +665,11 @@ func (ugb *UserGroupBy) Aggregate(fns ...Aggregate) *UserGroupBy {
|
||||
|
||||
// Scan applies the group-by query and scan the result into the given value.
|
||||
func (ugb *UserGroupBy) Scan(ctx context.Context, v interface{}) error {
|
||||
query, err := ugb.path(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
ugb.sql = query
|
||||
return ugb.sqlScan(ctx, v)
|
||||
}
|
||||
|
||||
@@ -725,12 +788,18 @@ func (ugb *UserGroupBy) sqlQuery() *sql.Selector {
|
||||
type UserSelect struct {
|
||||
config
|
||||
fields []string
|
||||
// intermediate queries.
|
||||
sql *sql.Selector
|
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector
|
||||
path func(context.Context) (*sql.Selector, error)
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scan the result into the given value.
|
||||
func (us *UserSelect) Scan(ctx context.Context, v interface{}) error {
|
||||
query, err := us.path(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
us.sql = query
|
||||
return us.sqlScan(ctx, v)
|
||||
}
|
||||
|
||||
|
||||
@@ -31,8 +31,9 @@ type CarQuery struct {
|
||||
// eager-loading edges.
|
||||
withOwner *UserQuery
|
||||
withFKs bool
|
||||
// intermediate query.
|
||||
sql *sql.Selector
|
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector
|
||||
path func(context.Context) (*sql.Selector, error)
|
||||
}
|
||||
|
||||
// Where adds a new predicate for the builder.
|
||||
@@ -62,12 +63,18 @@ func (cq *CarQuery) Order(o ...Order) *CarQuery {
|
||||
// QueryOwner chains the current query on the owner edge.
|
||||
func (cq *CarQuery) QueryOwner() *UserQuery {
|
||||
query := &UserQuery{config: cq.config}
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(car.Table, car.FieldID, cq.sqlQuery()),
|
||||
sqlgraph.To(user.Table, user.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, true, car.OwnerTable, car.OwnerColumn),
|
||||
)
|
||||
query.sql = sqlgraph.SetNeighbors(cq.driver.Dialect(), step)
|
||||
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
|
||||
if err := cq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(car.Table, car.FieldID, cq.sqlQuery()),
|
||||
sqlgraph.To(user.Table, user.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, true, car.OwnerTable, car.OwnerColumn),
|
||||
)
|
||||
fromU = sqlgraph.SetNeighbors(cq.driver.Dialect(), step)
|
||||
return fromU, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
@@ -167,6 +174,9 @@ func (cq *CarQuery) OnlyXID(ctx context.Context) int {
|
||||
|
||||
// All executes the query and returns a list of Cars.
|
||||
func (cq *CarQuery) All(ctx context.Context) ([]*Car, error) {
|
||||
if err := cq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return cq.sqlAll(ctx)
|
||||
}
|
||||
|
||||
@@ -199,6 +209,9 @@ func (cq *CarQuery) IDsX(ctx context.Context) []int {
|
||||
|
||||
// Count returns the count of the given query.
|
||||
func (cq *CarQuery) Count(ctx context.Context) (int, error) {
|
||||
if err := cq.prepareQuery(ctx); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return cq.sqlCount(ctx)
|
||||
}
|
||||
|
||||
@@ -213,6 +226,9 @@ func (cq *CarQuery) CountX(ctx context.Context) int {
|
||||
|
||||
// Exist returns true if the query has elements in the graph.
|
||||
func (cq *CarQuery) Exist(ctx context.Context) (bool, error) {
|
||||
if err := cq.prepareQuery(ctx); err != nil {
|
||||
return false, err
|
||||
}
|
||||
return cq.sqlExist(ctx)
|
||||
}
|
||||
|
||||
@@ -236,7 +252,8 @@ func (cq *CarQuery) Clone() *CarQuery {
|
||||
unique: append([]string{}, cq.unique...),
|
||||
predicates: append([]predicate.Car{}, cq.predicates...),
|
||||
// clone intermediate query.
|
||||
sql: cq.sql.Clone(),
|
||||
sql: cq.sql.Clone(),
|
||||
path: cq.path,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -256,7 +273,12 @@ func (cq *CarQuery) WithOwner(opts ...func(*UserQuery)) *CarQuery {
|
||||
func (cq *CarQuery) GroupBy(field string, fields ...string) *CarGroupBy {
|
||||
group := &CarGroupBy{config: cq.config}
|
||||
group.fields = append([]string{field}, fields...)
|
||||
group.sql = cq.sqlQuery()
|
||||
group.path = func(ctx context.Context) (prev *sql.Selector, err error) {
|
||||
if err := cq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return cq.sqlQuery(), nil
|
||||
}
|
||||
return group
|
||||
}
|
||||
|
||||
@@ -264,10 +286,27 @@ func (cq *CarQuery) GroupBy(field string, fields ...string) *CarGroupBy {
|
||||
func (cq *CarQuery) Select(field string, fields ...string) *CarSelect {
|
||||
selector := &CarSelect{config: cq.config}
|
||||
selector.fields = append([]string{field}, fields...)
|
||||
selector.sql = cq.sqlQuery()
|
||||
selector.path = func(ctx context.Context) (prev *sql.Selector, err error) {
|
||||
if err := cq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return cq.sqlQuery(), nil
|
||||
}
|
||||
return selector
|
||||
}
|
||||
|
||||
func (cq *CarQuery) prepareQuery(ctx context.Context) error {
|
||||
if cq.path != nil {
|
||||
prev, err := cq.path(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
cq.sql = prev
|
||||
}
|
||||
// Privacy and query checks go here.
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cq *CarQuery) sqlAll(ctx context.Context) ([]*Car, error) {
|
||||
var (
|
||||
nodes = []*Car{}
|
||||
@@ -414,8 +453,9 @@ type CarGroupBy struct {
|
||||
config
|
||||
fields []string
|
||||
fns []Aggregate
|
||||
// intermediate query.
|
||||
sql *sql.Selector
|
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector
|
||||
path func(context.Context) (*sql.Selector, error)
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the group-by query.
|
||||
@@ -426,6 +466,11 @@ func (cgb *CarGroupBy) Aggregate(fns ...Aggregate) *CarGroupBy {
|
||||
|
||||
// Scan applies the group-by query and scan the result into the given value.
|
||||
func (cgb *CarGroupBy) Scan(ctx context.Context, v interface{}) error {
|
||||
query, err := cgb.path(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
cgb.sql = query
|
||||
return cgb.sqlScan(ctx, v)
|
||||
}
|
||||
|
||||
@@ -544,12 +589,18 @@ func (cgb *CarGroupBy) sqlQuery() *sql.Selector {
|
||||
type CarSelect struct {
|
||||
config
|
||||
fields []string
|
||||
// intermediate queries.
|
||||
sql *sql.Selector
|
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector
|
||||
path func(context.Context) (*sql.Selector, error)
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scan the result into the given value.
|
||||
func (cs *CarSelect) Scan(ctx context.Context, v interface{}) error {
|
||||
query, err := cs.path(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
cs.sql = query
|
||||
return cs.sqlScan(ctx, v)
|
||||
}
|
||||
|
||||
|
||||
@@ -202,14 +202,16 @@ func (c *CarClient) GetX(ctx context.Context, id int) *Car {
|
||||
// QueryOwner queries the owner edge of a Car.
|
||||
func (c *CarClient) QueryOwner(ca *Car) *UserQuery {
|
||||
query := &UserQuery{config: c.config}
|
||||
id := ca.ID
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(car.Table, car.FieldID, id),
|
||||
sqlgraph.To(user.Table, user.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, true, car.OwnerTable, car.OwnerColumn),
|
||||
)
|
||||
query.sql = sqlgraph.Neighbors(ca.driver.Dialect(), step)
|
||||
|
||||
query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) {
|
||||
id := ca.ID
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(car.Table, car.FieldID, id),
|
||||
sqlgraph.To(user.Table, user.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, true, car.OwnerTable, car.OwnerColumn),
|
||||
)
|
||||
fromV = sqlgraph.Neighbors(ca.driver.Dialect(), step)
|
||||
return fromV, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
@@ -465,28 +467,32 @@ func (c *UserClient) GetX(ctx context.Context, id int) *User {
|
||||
// QueryCar queries the car edge of a User.
|
||||
func (c *UserClient) QueryCar(u *User) *CarQuery {
|
||||
query := &CarQuery{config: c.config}
|
||||
id := u.ID
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(user.Table, user.FieldID, id),
|
||||
sqlgraph.To(car.Table, car.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2M, false, user.CarTable, user.CarColumn),
|
||||
)
|
||||
query.sql = sqlgraph.Neighbors(u.driver.Dialect(), step)
|
||||
|
||||
query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) {
|
||||
id := u.ID
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(user.Table, user.FieldID, id),
|
||||
sqlgraph.To(car.Table, car.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2M, false, user.CarTable, user.CarColumn),
|
||||
)
|
||||
fromV = sqlgraph.Neighbors(u.driver.Dialect(), step)
|
||||
return fromV, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// QueryPets queries the pets edge of a User.
|
||||
func (c *UserClient) QueryPets(u *User) *PetQuery {
|
||||
query := &PetQuery{config: c.config}
|
||||
id := u.ID
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(user.Table, user.FieldID, id),
|
||||
sqlgraph.To(pet.Table, pet.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, false, user.PetsTable, user.PetsColumn),
|
||||
)
|
||||
query.sql = sqlgraph.Neighbors(u.driver.Dialect(), step)
|
||||
|
||||
query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) {
|
||||
id := u.ID
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(user.Table, user.FieldID, id),
|
||||
sqlgraph.To(pet.Table, pet.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, false, user.PetsTable, user.PetsColumn),
|
||||
)
|
||||
fromV = sqlgraph.Neighbors(u.driver.Dialect(), step)
|
||||
return fromV, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
|
||||
@@ -27,8 +27,9 @@ type GroupQuery struct {
|
||||
order []Order
|
||||
unique []string
|
||||
predicates []predicate.Group
|
||||
// intermediate query.
|
||||
sql *sql.Selector
|
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector
|
||||
path func(context.Context) (*sql.Selector, error)
|
||||
}
|
||||
|
||||
// Where adds a new predicate for the builder.
|
||||
@@ -151,6 +152,9 @@ func (gq *GroupQuery) OnlyXID(ctx context.Context) int {
|
||||
|
||||
// All executes the query and returns a list of Groups.
|
||||
func (gq *GroupQuery) All(ctx context.Context) ([]*Group, error) {
|
||||
if err := gq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return gq.sqlAll(ctx)
|
||||
}
|
||||
|
||||
@@ -183,6 +187,9 @@ func (gq *GroupQuery) IDsX(ctx context.Context) []int {
|
||||
|
||||
// Count returns the count of the given query.
|
||||
func (gq *GroupQuery) Count(ctx context.Context) (int, error) {
|
||||
if err := gq.prepareQuery(ctx); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return gq.sqlCount(ctx)
|
||||
}
|
||||
|
||||
@@ -197,6 +204,9 @@ func (gq *GroupQuery) CountX(ctx context.Context) int {
|
||||
|
||||
// Exist returns true if the query has elements in the graph.
|
||||
func (gq *GroupQuery) Exist(ctx context.Context) (bool, error) {
|
||||
if err := gq.prepareQuery(ctx); err != nil {
|
||||
return false, err
|
||||
}
|
||||
return gq.sqlExist(ctx)
|
||||
}
|
||||
|
||||
@@ -220,7 +230,8 @@ func (gq *GroupQuery) Clone() *GroupQuery {
|
||||
unique: append([]string{}, gq.unique...),
|
||||
predicates: append([]predicate.Group{}, gq.predicates...),
|
||||
// clone intermediate query.
|
||||
sql: gq.sql.Clone(),
|
||||
sql: gq.sql.Clone(),
|
||||
path: gq.path,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -229,7 +240,12 @@ func (gq *GroupQuery) Clone() *GroupQuery {
|
||||
func (gq *GroupQuery) GroupBy(field string, fields ...string) *GroupGroupBy {
|
||||
group := &GroupGroupBy{config: gq.config}
|
||||
group.fields = append([]string{field}, fields...)
|
||||
group.sql = gq.sqlQuery()
|
||||
group.path = func(ctx context.Context) (prev *sql.Selector, err error) {
|
||||
if err := gq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return gq.sqlQuery(), nil
|
||||
}
|
||||
return group
|
||||
}
|
||||
|
||||
@@ -237,10 +253,27 @@ func (gq *GroupQuery) GroupBy(field string, fields ...string) *GroupGroupBy {
|
||||
func (gq *GroupQuery) Select(field string, fields ...string) *GroupSelect {
|
||||
selector := &GroupSelect{config: gq.config}
|
||||
selector.fields = append([]string{field}, fields...)
|
||||
selector.sql = gq.sqlQuery()
|
||||
selector.path = func(ctx context.Context) (prev *sql.Selector, err error) {
|
||||
if err := gq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return gq.sqlQuery(), nil
|
||||
}
|
||||
return selector
|
||||
}
|
||||
|
||||
func (gq *GroupQuery) prepareQuery(ctx context.Context) error {
|
||||
if gq.path != nil {
|
||||
prev, err := gq.path(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
gq.sql = prev
|
||||
}
|
||||
// Privacy and query checks go here.
|
||||
return nil
|
||||
}
|
||||
|
||||
func (gq *GroupQuery) sqlAll(ctx context.Context) ([]*Group, error) {
|
||||
var (
|
||||
nodes = []*Group{}
|
||||
@@ -347,8 +380,9 @@ type GroupGroupBy struct {
|
||||
config
|
||||
fields []string
|
||||
fns []Aggregate
|
||||
// intermediate query.
|
||||
sql *sql.Selector
|
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector
|
||||
path func(context.Context) (*sql.Selector, error)
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the group-by query.
|
||||
@@ -359,6 +393,11 @@ func (ggb *GroupGroupBy) Aggregate(fns ...Aggregate) *GroupGroupBy {
|
||||
|
||||
// Scan applies the group-by query and scan the result into the given value.
|
||||
func (ggb *GroupGroupBy) Scan(ctx context.Context, v interface{}) error {
|
||||
query, err := ggb.path(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
ggb.sql = query
|
||||
return ggb.sqlScan(ctx, v)
|
||||
}
|
||||
|
||||
@@ -477,12 +516,18 @@ func (ggb *GroupGroupBy) sqlQuery() *sql.Selector {
|
||||
type GroupSelect struct {
|
||||
config
|
||||
fields []string
|
||||
// intermediate queries.
|
||||
sql *sql.Selector
|
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector
|
||||
path func(context.Context) (*sql.Selector, error)
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scan the result into the given value.
|
||||
func (gs *GroupSelect) Scan(ctx context.Context, v interface{}) error {
|
||||
query, err := gs.path(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
gs.sql = query
|
||||
return gs.sqlScan(ctx, v)
|
||||
}
|
||||
|
||||
|
||||
@@ -27,8 +27,9 @@ type PetQuery struct {
|
||||
order []Order
|
||||
unique []string
|
||||
predicates []predicate.Pet
|
||||
// intermediate query.
|
||||
sql *sql.Selector
|
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector
|
||||
path func(context.Context) (*sql.Selector, error)
|
||||
}
|
||||
|
||||
// Where adds a new predicate for the builder.
|
||||
@@ -151,6 +152,9 @@ func (pq *PetQuery) OnlyXID(ctx context.Context) int {
|
||||
|
||||
// All executes the query and returns a list of Pets.
|
||||
func (pq *PetQuery) All(ctx context.Context) ([]*Pet, error) {
|
||||
if err := pq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return pq.sqlAll(ctx)
|
||||
}
|
||||
|
||||
@@ -183,6 +187,9 @@ func (pq *PetQuery) IDsX(ctx context.Context) []int {
|
||||
|
||||
// Count returns the count of the given query.
|
||||
func (pq *PetQuery) Count(ctx context.Context) (int, error) {
|
||||
if err := pq.prepareQuery(ctx); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return pq.sqlCount(ctx)
|
||||
}
|
||||
|
||||
@@ -197,6 +204,9 @@ func (pq *PetQuery) CountX(ctx context.Context) int {
|
||||
|
||||
// Exist returns true if the query has elements in the graph.
|
||||
func (pq *PetQuery) Exist(ctx context.Context) (bool, error) {
|
||||
if err := pq.prepareQuery(ctx); err != nil {
|
||||
return false, err
|
||||
}
|
||||
return pq.sqlExist(ctx)
|
||||
}
|
||||
|
||||
@@ -220,7 +230,8 @@ func (pq *PetQuery) Clone() *PetQuery {
|
||||
unique: append([]string{}, pq.unique...),
|
||||
predicates: append([]predicate.Pet{}, pq.predicates...),
|
||||
// clone intermediate query.
|
||||
sql: pq.sql.Clone(),
|
||||
sql: pq.sql.Clone(),
|
||||
path: pq.path,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -229,7 +240,12 @@ func (pq *PetQuery) Clone() *PetQuery {
|
||||
func (pq *PetQuery) GroupBy(field string, fields ...string) *PetGroupBy {
|
||||
group := &PetGroupBy{config: pq.config}
|
||||
group.fields = append([]string{field}, fields...)
|
||||
group.sql = pq.sqlQuery()
|
||||
group.path = func(ctx context.Context) (prev *sql.Selector, err error) {
|
||||
if err := pq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return pq.sqlQuery(), nil
|
||||
}
|
||||
return group
|
||||
}
|
||||
|
||||
@@ -237,10 +253,27 @@ func (pq *PetQuery) GroupBy(field string, fields ...string) *PetGroupBy {
|
||||
func (pq *PetQuery) Select(field string, fields ...string) *PetSelect {
|
||||
selector := &PetSelect{config: pq.config}
|
||||
selector.fields = append([]string{field}, fields...)
|
||||
selector.sql = pq.sqlQuery()
|
||||
selector.path = func(ctx context.Context) (prev *sql.Selector, err error) {
|
||||
if err := pq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return pq.sqlQuery(), nil
|
||||
}
|
||||
return selector
|
||||
}
|
||||
|
||||
func (pq *PetQuery) prepareQuery(ctx context.Context) error {
|
||||
if pq.path != nil {
|
||||
prev, err := pq.path(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
pq.sql = prev
|
||||
}
|
||||
// Privacy and query checks go here.
|
||||
return nil
|
||||
}
|
||||
|
||||
func (pq *PetQuery) sqlAll(ctx context.Context) ([]*Pet, error) {
|
||||
var (
|
||||
nodes = []*Pet{}
|
||||
@@ -347,8 +380,9 @@ type PetGroupBy struct {
|
||||
config
|
||||
fields []string
|
||||
fns []Aggregate
|
||||
// intermediate query.
|
||||
sql *sql.Selector
|
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector
|
||||
path func(context.Context) (*sql.Selector, error)
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the group-by query.
|
||||
@@ -359,6 +393,11 @@ func (pgb *PetGroupBy) Aggregate(fns ...Aggregate) *PetGroupBy {
|
||||
|
||||
// Scan applies the group-by query and scan the result into the given value.
|
||||
func (pgb *PetGroupBy) Scan(ctx context.Context, v interface{}) error {
|
||||
query, err := pgb.path(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
pgb.sql = query
|
||||
return pgb.sqlScan(ctx, v)
|
||||
}
|
||||
|
||||
@@ -477,12 +516,18 @@ func (pgb *PetGroupBy) sqlQuery() *sql.Selector {
|
||||
type PetSelect struct {
|
||||
config
|
||||
fields []string
|
||||
// intermediate queries.
|
||||
sql *sql.Selector
|
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector
|
||||
path func(context.Context) (*sql.Selector, error)
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scan the result into the given value.
|
||||
func (ps *PetSelect) Scan(ctx context.Context, v interface{}) error {
|
||||
query, err := ps.path(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
ps.sql = query
|
||||
return ps.sqlScan(ctx, v)
|
||||
}
|
||||
|
||||
|
||||
@@ -34,8 +34,9 @@ type UserQuery struct {
|
||||
withCar *CarQuery
|
||||
withPets *PetQuery
|
||||
withFKs bool
|
||||
// intermediate query.
|
||||
sql *sql.Selector
|
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector
|
||||
path func(context.Context) (*sql.Selector, error)
|
||||
}
|
||||
|
||||
// Where adds a new predicate for the builder.
|
||||
@@ -65,24 +66,36 @@ func (uq *UserQuery) Order(o ...Order) *UserQuery {
|
||||
// QueryCar chains the current query on the car edge.
|
||||
func (uq *UserQuery) QueryCar() *CarQuery {
|
||||
query := &CarQuery{config: uq.config}
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(user.Table, user.FieldID, uq.sqlQuery()),
|
||||
sqlgraph.To(car.Table, car.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2M, false, user.CarTable, user.CarColumn),
|
||||
)
|
||||
query.sql = sqlgraph.SetNeighbors(uq.driver.Dialect(), step)
|
||||
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
|
||||
if err := uq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(user.Table, user.FieldID, uq.sqlQuery()),
|
||||
sqlgraph.To(car.Table, car.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2M, false, user.CarTable, user.CarColumn),
|
||||
)
|
||||
fromU = sqlgraph.SetNeighbors(uq.driver.Dialect(), step)
|
||||
return fromU, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// QueryPets chains the current query on the pets edge.
|
||||
func (uq *UserQuery) QueryPets() *PetQuery {
|
||||
query := &PetQuery{config: uq.config}
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(user.Table, user.FieldID, uq.sqlQuery()),
|
||||
sqlgraph.To(pet.Table, pet.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, false, user.PetsTable, user.PetsColumn),
|
||||
)
|
||||
query.sql = sqlgraph.SetNeighbors(uq.driver.Dialect(), step)
|
||||
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
|
||||
if err := uq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(user.Table, user.FieldID, uq.sqlQuery()),
|
||||
sqlgraph.To(pet.Table, pet.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, false, user.PetsTable, user.PetsColumn),
|
||||
)
|
||||
fromU = sqlgraph.SetNeighbors(uq.driver.Dialect(), step)
|
||||
return fromU, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
@@ -182,6 +195,9 @@ func (uq *UserQuery) OnlyXID(ctx context.Context) int {
|
||||
|
||||
// All executes the query and returns a list of Users.
|
||||
func (uq *UserQuery) All(ctx context.Context) ([]*User, error) {
|
||||
if err := uq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return uq.sqlAll(ctx)
|
||||
}
|
||||
|
||||
@@ -214,6 +230,9 @@ func (uq *UserQuery) IDsX(ctx context.Context) []int {
|
||||
|
||||
// Count returns the count of the given query.
|
||||
func (uq *UserQuery) Count(ctx context.Context) (int, error) {
|
||||
if err := uq.prepareQuery(ctx); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return uq.sqlCount(ctx)
|
||||
}
|
||||
|
||||
@@ -228,6 +247,9 @@ func (uq *UserQuery) CountX(ctx context.Context) int {
|
||||
|
||||
// Exist returns true if the query has elements in the graph.
|
||||
func (uq *UserQuery) Exist(ctx context.Context) (bool, error) {
|
||||
if err := uq.prepareQuery(ctx); err != nil {
|
||||
return false, err
|
||||
}
|
||||
return uq.sqlExist(ctx)
|
||||
}
|
||||
|
||||
@@ -251,7 +273,8 @@ func (uq *UserQuery) Clone() *UserQuery {
|
||||
unique: append([]string{}, uq.unique...),
|
||||
predicates: append([]predicate.User{}, uq.predicates...),
|
||||
// clone intermediate query.
|
||||
sql: uq.sql.Clone(),
|
||||
sql: uq.sql.Clone(),
|
||||
path: uq.path,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -295,7 +318,12 @@ func (uq *UserQuery) WithPets(opts ...func(*PetQuery)) *UserQuery {
|
||||
func (uq *UserQuery) GroupBy(field string, fields ...string) *UserGroupBy {
|
||||
group := &UserGroupBy{config: uq.config}
|
||||
group.fields = append([]string{field}, fields...)
|
||||
group.sql = uq.sqlQuery()
|
||||
group.path = func(ctx context.Context) (prev *sql.Selector, err error) {
|
||||
if err := uq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return uq.sqlQuery(), nil
|
||||
}
|
||||
return group
|
||||
}
|
||||
|
||||
@@ -314,10 +342,27 @@ func (uq *UserQuery) GroupBy(field string, fields ...string) *UserGroupBy {
|
||||
func (uq *UserQuery) Select(field string, fields ...string) *UserSelect {
|
||||
selector := &UserSelect{config: uq.config}
|
||||
selector.fields = append([]string{field}, fields...)
|
||||
selector.sql = uq.sqlQuery()
|
||||
selector.path = func(ctx context.Context) (prev *sql.Selector, err error) {
|
||||
if err := uq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return uq.sqlQuery(), nil
|
||||
}
|
||||
return selector
|
||||
}
|
||||
|
||||
func (uq *UserQuery) prepareQuery(ctx context.Context) error {
|
||||
if uq.path != nil {
|
||||
prev, err := uq.path(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
uq.sql = prev
|
||||
}
|
||||
// Privacy and query checks go here.
|
||||
return nil
|
||||
}
|
||||
|
||||
func (uq *UserQuery) sqlAll(ctx context.Context) ([]*User, error) {
|
||||
var (
|
||||
nodes = []*User{}
|
||||
@@ -493,8 +538,9 @@ type UserGroupBy struct {
|
||||
config
|
||||
fields []string
|
||||
fns []Aggregate
|
||||
// intermediate query.
|
||||
sql *sql.Selector
|
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector
|
||||
path func(context.Context) (*sql.Selector, error)
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the group-by query.
|
||||
@@ -505,6 +551,11 @@ func (ugb *UserGroupBy) Aggregate(fns ...Aggregate) *UserGroupBy {
|
||||
|
||||
// Scan applies the group-by query and scan the result into the given value.
|
||||
func (ugb *UserGroupBy) Scan(ctx context.Context, v interface{}) error {
|
||||
query, err := ugb.path(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
ugb.sql = query
|
||||
return ugb.sqlScan(ctx, v)
|
||||
}
|
||||
|
||||
@@ -623,12 +674,18 @@ func (ugb *UserGroupBy) sqlQuery() *sql.Selector {
|
||||
type UserSelect struct {
|
||||
config
|
||||
fields []string
|
||||
// intermediate queries.
|
||||
sql *sql.Selector
|
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector
|
||||
path func(context.Context) (*sql.Selector, error)
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scan the result into the given value.
|
||||
func (us *UserSelect) Scan(ctx context.Context, v interface{}) error {
|
||||
query, err := us.path(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
us.sql = query
|
||||
return us.sqlScan(ctx, v)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user