chores/general-cleanup-release-prep (#31)

* do ent generation

* update edges

* fix redirect
This commit is contained in:
Hayden 2022-09-28 21:42:33 -08:00 committed by GitHub
parent 8a43fc953d
commit 1ca430af21
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
47 changed files with 785 additions and 765 deletions

View file

@ -31,9 +31,9 @@ type ItemQuery struct {
fields []string
predicates []predicate.Item
withGroup *GroupQuery
withLabel *LabelQuery
withLocation *LocationQuery
withFields *ItemFieldQuery
withLabel *LabelQuery
withAttachments *AttachmentQuery
withFKs bool
// intermediate query (i.e. traversal path).
@ -94,6 +94,28 @@ func (iq *ItemQuery) QueryGroup() *GroupQuery {
return query
}
// QueryLabel chains the current query on the "label" edge.
func (iq *ItemQuery) QueryLabel() *LabelQuery {
query := &LabelQuery{config: iq.config}
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
if err := iq.prepareQuery(ctx); err != nil {
return nil, err
}
selector := iq.sqlQuery(ctx)
if err := selector.Err(); err != nil {
return nil, err
}
step := sqlgraph.NewStep(
sqlgraph.From(item.Table, item.FieldID, selector),
sqlgraph.To(label.Table, label.FieldID),
sqlgraph.Edge(sqlgraph.M2M, true, item.LabelTable, item.LabelPrimaryKey...),
)
fromU = sqlgraph.SetNeighbors(iq.driver.Dialect(), step)
return fromU, nil
}
return query
}
// QueryLocation chains the current query on the "location" edge.
func (iq *ItemQuery) QueryLocation() *LocationQuery {
query := &LocationQuery{config: iq.config}
@ -138,28 +160,6 @@ func (iq *ItemQuery) QueryFields() *ItemFieldQuery {
return query
}
// QueryLabel chains the current query on the "label" edge.
func (iq *ItemQuery) QueryLabel() *LabelQuery {
query := &LabelQuery{config: iq.config}
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
if err := iq.prepareQuery(ctx); err != nil {
return nil, err
}
selector := iq.sqlQuery(ctx)
if err := selector.Err(); err != nil {
return nil, err
}
step := sqlgraph.NewStep(
sqlgraph.From(item.Table, item.FieldID, selector),
sqlgraph.To(label.Table, label.FieldID),
sqlgraph.Edge(sqlgraph.M2M, true, item.LabelTable, item.LabelPrimaryKey...),
)
fromU = sqlgraph.SetNeighbors(iq.driver.Dialect(), step)
return fromU, nil
}
return query
}
// QueryAttachments chains the current query on the "attachments" edge.
func (iq *ItemQuery) QueryAttachments() *AttachmentQuery {
query := &AttachmentQuery{config: iq.config}
@ -364,9 +364,9 @@ func (iq *ItemQuery) Clone() *ItemQuery {
order: append([]OrderFunc{}, iq.order...),
predicates: append([]predicate.Item{}, iq.predicates...),
withGroup: iq.withGroup.Clone(),
withLabel: iq.withLabel.Clone(),
withLocation: iq.withLocation.Clone(),
withFields: iq.withFields.Clone(),
withLabel: iq.withLabel.Clone(),
withAttachments: iq.withAttachments.Clone(),
// clone intermediate query.
sql: iq.sql.Clone(),
@ -386,6 +386,17 @@ func (iq *ItemQuery) WithGroup(opts ...func(*GroupQuery)) *ItemQuery {
return iq
}
// WithLabel tells the query-builder to eager-load the nodes that are connected to
// the "label" edge. The optional arguments are used to configure the query builder of the edge.
func (iq *ItemQuery) WithLabel(opts ...func(*LabelQuery)) *ItemQuery {
query := &LabelQuery{config: iq.config}
for _, opt := range opts {
opt(query)
}
iq.withLabel = query
return iq
}
// WithLocation tells the query-builder to eager-load the nodes that are connected to
// the "location" edge. The optional arguments are used to configure the query builder of the edge.
func (iq *ItemQuery) WithLocation(opts ...func(*LocationQuery)) *ItemQuery {
@ -408,17 +419,6 @@ func (iq *ItemQuery) WithFields(opts ...func(*ItemFieldQuery)) *ItemQuery {
return iq
}
// WithLabel tells the query-builder to eager-load the nodes that are connected to
// the "label" edge. The optional arguments are used to configure the query builder of the edge.
func (iq *ItemQuery) WithLabel(opts ...func(*LabelQuery)) *ItemQuery {
query := &LabelQuery{config: iq.config}
for _, opt := range opts {
opt(query)
}
iq.withLabel = query
return iq
}
// WithAttachments tells the query-builder to eager-load the nodes that are connected to
// the "attachments" edge. The optional arguments are used to configure the query builder of the edge.
func (iq *ItemQuery) WithAttachments(opts ...func(*AttachmentQuery)) *ItemQuery {
@ -501,9 +501,9 @@ func (iq *ItemQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Item, e
_spec = iq.querySpec()
loadedTypes = [5]bool{
iq.withGroup != nil,
iq.withLabel != nil,
iq.withLocation != nil,
iq.withFields != nil,
iq.withLabel != nil,
iq.withAttachments != nil,
}
)
@ -513,10 +513,10 @@ func (iq *ItemQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Item, e
if withFKs {
_spec.Node.Columns = append(_spec.Node.Columns, item.ForeignKeys...)
}
_spec.ScanValues = func(columns []string) ([]interface{}, error) {
_spec.ScanValues = func(columns []string) ([]any, error) {
return (*Item).scanValues(nil, columns)
}
_spec.Assign = func(columns []string, values []interface{}) error {
_spec.Assign = func(columns []string, values []any) error {
node := &Item{config: iq.config}
nodes = append(nodes, node)
node.Edges.loadedTypes = loadedTypes
@ -537,6 +537,13 @@ func (iq *ItemQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Item, e
return nil, err
}
}
if query := iq.withLabel; query != nil {
if err := iq.loadLabel(ctx, query, nodes,
func(n *Item) { n.Edges.Label = []*Label{} },
func(n *Item, e *Label) { n.Edges.Label = append(n.Edges.Label, e) }); err != nil {
return nil, err
}
}
if query := iq.withLocation; query != nil {
if err := iq.loadLocation(ctx, query, nodes, nil,
func(n *Item, e *Location) { n.Edges.Location = e }); err != nil {
@ -550,13 +557,6 @@ func (iq *ItemQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Item, e
return nil, err
}
}
if query := iq.withLabel; query != nil {
if err := iq.loadLabel(ctx, query, nodes,
func(n *Item) { n.Edges.Label = []*Label{} },
func(n *Item, e *Label) { n.Edges.Label = append(n.Edges.Label, e) }); err != nil {
return nil, err
}
}
if query := iq.withAttachments; query != nil {
if err := iq.loadAttachments(ctx, query, nodes,
func(n *Item) { n.Edges.Attachments = []*Attachment{} },
@ -596,6 +596,64 @@ func (iq *ItemQuery) loadGroup(ctx context.Context, query *GroupQuery, nodes []*
}
return nil
}
func (iq *ItemQuery) loadLabel(ctx context.Context, query *LabelQuery, nodes []*Item, init func(*Item), assign func(*Item, *Label)) error {
edgeIDs := make([]driver.Value, len(nodes))
byID := make(map[uuid.UUID]*Item)
nids := make(map[uuid.UUID]map[*Item]struct{})
for i, node := range nodes {
edgeIDs[i] = node.ID
byID[node.ID] = node
if init != nil {
init(node)
}
}
query.Where(func(s *sql.Selector) {
joinT := sql.Table(item.LabelTable)
s.Join(joinT).On(s.C(label.FieldID), joinT.C(item.LabelPrimaryKey[0]))
s.Where(sql.InValues(joinT.C(item.LabelPrimaryKey[1]), edgeIDs...))
columns := s.SelectedColumns()
s.Select(joinT.C(item.LabelPrimaryKey[1]))
s.AppendSelect(columns...)
s.SetDistinct(false)
})
if err := query.prepareQuery(ctx); err != nil {
return err
}
neighbors, err := query.sqlAll(ctx, func(_ context.Context, spec *sqlgraph.QuerySpec) {
assign := spec.Assign
values := spec.ScanValues
spec.ScanValues = func(columns []string) ([]any, error) {
values, err := values(columns[1:])
if err != nil {
return nil, err
}
return append([]any{new(uuid.UUID)}, values...), nil
}
spec.Assign = func(columns []string, values []any) error {
outValue := *values[0].(*uuid.UUID)
inValue := *values[1].(*uuid.UUID)
if nids[inValue] == nil {
nids[inValue] = map[*Item]struct{}{byID[outValue]: struct{}{}}
return assign(columns[1:], values[1:])
}
nids[inValue][byID[outValue]] = struct{}{}
return nil
}
})
if err != nil {
return err
}
for _, n := range neighbors {
nodes, ok := nids[n.ID]
if !ok {
return fmt.Errorf(`unexpected "label" node returned %v`, n.ID)
}
for kn := range nodes {
assign(kn, n)
}
}
return nil
}
func (iq *ItemQuery) loadLocation(ctx context.Context, query *LocationQuery, nodes []*Item, init func(*Item), assign func(*Item, *Location)) error {
ids := make([]uuid.UUID, 0, len(nodes))
nodeids := make(map[uuid.UUID][]*Item)
@ -656,64 +714,6 @@ func (iq *ItemQuery) loadFields(ctx context.Context, query *ItemFieldQuery, node
}
return nil
}
func (iq *ItemQuery) loadLabel(ctx context.Context, query *LabelQuery, nodes []*Item, init func(*Item), assign func(*Item, *Label)) error {
edgeIDs := make([]driver.Value, len(nodes))
byID := make(map[uuid.UUID]*Item)
nids := make(map[uuid.UUID]map[*Item]struct{})
for i, node := range nodes {
edgeIDs[i] = node.ID
byID[node.ID] = node
if init != nil {
init(node)
}
}
query.Where(func(s *sql.Selector) {
joinT := sql.Table(item.LabelTable)
s.Join(joinT).On(s.C(label.FieldID), joinT.C(item.LabelPrimaryKey[0]))
s.Where(sql.InValues(joinT.C(item.LabelPrimaryKey[1]), edgeIDs...))
columns := s.SelectedColumns()
s.Select(joinT.C(item.LabelPrimaryKey[1]))
s.AppendSelect(columns...)
s.SetDistinct(false)
})
if err := query.prepareQuery(ctx); err != nil {
return err
}
neighbors, err := query.sqlAll(ctx, func(_ context.Context, spec *sqlgraph.QuerySpec) {
assign := spec.Assign
values := spec.ScanValues
spec.ScanValues = func(columns []string) ([]interface{}, error) {
values, err := values(columns[1:])
if err != nil {
return nil, err
}
return append([]interface{}{new(uuid.UUID)}, values...), nil
}
spec.Assign = func(columns []string, values []interface{}) error {
outValue := *values[0].(*uuid.UUID)
inValue := *values[1].(*uuid.UUID)
if nids[inValue] == nil {
nids[inValue] = map[*Item]struct{}{byID[outValue]: struct{}{}}
return assign(columns[1:], values[1:])
}
nids[inValue][byID[outValue]] = struct{}{}
return nil
}
})
if err != nil {
return err
}
for _, n := range neighbors {
nodes, ok := nids[n.ID]
if !ok {
return fmt.Errorf(`unexpected "label" node returned %v`, n.ID)
}
for kn := range nodes {
assign(kn, n)
}
}
return nil
}
func (iq *ItemQuery) loadAttachments(ctx context.Context, query *AttachmentQuery, nodes []*Item, init func(*Item), assign func(*Item, *Attachment)) error {
fks := make([]driver.Value, 0, len(nodes))
nodeids := make(map[uuid.UUID]*Item)
@ -756,11 +756,14 @@ func (iq *ItemQuery) sqlCount(ctx context.Context) (int, error) {
}
func (iq *ItemQuery) sqlExist(ctx context.Context) (bool, error) {
n, err := iq.sqlCount(ctx)
if err != nil {
switch _, err := iq.FirstID(ctx); {
case IsNotFound(err):
return false, nil
case err != nil:
return false, fmt.Errorf("ent: check existence: %w", err)
default:
return true, nil
}
return n > 0, nil
}
func (iq *ItemQuery) querySpec() *sqlgraph.QuerySpec {
@ -861,7 +864,7 @@ func (igb *ItemGroupBy) Aggregate(fns ...AggregateFunc) *ItemGroupBy {
}
// Scan applies the group-by query and scans the result into the given value.
func (igb *ItemGroupBy) Scan(ctx context.Context, v interface{}) error {
func (igb *ItemGroupBy) Scan(ctx context.Context, v any) error {
query, err := igb.path(ctx)
if err != nil {
return err
@ -870,7 +873,7 @@ func (igb *ItemGroupBy) Scan(ctx context.Context, v interface{}) error {
return igb.sqlScan(ctx, v)
}
func (igb *ItemGroupBy) sqlScan(ctx context.Context, v interface{}) error {
func (igb *ItemGroupBy) sqlScan(ctx context.Context, v any) error {
for _, f := range igb.fields {
if !item.ValidColumn(f) {
return &ValidationError{Name: f, err: fmt.Errorf("invalid field %q for group-by", f)}
@ -917,7 +920,7 @@ type ItemSelect struct {
}
// Scan applies the selector query and scans the result into the given value.
func (is *ItemSelect) Scan(ctx context.Context, v interface{}) error {
func (is *ItemSelect) Scan(ctx context.Context, v any) error {
if err := is.prepareQuery(ctx); err != nil {
return err
}
@ -925,7 +928,7 @@ func (is *ItemSelect) Scan(ctx context.Context, v interface{}) error {
return is.sqlScan(ctx, v)
}
func (is *ItemSelect) sqlScan(ctx context.Context, v interface{}) error {
func (is *ItemSelect) sqlScan(ctx context.Context, v any) error {
rows := &sql.Rows{}
query, args := is.sql.Query()
if err := is.driver.Query(ctx, query, args, rows); err != nil {