1
0

add seven

This commit is contained in:
2024-04-11 06:11:26 +09:00
parent 1d5cb2ad9f
commit 336827433e
42 changed files with 16234 additions and 20 deletions

View File

@@ -6,6 +6,7 @@ import (
"api/ent/card"
"api/ent/ma"
"api/ent/predicate"
"api/ent/sev"
"api/ent/ue"
"api/ent/user"
"context"
@@ -28,6 +29,7 @@ type UserQuery struct {
withCard *CardQuery
withUe *UeQuery
withMa *MaQuery
withSev *SevQuery
withFKs bool
// intermediate query (i.e. traversal path).
sql *sql.Selector
@@ -131,6 +133,28 @@ func (uq *UserQuery) QueryMa() *MaQuery {
return query
}
// QuerySev chains the current query on the "sev" edge.
func (uq *UserQuery) QuerySev() *SevQuery {
query := (&SevClient{config: uq.config}).Query()
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(sev.Table, sev.FieldID),
sqlgraph.Edge(sqlgraph.O2M, false, user.SevTable, user.SevColumn),
)
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) {
@@ -326,6 +350,7 @@ func (uq *UserQuery) Clone() *UserQuery {
withCard: uq.withCard.Clone(),
withUe: uq.withUe.Clone(),
withMa: uq.withMa.Clone(),
withSev: uq.withSev.Clone(),
// clone intermediate query.
sql: uq.sql.Clone(),
path: uq.path,
@@ -365,6 +390,17 @@ func (uq *UserQuery) WithMa(opts ...func(*MaQuery)) *UserQuery {
return uq
}
// WithSev tells the query-builder to eager-load the nodes that are connected to
// the "sev" edge. The optional arguments are used to configure the query builder of the edge.
func (uq *UserQuery) WithSev(opts ...func(*SevQuery)) *UserQuery {
query := (&SevClient{config: uq.config}).Query()
for _, opt := range opts {
opt(query)
}
uq.withSev = 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.
//
@@ -444,10 +480,11 @@ func (uq *UserQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*User, e
nodes = []*User{}
withFKs = uq.withFKs
_spec = uq.querySpec()
loadedTypes = [3]bool{
loadedTypes = [4]bool{
uq.withCard != nil,
uq.withUe != nil,
uq.withMa != nil,
uq.withSev != nil,
}
)
if withFKs {
@@ -492,6 +529,13 @@ func (uq *UserQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*User, e
return nil, err
}
}
if query := uq.withSev; query != nil {
if err := uq.loadSev(ctx, query, nodes,
func(n *User) { n.Edges.Sev = []*Sev{} },
func(n *User, e *Sev) { n.Edges.Sev = append(n.Edges.Sev, e) }); err != nil {
return nil, err
}
}
return nodes, nil
}
@@ -588,6 +632,37 @@ func (uq *UserQuery) loadMa(ctx context.Context, query *MaQuery, nodes []*User,
}
return nil
}
func (uq *UserQuery) loadSev(ctx context.Context, query *SevQuery, nodes []*User, init func(*User), assign func(*User, *Sev)) error {
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]
if init != nil {
init(nodes[i])
}
}
query.withFKs = true
query.Where(predicate.Sev(func(s *sql.Selector) {
s.Where(sql.InValues(s.C(user.SevColumn), fks...))
}))
neighbors, err := query.All(ctx)
if err != nil {
return err
}
for _, n := range neighbors {
fk := n.user_sev
if fk == nil {
return fmt.Errorf(`foreign-key "user_sev" is nil for node %v`, n.ID)
}
node, ok := nodeids[*fk]
if !ok {
return fmt.Errorf(`unexpected referenced foreign-key "user_sev" returned %v for node %v`, *fk, n.ID)
}
assign(node, n)
}
return nil
}
func (uq *UserQuery) sqlCount(ctx context.Context) (int, error) {
_spec := uq.querySpec()