Added password token entity.
This commit is contained in:
parent
1ac68b7d9f
commit
c9d50cb3d4
25 changed files with 3489 additions and 20 deletions
|
|
@ -4,8 +4,10 @@ package ent
|
|||
|
||||
import (
|
||||
"context"
|
||||
"database/sql/driver"
|
||||
"errors"
|
||||
"fmt"
|
||||
"goweb/ent/passwordtoken"
|
||||
"goweb/ent/predicate"
|
||||
"goweb/ent/user"
|
||||
"math"
|
||||
|
|
@ -24,6 +26,8 @@ type UserQuery struct {
|
|||
order []OrderFunc
|
||||
fields []string
|
||||
predicates []predicate.User
|
||||
// eager-loading edges.
|
||||
withOwner *PasswordTokenQuery
|
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector
|
||||
path func(context.Context) (*sql.Selector, error)
|
||||
|
|
@ -60,6 +64,28 @@ func (uq *UserQuery) Order(o ...OrderFunc) *UserQuery {
|
|||
return uq
|
||||
}
|
||||
|
||||
// QueryOwner chains the current query on the "owner" edge.
|
||||
func (uq *UserQuery) QueryOwner() *PasswordTokenQuery {
|
||||
query := &PasswordTokenQuery{config: uq.config}
|
||||
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
|
||||
if err := uq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
selector := uq.sqlQuery(ctx)
|
||||
if err := selector.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(user.Table, user.FieldID, selector),
|
||||
sqlgraph.To(passwordtoken.Table, passwordtoken.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2M, true, user.OwnerTable, user.OwnerColumn),
|
||||
)
|
||||
fromU = sqlgraph.SetNeighbors(uq.driver.Dialect(), step)
|
||||
return fromU, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// First returns the first User entity from the query.
|
||||
// Returns a *NotFoundError when no User was found.
|
||||
func (uq *UserQuery) First(ctx context.Context) (*User, error) {
|
||||
|
|
@ -241,12 +267,24 @@ func (uq *UserQuery) Clone() *UserQuery {
|
|||
offset: uq.offset,
|
||||
order: append([]OrderFunc{}, uq.order...),
|
||||
predicates: append([]predicate.User{}, uq.predicates...),
|
||||
withOwner: uq.withOwner.Clone(),
|
||||
// clone intermediate query.
|
||||
sql: uq.sql.Clone(),
|
||||
path: uq.path,
|
||||
}
|
||||
}
|
||||
|
||||
// WithOwner tells the query-builder to eager-load the nodes that are connected to
|
||||
// the "owner" edge. The optional arguments are used to configure the query builder of the edge.
|
||||
func (uq *UserQuery) WithOwner(opts ...func(*PasswordTokenQuery)) *UserQuery {
|
||||
query := &PasswordTokenQuery{config: uq.config}
|
||||
for _, opt := range opts {
|
||||
opt(query)
|
||||
}
|
||||
uq.withOwner = query
|
||||
return uq
|
||||
}
|
||||
|
||||
// GroupBy is used to group vertices by one or more fields/columns.
|
||||
// It is often used with aggregate functions, like: count, max, mean, min, sum.
|
||||
//
|
||||
|
|
@ -310,8 +348,11 @@ func (uq *UserQuery) prepareQuery(ctx context.Context) error {
|
|||
|
||||
func (uq *UserQuery) sqlAll(ctx context.Context) ([]*User, error) {
|
||||
var (
|
||||
nodes = []*User{}
|
||||
_spec = uq.querySpec()
|
||||
nodes = []*User{}
|
||||
_spec = uq.querySpec()
|
||||
loadedTypes = [1]bool{
|
||||
uq.withOwner != nil,
|
||||
}
|
||||
)
|
||||
_spec.ScanValues = func(columns []string) ([]interface{}, error) {
|
||||
node := &User{config: uq.config}
|
||||
|
|
@ -323,6 +364,7 @@ func (uq *UserQuery) sqlAll(ctx context.Context) ([]*User, error) {
|
|||
return fmt.Errorf("ent: Assign called without calling ScanValues")
|
||||
}
|
||||
node := nodes[len(nodes)-1]
|
||||
node.Edges.loadedTypes = loadedTypes
|
||||
return node.assignValues(columns, values)
|
||||
}
|
||||
if err := sqlgraph.QueryNodes(ctx, uq.driver, _spec); err != nil {
|
||||
|
|
@ -331,6 +373,36 @@ func (uq *UserQuery) sqlAll(ctx context.Context) ([]*User, error) {
|
|||
if len(nodes) == 0 {
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
if query := uq.withOwner; query != nil {
|
||||
fks := make([]driver.Value, 0, len(nodes))
|
||||
nodeids := make(map[int]*User)
|
||||
for i := range nodes {
|
||||
fks = append(fks, nodes[i].ID)
|
||||
nodeids[nodes[i].ID] = nodes[i]
|
||||
nodes[i].Edges.Owner = []*PasswordToken{}
|
||||
}
|
||||
query.withFKs = true
|
||||
query.Where(predicate.PasswordToken(func(s *sql.Selector) {
|
||||
s.Where(sql.InValues(user.OwnerColumn, fks...))
|
||||
}))
|
||||
neighbors, err := query.All(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, n := range neighbors {
|
||||
fk := n.password_token_user
|
||||
if fk == nil {
|
||||
return nil, fmt.Errorf(`foreign-key "password_token_user" is nil for node %v`, n.ID)
|
||||
}
|
||||
node, ok := nodeids[*fk]
|
||||
if !ok {
|
||||
return nil, fmt.Errorf(`unexpected foreign-key "password_token_user" returned %v for node %v`, *fk, n.ID)
|
||||
}
|
||||
node.Edges.Owner = append(node.Edges.Owner, n)
|
||||
}
|
||||
}
|
||||
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue