From 31f4840f64dbef18bb92937fcee258c891c9f59c Mon Sep 17 00:00:00 2001 From: cole kennedy Date: Tue, 11 Oct 2022 14:34:52 -0500 Subject: [PATCH] perf: add additional sql indexes --- ent/attestation.go | 15 +- ent/attestation/attestation.go | 2 +- ent/attestation/where.go | 34 +-- ent/attestation_create.go | 6 +- ent/attestation_delete.go | 8 +- ent/attestation_query.go | 94 ++++---- ent/attestation_update.go | 6 +- ent/attestationcollection.go | 15 +- .../attestationcollection.go | 2 +- ent/attestationcollection/where.go | 34 +-- ent/attestationcollection_create.go | 6 +- ent/attestationcollection_delete.go | 8 +- ent/attestationcollection_query.go | 153 +++++++------ ent/attestationcollection_update.go | 6 +- ent/client.go | 7 +- ent/config.go | 6 +- ent/context.go | 2 +- ent/dsse.go | 15 +- ent/dsse/dsse.go | 2 +- ent/dsse/where.go | 50 +---- ent/dsse_create.go | 6 +- ent/dsse_delete.go | 8 +- ent/dsse_query.go | 212 ++++++++++-------- ent/dsse_update.go | 6 +- ent/ent.go | 6 +- ent/enttest/enttest.go | 22 +- ent/gql_collection.go | 2 +- ent/gql_edge.go | 2 +- ent/gql_node.go | 2 +- ent/gql_pagination.go | 2 +- ent/gql_transaction.go | 2 +- ent/gql_where_input.go | 2 +- ent/hook/hook.go | 2 +- ent/migrate/migrate.go | 22 +- ent/migrate/schema.go | 51 ++++- ent/mutation.go | 10 +- ent/payloaddigest.go | 15 +- ent/payloaddigest/payloaddigest.go | 2 +- ent/payloaddigest/where.go | 50 +---- ent/payloaddigest_create.go | 6 +- ent/payloaddigest_delete.go | 8 +- ent/payloaddigest_query.go | 90 ++++---- ent/payloaddigest_update.go | 6 +- ent/predicate/predicate.go | 2 +- ent/runtime.go | 2 +- ent/runtime/runtime.go | 6 +- ent/schema/attestation.go | 7 + ent/schema/attestationcollection.go | 7 + ent/schema/payloaddigest.go | 7 + ent/schema/signature.go | 7 + ent/schema/statement.go | 7 + ent/schema/subject.go | 8 + ent/schema/subjectdigest.go | 8 + ent/signature.go | 15 +- ent/signature/signature.go | 2 +- ent/signature/where.go | 50 +---- ent/signature_create.go | 6 +- ent/signature_delete.go | 8 +- ent/signature_query.go | 90 ++++---- ent/signature_update.go | 6 +- ent/statement.go | 15 +- ent/statement/statement.go | 2 +- ent/statement/where.go | 34 +-- ent/statement_create.go | 6 +- ent/statement_delete.go | 8 +- ent/statement_query.go | 210 +++++++++-------- ent/statement_update.go | 6 +- ent/subject.go | 15 +- ent/subject/subject.go | 2 +- ent/subject/where.go | 34 +-- ent/subject_create.go | 6 +- ent/subject_delete.go | 8 +- ent/subject_query.go | 153 +++++++------ ent/subject_update.go | 6 +- ent/subjectdigest.go | 15 +- ent/subjectdigest/subjectdigest.go | 2 +- ent/subjectdigest/where.go | 50 +---- ent/subjectdigest_create.go | 6 +- ent/subjectdigest_delete.go | 8 +- ent/subjectdigest_query.go | 94 ++++---- ent/subjectdigest_update.go | 6 +- ent/tx.go | 6 +- go.mod | 8 +- go.sum | 33 +-- 84 files changed, 978 insertions(+), 998 deletions(-) diff --git a/ent/attestation.go b/ent/attestation.go index 9fd9a2be..3988b66f 100644 --- a/ent/attestation.go +++ b/ent/attestation.go @@ -1,4 +1,4 @@ -// Code generated by entc, DO NOT EDIT. +// Code generated by ent, DO NOT EDIT. package ent @@ -40,8 +40,7 @@ type AttestationEdges struct { func (e AttestationEdges) AttestationCollectionOrErr() (*AttestationCollection, error) { if e.loadedTypes[0] { if e.AttestationCollection == nil { - // The edge attestation_collection was loaded in eager-loading, - // but was not found. + // Edge was loaded but was not found. return nil, &NotFoundError{label: attestationcollection.Label} } return e.AttestationCollection, nil @@ -50,8 +49,8 @@ func (e AttestationEdges) AttestationCollectionOrErr() (*AttestationCollection, } // scanValues returns the types for scanning values from sql.Rows. -func (*Attestation) scanValues(columns []string) ([]interface{}, error) { - values := make([]interface{}, len(columns)) +func (*Attestation) scanValues(columns []string) ([]any, error) { + values := make([]any, len(columns)) for i := range columns { switch columns[i] { case attestation.FieldID: @@ -69,7 +68,7 @@ func (*Attestation) scanValues(columns []string) ([]interface{}, error) { // assignValues assigns the values that were returned from sql.Rows (after scanning) // to the Attestation fields. -func (a *Attestation) assignValues(columns []string, values []interface{}) error { +func (a *Attestation) assignValues(columns []string, values []any) error { if m, n := len(values), len(columns); m < n { return fmt.Errorf("mismatch number of scan values: %d != %d", m, n) } @@ -114,11 +113,11 @@ func (a *Attestation) Update() *AttestationUpdateOne { // Unwrap unwraps the Attestation entity that was returned from a transaction after it was closed, // so that all future queries will be executed through the driver which created the transaction. func (a *Attestation) Unwrap() *Attestation { - tx, ok := a.config.driver.(*txDriver) + _tx, ok := a.config.driver.(*txDriver) if !ok { panic("ent: Attestation is not a transactional entity") } - a.config.driver = tx.drv + a.config.driver = _tx.drv return a } diff --git a/ent/attestation/attestation.go b/ent/attestation/attestation.go index c053e3d8..1f77e187 100644 --- a/ent/attestation/attestation.go +++ b/ent/attestation/attestation.go @@ -1,4 +1,4 @@ -// Code generated by entc, DO NOT EDIT. +// Code generated by ent, DO NOT EDIT. package attestation diff --git a/ent/attestation/where.go b/ent/attestation/where.go index d2cc3d33..1f381d67 100644 --- a/ent/attestation/where.go +++ b/ent/attestation/where.go @@ -1,4 +1,4 @@ -// Code generated by entc, DO NOT EDIT. +// Code generated by ent, DO NOT EDIT. package attestation @@ -32,13 +32,7 @@ func IDNEQ(id int) predicate.Attestation { // IDIn applies the In predicate on the ID field. func IDIn(ids ...int) predicate.Attestation { return predicate.Attestation(func(s *sql.Selector) { - // if not arguments were provided, append the FALSE constants, - // since we can't apply "IN ()". This will make this predicate falsy. - if len(ids) == 0 { - s.Where(sql.False()) - return - } - v := make([]interface{}, len(ids)) + v := make([]any, len(ids)) for i := range v { v[i] = ids[i] } @@ -49,13 +43,7 @@ func IDIn(ids ...int) predicate.Attestation { // IDNotIn applies the NotIn predicate on the ID field. func IDNotIn(ids ...int) predicate.Attestation { return predicate.Attestation(func(s *sql.Selector) { - // if not arguments were provided, append the FALSE constants, - // since we can't apply "IN ()". This will make this predicate falsy. - if len(ids) == 0 { - s.Where(sql.False()) - return - } - v := make([]interface{}, len(ids)) + v := make([]any, len(ids)) for i := range v { v[i] = ids[i] } @@ -114,34 +102,22 @@ func TypeNEQ(v string) predicate.Attestation { // TypeIn applies the In predicate on the "type" field. func TypeIn(vs ...string) predicate.Attestation { - v := make([]interface{}, len(vs)) + v := make([]any, len(vs)) for i := range v { v[i] = vs[i] } return predicate.Attestation(func(s *sql.Selector) { - // if not arguments were provided, append the FALSE constants, - // since we can't apply "IN ()". This will make this predicate falsy. - if len(v) == 0 { - s.Where(sql.False()) - return - } s.Where(sql.In(s.C(FieldType), v...)) }) } // TypeNotIn applies the NotIn predicate on the "type" field. func TypeNotIn(vs ...string) predicate.Attestation { - v := make([]interface{}, len(vs)) + v := make([]any, len(vs)) for i := range v { v[i] = vs[i] } return predicate.Attestation(func(s *sql.Selector) { - // if not arguments were provided, append the FALSE constants, - // since we can't apply "IN ()". This will make this predicate falsy. - if len(v) == 0 { - s.Where(sql.False()) - return - } s.Where(sql.NotIn(s.C(FieldType), v...)) }) } diff --git a/ent/attestation_create.go b/ent/attestation_create.go index b1c3bd4a..a3b85c7a 100644 --- a/ent/attestation_create.go +++ b/ent/attestation_create.go @@ -1,4 +1,4 @@ -// Code generated by entc, DO NOT EDIT. +// Code generated by ent, DO NOT EDIT. package ent @@ -131,7 +131,7 @@ func (ac *AttestationCreate) sqlSave(ctx context.Context) (*Attestation, error) _node, _spec := ac.createSpec() if err := sqlgraph.CreateNode(ctx, ac.driver, _spec); err != nil { if sqlgraph.IsConstraintError(err) { - err = &ConstraintError{err.Error(), err} + err = &ConstraintError{msg: err.Error(), wrap: err} } return nil, err } @@ -214,7 +214,7 @@ func (acb *AttestationCreateBulk) Save(ctx context.Context) ([]*Attestation, err // Invoke the actual operation on the latest mutation in the chain. if err = sqlgraph.BatchCreate(ctx, acb.driver, spec); err != nil { if sqlgraph.IsConstraintError(err) { - err = &ConstraintError{err.Error(), err} + err = &ConstraintError{msg: err.Error(), wrap: err} } } } diff --git a/ent/attestation_delete.go b/ent/attestation_delete.go index 45c1641d..9076cd64 100644 --- a/ent/attestation_delete.go +++ b/ent/attestation_delete.go @@ -1,4 +1,4 @@ -// Code generated by entc, DO NOT EDIT. +// Code generated by ent, DO NOT EDIT. package ent @@ -84,7 +84,11 @@ func (ad *AttestationDelete) sqlExec(ctx context.Context) (int, error) { } } } - return sqlgraph.DeleteNodes(ctx, ad.driver, _spec) + affected, err := sqlgraph.DeleteNodes(ctx, ad.driver, _spec) + if err != nil && sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return affected, err } // AttestationDeleteOne is the builder for deleting a single Attestation entity. diff --git a/ent/attestation_query.go b/ent/attestation_query.go index dcf9c269..7c21d47e 100644 --- a/ent/attestation_query.go +++ b/ent/attestation_query.go @@ -1,4 +1,4 @@ -// Code generated by entc, DO NOT EDIT. +// Code generated by ent, DO NOT EDIT. package ent @@ -18,13 +18,12 @@ import ( // AttestationQuery is the builder for querying Attestation entities. type AttestationQuery struct { config - limit *int - offset *int - unique *bool - order []OrderFunc - fields []string - predicates []predicate.Attestation - // eager-loading edges. + limit *int + offset *int + unique *bool + order []OrderFunc + fields []string + predicates []predicate.Attestation withAttestationCollection *AttestationCollectionQuery withFKs bool modifiers []func(*sql.Selector) @@ -366,10 +365,10 @@ func (aq *AttestationQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]* if withFKs { _spec.Node.Columns = append(_spec.Node.Columns, attestation.ForeignKeys...) } - _spec.ScanValues = func(columns []string) ([]interface{}, error) { + _spec.ScanValues = func(columns []string) ([]any, error) { return (*Attestation).scanValues(nil, columns) } - _spec.Assign = func(columns []string, values []interface{}) error { + _spec.Assign = func(columns []string, values []any) error { node := &Attestation{config: aq.config} nodes = append(nodes, node) node.Edges.loadedTypes = loadedTypes @@ -387,36 +386,12 @@ func (aq *AttestationQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]* if len(nodes) == 0 { return nodes, nil } - if query := aq.withAttestationCollection; query != nil { - ids := make([]int, 0, len(nodes)) - nodeids := make(map[int][]*Attestation) - for i := range nodes { - if nodes[i].attestation_collection_attestations == nil { - continue - } - fk := *nodes[i].attestation_collection_attestations - if _, ok := nodeids[fk]; !ok { - ids = append(ids, fk) - } - nodeids[fk] = append(nodeids[fk], nodes[i]) - } - query.Where(attestationcollection.IDIn(ids...)) - neighbors, err := query.All(ctx) - if err != nil { + if err := aq.loadAttestationCollection(ctx, query, nodes, nil, + func(n *Attestation, e *AttestationCollection) { n.Edges.AttestationCollection = e }); err != nil { return nil, err } - for _, n := range neighbors { - nodes, ok := nodeids[n.ID] - if !ok { - return nil, fmt.Errorf(`unexpected foreign-key "attestation_collection_attestations" returned %v`, n.ID) - } - for i := range nodes { - nodes[i].Edges.AttestationCollection = n - } - } } - for i := range aq.loadTotal { if err := aq.loadTotal[i](ctx, nodes); err != nil { return nil, err @@ -425,6 +400,36 @@ func (aq *AttestationQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]* return nodes, nil } +func (aq *AttestationQuery) loadAttestationCollection(ctx context.Context, query *AttestationCollectionQuery, nodes []*Attestation, init func(*Attestation), assign func(*Attestation, *AttestationCollection)) error { + ids := make([]int, 0, len(nodes)) + nodeids := make(map[int][]*Attestation) + for i := range nodes { + if nodes[i].attestation_collection_attestations == nil { + continue + } + fk := *nodes[i].attestation_collection_attestations + if _, ok := nodeids[fk]; !ok { + ids = append(ids, fk) + } + nodeids[fk] = append(nodeids[fk], nodes[i]) + } + query.Where(attestationcollection.IDIn(ids...)) + neighbors, err := query.All(ctx) + if err != nil { + return err + } + for _, n := range neighbors { + nodes, ok := nodeids[n.ID] + if !ok { + return fmt.Errorf(`unexpected foreign-key "attestation_collection_attestations" returned %v`, n.ID) + } + for i := range nodes { + assign(nodes[i], n) + } + } + return nil +} + func (aq *AttestationQuery) sqlCount(ctx context.Context) (int, error) { _spec := aq.querySpec() if len(aq.modifiers) > 0 { @@ -438,11 +443,14 @@ func (aq *AttestationQuery) sqlCount(ctx context.Context) (int, error) { } func (aq *AttestationQuery) sqlExist(ctx context.Context) (bool, error) { - n, err := aq.sqlCount(ctx) - if err != nil { + switch _, err := aq.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 (aq *AttestationQuery) querySpec() *sqlgraph.QuerySpec { @@ -543,7 +551,7 @@ func (agb *AttestationGroupBy) Aggregate(fns ...AggregateFunc) *AttestationGroup } // Scan applies the group-by query and scans the result into the given value. -func (agb *AttestationGroupBy) Scan(ctx context.Context, v interface{}) error { +func (agb *AttestationGroupBy) Scan(ctx context.Context, v any) error { query, err := agb.path(ctx) if err != nil { return err @@ -552,7 +560,7 @@ func (agb *AttestationGroupBy) Scan(ctx context.Context, v interface{}) error { return agb.sqlScan(ctx, v) } -func (agb *AttestationGroupBy) sqlScan(ctx context.Context, v interface{}) error { +func (agb *AttestationGroupBy) sqlScan(ctx context.Context, v any) error { for _, f := range agb.fields { if !attestation.ValidColumn(f) { return &ValidationError{Name: f, err: fmt.Errorf("invalid field %q for group-by", f)} @@ -599,7 +607,7 @@ type AttestationSelect struct { } // Scan applies the selector query and scans the result into the given value. -func (as *AttestationSelect) Scan(ctx context.Context, v interface{}) error { +func (as *AttestationSelect) Scan(ctx context.Context, v any) error { if err := as.prepareQuery(ctx); err != nil { return err } @@ -607,7 +615,7 @@ func (as *AttestationSelect) Scan(ctx context.Context, v interface{}) error { return as.sqlScan(ctx, v) } -func (as *AttestationSelect) sqlScan(ctx context.Context, v interface{}) error { +func (as *AttestationSelect) sqlScan(ctx context.Context, v any) error { rows := &sql.Rows{} query, args := as.sql.Query() if err := as.driver.Query(ctx, query, args, rows); err != nil { diff --git a/ent/attestation_update.go b/ent/attestation_update.go index 26ee7fdb..c7045820 100644 --- a/ent/attestation_update.go +++ b/ent/attestation_update.go @@ -1,4 +1,4 @@ -// Code generated by entc, DO NOT EDIT. +// Code generated by ent, DO NOT EDIT. package ent @@ -193,7 +193,7 @@ func (au *AttestationUpdate) sqlSave(ctx context.Context) (n int, err error) { if _, ok := err.(*sqlgraph.NotFoundError); ok { err = &NotFoundError{attestation.Label} } else if sqlgraph.IsConstraintError(err) { - err = &ConstraintError{err.Error(), err} + err = &ConstraintError{msg: err.Error(), wrap: err} } return 0, err } @@ -406,7 +406,7 @@ func (auo *AttestationUpdateOne) sqlSave(ctx context.Context) (_node *Attestatio if _, ok := err.(*sqlgraph.NotFoundError); ok { err = &NotFoundError{attestation.Label} } else if sqlgraph.IsConstraintError(err) { - err = &ConstraintError{err.Error(), err} + err = &ConstraintError{msg: err.Error(), wrap: err} } return nil, err } diff --git a/ent/attestationcollection.go b/ent/attestationcollection.go index 9079d6e1..3cfa77f4 100644 --- a/ent/attestationcollection.go +++ b/ent/attestationcollection.go @@ -1,4 +1,4 @@ -// Code generated by entc, DO NOT EDIT. +// Code generated by ent, DO NOT EDIT. package ent @@ -51,8 +51,7 @@ func (e AttestationCollectionEdges) AttestationsOrErr() ([]*Attestation, error) func (e AttestationCollectionEdges) StatementOrErr() (*Statement, error) { if e.loadedTypes[1] { if e.Statement == nil { - // The edge statement was loaded in eager-loading, - // but was not found. + // Edge was loaded but was not found. return nil, &NotFoundError{label: statement.Label} } return e.Statement, nil @@ -61,8 +60,8 @@ func (e AttestationCollectionEdges) StatementOrErr() (*Statement, error) { } // scanValues returns the types for scanning values from sql.Rows. -func (*AttestationCollection) scanValues(columns []string) ([]interface{}, error) { - values := make([]interface{}, len(columns)) +func (*AttestationCollection) scanValues(columns []string) ([]any, error) { + values := make([]any, len(columns)) for i := range columns { switch columns[i] { case attestationcollection.FieldID: @@ -80,7 +79,7 @@ func (*AttestationCollection) scanValues(columns []string) ([]interface{}, error // assignValues assigns the values that were returned from sql.Rows (after scanning) // to the AttestationCollection fields. -func (ac *AttestationCollection) assignValues(columns []string, values []interface{}) error { +func (ac *AttestationCollection) assignValues(columns []string, values []any) error { if m, n := len(values), len(columns); m < n { return fmt.Errorf("mismatch number of scan values: %d != %d", m, n) } @@ -130,11 +129,11 @@ func (ac *AttestationCollection) Update() *AttestationCollectionUpdateOne { // Unwrap unwraps the AttestationCollection entity that was returned from a transaction after it was closed, // so that all future queries will be executed through the driver which created the transaction. func (ac *AttestationCollection) Unwrap() *AttestationCollection { - tx, ok := ac.config.driver.(*txDriver) + _tx, ok := ac.config.driver.(*txDriver) if !ok { panic("ent: AttestationCollection is not a transactional entity") } - ac.config.driver = tx.drv + ac.config.driver = _tx.drv return ac } diff --git a/ent/attestationcollection/attestationcollection.go b/ent/attestationcollection/attestationcollection.go index 08bebb5f..4bebfb86 100644 --- a/ent/attestationcollection/attestationcollection.go +++ b/ent/attestationcollection/attestationcollection.go @@ -1,4 +1,4 @@ -// Code generated by entc, DO NOT EDIT. +// Code generated by ent, DO NOT EDIT. package attestationcollection diff --git a/ent/attestationcollection/where.go b/ent/attestationcollection/where.go index e5661ca5..16ea8740 100644 --- a/ent/attestationcollection/where.go +++ b/ent/attestationcollection/where.go @@ -1,4 +1,4 @@ -// Code generated by entc, DO NOT EDIT. +// Code generated by ent, DO NOT EDIT. package attestationcollection @@ -32,13 +32,7 @@ func IDNEQ(id int) predicate.AttestationCollection { // IDIn applies the In predicate on the ID field. func IDIn(ids ...int) predicate.AttestationCollection { return predicate.AttestationCollection(func(s *sql.Selector) { - // if not arguments were provided, append the FALSE constants, - // since we can't apply "IN ()". This will make this predicate falsy. - if len(ids) == 0 { - s.Where(sql.False()) - return - } - v := make([]interface{}, len(ids)) + v := make([]any, len(ids)) for i := range v { v[i] = ids[i] } @@ -49,13 +43,7 @@ func IDIn(ids ...int) predicate.AttestationCollection { // IDNotIn applies the NotIn predicate on the ID field. func IDNotIn(ids ...int) predicate.AttestationCollection { return predicate.AttestationCollection(func(s *sql.Selector) { - // if not arguments were provided, append the FALSE constants, - // since we can't apply "IN ()". This will make this predicate falsy. - if len(ids) == 0 { - s.Where(sql.False()) - return - } - v := make([]interface{}, len(ids)) + v := make([]any, len(ids)) for i := range v { v[i] = ids[i] } @@ -114,34 +102,22 @@ func NameNEQ(v string) predicate.AttestationCollection { // NameIn applies the In predicate on the "name" field. func NameIn(vs ...string) predicate.AttestationCollection { - v := make([]interface{}, len(vs)) + v := make([]any, len(vs)) for i := range v { v[i] = vs[i] } return predicate.AttestationCollection(func(s *sql.Selector) { - // if not arguments were provided, append the FALSE constants, - // since we can't apply "IN ()". This will make this predicate falsy. - if len(v) == 0 { - s.Where(sql.False()) - return - } s.Where(sql.In(s.C(FieldName), v...)) }) } // NameNotIn applies the NotIn predicate on the "name" field. func NameNotIn(vs ...string) predicate.AttestationCollection { - v := make([]interface{}, len(vs)) + v := make([]any, len(vs)) for i := range v { v[i] = vs[i] } return predicate.AttestationCollection(func(s *sql.Selector) { - // if not arguments were provided, append the FALSE constants, - // since we can't apply "IN ()". This will make this predicate falsy. - if len(v) == 0 { - s.Where(sql.False()) - return - } s.Where(sql.NotIn(s.C(FieldName), v...)) }) } diff --git a/ent/attestationcollection_create.go b/ent/attestationcollection_create.go index df6d2d42..a9855c3b 100644 --- a/ent/attestationcollection_create.go +++ b/ent/attestationcollection_create.go @@ -1,4 +1,4 @@ -// Code generated by entc, DO NOT EDIT. +// Code generated by ent, DO NOT EDIT. package ent @@ -147,7 +147,7 @@ func (acc *AttestationCollectionCreate) sqlSave(ctx context.Context) (*Attestati _node, _spec := acc.createSpec() if err := sqlgraph.CreateNode(ctx, acc.driver, _spec); err != nil { if sqlgraph.IsConstraintError(err) { - err = &ConstraintError{err.Error(), err} + err = &ConstraintError{msg: err.Error(), wrap: err} } return nil, err } @@ -249,7 +249,7 @@ func (accb *AttestationCollectionCreateBulk) Save(ctx context.Context) ([]*Attes // Invoke the actual operation on the latest mutation in the chain. if err = sqlgraph.BatchCreate(ctx, accb.driver, spec); err != nil { if sqlgraph.IsConstraintError(err) { - err = &ConstraintError{err.Error(), err} + err = &ConstraintError{msg: err.Error(), wrap: err} } } } diff --git a/ent/attestationcollection_delete.go b/ent/attestationcollection_delete.go index 4fcdbad3..3de8e437 100644 --- a/ent/attestationcollection_delete.go +++ b/ent/attestationcollection_delete.go @@ -1,4 +1,4 @@ -// Code generated by entc, DO NOT EDIT. +// Code generated by ent, DO NOT EDIT. package ent @@ -84,7 +84,11 @@ func (acd *AttestationCollectionDelete) sqlExec(ctx context.Context) (int, error } } } - return sqlgraph.DeleteNodes(ctx, acd.driver, _spec) + affected, err := sqlgraph.DeleteNodes(ctx, acd.driver, _spec) + if err != nil && sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return affected, err } // AttestationCollectionDeleteOne is the builder for deleting a single AttestationCollection entity. diff --git a/ent/attestationcollection_query.go b/ent/attestationcollection_query.go index bcee79c5..e94cc8f0 100644 --- a/ent/attestationcollection_query.go +++ b/ent/attestationcollection_query.go @@ -1,4 +1,4 @@ -// Code generated by entc, DO NOT EDIT. +// Code generated by ent, DO NOT EDIT. package ent @@ -20,13 +20,12 @@ import ( // AttestationCollectionQuery is the builder for querying AttestationCollection entities. type AttestationCollectionQuery struct { config - limit *int - offset *int - unique *bool - order []OrderFunc - fields []string - predicates []predicate.AttestationCollection - // eager-loading edges. + limit *int + offset *int + unique *bool + order []OrderFunc + fields []string + predicates []predicate.AttestationCollection withAttestations *AttestationQuery withStatement *StatementQuery withFKs bool @@ -404,10 +403,10 @@ func (acq *AttestationCollectionQuery) sqlAll(ctx context.Context, hooks ...quer if withFKs { _spec.Node.Columns = append(_spec.Node.Columns, attestationcollection.ForeignKeys...) } - _spec.ScanValues = func(columns []string) ([]interface{}, error) { + _spec.ScanValues = func(columns []string) ([]any, error) { return (*AttestationCollection).scanValues(nil, columns) } - _spec.Assign = func(columns []string, values []interface{}) error { + _spec.Assign = func(columns []string, values []any) error { node := &AttestationCollection{config: acq.config} nodes = append(nodes, node) node.Edges.loadedTypes = loadedTypes @@ -425,65 +424,19 @@ func (acq *AttestationCollectionQuery) sqlAll(ctx context.Context, hooks ...quer if len(nodes) == 0 { return nodes, nil } - if query := acq.withAttestations; query != nil { - fks := make([]driver.Value, 0, len(nodes)) - nodeids := make(map[int]*AttestationCollection) - for i := range nodes { - fks = append(fks, nodes[i].ID) - nodeids[nodes[i].ID] = nodes[i] - nodes[i].Edges.Attestations = []*Attestation{} - } - query.withFKs = true - query.Where(predicate.Attestation(func(s *sql.Selector) { - s.Where(sql.InValues(attestationcollection.AttestationsColumn, fks...)) - })) - neighbors, err := query.All(ctx) - if err != nil { + if err := acq.loadAttestations(ctx, query, nodes, + func(n *AttestationCollection) { n.Edges.Attestations = []*Attestation{} }, + func(n *AttestationCollection, e *Attestation) { n.Edges.Attestations = append(n.Edges.Attestations, e) }); err != nil { return nil, err } - for _, n := range neighbors { - fk := n.attestation_collection_attestations - if fk == nil { - return nil, fmt.Errorf(`foreign-key "attestation_collection_attestations" is nil for node %v`, n.ID) - } - node, ok := nodeids[*fk] - if !ok { - return nil, fmt.Errorf(`unexpected foreign-key "attestation_collection_attestations" returned %v for node %v`, *fk, n.ID) - } - node.Edges.Attestations = append(node.Edges.Attestations, n) - } } - if query := acq.withStatement; query != nil { - ids := make([]int, 0, len(nodes)) - nodeids := make(map[int][]*AttestationCollection) - for i := range nodes { - if nodes[i].statement_attestation_collections == nil { - continue - } - fk := *nodes[i].statement_attestation_collections - if _, ok := nodeids[fk]; !ok { - ids = append(ids, fk) - } - nodeids[fk] = append(nodeids[fk], nodes[i]) - } - query.Where(statement.IDIn(ids...)) - neighbors, err := query.All(ctx) - if err != nil { + if err := acq.loadStatement(ctx, query, nodes, nil, + func(n *AttestationCollection, e *Statement) { n.Edges.Statement = e }); err != nil { return nil, err } - for _, n := range neighbors { - nodes, ok := nodeids[n.ID] - if !ok { - return nil, fmt.Errorf(`unexpected foreign-key "statement_attestation_collections" returned %v`, n.ID) - } - for i := range nodes { - nodes[i].Edges.Statement = n - } - } } - for i := range acq.loadTotal { if err := acq.loadTotal[i](ctx, nodes); err != nil { return nil, err @@ -492,6 +445,67 @@ func (acq *AttestationCollectionQuery) sqlAll(ctx context.Context, hooks ...quer return nodes, nil } +func (acq *AttestationCollectionQuery) loadAttestations(ctx context.Context, query *AttestationQuery, nodes []*AttestationCollection, init func(*AttestationCollection), assign func(*AttestationCollection, *Attestation)) error { + fks := make([]driver.Value, 0, len(nodes)) + nodeids := make(map[int]*AttestationCollection) + 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.Attestation(func(s *sql.Selector) { + s.Where(sql.InValues(attestationcollection.AttestationsColumn, fks...)) + })) + neighbors, err := query.All(ctx) + if err != nil { + return err + } + for _, n := range neighbors { + fk := n.attestation_collection_attestations + if fk == nil { + return fmt.Errorf(`foreign-key "attestation_collection_attestations" is nil for node %v`, n.ID) + } + node, ok := nodeids[*fk] + if !ok { + return fmt.Errorf(`unexpected foreign-key "attestation_collection_attestations" returned %v for node %v`, *fk, n.ID) + } + assign(node, n) + } + return nil +} +func (acq *AttestationCollectionQuery) loadStatement(ctx context.Context, query *StatementQuery, nodes []*AttestationCollection, init func(*AttestationCollection), assign func(*AttestationCollection, *Statement)) error { + ids := make([]int, 0, len(nodes)) + nodeids := make(map[int][]*AttestationCollection) + for i := range nodes { + if nodes[i].statement_attestation_collections == nil { + continue + } + fk := *nodes[i].statement_attestation_collections + if _, ok := nodeids[fk]; !ok { + ids = append(ids, fk) + } + nodeids[fk] = append(nodeids[fk], nodes[i]) + } + query.Where(statement.IDIn(ids...)) + neighbors, err := query.All(ctx) + if err != nil { + return err + } + for _, n := range neighbors { + nodes, ok := nodeids[n.ID] + if !ok { + return fmt.Errorf(`unexpected foreign-key "statement_attestation_collections" returned %v`, n.ID) + } + for i := range nodes { + assign(nodes[i], n) + } + } + return nil +} + func (acq *AttestationCollectionQuery) sqlCount(ctx context.Context) (int, error) { _spec := acq.querySpec() if len(acq.modifiers) > 0 { @@ -505,11 +519,14 @@ func (acq *AttestationCollectionQuery) sqlCount(ctx context.Context) (int, error } func (acq *AttestationCollectionQuery) sqlExist(ctx context.Context) (bool, error) { - n, err := acq.sqlCount(ctx) - if err != nil { + switch _, err := acq.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 (acq *AttestationCollectionQuery) querySpec() *sqlgraph.QuerySpec { @@ -610,7 +627,7 @@ func (acgb *AttestationCollectionGroupBy) Aggregate(fns ...AggregateFunc) *Attes } // Scan applies the group-by query and scans the result into the given value. -func (acgb *AttestationCollectionGroupBy) Scan(ctx context.Context, v interface{}) error { +func (acgb *AttestationCollectionGroupBy) Scan(ctx context.Context, v any) error { query, err := acgb.path(ctx) if err != nil { return err @@ -619,7 +636,7 @@ func (acgb *AttestationCollectionGroupBy) Scan(ctx context.Context, v interface{ return acgb.sqlScan(ctx, v) } -func (acgb *AttestationCollectionGroupBy) sqlScan(ctx context.Context, v interface{}) error { +func (acgb *AttestationCollectionGroupBy) sqlScan(ctx context.Context, v any) error { for _, f := range acgb.fields { if !attestationcollection.ValidColumn(f) { return &ValidationError{Name: f, err: fmt.Errorf("invalid field %q for group-by", f)} @@ -666,7 +683,7 @@ type AttestationCollectionSelect struct { } // Scan applies the selector query and scans the result into the given value. -func (acs *AttestationCollectionSelect) Scan(ctx context.Context, v interface{}) error { +func (acs *AttestationCollectionSelect) Scan(ctx context.Context, v any) error { if err := acs.prepareQuery(ctx); err != nil { return err } @@ -674,7 +691,7 @@ func (acs *AttestationCollectionSelect) Scan(ctx context.Context, v interface{}) return acs.sqlScan(ctx, v) } -func (acs *AttestationCollectionSelect) sqlScan(ctx context.Context, v interface{}) error { +func (acs *AttestationCollectionSelect) sqlScan(ctx context.Context, v any) error { rows := &sql.Rows{} query, args := acs.sql.Query() if err := acs.driver.Query(ctx, query, args, rows); err != nil { diff --git a/ent/attestationcollection_update.go b/ent/attestationcollection_update.go index 6b57e1e7..b0156b17 100644 --- a/ent/attestationcollection_update.go +++ b/ent/attestationcollection_update.go @@ -1,4 +1,4 @@ -// Code generated by entc, DO NOT EDIT. +// Code generated by ent, DO NOT EDIT. package ent @@ -284,7 +284,7 @@ func (acu *AttestationCollectionUpdate) sqlSave(ctx context.Context) (n int, err if _, ok := err.(*sqlgraph.NotFoundError); ok { err = &NotFoundError{attestationcollection.Label} } else if sqlgraph.IsConstraintError(err) { - err = &ConstraintError{err.Error(), err} + err = &ConstraintError{msg: err.Error(), wrap: err} } return 0, err } @@ -587,7 +587,7 @@ func (acuo *AttestationCollectionUpdateOne) sqlSave(ctx context.Context) (_node if _, ok := err.(*sqlgraph.NotFoundError); ok { err = &NotFoundError{attestationcollection.Label} } else if sqlgraph.IsConstraintError(err) { - err = &ConstraintError{err.Error(), err} + err = &ConstraintError{msg: err.Error(), wrap: err} } return nil, err } diff --git a/ent/client.go b/ent/client.go index ce6b858b..bbec657a 100644 --- a/ent/client.go +++ b/ent/client.go @@ -1,9 +1,10 @@ -// Code generated by entc, DO NOT EDIT. +// Code generated by ent, DO NOT EDIT. package ent import ( "context" + "errors" "fmt" "log" @@ -89,7 +90,7 @@ func Open(driverName, dataSourceName string, options ...Option) (*Client, error) // is used until the transaction is committed or rolled back. func (c *Client) Tx(ctx context.Context) (*Tx, error) { if _, ok := c.driver.(*txDriver); ok { - return nil, fmt.Errorf("ent: cannot start a transaction within a transaction") + return nil, errors.New("ent: cannot start a transaction within a transaction") } tx, err := newTx(ctx, c.driver) if err != nil { @@ -114,7 +115,7 @@ func (c *Client) Tx(ctx context.Context) (*Tx, error) { // BeginTx returns a transactional client with specified options. func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error) { if _, ok := c.driver.(*txDriver); ok { - return nil, fmt.Errorf("ent: cannot start a transaction within a transaction") + return nil, errors.New("ent: cannot start a transaction within a transaction") } tx, err := c.driver.(interface { BeginTx(context.Context, *sql.TxOptions) (dialect.Tx, error) diff --git a/ent/config.go b/ent/config.go index e460931c..c9d2b1bb 100644 --- a/ent/config.go +++ b/ent/config.go @@ -1,4 +1,4 @@ -// Code generated by entc, DO NOT EDIT. +// Code generated by ent, DO NOT EDIT. package ent @@ -17,7 +17,7 @@ type config struct { // debug enable a debug logging. debug bool // log used for logging on debug mode. - log func(...interface{}) + log func(...any) // hooks to execute on mutations. hooks *hooks } @@ -52,7 +52,7 @@ func Debug() Option { } // Log sets the logging function for debug mode. -func Log(fn func(...interface{})) Option { +func Log(fn func(...any)) Option { return func(c *config) { c.log = fn } diff --git a/ent/context.go b/ent/context.go index 08407261..7811bfa2 100644 --- a/ent/context.go +++ b/ent/context.go @@ -1,4 +1,4 @@ -// Code generated by entc, DO NOT EDIT. +// Code generated by ent, DO NOT EDIT. package ent diff --git a/ent/dsse.go b/ent/dsse.go index e3bf23a1..e8d7f2aa 100644 --- a/ent/dsse.go +++ b/ent/dsse.go @@ -1,4 +1,4 @@ -// Code generated by entc, DO NOT EDIT. +// Code generated by ent, DO NOT EDIT. package ent @@ -46,8 +46,7 @@ type DsseEdges struct { func (e DsseEdges) StatementOrErr() (*Statement, error) { if e.loadedTypes[0] { if e.Statement == nil { - // The edge statement was loaded in eager-loading, - // but was not found. + // Edge was loaded but was not found. return nil, &NotFoundError{label: statement.Label} } return e.Statement, nil @@ -74,8 +73,8 @@ func (e DsseEdges) PayloadDigestsOrErr() ([]*PayloadDigest, error) { } // scanValues returns the types for scanning values from sql.Rows. -func (*Dsse) scanValues(columns []string) ([]interface{}, error) { - values := make([]interface{}, len(columns)) +func (*Dsse) scanValues(columns []string) ([]any, error) { + values := make([]any, len(columns)) for i := range columns { switch columns[i] { case dsse.FieldID: @@ -93,7 +92,7 @@ func (*Dsse) scanValues(columns []string) ([]interface{}, error) { // assignValues assigns the values that were returned from sql.Rows (after scanning) // to the Dsse fields. -func (d *Dsse) assignValues(columns []string, values []interface{}) error { +func (d *Dsse) assignValues(columns []string, values []any) error { if m, n := len(values), len(columns); m < n { return fmt.Errorf("mismatch number of scan values: %d != %d", m, n) } @@ -154,11 +153,11 @@ func (d *Dsse) Update() *DsseUpdateOne { // Unwrap unwraps the Dsse entity that was returned from a transaction after it was closed, // so that all future queries will be executed through the driver which created the transaction. func (d *Dsse) Unwrap() *Dsse { - tx, ok := d.config.driver.(*txDriver) + _tx, ok := d.config.driver.(*txDriver) if !ok { panic("ent: Dsse is not a transactional entity") } - d.config.driver = tx.drv + d.config.driver = _tx.drv return d } diff --git a/ent/dsse/dsse.go b/ent/dsse/dsse.go index c65a9141..cc047354 100644 --- a/ent/dsse/dsse.go +++ b/ent/dsse/dsse.go @@ -1,4 +1,4 @@ -// Code generated by entc, DO NOT EDIT. +// Code generated by ent, DO NOT EDIT. package dsse diff --git a/ent/dsse/where.go b/ent/dsse/where.go index aa0d92c1..255f01bc 100644 --- a/ent/dsse/where.go +++ b/ent/dsse/where.go @@ -1,4 +1,4 @@ -// Code generated by entc, DO NOT EDIT. +// Code generated by ent, DO NOT EDIT. package dsse @@ -32,13 +32,7 @@ func IDNEQ(id int) predicate.Dsse { // IDIn applies the In predicate on the ID field. func IDIn(ids ...int) predicate.Dsse { return predicate.Dsse(func(s *sql.Selector) { - // if not arguments were provided, append the FALSE constants, - // since we can't apply "IN ()". This will make this predicate falsy. - if len(ids) == 0 { - s.Where(sql.False()) - return - } - v := make([]interface{}, len(ids)) + v := make([]any, len(ids)) for i := range v { v[i] = ids[i] } @@ -49,13 +43,7 @@ func IDIn(ids ...int) predicate.Dsse { // IDNotIn applies the NotIn predicate on the ID field. func IDNotIn(ids ...int) predicate.Dsse { return predicate.Dsse(func(s *sql.Selector) { - // if not arguments were provided, append the FALSE constants, - // since we can't apply "IN ()". This will make this predicate falsy. - if len(ids) == 0 { - s.Where(sql.False()) - return - } - v := make([]interface{}, len(ids)) + v := make([]any, len(ids)) for i := range v { v[i] = ids[i] } @@ -121,34 +109,22 @@ func GitoidSha256NEQ(v string) predicate.Dsse { // GitoidSha256In applies the In predicate on the "gitoid_sha256" field. func GitoidSha256In(vs ...string) predicate.Dsse { - v := make([]interface{}, len(vs)) + v := make([]any, len(vs)) for i := range v { v[i] = vs[i] } return predicate.Dsse(func(s *sql.Selector) { - // if not arguments were provided, append the FALSE constants, - // since we can't apply "IN ()". This will make this predicate falsy. - if len(v) == 0 { - s.Where(sql.False()) - return - } s.Where(sql.In(s.C(FieldGitoidSha256), v...)) }) } // GitoidSha256NotIn applies the NotIn predicate on the "gitoid_sha256" field. func GitoidSha256NotIn(vs ...string) predicate.Dsse { - v := make([]interface{}, len(vs)) + v := make([]any, len(vs)) for i := range v { v[i] = vs[i] } return predicate.Dsse(func(s *sql.Selector) { - // if not arguments were provided, append the FALSE constants, - // since we can't apply "IN ()". This will make this predicate falsy. - if len(v) == 0 { - s.Where(sql.False()) - return - } s.Where(sql.NotIn(s.C(FieldGitoidSha256), v...)) }) } @@ -232,34 +208,22 @@ func PayloadTypeNEQ(v string) predicate.Dsse { // PayloadTypeIn applies the In predicate on the "payload_type" field. func PayloadTypeIn(vs ...string) predicate.Dsse { - v := make([]interface{}, len(vs)) + v := make([]any, len(vs)) for i := range v { v[i] = vs[i] } return predicate.Dsse(func(s *sql.Selector) { - // if not arguments were provided, append the FALSE constants, - // since we can't apply "IN ()". This will make this predicate falsy. - if len(v) == 0 { - s.Where(sql.False()) - return - } s.Where(sql.In(s.C(FieldPayloadType), v...)) }) } // PayloadTypeNotIn applies the NotIn predicate on the "payload_type" field. func PayloadTypeNotIn(vs ...string) predicate.Dsse { - v := make([]interface{}, len(vs)) + v := make([]any, len(vs)) for i := range v { v[i] = vs[i] } return predicate.Dsse(func(s *sql.Selector) { - // if not arguments were provided, append the FALSE constants, - // since we can't apply "IN ()". This will make this predicate falsy. - if len(v) == 0 { - s.Where(sql.False()) - return - } s.Where(sql.NotIn(s.C(FieldPayloadType), v...)) }) } diff --git a/ent/dsse_create.go b/ent/dsse_create.go index 0cf561ae..6d1c08ac 100644 --- a/ent/dsse_create.go +++ b/ent/dsse_create.go @@ -1,4 +1,4 @@ -// Code generated by entc, DO NOT EDIT. +// Code generated by ent, DO NOT EDIT. package ent @@ -182,7 +182,7 @@ func (dc *DsseCreate) sqlSave(ctx context.Context) (*Dsse, error) { _node, _spec := dc.createSpec() if err := sqlgraph.CreateNode(ctx, dc.driver, _spec); err != nil { if sqlgraph.IsConstraintError(err) { - err = &ConstraintError{err.Error(), err} + err = &ConstraintError{msg: err.Error(), wrap: err} } return nil, err } @@ -311,7 +311,7 @@ func (dcb *DsseCreateBulk) Save(ctx context.Context) ([]*Dsse, error) { // Invoke the actual operation on the latest mutation in the chain. if err = sqlgraph.BatchCreate(ctx, dcb.driver, spec); err != nil { if sqlgraph.IsConstraintError(err) { - err = &ConstraintError{err.Error(), err} + err = &ConstraintError{msg: err.Error(), wrap: err} } } } diff --git a/ent/dsse_delete.go b/ent/dsse_delete.go index eeb9cb0a..01a34311 100644 --- a/ent/dsse_delete.go +++ b/ent/dsse_delete.go @@ -1,4 +1,4 @@ -// Code generated by entc, DO NOT EDIT. +// Code generated by ent, DO NOT EDIT. package ent @@ -84,7 +84,11 @@ func (dd *DsseDelete) sqlExec(ctx context.Context) (int, error) { } } } - return sqlgraph.DeleteNodes(ctx, dd.driver, _spec) + affected, err := sqlgraph.DeleteNodes(ctx, dd.driver, _spec) + if err != nil && sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return affected, err } // DsseDeleteOne is the builder for deleting a single Dsse entity. diff --git a/ent/dsse_query.go b/ent/dsse_query.go index ea83c64f..07df9edc 100644 --- a/ent/dsse_query.go +++ b/ent/dsse_query.go @@ -1,4 +1,4 @@ -// Code generated by entc, DO NOT EDIT. +// Code generated by ent, DO NOT EDIT. package ent @@ -21,13 +21,12 @@ import ( // DsseQuery is the builder for querying Dsse entities. type DsseQuery struct { config - limit *int - offset *int - unique *bool - order []OrderFunc - fields []string - predicates []predicate.Dsse - // eager-loading edges. + limit *int + offset *int + unique *bool + order []OrderFunc + fields []string + predicates []predicate.Dsse withStatement *StatementQuery withSignatures *SignatureQuery withPayloadDigests *PayloadDigestQuery @@ -441,10 +440,10 @@ func (dq *DsseQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Dsse, e if withFKs { _spec.Node.Columns = append(_spec.Node.Columns, dsse.ForeignKeys...) } - _spec.ScanValues = func(columns []string) ([]interface{}, error) { + _spec.ScanValues = func(columns []string) ([]any, error) { return (*Dsse).scanValues(nil, columns) } - _spec.Assign = func(columns []string, values []interface{}) error { + _spec.Assign = func(columns []string, values []any) error { node := &Dsse{config: dq.config} nodes = append(nodes, node) node.Edges.loadedTypes = loadedTypes @@ -462,94 +461,26 @@ func (dq *DsseQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Dsse, e if len(nodes) == 0 { return nodes, nil } - if query := dq.withStatement; query != nil { - ids := make([]int, 0, len(nodes)) - nodeids := make(map[int][]*Dsse) - for i := range nodes { - if nodes[i].dsse_statement == nil { - continue - } - fk := *nodes[i].dsse_statement - if _, ok := nodeids[fk]; !ok { - ids = append(ids, fk) - } - nodeids[fk] = append(nodeids[fk], nodes[i]) - } - query.Where(statement.IDIn(ids...)) - neighbors, err := query.All(ctx) - if err != nil { + if err := dq.loadStatement(ctx, query, nodes, nil, + func(n *Dsse, e *Statement) { n.Edges.Statement = e }); err != nil { return nil, err } - for _, n := range neighbors { - nodes, ok := nodeids[n.ID] - if !ok { - return nil, fmt.Errorf(`unexpected foreign-key "dsse_statement" returned %v`, n.ID) - } - for i := range nodes { - nodes[i].Edges.Statement = n - } - } } - if query := dq.withSignatures; query != nil { - fks := make([]driver.Value, 0, len(nodes)) - nodeids := make(map[int]*Dsse) - for i := range nodes { - fks = append(fks, nodes[i].ID) - nodeids[nodes[i].ID] = nodes[i] - nodes[i].Edges.Signatures = []*Signature{} - } - query.withFKs = true - query.Where(predicate.Signature(func(s *sql.Selector) { - s.Where(sql.InValues(dsse.SignaturesColumn, fks...)) - })) - neighbors, err := query.All(ctx) - if err != nil { + if err := dq.loadSignatures(ctx, query, nodes, + func(n *Dsse) { n.Edges.Signatures = []*Signature{} }, + func(n *Dsse, e *Signature) { n.Edges.Signatures = append(n.Edges.Signatures, e) }); err != nil { return nil, err } - for _, n := range neighbors { - fk := n.dsse_signatures - if fk == nil { - return nil, fmt.Errorf(`foreign-key "dsse_signatures" is nil for node %v`, n.ID) - } - node, ok := nodeids[*fk] - if !ok { - return nil, fmt.Errorf(`unexpected foreign-key "dsse_signatures" returned %v for node %v`, *fk, n.ID) - } - node.Edges.Signatures = append(node.Edges.Signatures, n) - } } - if query := dq.withPayloadDigests; query != nil { - fks := make([]driver.Value, 0, len(nodes)) - nodeids := make(map[int]*Dsse) - for i := range nodes { - fks = append(fks, nodes[i].ID) - nodeids[nodes[i].ID] = nodes[i] - nodes[i].Edges.PayloadDigests = []*PayloadDigest{} - } - query.withFKs = true - query.Where(predicate.PayloadDigest(func(s *sql.Selector) { - s.Where(sql.InValues(dsse.PayloadDigestsColumn, fks...)) - })) - neighbors, err := query.All(ctx) - if err != nil { + if err := dq.loadPayloadDigests(ctx, query, nodes, + func(n *Dsse) { n.Edges.PayloadDigests = []*PayloadDigest{} }, + func(n *Dsse, e *PayloadDigest) { n.Edges.PayloadDigests = append(n.Edges.PayloadDigests, e) }); err != nil { return nil, err } - for _, n := range neighbors { - fk := n.dsse_payload_digests - if fk == nil { - return nil, fmt.Errorf(`foreign-key "dsse_payload_digests" is nil for node %v`, n.ID) - } - node, ok := nodeids[*fk] - if !ok { - return nil, fmt.Errorf(`unexpected foreign-key "dsse_payload_digests" returned %v for node %v`, *fk, n.ID) - } - node.Edges.PayloadDigests = append(node.Edges.PayloadDigests, n) - } } - for i := range dq.loadTotal { if err := dq.loadTotal[i](ctx, nodes); err != nil { return nil, err @@ -558,6 +489,98 @@ func (dq *DsseQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Dsse, e return nodes, nil } +func (dq *DsseQuery) loadStatement(ctx context.Context, query *StatementQuery, nodes []*Dsse, init func(*Dsse), assign func(*Dsse, *Statement)) error { + ids := make([]int, 0, len(nodes)) + nodeids := make(map[int][]*Dsse) + for i := range nodes { + if nodes[i].dsse_statement == nil { + continue + } + fk := *nodes[i].dsse_statement + if _, ok := nodeids[fk]; !ok { + ids = append(ids, fk) + } + nodeids[fk] = append(nodeids[fk], nodes[i]) + } + query.Where(statement.IDIn(ids...)) + neighbors, err := query.All(ctx) + if err != nil { + return err + } + for _, n := range neighbors { + nodes, ok := nodeids[n.ID] + if !ok { + return fmt.Errorf(`unexpected foreign-key "dsse_statement" returned %v`, n.ID) + } + for i := range nodes { + assign(nodes[i], n) + } + } + return nil +} +func (dq *DsseQuery) loadSignatures(ctx context.Context, query *SignatureQuery, nodes []*Dsse, init func(*Dsse), assign func(*Dsse, *Signature)) error { + fks := make([]driver.Value, 0, len(nodes)) + nodeids := make(map[int]*Dsse) + 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.Signature(func(s *sql.Selector) { + s.Where(sql.InValues(dsse.SignaturesColumn, fks...)) + })) + neighbors, err := query.All(ctx) + if err != nil { + return err + } + for _, n := range neighbors { + fk := n.dsse_signatures + if fk == nil { + return fmt.Errorf(`foreign-key "dsse_signatures" is nil for node %v`, n.ID) + } + node, ok := nodeids[*fk] + if !ok { + return fmt.Errorf(`unexpected foreign-key "dsse_signatures" returned %v for node %v`, *fk, n.ID) + } + assign(node, n) + } + return nil +} +func (dq *DsseQuery) loadPayloadDigests(ctx context.Context, query *PayloadDigestQuery, nodes []*Dsse, init func(*Dsse), assign func(*Dsse, *PayloadDigest)) error { + fks := make([]driver.Value, 0, len(nodes)) + nodeids := make(map[int]*Dsse) + 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.PayloadDigest(func(s *sql.Selector) { + s.Where(sql.InValues(dsse.PayloadDigestsColumn, fks...)) + })) + neighbors, err := query.All(ctx) + if err != nil { + return err + } + for _, n := range neighbors { + fk := n.dsse_payload_digests + if fk == nil { + return fmt.Errorf(`foreign-key "dsse_payload_digests" is nil for node %v`, n.ID) + } + node, ok := nodeids[*fk] + if !ok { + return fmt.Errorf(`unexpected foreign-key "dsse_payload_digests" returned %v for node %v`, *fk, n.ID) + } + assign(node, n) + } + return nil +} + func (dq *DsseQuery) sqlCount(ctx context.Context) (int, error) { _spec := dq.querySpec() if len(dq.modifiers) > 0 { @@ -571,11 +594,14 @@ func (dq *DsseQuery) sqlCount(ctx context.Context) (int, error) { } func (dq *DsseQuery) sqlExist(ctx context.Context) (bool, error) { - n, err := dq.sqlCount(ctx) - if err != nil { + switch _, err := dq.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 (dq *DsseQuery) querySpec() *sqlgraph.QuerySpec { @@ -676,7 +702,7 @@ func (dgb *DsseGroupBy) Aggregate(fns ...AggregateFunc) *DsseGroupBy { } // Scan applies the group-by query and scans the result into the given value. -func (dgb *DsseGroupBy) Scan(ctx context.Context, v interface{}) error { +func (dgb *DsseGroupBy) Scan(ctx context.Context, v any) error { query, err := dgb.path(ctx) if err != nil { return err @@ -685,7 +711,7 @@ func (dgb *DsseGroupBy) Scan(ctx context.Context, v interface{}) error { return dgb.sqlScan(ctx, v) } -func (dgb *DsseGroupBy) sqlScan(ctx context.Context, v interface{}) error { +func (dgb *DsseGroupBy) sqlScan(ctx context.Context, v any) error { for _, f := range dgb.fields { if !dsse.ValidColumn(f) { return &ValidationError{Name: f, err: fmt.Errorf("invalid field %q for group-by", f)} @@ -732,7 +758,7 @@ type DsseSelect struct { } // Scan applies the selector query and scans the result into the given value. -func (ds *DsseSelect) Scan(ctx context.Context, v interface{}) error { +func (ds *DsseSelect) Scan(ctx context.Context, v any) error { if err := ds.prepareQuery(ctx); err != nil { return err } @@ -740,7 +766,7 @@ func (ds *DsseSelect) Scan(ctx context.Context, v interface{}) error { return ds.sqlScan(ctx, v) } -func (ds *DsseSelect) sqlScan(ctx context.Context, v interface{}) error { +func (ds *DsseSelect) sqlScan(ctx context.Context, v any) error { rows := &sql.Rows{} query, args := ds.sql.Query() if err := ds.driver.Query(ctx, query, args, rows); err != nil { diff --git a/ent/dsse_update.go b/ent/dsse_update.go index 7fbef912..2fc613f6 100644 --- a/ent/dsse_update.go +++ b/ent/dsse_update.go @@ -1,4 +1,4 @@ -// Code generated by entc, DO NOT EDIT. +// Code generated by ent, DO NOT EDIT. package ent @@ -398,7 +398,7 @@ func (du *DsseUpdate) sqlSave(ctx context.Context) (n int, err error) { if _, ok := err.(*sqlgraph.NotFoundError); ok { err = &NotFoundError{dsse.Label} } else if sqlgraph.IsConstraintError(err) { - err = &ConstraintError{err.Error(), err} + err = &ConstraintError{msg: err.Error(), wrap: err} } return 0, err } @@ -814,7 +814,7 @@ func (duo *DsseUpdateOne) sqlSave(ctx context.Context) (_node *Dsse, err error) if _, ok := err.(*sqlgraph.NotFoundError); ok { err = &NotFoundError{dsse.Label} } else if sqlgraph.IsConstraintError(err) { - err = &ConstraintError{err.Error(), err} + err = &ConstraintError{msg: err.Error(), wrap: err} } return nil, err } diff --git a/ent/ent.go b/ent/ent.go index 1509b0e7..164475bf 100644 --- a/ent/ent.go +++ b/ent/ent.go @@ -1,4 +1,4 @@ -// Code generated by entc, DO NOT EDIT. +// Code generated by ent, DO NOT EDIT. package ent @@ -277,11 +277,11 @@ func IsConstraintError(err error) bool { type selector struct { label string flds *[]string - scan func(context.Context, interface{}) error + scan func(context.Context, any) error } // ScanX is like Scan, but panics if an error occurs. -func (s *selector) ScanX(ctx context.Context, v interface{}) { +func (s *selector) ScanX(ctx context.Context, v any) { if err := s.scan(ctx, v); err != nil { panic(err) } diff --git a/ent/enttest/enttest.go b/ent/enttest/enttest.go index 7aae1d1a..ee46577c 100644 --- a/ent/enttest/enttest.go +++ b/ent/enttest/enttest.go @@ -1,4 +1,4 @@ -// Code generated by entc, DO NOT EDIT. +// Code generated by ent, DO NOT EDIT. package enttest @@ -10,6 +10,7 @@ import ( _ "github.com/testifysec/archivist/ent/runtime" "entgo.io/ent/dialect/sql/schema" + "github.com/testifysec/archivist/ent/migrate" ) type ( @@ -17,7 +18,7 @@ type ( // testing.T and testing.B and used by enttest. TestingT interface { FailNow() - Error(...interface{}) + Error(...any) } // Option configures client creation. @@ -59,10 +60,7 @@ func Open(t TestingT, driverName, dataSourceName string, opts ...Option) *ent.Cl t.Error(err) t.FailNow() } - if err := c.Schema.Create(context.Background(), o.migrateOpts...); err != nil { - t.Error(err) - t.FailNow() - } + migrateSchema(t, c, o) return c } @@ -70,9 +68,17 @@ func Open(t TestingT, driverName, dataSourceName string, opts ...Option) *ent.Cl func NewClient(t TestingT, opts ...Option) *ent.Client { o := newOptions(opts) c := ent.NewClient(o.opts...) - if err := c.Schema.Create(context.Background(), o.migrateOpts...); err != nil { + migrateSchema(t, c, o) + return c +} +func migrateSchema(t TestingT, c *ent.Client, o *options) { + tables, err := schema.CopyTables(migrate.Tables) + if err != nil { + t.Error(err) + t.FailNow() + } + if err := migrate.Create(context.Background(), c.Schema, tables, o.migrateOpts...); err != nil { t.Error(err) t.FailNow() } - return c } diff --git a/ent/gql_collection.go b/ent/gql_collection.go index 7f9eb136..c37e9fad 100644 --- a/ent/gql_collection.go +++ b/ent/gql_collection.go @@ -1,4 +1,4 @@ -// Code generated by entc, DO NOT EDIT. +// Code generated by ent, DO NOT EDIT. package ent diff --git a/ent/gql_edge.go b/ent/gql_edge.go index 6a37e0fc..8a2c20e3 100644 --- a/ent/gql_edge.go +++ b/ent/gql_edge.go @@ -1,4 +1,4 @@ -// Code generated by entc, DO NOT EDIT. +// Code generated by ent, DO NOT EDIT. package ent diff --git a/ent/gql_node.go b/ent/gql_node.go index a7aaf919..37adf9b0 100644 --- a/ent/gql_node.go +++ b/ent/gql_node.go @@ -1,4 +1,4 @@ -// Code generated by entc, DO NOT EDIT. +// Code generated by ent, DO NOT EDIT. package ent diff --git a/ent/gql_pagination.go b/ent/gql_pagination.go index e0f6f74c..7f00b9ef 100644 --- a/ent/gql_pagination.go +++ b/ent/gql_pagination.go @@ -1,4 +1,4 @@ -// Code generated by entc, DO NOT EDIT. +// Code generated by ent, DO NOT EDIT. package ent diff --git a/ent/gql_transaction.go b/ent/gql_transaction.go index 5fb5120d..96117136 100644 --- a/ent/gql_transaction.go +++ b/ent/gql_transaction.go @@ -1,4 +1,4 @@ -// Code generated by entc, DO NOT EDIT. +// Code generated by ent, DO NOT EDIT. package ent diff --git a/ent/gql_where_input.go b/ent/gql_where_input.go index 9133dd3b..7a7a74b7 100644 --- a/ent/gql_where_input.go +++ b/ent/gql_where_input.go @@ -1,4 +1,4 @@ -// Code generated by entc, DO NOT EDIT. +// Code generated by ent, DO NOT EDIT. package ent diff --git a/ent/hook/hook.go b/ent/hook/hook.go index 0886c436..3177a168 100644 --- a/ent/hook/hook.go +++ b/ent/hook/hook.go @@ -1,4 +1,4 @@ -// Code generated by entc, DO NOT EDIT. +// Code generated by ent, DO NOT EDIT. package hook diff --git a/ent/migrate/migrate.go b/ent/migrate/migrate.go index c31b5820..1956a6bf 100644 --- a/ent/migrate/migrate.go +++ b/ent/migrate/migrate.go @@ -1,4 +1,4 @@ -// Code generated by entc, DO NOT EDIT. +// Code generated by ent, DO NOT EDIT. package migrate @@ -28,9 +28,6 @@ var ( // and therefore, it's recommended to enable this option to get more // flexibility in the schema changes. WithDropIndex = schema.WithDropIndex - // WithFixture sets the foreign-key renaming option to the migration when upgrading - // ent from v0.1.0 (issue-#285). Defaults to false. - WithFixture = schema.WithFixture // WithForeignKeys enables creating foreign-key in schema DDL. This defaults to true. WithForeignKeys = schema.WithForeignKeys ) @@ -45,11 +42,16 @@ func NewSchema(drv dialect.Driver) *Schema { return &Schema{drv: drv} } // Create creates all schema resources. func (s *Schema) Create(ctx context.Context, opts ...schema.MigrateOption) error { + return Create(ctx, s, Tables, opts...) +} + +// Create creates all table resources using the given schema driver. +func Create(ctx context.Context, s *Schema, tables []*schema.Table, opts ...schema.MigrateOption) error { migrate, err := schema.NewMigrate(s.drv, opts...) if err != nil { return fmt.Errorf("ent/migrate: %w", err) } - return migrate.Create(ctx, Tables...) + return migrate.Create(ctx, tables...) } // WriteTo writes the schema changes to w instead of running them against the database. @@ -58,13 +60,5 @@ func (s *Schema) Create(ctx context.Context, opts ...schema.MigrateOption) error // log.Fatal(err) // } func (s *Schema) WriteTo(ctx context.Context, w io.Writer, opts ...schema.MigrateOption) error { - drv := &schema.WriteDriver{ - Writer: w, - Driver: s.drv, - } - migrate, err := schema.NewMigrate(drv, opts...) - if err != nil { - return fmt.Errorf("ent/migrate: %w", err) - } - return migrate.Create(ctx, Tables...) + return Create(ctx, &Schema{drv: &schema.WriteDriver{Writer: w, Driver: s.drv}}, Tables, opts...) } diff --git a/ent/migrate/schema.go b/ent/migrate/schema.go index 82d7b41b..1f0e2db5 100644 --- a/ent/migrate/schema.go +++ b/ent/migrate/schema.go @@ -1,4 +1,4 @@ -// Code generated by entc, DO NOT EDIT. +// Code generated by ent, DO NOT EDIT. package migrate @@ -27,6 +27,13 @@ var ( OnDelete: schema.NoAction, }, }, + Indexes: []*schema.Index{ + { + Name: "attestation_type", + Unique: false, + Columns: []*schema.Column{AttestationsColumns[1]}, + }, + }, } // AttestationCollectionsColumns holds the columns for the "attestation_collections" table. AttestationCollectionsColumns = []*schema.Column{ @@ -47,6 +54,13 @@ var ( OnDelete: schema.NoAction, }, }, + Indexes: []*schema.Index{ + { + Name: "attestationcollection_name", + Unique: false, + Columns: []*schema.Column{AttestationCollectionsColumns[1]}, + }, + }, } // DssesColumns holds the columns for the "dsses" table. DssesColumns = []*schema.Column{ @@ -89,6 +103,13 @@ var ( OnDelete: schema.SetNull, }, }, + Indexes: []*schema.Index{ + { + Name: "payloaddigest_value", + Unique: false, + Columns: []*schema.Column{PayloadDigestsColumns[2]}, + }, + }, } // SignaturesColumns holds the columns for the "signatures" table. SignaturesColumns = []*schema.Column{ @@ -110,6 +131,13 @@ var ( OnDelete: schema.SetNull, }, }, + Indexes: []*schema.Index{ + { + Name: "signature_key_id", + Unique: false, + Columns: []*schema.Column{SignaturesColumns[1]}, + }, + }, } // StatementsColumns holds the columns for the "statements" table. StatementsColumns = []*schema.Column{ @@ -121,6 +149,13 @@ var ( Name: "statements", Columns: StatementsColumns, PrimaryKey: []*schema.Column{StatementsColumns[0]}, + Indexes: []*schema.Index{ + { + Name: "statement_predicate", + Unique: false, + Columns: []*schema.Column{StatementsColumns[1]}, + }, + }, } // SubjectsColumns holds the columns for the "subjects" table. SubjectsColumns = []*schema.Column{ @@ -141,6 +176,13 @@ var ( OnDelete: schema.SetNull, }, }, + Indexes: []*schema.Index{ + { + Name: "subject_name", + Unique: false, + Columns: []*schema.Column{SubjectsColumns[1]}, + }, + }, } // SubjectDigestsColumns holds the columns for the "subject_digests" table. SubjectDigestsColumns = []*schema.Column{ @@ -162,6 +204,13 @@ var ( OnDelete: schema.SetNull, }, }, + Indexes: []*schema.Index{ + { + Name: "subjectdigest_value", + Unique: false, + Columns: []*schema.Column{SubjectDigestsColumns[2]}, + }, + }, } // Tables holds all the tables in the schema. Tables = []*schema.Table{ diff --git a/ent/mutation.go b/ent/mutation.go index d097d88a..06cfc05c 100644 --- a/ent/mutation.go +++ b/ent/mutation.go @@ -1,4 +1,4 @@ -// Code generated by entc, DO NOT EDIT. +// Code generated by ent, DO NOT EDIT. package ent @@ -374,8 +374,6 @@ func (m *AttestationMutation) RemovedEdges() []string { // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with // the given name in this mutation. func (m *AttestationMutation) RemovedIDs(name string) []ent.Value { - switch name { - } return nil } @@ -1871,8 +1869,6 @@ func (m *PayloadDigestMutation) RemovedEdges() []string { // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with // the given name in this mutation. func (m *PayloadDigestMutation) RemovedIDs(name string) []ent.Value { - switch name { - } return nil } @@ -2305,8 +2301,6 @@ func (m *SignatureMutation) RemovedEdges() []string { // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with // the given name in this mutation. func (m *SignatureMutation) RemovedIDs(name string) []ent.Value { - switch name { - } return nil } @@ -3748,8 +3742,6 @@ func (m *SubjectDigestMutation) RemovedEdges() []string { // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with // the given name in this mutation. func (m *SubjectDigestMutation) RemovedIDs(name string) []ent.Value { - switch name { - } return nil } diff --git a/ent/payloaddigest.go b/ent/payloaddigest.go index 59ab3226..dd4c4356 100644 --- a/ent/payloaddigest.go +++ b/ent/payloaddigest.go @@ -1,4 +1,4 @@ -// Code generated by entc, DO NOT EDIT. +// Code generated by ent, DO NOT EDIT. package ent @@ -42,8 +42,7 @@ type PayloadDigestEdges struct { func (e PayloadDigestEdges) DsseOrErr() (*Dsse, error) { if e.loadedTypes[0] { if e.Dsse == nil { - // The edge dsse was loaded in eager-loading, - // but was not found. + // Edge was loaded but was not found. return nil, &NotFoundError{label: dsse.Label} } return e.Dsse, nil @@ -52,8 +51,8 @@ func (e PayloadDigestEdges) DsseOrErr() (*Dsse, error) { } // scanValues returns the types for scanning values from sql.Rows. -func (*PayloadDigest) scanValues(columns []string) ([]interface{}, error) { - values := make([]interface{}, len(columns)) +func (*PayloadDigest) scanValues(columns []string) ([]any, error) { + values := make([]any, len(columns)) for i := range columns { switch columns[i] { case payloaddigest.FieldID: @@ -71,7 +70,7 @@ func (*PayloadDigest) scanValues(columns []string) ([]interface{}, error) { // assignValues assigns the values that were returned from sql.Rows (after scanning) // to the PayloadDigest fields. -func (pd *PayloadDigest) assignValues(columns []string, values []interface{}) error { +func (pd *PayloadDigest) assignValues(columns []string, values []any) error { if m, n := len(values), len(columns); m < n { return fmt.Errorf("mismatch number of scan values: %d != %d", m, n) } @@ -122,11 +121,11 @@ func (pd *PayloadDigest) Update() *PayloadDigestUpdateOne { // Unwrap unwraps the PayloadDigest entity that was returned from a transaction after it was closed, // so that all future queries will be executed through the driver which created the transaction. func (pd *PayloadDigest) Unwrap() *PayloadDigest { - tx, ok := pd.config.driver.(*txDriver) + _tx, ok := pd.config.driver.(*txDriver) if !ok { panic("ent: PayloadDigest is not a transactional entity") } - pd.config.driver = tx.drv + pd.config.driver = _tx.drv return pd } diff --git a/ent/payloaddigest/payloaddigest.go b/ent/payloaddigest/payloaddigest.go index 0023fc9d..85a78cd4 100644 --- a/ent/payloaddigest/payloaddigest.go +++ b/ent/payloaddigest/payloaddigest.go @@ -1,4 +1,4 @@ -// Code generated by entc, DO NOT EDIT. +// Code generated by ent, DO NOT EDIT. package payloaddigest diff --git a/ent/payloaddigest/where.go b/ent/payloaddigest/where.go index 688984ba..95a2d4c3 100644 --- a/ent/payloaddigest/where.go +++ b/ent/payloaddigest/where.go @@ -1,4 +1,4 @@ -// Code generated by entc, DO NOT EDIT. +// Code generated by ent, DO NOT EDIT. package payloaddigest @@ -32,13 +32,7 @@ func IDNEQ(id int) predicate.PayloadDigest { // IDIn applies the In predicate on the ID field. func IDIn(ids ...int) predicate.PayloadDigest { return predicate.PayloadDigest(func(s *sql.Selector) { - // if not arguments were provided, append the FALSE constants, - // since we can't apply "IN ()". This will make this predicate falsy. - if len(ids) == 0 { - s.Where(sql.False()) - return - } - v := make([]interface{}, len(ids)) + v := make([]any, len(ids)) for i := range v { v[i] = ids[i] } @@ -49,13 +43,7 @@ func IDIn(ids ...int) predicate.PayloadDigest { // IDNotIn applies the NotIn predicate on the ID field. func IDNotIn(ids ...int) predicate.PayloadDigest { return predicate.PayloadDigest(func(s *sql.Selector) { - // if not arguments were provided, append the FALSE constants, - // since we can't apply "IN ()". This will make this predicate falsy. - if len(ids) == 0 { - s.Where(sql.False()) - return - } - v := make([]interface{}, len(ids)) + v := make([]any, len(ids)) for i := range v { v[i] = ids[i] } @@ -121,34 +109,22 @@ func AlgorithmNEQ(v string) predicate.PayloadDigest { // AlgorithmIn applies the In predicate on the "algorithm" field. func AlgorithmIn(vs ...string) predicate.PayloadDigest { - v := make([]interface{}, len(vs)) + v := make([]any, len(vs)) for i := range v { v[i] = vs[i] } return predicate.PayloadDigest(func(s *sql.Selector) { - // if not arguments were provided, append the FALSE constants, - // since we can't apply "IN ()". This will make this predicate falsy. - if len(v) == 0 { - s.Where(sql.False()) - return - } s.Where(sql.In(s.C(FieldAlgorithm), v...)) }) } // AlgorithmNotIn applies the NotIn predicate on the "algorithm" field. func AlgorithmNotIn(vs ...string) predicate.PayloadDigest { - v := make([]interface{}, len(vs)) + v := make([]any, len(vs)) for i := range v { v[i] = vs[i] } return predicate.PayloadDigest(func(s *sql.Selector) { - // if not arguments were provided, append the FALSE constants, - // since we can't apply "IN ()". This will make this predicate falsy. - if len(v) == 0 { - s.Where(sql.False()) - return - } s.Where(sql.NotIn(s.C(FieldAlgorithm), v...)) }) } @@ -232,34 +208,22 @@ func ValueNEQ(v string) predicate.PayloadDigest { // ValueIn applies the In predicate on the "value" field. func ValueIn(vs ...string) predicate.PayloadDigest { - v := make([]interface{}, len(vs)) + v := make([]any, len(vs)) for i := range v { v[i] = vs[i] } return predicate.PayloadDigest(func(s *sql.Selector) { - // if not arguments were provided, append the FALSE constants, - // since we can't apply "IN ()". This will make this predicate falsy. - if len(v) == 0 { - s.Where(sql.False()) - return - } s.Where(sql.In(s.C(FieldValue), v...)) }) } // ValueNotIn applies the NotIn predicate on the "value" field. func ValueNotIn(vs ...string) predicate.PayloadDigest { - v := make([]interface{}, len(vs)) + v := make([]any, len(vs)) for i := range v { v[i] = vs[i] } return predicate.PayloadDigest(func(s *sql.Selector) { - // if not arguments were provided, append the FALSE constants, - // since we can't apply "IN ()". This will make this predicate falsy. - if len(v) == 0 { - s.Where(sql.False()) - return - } s.Where(sql.NotIn(s.C(FieldValue), v...)) }) } diff --git a/ent/payloaddigest_create.go b/ent/payloaddigest_create.go index 3d32a4b6..20d90b10 100644 --- a/ent/payloaddigest_create.go +++ b/ent/payloaddigest_create.go @@ -1,4 +1,4 @@ -// Code generated by entc, DO NOT EDIT. +// Code generated by ent, DO NOT EDIT. package ent @@ -150,7 +150,7 @@ func (pdc *PayloadDigestCreate) sqlSave(ctx context.Context) (*PayloadDigest, er _node, _spec := pdc.createSpec() if err := sqlgraph.CreateNode(ctx, pdc.driver, _spec); err != nil { if sqlgraph.IsConstraintError(err) { - err = &ConstraintError{err.Error(), err} + err = &ConstraintError{msg: err.Error(), wrap: err} } return nil, err } @@ -241,7 +241,7 @@ func (pdcb *PayloadDigestCreateBulk) Save(ctx context.Context) ([]*PayloadDigest // Invoke the actual operation on the latest mutation in the chain. if err = sqlgraph.BatchCreate(ctx, pdcb.driver, spec); err != nil { if sqlgraph.IsConstraintError(err) { - err = &ConstraintError{err.Error(), err} + err = &ConstraintError{msg: err.Error(), wrap: err} } } } diff --git a/ent/payloaddigest_delete.go b/ent/payloaddigest_delete.go index ee53ca88..396e4d70 100644 --- a/ent/payloaddigest_delete.go +++ b/ent/payloaddigest_delete.go @@ -1,4 +1,4 @@ -// Code generated by entc, DO NOT EDIT. +// Code generated by ent, DO NOT EDIT. package ent @@ -84,7 +84,11 @@ func (pdd *PayloadDigestDelete) sqlExec(ctx context.Context) (int, error) { } } } - return sqlgraph.DeleteNodes(ctx, pdd.driver, _spec) + affected, err := sqlgraph.DeleteNodes(ctx, pdd.driver, _spec) + if err != nil && sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return affected, err } // PayloadDigestDeleteOne is the builder for deleting a single PayloadDigest entity. diff --git a/ent/payloaddigest_query.go b/ent/payloaddigest_query.go index 91c7c070..90e15f97 100644 --- a/ent/payloaddigest_query.go +++ b/ent/payloaddigest_query.go @@ -1,4 +1,4 @@ -// Code generated by entc, DO NOT EDIT. +// Code generated by ent, DO NOT EDIT. package ent @@ -24,11 +24,10 @@ type PayloadDigestQuery struct { order []OrderFunc fields []string predicates []predicate.PayloadDigest - // eager-loading edges. - withDsse *DsseQuery - withFKs bool - modifiers []func(*sql.Selector) - loadTotal []func(context.Context, []*PayloadDigest) error + withDsse *DsseQuery + withFKs bool + modifiers []func(*sql.Selector) + loadTotal []func(context.Context, []*PayloadDigest) error // intermediate query (i.e. traversal path). sql *sql.Selector path func(context.Context) (*sql.Selector, error) @@ -366,10 +365,10 @@ func (pdq *PayloadDigestQuery) sqlAll(ctx context.Context, hooks ...queryHook) ( if withFKs { _spec.Node.Columns = append(_spec.Node.Columns, payloaddigest.ForeignKeys...) } - _spec.ScanValues = func(columns []string) ([]interface{}, error) { + _spec.ScanValues = func(columns []string) ([]any, error) { return (*PayloadDigest).scanValues(nil, columns) } - _spec.Assign = func(columns []string, values []interface{}) error { + _spec.Assign = func(columns []string, values []any) error { node := &PayloadDigest{config: pdq.config} nodes = append(nodes, node) node.Edges.loadedTypes = loadedTypes @@ -387,36 +386,12 @@ func (pdq *PayloadDigestQuery) sqlAll(ctx context.Context, hooks ...queryHook) ( if len(nodes) == 0 { return nodes, nil } - if query := pdq.withDsse; query != nil { - ids := make([]int, 0, len(nodes)) - nodeids := make(map[int][]*PayloadDigest) - for i := range nodes { - if nodes[i].dsse_payload_digests == nil { - continue - } - fk := *nodes[i].dsse_payload_digests - if _, ok := nodeids[fk]; !ok { - ids = append(ids, fk) - } - nodeids[fk] = append(nodeids[fk], nodes[i]) - } - query.Where(dsse.IDIn(ids...)) - neighbors, err := query.All(ctx) - if err != nil { + if err := pdq.loadDsse(ctx, query, nodes, nil, + func(n *PayloadDigest, e *Dsse) { n.Edges.Dsse = e }); err != nil { return nil, err } - for _, n := range neighbors { - nodes, ok := nodeids[n.ID] - if !ok { - return nil, fmt.Errorf(`unexpected foreign-key "dsse_payload_digests" returned %v`, n.ID) - } - for i := range nodes { - nodes[i].Edges.Dsse = n - } - } } - for i := range pdq.loadTotal { if err := pdq.loadTotal[i](ctx, nodes); err != nil { return nil, err @@ -425,6 +400,36 @@ func (pdq *PayloadDigestQuery) sqlAll(ctx context.Context, hooks ...queryHook) ( return nodes, nil } +func (pdq *PayloadDigestQuery) loadDsse(ctx context.Context, query *DsseQuery, nodes []*PayloadDigest, init func(*PayloadDigest), assign func(*PayloadDigest, *Dsse)) error { + ids := make([]int, 0, len(nodes)) + nodeids := make(map[int][]*PayloadDigest) + for i := range nodes { + if nodes[i].dsse_payload_digests == nil { + continue + } + fk := *nodes[i].dsse_payload_digests + if _, ok := nodeids[fk]; !ok { + ids = append(ids, fk) + } + nodeids[fk] = append(nodeids[fk], nodes[i]) + } + query.Where(dsse.IDIn(ids...)) + neighbors, err := query.All(ctx) + if err != nil { + return err + } + for _, n := range neighbors { + nodes, ok := nodeids[n.ID] + if !ok { + return fmt.Errorf(`unexpected foreign-key "dsse_payload_digests" returned %v`, n.ID) + } + for i := range nodes { + assign(nodes[i], n) + } + } + return nil +} + func (pdq *PayloadDigestQuery) sqlCount(ctx context.Context) (int, error) { _spec := pdq.querySpec() if len(pdq.modifiers) > 0 { @@ -438,11 +443,14 @@ func (pdq *PayloadDigestQuery) sqlCount(ctx context.Context) (int, error) { } func (pdq *PayloadDigestQuery) sqlExist(ctx context.Context) (bool, error) { - n, err := pdq.sqlCount(ctx) - if err != nil { + switch _, err := pdq.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 (pdq *PayloadDigestQuery) querySpec() *sqlgraph.QuerySpec { @@ -543,7 +551,7 @@ func (pdgb *PayloadDigestGroupBy) Aggregate(fns ...AggregateFunc) *PayloadDigest } // Scan applies the group-by query and scans the result into the given value. -func (pdgb *PayloadDigestGroupBy) Scan(ctx context.Context, v interface{}) error { +func (pdgb *PayloadDigestGroupBy) Scan(ctx context.Context, v any) error { query, err := pdgb.path(ctx) if err != nil { return err @@ -552,7 +560,7 @@ func (pdgb *PayloadDigestGroupBy) Scan(ctx context.Context, v interface{}) error return pdgb.sqlScan(ctx, v) } -func (pdgb *PayloadDigestGroupBy) sqlScan(ctx context.Context, v interface{}) error { +func (pdgb *PayloadDigestGroupBy) sqlScan(ctx context.Context, v any) error { for _, f := range pdgb.fields { if !payloaddigest.ValidColumn(f) { return &ValidationError{Name: f, err: fmt.Errorf("invalid field %q for group-by", f)} @@ -599,7 +607,7 @@ type PayloadDigestSelect struct { } // Scan applies the selector query and scans the result into the given value. -func (pds *PayloadDigestSelect) Scan(ctx context.Context, v interface{}) error { +func (pds *PayloadDigestSelect) Scan(ctx context.Context, v any) error { if err := pds.prepareQuery(ctx); err != nil { return err } @@ -607,7 +615,7 @@ func (pds *PayloadDigestSelect) Scan(ctx context.Context, v interface{}) error { return pds.sqlScan(ctx, v) } -func (pds *PayloadDigestSelect) sqlScan(ctx context.Context, v interface{}) error { +func (pds *PayloadDigestSelect) sqlScan(ctx context.Context, v any) error { rows := &sql.Rows{} query, args := pds.sql.Query() if err := pds.driver.Query(ctx, query, args, rows); err != nil { diff --git a/ent/payloaddigest_update.go b/ent/payloaddigest_update.go index 4d286c0c..6f6e23c2 100644 --- a/ent/payloaddigest_update.go +++ b/ent/payloaddigest_update.go @@ -1,4 +1,4 @@ -// Code generated by entc, DO NOT EDIT. +// Code generated by ent, DO NOT EDIT. package ent @@ -216,7 +216,7 @@ func (pdu *PayloadDigestUpdate) sqlSave(ctx context.Context) (n int, err error) if _, ok := err.(*sqlgraph.NotFoundError); ok { err = &NotFoundError{payloaddigest.Label} } else if sqlgraph.IsConstraintError(err) { - err = &ConstraintError{err.Error(), err} + err = &ConstraintError{msg: err.Error(), wrap: err} } return 0, err } @@ -452,7 +452,7 @@ func (pduo *PayloadDigestUpdateOne) sqlSave(ctx context.Context) (_node *Payload if _, ok := err.(*sqlgraph.NotFoundError); ok { err = &NotFoundError{payloaddigest.Label} } else if sqlgraph.IsConstraintError(err) { - err = &ConstraintError{err.Error(), err} + err = &ConstraintError{msg: err.Error(), wrap: err} } return nil, err } diff --git a/ent/predicate/predicate.go b/ent/predicate/predicate.go index be419cf8..5b7941ba 100644 --- a/ent/predicate/predicate.go +++ b/ent/predicate/predicate.go @@ -1,4 +1,4 @@ -// Code generated by entc, DO NOT EDIT. +// Code generated by ent, DO NOT EDIT. package predicate diff --git a/ent/runtime.go b/ent/runtime.go index b4865cbb..f3de9653 100644 --- a/ent/runtime.go +++ b/ent/runtime.go @@ -1,4 +1,4 @@ -// Code generated by entc, DO NOT EDIT. +// Code generated by ent, DO NOT EDIT. package ent diff --git a/ent/runtime/runtime.go b/ent/runtime/runtime.go index 115c4109..d1cecd16 100644 --- a/ent/runtime/runtime.go +++ b/ent/runtime/runtime.go @@ -1,10 +1,10 @@ -// Code generated by entc, DO NOT EDIT. +// Code generated by ent, DO NOT EDIT. package runtime // The schema-stitching logic is generated in github.com/testifysec/archivist/ent/runtime.go const ( - Version = "v0.10.2-0.20220528091257-0917701f9114" // Version of ent codegen. - Sum = "h1:BJ3c7WialDUYIM+lzdbON5UO8nWAgcccWde6AaqlK68=" // Sum of ent codegen. + Version = "v0.11.3" // Version of ent codegen. + Sum = "h1:F5FBGAWiDCGder7YT+lqMnyzXl6d0xU3xMBM/SO3CMc=" // Sum of ent codegen. ) diff --git a/ent/schema/attestation.go b/ent/schema/attestation.go index 295c9739..1b5b3ddd 100644 --- a/ent/schema/attestation.go +++ b/ent/schema/attestation.go @@ -18,6 +18,7 @@ import ( "entgo.io/ent" "entgo.io/ent/schema/edge" "entgo.io/ent/schema/field" + "entgo.io/ent/schema/index" ) // Attestation represents an attestation from a witness attestation collection @@ -36,3 +37,9 @@ func (Attestation) Edges() []ent.Edge { edge.From("attestation_collection", AttestationCollection.Type).Ref("attestations").Unique().Required(), } } + +func (Attestation) Indexes() []ent.Index { + return []ent.Index{ + index.Fields("type"), + } +} diff --git a/ent/schema/attestationcollection.go b/ent/schema/attestationcollection.go index ba61074c..9978b187 100644 --- a/ent/schema/attestationcollection.go +++ b/ent/schema/attestationcollection.go @@ -18,6 +18,7 @@ import ( "entgo.io/ent" "entgo.io/ent/schema/edge" "entgo.io/ent/schema/field" + "entgo.io/ent/schema/index" ) // AttestationCollection represents a witness attestation collection @@ -37,3 +38,9 @@ func (AttestationCollection) Edges() []ent.Edge { edge.From("statement", Statement.Type).Ref("attestation_collections").Unique().Required(), } } + +func (AttestationCollection) Indexes() []ent.Index { + return []ent.Index{ + index.Fields("name"), + } +} diff --git a/ent/schema/payloaddigest.go b/ent/schema/payloaddigest.go index 7086f8a1..2278d4e9 100644 --- a/ent/schema/payloaddigest.go +++ b/ent/schema/payloaddigest.go @@ -18,6 +18,7 @@ import ( "entgo.io/ent" "entgo.io/ent/schema/edge" "entgo.io/ent/schema/field" + "entgo.io/ent/schema/index" ) // PayloadDigest represents the digest of the payload of a DSSE envelope @@ -41,3 +42,9 @@ func (PayloadDigest) Edges() []ent.Edge { Unique(), } } + +func (PayloadDigest) Indexes() []ent.Index { + return []ent.Index{ + index.Fields("value"), + } +} diff --git a/ent/schema/signature.go b/ent/schema/signature.go index 9936a2f6..95c86a76 100644 --- a/ent/schema/signature.go +++ b/ent/schema/signature.go @@ -19,6 +19,7 @@ import ( "entgo.io/ent/dialect" "entgo.io/ent/schema/edge" "entgo.io/ent/schema/field" + "entgo.io/ent/schema/index" ) // Signature represents signatures on a DSSE envelope @@ -40,3 +41,9 @@ func (Signature) Edges() []ent.Edge { edge.From("dsse", Dsse.Type).Ref("signatures").Unique(), } } + +func (Signature) Indexes() []ent.Index { + return []ent.Index{ + index.Fields("key_id"), + } +} diff --git a/ent/schema/statement.go b/ent/schema/statement.go index 5ead652b..0c59280d 100644 --- a/ent/schema/statement.go +++ b/ent/schema/statement.go @@ -18,6 +18,7 @@ import ( "entgo.io/ent" "entgo.io/ent/schema/edge" "entgo.io/ent/schema/field" + "entgo.io/ent/schema/index" ) // Statement represents an in-toto statement from an archived dsse envelope @@ -41,3 +42,9 @@ func (Statement) Edges() []ent.Edge { edge.From("dsse", Dsse.Type).Ref("statement"), } } + +func (Statement) Indexes() []ent.Index { + return []ent.Index{ + index.Fields("predicate"), + } +} diff --git a/ent/schema/subject.go b/ent/schema/subject.go index 0d440c8c..34e8e002 100644 --- a/ent/schema/subject.go +++ b/ent/schema/subject.go @@ -18,6 +18,7 @@ import ( "entgo.io/ent" "entgo.io/ent/schema/edge" "entgo.io/ent/schema/field" + "entgo.io/ent/schema/index" ) // Subject represents subjects from an in-toto statement. @@ -41,3 +42,10 @@ func (Subject) Edges() []ent.Edge { Ref("subjects").Unique(), } } + +func (Subject) Indexes() []ent.Index { + return []ent.Index{ + // Index on the "name" field. + index.Fields("name"), + } +} diff --git a/ent/schema/subjectdigest.go b/ent/schema/subjectdigest.go index 601250f5..a1e687d2 100644 --- a/ent/schema/subjectdigest.go +++ b/ent/schema/subjectdigest.go @@ -18,6 +18,7 @@ import ( "entgo.io/ent" "entgo.io/ent/schema/edge" "entgo.io/ent/schema/field" + "entgo.io/ent/schema/index" ) // SubjectDigest represents the digests of a subject from an in-toto statement @@ -41,3 +42,10 @@ func (SubjectDigest) Edges() []ent.Edge { Unique(), } } + +func (SubjectDigest) Indexes() []ent.Index { + return []ent.Index{ + // Index on the "value" field. + index.Fields("value"), + } +} diff --git a/ent/signature.go b/ent/signature.go index e8c657cd..7c9aaebf 100644 --- a/ent/signature.go +++ b/ent/signature.go @@ -1,4 +1,4 @@ -// Code generated by entc, DO NOT EDIT. +// Code generated by ent, DO NOT EDIT. package ent @@ -42,8 +42,7 @@ type SignatureEdges struct { func (e SignatureEdges) DsseOrErr() (*Dsse, error) { if e.loadedTypes[0] { if e.Dsse == nil { - // The edge dsse was loaded in eager-loading, - // but was not found. + // Edge was loaded but was not found. return nil, &NotFoundError{label: dsse.Label} } return e.Dsse, nil @@ -52,8 +51,8 @@ func (e SignatureEdges) DsseOrErr() (*Dsse, error) { } // scanValues returns the types for scanning values from sql.Rows. -func (*Signature) scanValues(columns []string) ([]interface{}, error) { - values := make([]interface{}, len(columns)) +func (*Signature) scanValues(columns []string) ([]any, error) { + values := make([]any, len(columns)) for i := range columns { switch columns[i] { case signature.FieldID: @@ -71,7 +70,7 @@ func (*Signature) scanValues(columns []string) ([]interface{}, error) { // assignValues assigns the values that were returned from sql.Rows (after scanning) // to the Signature fields. -func (s *Signature) assignValues(columns []string, values []interface{}) error { +func (s *Signature) assignValues(columns []string, values []any) error { if m, n := len(values), len(columns); m < n { return fmt.Errorf("mismatch number of scan values: %d != %d", m, n) } @@ -122,11 +121,11 @@ func (s *Signature) Update() *SignatureUpdateOne { // Unwrap unwraps the Signature entity that was returned from a transaction after it was closed, // so that all future queries will be executed through the driver which created the transaction. func (s *Signature) Unwrap() *Signature { - tx, ok := s.config.driver.(*txDriver) + _tx, ok := s.config.driver.(*txDriver) if !ok { panic("ent: Signature is not a transactional entity") } - s.config.driver = tx.drv + s.config.driver = _tx.drv return s } diff --git a/ent/signature/signature.go b/ent/signature/signature.go index 73aa56a4..9e6998de 100644 --- a/ent/signature/signature.go +++ b/ent/signature/signature.go @@ -1,4 +1,4 @@ -// Code generated by entc, DO NOT EDIT. +// Code generated by ent, DO NOT EDIT. package signature diff --git a/ent/signature/where.go b/ent/signature/where.go index 67572cc7..476a192b 100644 --- a/ent/signature/where.go +++ b/ent/signature/where.go @@ -1,4 +1,4 @@ -// Code generated by entc, DO NOT EDIT. +// Code generated by ent, DO NOT EDIT. package signature @@ -32,13 +32,7 @@ func IDNEQ(id int) predicate.Signature { // IDIn applies the In predicate on the ID field. func IDIn(ids ...int) predicate.Signature { return predicate.Signature(func(s *sql.Selector) { - // if not arguments were provided, append the FALSE constants, - // since we can't apply "IN ()". This will make this predicate falsy. - if len(ids) == 0 { - s.Where(sql.False()) - return - } - v := make([]interface{}, len(ids)) + v := make([]any, len(ids)) for i := range v { v[i] = ids[i] } @@ -49,13 +43,7 @@ func IDIn(ids ...int) predicate.Signature { // IDNotIn applies the NotIn predicate on the ID field. func IDNotIn(ids ...int) predicate.Signature { return predicate.Signature(func(s *sql.Selector) { - // if not arguments were provided, append the FALSE constants, - // since we can't apply "IN ()". This will make this predicate falsy. - if len(ids) == 0 { - s.Where(sql.False()) - return - } - v := make([]interface{}, len(ids)) + v := make([]any, len(ids)) for i := range v { v[i] = ids[i] } @@ -121,34 +109,22 @@ func KeyIDNEQ(v string) predicate.Signature { // KeyIDIn applies the In predicate on the "key_id" field. func KeyIDIn(vs ...string) predicate.Signature { - v := make([]interface{}, len(vs)) + v := make([]any, len(vs)) for i := range v { v[i] = vs[i] } return predicate.Signature(func(s *sql.Selector) { - // if not arguments were provided, append the FALSE constants, - // since we can't apply "IN ()". This will make this predicate falsy. - if len(v) == 0 { - s.Where(sql.False()) - return - } s.Where(sql.In(s.C(FieldKeyID), v...)) }) } // KeyIDNotIn applies the NotIn predicate on the "key_id" field. func KeyIDNotIn(vs ...string) predicate.Signature { - v := make([]interface{}, len(vs)) + v := make([]any, len(vs)) for i := range v { v[i] = vs[i] } return predicate.Signature(func(s *sql.Selector) { - // if not arguments were provided, append the FALSE constants, - // since we can't apply "IN ()". This will make this predicate falsy. - if len(v) == 0 { - s.Where(sql.False()) - return - } s.Where(sql.NotIn(s.C(FieldKeyID), v...)) }) } @@ -232,34 +208,22 @@ func SignatureNEQ(v string) predicate.Signature { // SignatureIn applies the In predicate on the "signature" field. func SignatureIn(vs ...string) predicate.Signature { - v := make([]interface{}, len(vs)) + v := make([]any, len(vs)) for i := range v { v[i] = vs[i] } return predicate.Signature(func(s *sql.Selector) { - // if not arguments were provided, append the FALSE constants, - // since we can't apply "IN ()". This will make this predicate falsy. - if len(v) == 0 { - s.Where(sql.False()) - return - } s.Where(sql.In(s.C(FieldSignature), v...)) }) } // SignatureNotIn applies the NotIn predicate on the "signature" field. func SignatureNotIn(vs ...string) predicate.Signature { - v := make([]interface{}, len(vs)) + v := make([]any, len(vs)) for i := range v { v[i] = vs[i] } return predicate.Signature(func(s *sql.Selector) { - // if not arguments were provided, append the FALSE constants, - // since we can't apply "IN ()". This will make this predicate falsy. - if len(v) == 0 { - s.Where(sql.False()) - return - } s.Where(sql.NotIn(s.C(FieldSignature), v...)) }) } diff --git a/ent/signature_create.go b/ent/signature_create.go index 9bed9369..08413088 100644 --- a/ent/signature_create.go +++ b/ent/signature_create.go @@ -1,4 +1,4 @@ -// Code generated by entc, DO NOT EDIT. +// Code generated by ent, DO NOT EDIT. package ent @@ -150,7 +150,7 @@ func (sc *SignatureCreate) sqlSave(ctx context.Context) (*Signature, error) { _node, _spec := sc.createSpec() if err := sqlgraph.CreateNode(ctx, sc.driver, _spec); err != nil { if sqlgraph.IsConstraintError(err) { - err = &ConstraintError{err.Error(), err} + err = &ConstraintError{msg: err.Error(), wrap: err} } return nil, err } @@ -241,7 +241,7 @@ func (scb *SignatureCreateBulk) Save(ctx context.Context) ([]*Signature, error) // Invoke the actual operation on the latest mutation in the chain. if err = sqlgraph.BatchCreate(ctx, scb.driver, spec); err != nil { if sqlgraph.IsConstraintError(err) { - err = &ConstraintError{err.Error(), err} + err = &ConstraintError{msg: err.Error(), wrap: err} } } } diff --git a/ent/signature_delete.go b/ent/signature_delete.go index 32547258..737eb253 100644 --- a/ent/signature_delete.go +++ b/ent/signature_delete.go @@ -1,4 +1,4 @@ -// Code generated by entc, DO NOT EDIT. +// Code generated by ent, DO NOT EDIT. package ent @@ -84,7 +84,11 @@ func (sd *SignatureDelete) sqlExec(ctx context.Context) (int, error) { } } } - return sqlgraph.DeleteNodes(ctx, sd.driver, _spec) + affected, err := sqlgraph.DeleteNodes(ctx, sd.driver, _spec) + if err != nil && sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return affected, err } // SignatureDeleteOne is the builder for deleting a single Signature entity. diff --git a/ent/signature_query.go b/ent/signature_query.go index 10716e9f..58dd70fa 100644 --- a/ent/signature_query.go +++ b/ent/signature_query.go @@ -1,4 +1,4 @@ -// Code generated by entc, DO NOT EDIT. +// Code generated by ent, DO NOT EDIT. package ent @@ -24,11 +24,10 @@ type SignatureQuery struct { order []OrderFunc fields []string predicates []predicate.Signature - // eager-loading edges. - withDsse *DsseQuery - withFKs bool - modifiers []func(*sql.Selector) - loadTotal []func(context.Context, []*Signature) error + withDsse *DsseQuery + withFKs bool + modifiers []func(*sql.Selector) + loadTotal []func(context.Context, []*Signature) error // intermediate query (i.e. traversal path). sql *sql.Selector path func(context.Context) (*sql.Selector, error) @@ -366,10 +365,10 @@ func (sq *SignatureQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Si if withFKs { _spec.Node.Columns = append(_spec.Node.Columns, signature.ForeignKeys...) } - _spec.ScanValues = func(columns []string) ([]interface{}, error) { + _spec.ScanValues = func(columns []string) ([]any, error) { return (*Signature).scanValues(nil, columns) } - _spec.Assign = func(columns []string, values []interface{}) error { + _spec.Assign = func(columns []string, values []any) error { node := &Signature{config: sq.config} nodes = append(nodes, node) node.Edges.loadedTypes = loadedTypes @@ -387,36 +386,12 @@ func (sq *SignatureQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Si if len(nodes) == 0 { return nodes, nil } - if query := sq.withDsse; query != nil { - ids := make([]int, 0, len(nodes)) - nodeids := make(map[int][]*Signature) - for i := range nodes { - if nodes[i].dsse_signatures == nil { - continue - } - fk := *nodes[i].dsse_signatures - if _, ok := nodeids[fk]; !ok { - ids = append(ids, fk) - } - nodeids[fk] = append(nodeids[fk], nodes[i]) - } - query.Where(dsse.IDIn(ids...)) - neighbors, err := query.All(ctx) - if err != nil { + if err := sq.loadDsse(ctx, query, nodes, nil, + func(n *Signature, e *Dsse) { n.Edges.Dsse = e }); err != nil { return nil, err } - for _, n := range neighbors { - nodes, ok := nodeids[n.ID] - if !ok { - return nil, fmt.Errorf(`unexpected foreign-key "dsse_signatures" returned %v`, n.ID) - } - for i := range nodes { - nodes[i].Edges.Dsse = n - } - } } - for i := range sq.loadTotal { if err := sq.loadTotal[i](ctx, nodes); err != nil { return nil, err @@ -425,6 +400,36 @@ func (sq *SignatureQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Si return nodes, nil } +func (sq *SignatureQuery) loadDsse(ctx context.Context, query *DsseQuery, nodes []*Signature, init func(*Signature), assign func(*Signature, *Dsse)) error { + ids := make([]int, 0, len(nodes)) + nodeids := make(map[int][]*Signature) + for i := range nodes { + if nodes[i].dsse_signatures == nil { + continue + } + fk := *nodes[i].dsse_signatures + if _, ok := nodeids[fk]; !ok { + ids = append(ids, fk) + } + nodeids[fk] = append(nodeids[fk], nodes[i]) + } + query.Where(dsse.IDIn(ids...)) + neighbors, err := query.All(ctx) + if err != nil { + return err + } + for _, n := range neighbors { + nodes, ok := nodeids[n.ID] + if !ok { + return fmt.Errorf(`unexpected foreign-key "dsse_signatures" returned %v`, n.ID) + } + for i := range nodes { + assign(nodes[i], n) + } + } + return nil +} + func (sq *SignatureQuery) sqlCount(ctx context.Context) (int, error) { _spec := sq.querySpec() if len(sq.modifiers) > 0 { @@ -438,11 +443,14 @@ func (sq *SignatureQuery) sqlCount(ctx context.Context) (int, error) { } func (sq *SignatureQuery) sqlExist(ctx context.Context) (bool, error) { - n, err := sq.sqlCount(ctx) - if err != nil { + switch _, err := sq.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 (sq *SignatureQuery) querySpec() *sqlgraph.QuerySpec { @@ -543,7 +551,7 @@ func (sgb *SignatureGroupBy) Aggregate(fns ...AggregateFunc) *SignatureGroupBy { } // Scan applies the group-by query and scans the result into the given value. -func (sgb *SignatureGroupBy) Scan(ctx context.Context, v interface{}) error { +func (sgb *SignatureGroupBy) Scan(ctx context.Context, v any) error { query, err := sgb.path(ctx) if err != nil { return err @@ -552,7 +560,7 @@ func (sgb *SignatureGroupBy) Scan(ctx context.Context, v interface{}) error { return sgb.sqlScan(ctx, v) } -func (sgb *SignatureGroupBy) sqlScan(ctx context.Context, v interface{}) error { +func (sgb *SignatureGroupBy) sqlScan(ctx context.Context, v any) error { for _, f := range sgb.fields { if !signature.ValidColumn(f) { return &ValidationError{Name: f, err: fmt.Errorf("invalid field %q for group-by", f)} @@ -599,7 +607,7 @@ type SignatureSelect struct { } // Scan applies the selector query and scans the result into the given value. -func (ss *SignatureSelect) Scan(ctx context.Context, v interface{}) error { +func (ss *SignatureSelect) Scan(ctx context.Context, v any) error { if err := ss.prepareQuery(ctx); err != nil { return err } @@ -607,7 +615,7 @@ func (ss *SignatureSelect) Scan(ctx context.Context, v interface{}) error { return ss.sqlScan(ctx, v) } -func (ss *SignatureSelect) sqlScan(ctx context.Context, v interface{}) error { +func (ss *SignatureSelect) sqlScan(ctx context.Context, v any) error { rows := &sql.Rows{} query, args := ss.sql.Query() if err := ss.driver.Query(ctx, query, args, rows); err != nil { diff --git a/ent/signature_update.go b/ent/signature_update.go index 0d1bb63f..9f424da1 100644 --- a/ent/signature_update.go +++ b/ent/signature_update.go @@ -1,4 +1,4 @@ -// Code generated by entc, DO NOT EDIT. +// Code generated by ent, DO NOT EDIT. package ent @@ -216,7 +216,7 @@ func (su *SignatureUpdate) sqlSave(ctx context.Context) (n int, err error) { if _, ok := err.(*sqlgraph.NotFoundError); ok { err = &NotFoundError{signature.Label} } else if sqlgraph.IsConstraintError(err) { - err = &ConstraintError{err.Error(), err} + err = &ConstraintError{msg: err.Error(), wrap: err} } return 0, err } @@ -452,7 +452,7 @@ func (suo *SignatureUpdateOne) sqlSave(ctx context.Context) (_node *Signature, e if _, ok := err.(*sqlgraph.NotFoundError); ok { err = &NotFoundError{signature.Label} } else if sqlgraph.IsConstraintError(err) { - err = &ConstraintError{err.Error(), err} + err = &ConstraintError{msg: err.Error(), wrap: err} } return nil, err } diff --git a/ent/statement.go b/ent/statement.go index 7a33455f..72ee19e6 100644 --- a/ent/statement.go +++ b/ent/statement.go @@ -1,4 +1,4 @@ -// Code generated by entc, DO NOT EDIT. +// Code generated by ent, DO NOT EDIT. package ent @@ -52,8 +52,7 @@ func (e StatementEdges) SubjectsOrErr() ([]*Subject, error) { func (e StatementEdges) AttestationCollectionsOrErr() (*AttestationCollection, error) { if e.loadedTypes[1] { if e.AttestationCollections == nil { - // The edge attestation_collections was loaded in eager-loading, - // but was not found. + // Edge was loaded but was not found. return nil, &NotFoundError{label: attestationcollection.Label} } return e.AttestationCollections, nil @@ -71,8 +70,8 @@ func (e StatementEdges) DsseOrErr() ([]*Dsse, error) { } // scanValues returns the types for scanning values from sql.Rows. -func (*Statement) scanValues(columns []string) ([]interface{}, error) { - values := make([]interface{}, len(columns)) +func (*Statement) scanValues(columns []string) ([]any, error) { + values := make([]any, len(columns)) for i := range columns { switch columns[i] { case statement.FieldID: @@ -88,7 +87,7 @@ func (*Statement) scanValues(columns []string) ([]interface{}, error) { // assignValues assigns the values that were returned from sql.Rows (after scanning) // to the Statement fields. -func (s *Statement) assignValues(columns []string, values []interface{}) error { +func (s *Statement) assignValues(columns []string, values []any) error { if m, n := len(values), len(columns); m < n { return fmt.Errorf("mismatch number of scan values: %d != %d", m, n) } @@ -136,11 +135,11 @@ func (s *Statement) Update() *StatementUpdateOne { // Unwrap unwraps the Statement entity that was returned from a transaction after it was closed, // so that all future queries will be executed through the driver which created the transaction. func (s *Statement) Unwrap() *Statement { - tx, ok := s.config.driver.(*txDriver) + _tx, ok := s.config.driver.(*txDriver) if !ok { panic("ent: Statement is not a transactional entity") } - s.config.driver = tx.drv + s.config.driver = _tx.drv return s } diff --git a/ent/statement/statement.go b/ent/statement/statement.go index 9a266fd0..a76160c8 100644 --- a/ent/statement/statement.go +++ b/ent/statement/statement.go @@ -1,4 +1,4 @@ -// Code generated by entc, DO NOT EDIT. +// Code generated by ent, DO NOT EDIT. package statement diff --git a/ent/statement/where.go b/ent/statement/where.go index cdea0799..abc2d5a0 100644 --- a/ent/statement/where.go +++ b/ent/statement/where.go @@ -1,4 +1,4 @@ -// Code generated by entc, DO NOT EDIT. +// Code generated by ent, DO NOT EDIT. package statement @@ -32,13 +32,7 @@ func IDNEQ(id int) predicate.Statement { // IDIn applies the In predicate on the ID field. func IDIn(ids ...int) predicate.Statement { return predicate.Statement(func(s *sql.Selector) { - // if not arguments were provided, append the FALSE constants, - // since we can't apply "IN ()". This will make this predicate falsy. - if len(ids) == 0 { - s.Where(sql.False()) - return - } - v := make([]interface{}, len(ids)) + v := make([]any, len(ids)) for i := range v { v[i] = ids[i] } @@ -49,13 +43,7 @@ func IDIn(ids ...int) predicate.Statement { // IDNotIn applies the NotIn predicate on the ID field. func IDNotIn(ids ...int) predicate.Statement { return predicate.Statement(func(s *sql.Selector) { - // if not arguments were provided, append the FALSE constants, - // since we can't apply "IN ()". This will make this predicate falsy. - if len(ids) == 0 { - s.Where(sql.False()) - return - } - v := make([]interface{}, len(ids)) + v := make([]any, len(ids)) for i := range v { v[i] = ids[i] } @@ -114,34 +102,22 @@ func PredicateNEQ(v string) predicate.Statement { // PredicateIn applies the In predicate on the "predicate" field. func PredicateIn(vs ...string) predicate.Statement { - v := make([]interface{}, len(vs)) + v := make([]any, len(vs)) for i := range v { v[i] = vs[i] } return predicate.Statement(func(s *sql.Selector) { - // if not arguments were provided, append the FALSE constants, - // since we can't apply "IN ()". This will make this predicate falsy. - if len(v) == 0 { - s.Where(sql.False()) - return - } s.Where(sql.In(s.C(FieldPredicate), v...)) }) } // PredicateNotIn applies the NotIn predicate on the "predicate" field. func PredicateNotIn(vs ...string) predicate.Statement { - v := make([]interface{}, len(vs)) + v := make([]any, len(vs)) for i := range v { v[i] = vs[i] } return predicate.Statement(func(s *sql.Selector) { - // if not arguments were provided, append the FALSE constants, - // since we can't apply "IN ()". This will make this predicate falsy. - if len(v) == 0 { - s.Where(sql.False()) - return - } s.Where(sql.NotIn(s.C(FieldPredicate), v...)) }) } diff --git a/ent/statement_create.go b/ent/statement_create.go index 7c6b756c..aa43fb02 100644 --- a/ent/statement_create.go +++ b/ent/statement_create.go @@ -1,4 +1,4 @@ -// Code generated by entc, DO NOT EDIT. +// Code generated by ent, DO NOT EDIT. package ent @@ -168,7 +168,7 @@ func (sc *StatementCreate) sqlSave(ctx context.Context) (*Statement, error) { _node, _spec := sc.createSpec() if err := sqlgraph.CreateNode(ctx, sc.driver, _spec); err != nil { if sqlgraph.IsConstraintError(err) { - err = &ConstraintError{err.Error(), err} + err = &ConstraintError{msg: err.Error(), wrap: err} } return nil, err } @@ -288,7 +288,7 @@ func (scb *StatementCreateBulk) Save(ctx context.Context) ([]*Statement, error) // Invoke the actual operation on the latest mutation in the chain. if err = sqlgraph.BatchCreate(ctx, scb.driver, spec); err != nil { if sqlgraph.IsConstraintError(err) { - err = &ConstraintError{err.Error(), err} + err = &ConstraintError{msg: err.Error(), wrap: err} } } } diff --git a/ent/statement_delete.go b/ent/statement_delete.go index a4811e89..6f7b926f 100644 --- a/ent/statement_delete.go +++ b/ent/statement_delete.go @@ -1,4 +1,4 @@ -// Code generated by entc, DO NOT EDIT. +// Code generated by ent, DO NOT EDIT. package ent @@ -84,7 +84,11 @@ func (sd *StatementDelete) sqlExec(ctx context.Context) (int, error) { } } } - return sqlgraph.DeleteNodes(ctx, sd.driver, _spec) + affected, err := sqlgraph.DeleteNodes(ctx, sd.driver, _spec) + if err != nil && sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return affected, err } // StatementDeleteOne is the builder for deleting a single Statement entity. diff --git a/ent/statement_query.go b/ent/statement_query.go index 3966c83a..13f8472e 100644 --- a/ent/statement_query.go +++ b/ent/statement_query.go @@ -1,4 +1,4 @@ -// Code generated by entc, DO NOT EDIT. +// Code generated by ent, DO NOT EDIT. package ent @@ -21,13 +21,12 @@ import ( // StatementQuery is the builder for querying Statement entities. type StatementQuery struct { config - limit *int - offset *int - unique *bool - order []OrderFunc - fields []string - predicates []predicate.Statement - // eager-loading edges. + limit *int + offset *int + unique *bool + order []OrderFunc + fields []string + predicates []predicate.Statement withSubjects *SubjectQuery withAttestationCollections *AttestationCollectionQuery withDsse *DsseQuery @@ -433,10 +432,10 @@ func (sq *StatementQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*St sq.withDsse != nil, } ) - _spec.ScanValues = func(columns []string) ([]interface{}, error) { + _spec.ScanValues = func(columns []string) ([]any, error) { return (*Statement).scanValues(nil, columns) } - _spec.Assign = func(columns []string, values []interface{}) error { + _spec.Assign = func(columns []string, values []any) error { node := &Statement{config: sq.config} nodes = append(nodes, node) node.Edges.loadedTypes = loadedTypes @@ -454,93 +453,26 @@ func (sq *StatementQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*St if len(nodes) == 0 { return nodes, nil } - if query := sq.withSubjects; query != nil { - fks := make([]driver.Value, 0, len(nodes)) - nodeids := make(map[int]*Statement) - for i := range nodes { - fks = append(fks, nodes[i].ID) - nodeids[nodes[i].ID] = nodes[i] - nodes[i].Edges.Subjects = []*Subject{} - } - query.withFKs = true - query.Where(predicate.Subject(func(s *sql.Selector) { - s.Where(sql.InValues(statement.SubjectsColumn, fks...)) - })) - neighbors, err := query.All(ctx) - if err != nil { + if err := sq.loadSubjects(ctx, query, nodes, + func(n *Statement) { n.Edges.Subjects = []*Subject{} }, + func(n *Statement, e *Subject) { n.Edges.Subjects = append(n.Edges.Subjects, e) }); err != nil { return nil, err } - for _, n := range neighbors { - fk := n.statement_subjects - if fk == nil { - return nil, fmt.Errorf(`foreign-key "statement_subjects" is nil for node %v`, n.ID) - } - node, ok := nodeids[*fk] - if !ok { - return nil, fmt.Errorf(`unexpected foreign-key "statement_subjects" returned %v for node %v`, *fk, n.ID) - } - node.Edges.Subjects = append(node.Edges.Subjects, n) - } } - if query := sq.withAttestationCollections; query != nil { - fks := make([]driver.Value, 0, len(nodes)) - nodeids := make(map[int]*Statement) - for i := range nodes { - fks = append(fks, nodes[i].ID) - nodeids[nodes[i].ID] = nodes[i] - } - query.withFKs = true - query.Where(predicate.AttestationCollection(func(s *sql.Selector) { - s.Where(sql.InValues(statement.AttestationCollectionsColumn, fks...)) - })) - neighbors, err := query.All(ctx) - if err != nil { + if err := sq.loadAttestationCollections(ctx, query, nodes, nil, + func(n *Statement, e *AttestationCollection) { n.Edges.AttestationCollections = e }); err != nil { return nil, err } - for _, n := range neighbors { - fk := n.statement_attestation_collections - if fk == nil { - return nil, fmt.Errorf(`foreign-key "statement_attestation_collections" is nil for node %v`, n.ID) - } - node, ok := nodeids[*fk] - if !ok { - return nil, fmt.Errorf(`unexpected foreign-key "statement_attestation_collections" returned %v for node %v`, *fk, n.ID) - } - node.Edges.AttestationCollections = n - } } - if query := sq.withDsse; query != nil { - fks := make([]driver.Value, 0, len(nodes)) - nodeids := make(map[int]*Statement) - for i := range nodes { - fks = append(fks, nodes[i].ID) - nodeids[nodes[i].ID] = nodes[i] - nodes[i].Edges.Dsse = []*Dsse{} - } - query.withFKs = true - query.Where(predicate.Dsse(func(s *sql.Selector) { - s.Where(sql.InValues(statement.DsseColumn, fks...)) - })) - neighbors, err := query.All(ctx) - if err != nil { + if err := sq.loadDsse(ctx, query, nodes, + func(n *Statement) { n.Edges.Dsse = []*Dsse{} }, + func(n *Statement, e *Dsse) { n.Edges.Dsse = append(n.Edges.Dsse, e) }); err != nil { return nil, err } - for _, n := range neighbors { - fk := n.dsse_statement - if fk == nil { - return nil, fmt.Errorf(`foreign-key "dsse_statement" is nil for node %v`, n.ID) - } - node, ok := nodeids[*fk] - if !ok { - return nil, fmt.Errorf(`unexpected foreign-key "dsse_statement" returned %v for node %v`, *fk, n.ID) - } - node.Edges.Dsse = append(node.Edges.Dsse, n) - } } - for i := range sq.loadTotal { if err := sq.loadTotal[i](ctx, nodes); err != nil { return nil, err @@ -549,6 +481,97 @@ func (sq *StatementQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*St return nodes, nil } +func (sq *StatementQuery) loadSubjects(ctx context.Context, query *SubjectQuery, nodes []*Statement, init func(*Statement), assign func(*Statement, *Subject)) error { + fks := make([]driver.Value, 0, len(nodes)) + nodeids := make(map[int]*Statement) + 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.Subject(func(s *sql.Selector) { + s.Where(sql.InValues(statement.SubjectsColumn, fks...)) + })) + neighbors, err := query.All(ctx) + if err != nil { + return err + } + for _, n := range neighbors { + fk := n.statement_subjects + if fk == nil { + return fmt.Errorf(`foreign-key "statement_subjects" is nil for node %v`, n.ID) + } + node, ok := nodeids[*fk] + if !ok { + return fmt.Errorf(`unexpected foreign-key "statement_subjects" returned %v for node %v`, *fk, n.ID) + } + assign(node, n) + } + return nil +} +func (sq *StatementQuery) loadAttestationCollections(ctx context.Context, query *AttestationCollectionQuery, nodes []*Statement, init func(*Statement), assign func(*Statement, *AttestationCollection)) error { + fks := make([]driver.Value, 0, len(nodes)) + nodeids := make(map[int]*Statement) + for i := range nodes { + fks = append(fks, nodes[i].ID) + nodeids[nodes[i].ID] = nodes[i] + } + query.withFKs = true + query.Where(predicate.AttestationCollection(func(s *sql.Selector) { + s.Where(sql.InValues(statement.AttestationCollectionsColumn, fks...)) + })) + neighbors, err := query.All(ctx) + if err != nil { + return err + } + for _, n := range neighbors { + fk := n.statement_attestation_collections + if fk == nil { + return fmt.Errorf(`foreign-key "statement_attestation_collections" is nil for node %v`, n.ID) + } + node, ok := nodeids[*fk] + if !ok { + return fmt.Errorf(`unexpected foreign-key "statement_attestation_collections" returned %v for node %v`, *fk, n.ID) + } + assign(node, n) + } + return nil +} +func (sq *StatementQuery) loadDsse(ctx context.Context, query *DsseQuery, nodes []*Statement, init func(*Statement), assign func(*Statement, *Dsse)) error { + fks := make([]driver.Value, 0, len(nodes)) + nodeids := make(map[int]*Statement) + 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.Dsse(func(s *sql.Selector) { + s.Where(sql.InValues(statement.DsseColumn, fks...)) + })) + neighbors, err := query.All(ctx) + if err != nil { + return err + } + for _, n := range neighbors { + fk := n.dsse_statement + if fk == nil { + return fmt.Errorf(`foreign-key "dsse_statement" is nil for node %v`, n.ID) + } + node, ok := nodeids[*fk] + if !ok { + return fmt.Errorf(`unexpected foreign-key "dsse_statement" returned %v for node %v`, *fk, n.ID) + } + assign(node, n) + } + return nil +} + func (sq *StatementQuery) sqlCount(ctx context.Context) (int, error) { _spec := sq.querySpec() if len(sq.modifiers) > 0 { @@ -562,11 +585,14 @@ func (sq *StatementQuery) sqlCount(ctx context.Context) (int, error) { } func (sq *StatementQuery) sqlExist(ctx context.Context) (bool, error) { - n, err := sq.sqlCount(ctx) - if err != nil { + switch _, err := sq.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 (sq *StatementQuery) querySpec() *sqlgraph.QuerySpec { @@ -667,7 +693,7 @@ func (sgb *StatementGroupBy) Aggregate(fns ...AggregateFunc) *StatementGroupBy { } // Scan applies the group-by query and scans the result into the given value. -func (sgb *StatementGroupBy) Scan(ctx context.Context, v interface{}) error { +func (sgb *StatementGroupBy) Scan(ctx context.Context, v any) error { query, err := sgb.path(ctx) if err != nil { return err @@ -676,7 +702,7 @@ func (sgb *StatementGroupBy) Scan(ctx context.Context, v interface{}) error { return sgb.sqlScan(ctx, v) } -func (sgb *StatementGroupBy) sqlScan(ctx context.Context, v interface{}) error { +func (sgb *StatementGroupBy) sqlScan(ctx context.Context, v any) error { for _, f := range sgb.fields { if !statement.ValidColumn(f) { return &ValidationError{Name: f, err: fmt.Errorf("invalid field %q for group-by", f)} @@ -723,7 +749,7 @@ type StatementSelect struct { } // Scan applies the selector query and scans the result into the given value. -func (ss *StatementSelect) Scan(ctx context.Context, v interface{}) error { +func (ss *StatementSelect) Scan(ctx context.Context, v any) error { if err := ss.prepareQuery(ctx); err != nil { return err } @@ -731,7 +757,7 @@ func (ss *StatementSelect) Scan(ctx context.Context, v interface{}) error { return ss.sqlScan(ctx, v) } -func (ss *StatementSelect) sqlScan(ctx context.Context, v interface{}) error { +func (ss *StatementSelect) sqlScan(ctx context.Context, v any) error { rows := &sql.Rows{} query, args := ss.sql.Query() if err := ss.driver.Query(ctx, query, args, rows); err != nil { diff --git a/ent/statement_update.go b/ent/statement_update.go index 7a84dba7..d64a579c 100644 --- a/ent/statement_update.go +++ b/ent/statement_update.go @@ -1,4 +1,4 @@ -// Code generated by entc, DO NOT EDIT. +// Code generated by ent, DO NOT EDIT. package ent @@ -380,7 +380,7 @@ func (su *StatementUpdate) sqlSave(ctx context.Context) (n int, err error) { if _, ok := err.(*sqlgraph.NotFoundError); ok { err = &NotFoundError{statement.Label} } else if sqlgraph.IsConstraintError(err) { - err = &ConstraintError{err.Error(), err} + err = &ConstraintError{msg: err.Error(), wrap: err} } return 0, err } @@ -778,7 +778,7 @@ func (suo *StatementUpdateOne) sqlSave(ctx context.Context) (_node *Statement, e if _, ok := err.(*sqlgraph.NotFoundError); ok { err = &NotFoundError{statement.Label} } else if sqlgraph.IsConstraintError(err) { - err = &ConstraintError{err.Error(), err} + err = &ConstraintError{msg: err.Error(), wrap: err} } return nil, err } diff --git a/ent/subject.go b/ent/subject.go index ac3a4b50..e08a4518 100644 --- a/ent/subject.go +++ b/ent/subject.go @@ -1,4 +1,4 @@ -// Code generated by entc, DO NOT EDIT. +// Code generated by ent, DO NOT EDIT. package ent @@ -51,8 +51,7 @@ func (e SubjectEdges) SubjectDigestsOrErr() ([]*SubjectDigest, error) { func (e SubjectEdges) StatementOrErr() (*Statement, error) { if e.loadedTypes[1] { if e.Statement == nil { - // The edge statement was loaded in eager-loading, - // but was not found. + // Edge was loaded but was not found. return nil, &NotFoundError{label: statement.Label} } return e.Statement, nil @@ -61,8 +60,8 @@ func (e SubjectEdges) StatementOrErr() (*Statement, error) { } // scanValues returns the types for scanning values from sql.Rows. -func (*Subject) scanValues(columns []string) ([]interface{}, error) { - values := make([]interface{}, len(columns)) +func (*Subject) scanValues(columns []string) ([]any, error) { + values := make([]any, len(columns)) for i := range columns { switch columns[i] { case subject.FieldID: @@ -80,7 +79,7 @@ func (*Subject) scanValues(columns []string) ([]interface{}, error) { // assignValues assigns the values that were returned from sql.Rows (after scanning) // to the Subject fields. -func (s *Subject) assignValues(columns []string, values []interface{}) error { +func (s *Subject) assignValues(columns []string, values []any) error { if m, n := len(values), len(columns); m < n { return fmt.Errorf("mismatch number of scan values: %d != %d", m, n) } @@ -130,11 +129,11 @@ func (s *Subject) Update() *SubjectUpdateOne { // Unwrap unwraps the Subject entity that was returned from a transaction after it was closed, // so that all future queries will be executed through the driver which created the transaction. func (s *Subject) Unwrap() *Subject { - tx, ok := s.config.driver.(*txDriver) + _tx, ok := s.config.driver.(*txDriver) if !ok { panic("ent: Subject is not a transactional entity") } - s.config.driver = tx.drv + s.config.driver = _tx.drv return s } diff --git a/ent/subject/subject.go b/ent/subject/subject.go index 3794f443..02a613ca 100644 --- a/ent/subject/subject.go +++ b/ent/subject/subject.go @@ -1,4 +1,4 @@ -// Code generated by entc, DO NOT EDIT. +// Code generated by ent, DO NOT EDIT. package subject diff --git a/ent/subject/where.go b/ent/subject/where.go index 5da59052..64e326b0 100644 --- a/ent/subject/where.go +++ b/ent/subject/where.go @@ -1,4 +1,4 @@ -// Code generated by entc, DO NOT EDIT. +// Code generated by ent, DO NOT EDIT. package subject @@ -32,13 +32,7 @@ func IDNEQ(id int) predicate.Subject { // IDIn applies the In predicate on the ID field. func IDIn(ids ...int) predicate.Subject { return predicate.Subject(func(s *sql.Selector) { - // if not arguments were provided, append the FALSE constants, - // since we can't apply "IN ()". This will make this predicate falsy. - if len(ids) == 0 { - s.Where(sql.False()) - return - } - v := make([]interface{}, len(ids)) + v := make([]any, len(ids)) for i := range v { v[i] = ids[i] } @@ -49,13 +43,7 @@ func IDIn(ids ...int) predicate.Subject { // IDNotIn applies the NotIn predicate on the ID field. func IDNotIn(ids ...int) predicate.Subject { return predicate.Subject(func(s *sql.Selector) { - // if not arguments were provided, append the FALSE constants, - // since we can't apply "IN ()". This will make this predicate falsy. - if len(ids) == 0 { - s.Where(sql.False()) - return - } - v := make([]interface{}, len(ids)) + v := make([]any, len(ids)) for i := range v { v[i] = ids[i] } @@ -114,34 +102,22 @@ func NameNEQ(v string) predicate.Subject { // NameIn applies the In predicate on the "name" field. func NameIn(vs ...string) predicate.Subject { - v := make([]interface{}, len(vs)) + v := make([]any, len(vs)) for i := range v { v[i] = vs[i] } return predicate.Subject(func(s *sql.Selector) { - // if not arguments were provided, append the FALSE constants, - // since we can't apply "IN ()". This will make this predicate falsy. - if len(v) == 0 { - s.Where(sql.False()) - return - } s.Where(sql.In(s.C(FieldName), v...)) }) } // NameNotIn applies the NotIn predicate on the "name" field. func NameNotIn(vs ...string) predicate.Subject { - v := make([]interface{}, len(vs)) + v := make([]any, len(vs)) for i := range v { v[i] = vs[i] } return predicate.Subject(func(s *sql.Selector) { - // if not arguments were provided, append the FALSE constants, - // since we can't apply "IN ()". This will make this predicate falsy. - if len(v) == 0 { - s.Where(sql.False()) - return - } s.Where(sql.NotIn(s.C(FieldName), v...)) }) } diff --git a/ent/subject_create.go b/ent/subject_create.go index 408d8370..f3c44636 100644 --- a/ent/subject_create.go +++ b/ent/subject_create.go @@ -1,4 +1,4 @@ -// Code generated by entc, DO NOT EDIT. +// Code generated by ent, DO NOT EDIT. package ent @@ -152,7 +152,7 @@ func (sc *SubjectCreate) sqlSave(ctx context.Context) (*Subject, error) { _node, _spec := sc.createSpec() if err := sqlgraph.CreateNode(ctx, sc.driver, _spec); err != nil { if sqlgraph.IsConstraintError(err) { - err = &ConstraintError{err.Error(), err} + err = &ConstraintError{msg: err.Error(), wrap: err} } return nil, err } @@ -254,7 +254,7 @@ func (scb *SubjectCreateBulk) Save(ctx context.Context) ([]*Subject, error) { // Invoke the actual operation on the latest mutation in the chain. if err = sqlgraph.BatchCreate(ctx, scb.driver, spec); err != nil { if sqlgraph.IsConstraintError(err) { - err = &ConstraintError{err.Error(), err} + err = &ConstraintError{msg: err.Error(), wrap: err} } } } diff --git a/ent/subject_delete.go b/ent/subject_delete.go index d55eab21..f8f6bb23 100644 --- a/ent/subject_delete.go +++ b/ent/subject_delete.go @@ -1,4 +1,4 @@ -// Code generated by entc, DO NOT EDIT. +// Code generated by ent, DO NOT EDIT. package ent @@ -84,7 +84,11 @@ func (sd *SubjectDelete) sqlExec(ctx context.Context) (int, error) { } } } - return sqlgraph.DeleteNodes(ctx, sd.driver, _spec) + affected, err := sqlgraph.DeleteNodes(ctx, sd.driver, _spec) + if err != nil && sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return affected, err } // SubjectDeleteOne is the builder for deleting a single Subject entity. diff --git a/ent/subject_query.go b/ent/subject_query.go index 52c493b3..05306655 100644 --- a/ent/subject_query.go +++ b/ent/subject_query.go @@ -1,4 +1,4 @@ -// Code generated by entc, DO NOT EDIT. +// Code generated by ent, DO NOT EDIT. package ent @@ -20,13 +20,12 @@ import ( // SubjectQuery is the builder for querying Subject entities. type SubjectQuery struct { config - limit *int - offset *int - unique *bool - order []OrderFunc - fields []string - predicates []predicate.Subject - // eager-loading edges. + limit *int + offset *int + unique *bool + order []OrderFunc + fields []string + predicates []predicate.Subject withSubjectDigests *SubjectDigestQuery withStatement *StatementQuery withFKs bool @@ -404,10 +403,10 @@ func (sq *SubjectQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Subj if withFKs { _spec.Node.Columns = append(_spec.Node.Columns, subject.ForeignKeys...) } - _spec.ScanValues = func(columns []string) ([]interface{}, error) { + _spec.ScanValues = func(columns []string) ([]any, error) { return (*Subject).scanValues(nil, columns) } - _spec.Assign = func(columns []string, values []interface{}) error { + _spec.Assign = func(columns []string, values []any) error { node := &Subject{config: sq.config} nodes = append(nodes, node) node.Edges.loadedTypes = loadedTypes @@ -425,65 +424,19 @@ func (sq *SubjectQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Subj if len(nodes) == 0 { return nodes, nil } - if query := sq.withSubjectDigests; query != nil { - fks := make([]driver.Value, 0, len(nodes)) - nodeids := make(map[int]*Subject) - for i := range nodes { - fks = append(fks, nodes[i].ID) - nodeids[nodes[i].ID] = nodes[i] - nodes[i].Edges.SubjectDigests = []*SubjectDigest{} - } - query.withFKs = true - query.Where(predicate.SubjectDigest(func(s *sql.Selector) { - s.Where(sql.InValues(subject.SubjectDigestsColumn, fks...)) - })) - neighbors, err := query.All(ctx) - if err != nil { + if err := sq.loadSubjectDigests(ctx, query, nodes, + func(n *Subject) { n.Edges.SubjectDigests = []*SubjectDigest{} }, + func(n *Subject, e *SubjectDigest) { n.Edges.SubjectDigests = append(n.Edges.SubjectDigests, e) }); err != nil { return nil, err } - for _, n := range neighbors { - fk := n.subject_subject_digests - if fk == nil { - return nil, fmt.Errorf(`foreign-key "subject_subject_digests" is nil for node %v`, n.ID) - } - node, ok := nodeids[*fk] - if !ok { - return nil, fmt.Errorf(`unexpected foreign-key "subject_subject_digests" returned %v for node %v`, *fk, n.ID) - } - node.Edges.SubjectDigests = append(node.Edges.SubjectDigests, n) - } } - if query := sq.withStatement; query != nil { - ids := make([]int, 0, len(nodes)) - nodeids := make(map[int][]*Subject) - for i := range nodes { - if nodes[i].statement_subjects == nil { - continue - } - fk := *nodes[i].statement_subjects - if _, ok := nodeids[fk]; !ok { - ids = append(ids, fk) - } - nodeids[fk] = append(nodeids[fk], nodes[i]) - } - query.Where(statement.IDIn(ids...)) - neighbors, err := query.All(ctx) - if err != nil { + if err := sq.loadStatement(ctx, query, nodes, nil, + func(n *Subject, e *Statement) { n.Edges.Statement = e }); err != nil { return nil, err } - for _, n := range neighbors { - nodes, ok := nodeids[n.ID] - if !ok { - return nil, fmt.Errorf(`unexpected foreign-key "statement_subjects" returned %v`, n.ID) - } - for i := range nodes { - nodes[i].Edges.Statement = n - } - } } - for i := range sq.loadTotal { if err := sq.loadTotal[i](ctx, nodes); err != nil { return nil, err @@ -492,6 +445,67 @@ func (sq *SubjectQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Subj return nodes, nil } +func (sq *SubjectQuery) loadSubjectDigests(ctx context.Context, query *SubjectDigestQuery, nodes []*Subject, init func(*Subject), assign func(*Subject, *SubjectDigest)) error { + fks := make([]driver.Value, 0, len(nodes)) + nodeids := make(map[int]*Subject) + 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.SubjectDigest(func(s *sql.Selector) { + s.Where(sql.InValues(subject.SubjectDigestsColumn, fks...)) + })) + neighbors, err := query.All(ctx) + if err != nil { + return err + } + for _, n := range neighbors { + fk := n.subject_subject_digests + if fk == nil { + return fmt.Errorf(`foreign-key "subject_subject_digests" is nil for node %v`, n.ID) + } + node, ok := nodeids[*fk] + if !ok { + return fmt.Errorf(`unexpected foreign-key "subject_subject_digests" returned %v for node %v`, *fk, n.ID) + } + assign(node, n) + } + return nil +} +func (sq *SubjectQuery) loadStatement(ctx context.Context, query *StatementQuery, nodes []*Subject, init func(*Subject), assign func(*Subject, *Statement)) error { + ids := make([]int, 0, len(nodes)) + nodeids := make(map[int][]*Subject) + for i := range nodes { + if nodes[i].statement_subjects == nil { + continue + } + fk := *nodes[i].statement_subjects + if _, ok := nodeids[fk]; !ok { + ids = append(ids, fk) + } + nodeids[fk] = append(nodeids[fk], nodes[i]) + } + query.Where(statement.IDIn(ids...)) + neighbors, err := query.All(ctx) + if err != nil { + return err + } + for _, n := range neighbors { + nodes, ok := nodeids[n.ID] + if !ok { + return fmt.Errorf(`unexpected foreign-key "statement_subjects" returned %v`, n.ID) + } + for i := range nodes { + assign(nodes[i], n) + } + } + return nil +} + func (sq *SubjectQuery) sqlCount(ctx context.Context) (int, error) { _spec := sq.querySpec() if len(sq.modifiers) > 0 { @@ -505,11 +519,14 @@ func (sq *SubjectQuery) sqlCount(ctx context.Context) (int, error) { } func (sq *SubjectQuery) sqlExist(ctx context.Context) (bool, error) { - n, err := sq.sqlCount(ctx) - if err != nil { + switch _, err := sq.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 (sq *SubjectQuery) querySpec() *sqlgraph.QuerySpec { @@ -610,7 +627,7 @@ func (sgb *SubjectGroupBy) Aggregate(fns ...AggregateFunc) *SubjectGroupBy { } // Scan applies the group-by query and scans the result into the given value. -func (sgb *SubjectGroupBy) Scan(ctx context.Context, v interface{}) error { +func (sgb *SubjectGroupBy) Scan(ctx context.Context, v any) error { query, err := sgb.path(ctx) if err != nil { return err @@ -619,7 +636,7 @@ func (sgb *SubjectGroupBy) Scan(ctx context.Context, v interface{}) error { return sgb.sqlScan(ctx, v) } -func (sgb *SubjectGroupBy) sqlScan(ctx context.Context, v interface{}) error { +func (sgb *SubjectGroupBy) sqlScan(ctx context.Context, v any) error { for _, f := range sgb.fields { if !subject.ValidColumn(f) { return &ValidationError{Name: f, err: fmt.Errorf("invalid field %q for group-by", f)} @@ -666,7 +683,7 @@ type SubjectSelect struct { } // Scan applies the selector query and scans the result into the given value. -func (ss *SubjectSelect) Scan(ctx context.Context, v interface{}) error { +func (ss *SubjectSelect) Scan(ctx context.Context, v any) error { if err := ss.prepareQuery(ctx); err != nil { return err } @@ -674,7 +691,7 @@ func (ss *SubjectSelect) Scan(ctx context.Context, v interface{}) error { return ss.sqlScan(ctx, v) } -func (ss *SubjectSelect) sqlScan(ctx context.Context, v interface{}) error { +func (ss *SubjectSelect) sqlScan(ctx context.Context, v any) error { rows := &sql.Rows{} query, args := ss.sql.Query() if err := ss.driver.Query(ctx, query, args, rows); err != nil { diff --git a/ent/subject_update.go b/ent/subject_update.go index 29acd748..f460b21e 100644 --- a/ent/subject_update.go +++ b/ent/subject_update.go @@ -1,4 +1,4 @@ -// Code generated by entc, DO NOT EDIT. +// Code generated by ent, DO NOT EDIT. package ent @@ -289,7 +289,7 @@ func (su *SubjectUpdate) sqlSave(ctx context.Context) (n int, err error) { if _, ok := err.(*sqlgraph.NotFoundError); ok { err = &NotFoundError{subject.Label} } else if sqlgraph.IsConstraintError(err) { - err = &ConstraintError{err.Error(), err} + err = &ConstraintError{msg: err.Error(), wrap: err} } return 0, err } @@ -597,7 +597,7 @@ func (suo *SubjectUpdateOne) sqlSave(ctx context.Context) (_node *Subject, err e if _, ok := err.(*sqlgraph.NotFoundError); ok { err = &NotFoundError{subject.Label} } else if sqlgraph.IsConstraintError(err) { - err = &ConstraintError{err.Error(), err} + err = &ConstraintError{msg: err.Error(), wrap: err} } return nil, err } diff --git a/ent/subjectdigest.go b/ent/subjectdigest.go index 049362f1..9ce642c0 100644 --- a/ent/subjectdigest.go +++ b/ent/subjectdigest.go @@ -1,4 +1,4 @@ -// Code generated by entc, DO NOT EDIT. +// Code generated by ent, DO NOT EDIT. package ent @@ -42,8 +42,7 @@ type SubjectDigestEdges struct { func (e SubjectDigestEdges) SubjectOrErr() (*Subject, error) { if e.loadedTypes[0] { if e.Subject == nil { - // The edge subject was loaded in eager-loading, - // but was not found. + // Edge was loaded but was not found. return nil, &NotFoundError{label: subject.Label} } return e.Subject, nil @@ -52,8 +51,8 @@ func (e SubjectDigestEdges) SubjectOrErr() (*Subject, error) { } // scanValues returns the types for scanning values from sql.Rows. -func (*SubjectDigest) scanValues(columns []string) ([]interface{}, error) { - values := make([]interface{}, len(columns)) +func (*SubjectDigest) scanValues(columns []string) ([]any, error) { + values := make([]any, len(columns)) for i := range columns { switch columns[i] { case subjectdigest.FieldID: @@ -71,7 +70,7 @@ func (*SubjectDigest) scanValues(columns []string) ([]interface{}, error) { // assignValues assigns the values that were returned from sql.Rows (after scanning) // to the SubjectDigest fields. -func (sd *SubjectDigest) assignValues(columns []string, values []interface{}) error { +func (sd *SubjectDigest) assignValues(columns []string, values []any) error { if m, n := len(values), len(columns); m < n { return fmt.Errorf("mismatch number of scan values: %d != %d", m, n) } @@ -122,11 +121,11 @@ func (sd *SubjectDigest) Update() *SubjectDigestUpdateOne { // Unwrap unwraps the SubjectDigest entity that was returned from a transaction after it was closed, // so that all future queries will be executed through the driver which created the transaction. func (sd *SubjectDigest) Unwrap() *SubjectDigest { - tx, ok := sd.config.driver.(*txDriver) + _tx, ok := sd.config.driver.(*txDriver) if !ok { panic("ent: SubjectDigest is not a transactional entity") } - sd.config.driver = tx.drv + sd.config.driver = _tx.drv return sd } diff --git a/ent/subjectdigest/subjectdigest.go b/ent/subjectdigest/subjectdigest.go index 3cfde892..8b546937 100644 --- a/ent/subjectdigest/subjectdigest.go +++ b/ent/subjectdigest/subjectdigest.go @@ -1,4 +1,4 @@ -// Code generated by entc, DO NOT EDIT. +// Code generated by ent, DO NOT EDIT. package subjectdigest diff --git a/ent/subjectdigest/where.go b/ent/subjectdigest/where.go index f00d219c..0a85b4f7 100644 --- a/ent/subjectdigest/where.go +++ b/ent/subjectdigest/where.go @@ -1,4 +1,4 @@ -// Code generated by entc, DO NOT EDIT. +// Code generated by ent, DO NOT EDIT. package subjectdigest @@ -32,13 +32,7 @@ func IDNEQ(id int) predicate.SubjectDigest { // IDIn applies the In predicate on the ID field. func IDIn(ids ...int) predicate.SubjectDigest { return predicate.SubjectDigest(func(s *sql.Selector) { - // if not arguments were provided, append the FALSE constants, - // since we can't apply "IN ()". This will make this predicate falsy. - if len(ids) == 0 { - s.Where(sql.False()) - return - } - v := make([]interface{}, len(ids)) + v := make([]any, len(ids)) for i := range v { v[i] = ids[i] } @@ -49,13 +43,7 @@ func IDIn(ids ...int) predicate.SubjectDigest { // IDNotIn applies the NotIn predicate on the ID field. func IDNotIn(ids ...int) predicate.SubjectDigest { return predicate.SubjectDigest(func(s *sql.Selector) { - // if not arguments were provided, append the FALSE constants, - // since we can't apply "IN ()". This will make this predicate falsy. - if len(ids) == 0 { - s.Where(sql.False()) - return - } - v := make([]interface{}, len(ids)) + v := make([]any, len(ids)) for i := range v { v[i] = ids[i] } @@ -121,34 +109,22 @@ func AlgorithmNEQ(v string) predicate.SubjectDigest { // AlgorithmIn applies the In predicate on the "algorithm" field. func AlgorithmIn(vs ...string) predicate.SubjectDigest { - v := make([]interface{}, len(vs)) + v := make([]any, len(vs)) for i := range v { v[i] = vs[i] } return predicate.SubjectDigest(func(s *sql.Selector) { - // if not arguments were provided, append the FALSE constants, - // since we can't apply "IN ()". This will make this predicate falsy. - if len(v) == 0 { - s.Where(sql.False()) - return - } s.Where(sql.In(s.C(FieldAlgorithm), v...)) }) } // AlgorithmNotIn applies the NotIn predicate on the "algorithm" field. func AlgorithmNotIn(vs ...string) predicate.SubjectDigest { - v := make([]interface{}, len(vs)) + v := make([]any, len(vs)) for i := range v { v[i] = vs[i] } return predicate.SubjectDigest(func(s *sql.Selector) { - // if not arguments were provided, append the FALSE constants, - // since we can't apply "IN ()". This will make this predicate falsy. - if len(v) == 0 { - s.Where(sql.False()) - return - } s.Where(sql.NotIn(s.C(FieldAlgorithm), v...)) }) } @@ -232,34 +208,22 @@ func ValueNEQ(v string) predicate.SubjectDigest { // ValueIn applies the In predicate on the "value" field. func ValueIn(vs ...string) predicate.SubjectDigest { - v := make([]interface{}, len(vs)) + v := make([]any, len(vs)) for i := range v { v[i] = vs[i] } return predicate.SubjectDigest(func(s *sql.Selector) { - // if not arguments were provided, append the FALSE constants, - // since we can't apply "IN ()". This will make this predicate falsy. - if len(v) == 0 { - s.Where(sql.False()) - return - } s.Where(sql.In(s.C(FieldValue), v...)) }) } // ValueNotIn applies the NotIn predicate on the "value" field. func ValueNotIn(vs ...string) predicate.SubjectDigest { - v := make([]interface{}, len(vs)) + v := make([]any, len(vs)) for i := range v { v[i] = vs[i] } return predicate.SubjectDigest(func(s *sql.Selector) { - // if not arguments were provided, append the FALSE constants, - // since we can't apply "IN ()". This will make this predicate falsy. - if len(v) == 0 { - s.Where(sql.False()) - return - } s.Where(sql.NotIn(s.C(FieldValue), v...)) }) } diff --git a/ent/subjectdigest_create.go b/ent/subjectdigest_create.go index f735305d..9a5cb53f 100644 --- a/ent/subjectdigest_create.go +++ b/ent/subjectdigest_create.go @@ -1,4 +1,4 @@ -// Code generated by entc, DO NOT EDIT. +// Code generated by ent, DO NOT EDIT. package ent @@ -150,7 +150,7 @@ func (sdc *SubjectDigestCreate) sqlSave(ctx context.Context) (*SubjectDigest, er _node, _spec := sdc.createSpec() if err := sqlgraph.CreateNode(ctx, sdc.driver, _spec); err != nil { if sqlgraph.IsConstraintError(err) { - err = &ConstraintError{err.Error(), err} + err = &ConstraintError{msg: err.Error(), wrap: err} } return nil, err } @@ -241,7 +241,7 @@ func (sdcb *SubjectDigestCreateBulk) Save(ctx context.Context) ([]*SubjectDigest // Invoke the actual operation on the latest mutation in the chain. if err = sqlgraph.BatchCreate(ctx, sdcb.driver, spec); err != nil { if sqlgraph.IsConstraintError(err) { - err = &ConstraintError{err.Error(), err} + err = &ConstraintError{msg: err.Error(), wrap: err} } } } diff --git a/ent/subjectdigest_delete.go b/ent/subjectdigest_delete.go index 8bcfc115..0ec837f5 100644 --- a/ent/subjectdigest_delete.go +++ b/ent/subjectdigest_delete.go @@ -1,4 +1,4 @@ -// Code generated by entc, DO NOT EDIT. +// Code generated by ent, DO NOT EDIT. package ent @@ -84,7 +84,11 @@ func (sdd *SubjectDigestDelete) sqlExec(ctx context.Context) (int, error) { } } } - return sqlgraph.DeleteNodes(ctx, sdd.driver, _spec) + affected, err := sqlgraph.DeleteNodes(ctx, sdd.driver, _spec) + if err != nil && sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return affected, err } // SubjectDigestDeleteOne is the builder for deleting a single SubjectDigest entity. diff --git a/ent/subjectdigest_query.go b/ent/subjectdigest_query.go index 376c42a7..1dc5c5cd 100644 --- a/ent/subjectdigest_query.go +++ b/ent/subjectdigest_query.go @@ -1,4 +1,4 @@ -// Code generated by entc, DO NOT EDIT. +// Code generated by ent, DO NOT EDIT. package ent @@ -18,13 +18,12 @@ import ( // SubjectDigestQuery is the builder for querying SubjectDigest entities. type SubjectDigestQuery struct { config - limit *int - offset *int - unique *bool - order []OrderFunc - fields []string - predicates []predicate.SubjectDigest - // eager-loading edges. + limit *int + offset *int + unique *bool + order []OrderFunc + fields []string + predicates []predicate.SubjectDigest withSubject *SubjectQuery withFKs bool modifiers []func(*sql.Selector) @@ -366,10 +365,10 @@ func (sdq *SubjectDigestQuery) sqlAll(ctx context.Context, hooks ...queryHook) ( if withFKs { _spec.Node.Columns = append(_spec.Node.Columns, subjectdigest.ForeignKeys...) } - _spec.ScanValues = func(columns []string) ([]interface{}, error) { + _spec.ScanValues = func(columns []string) ([]any, error) { return (*SubjectDigest).scanValues(nil, columns) } - _spec.Assign = func(columns []string, values []interface{}) error { + _spec.Assign = func(columns []string, values []any) error { node := &SubjectDigest{config: sdq.config} nodes = append(nodes, node) node.Edges.loadedTypes = loadedTypes @@ -387,36 +386,12 @@ func (sdq *SubjectDigestQuery) sqlAll(ctx context.Context, hooks ...queryHook) ( if len(nodes) == 0 { return nodes, nil } - if query := sdq.withSubject; query != nil { - ids := make([]int, 0, len(nodes)) - nodeids := make(map[int][]*SubjectDigest) - for i := range nodes { - if nodes[i].subject_subject_digests == nil { - continue - } - fk := *nodes[i].subject_subject_digests - if _, ok := nodeids[fk]; !ok { - ids = append(ids, fk) - } - nodeids[fk] = append(nodeids[fk], nodes[i]) - } - query.Where(subject.IDIn(ids...)) - neighbors, err := query.All(ctx) - if err != nil { + if err := sdq.loadSubject(ctx, query, nodes, nil, + func(n *SubjectDigest, e *Subject) { n.Edges.Subject = e }); err != nil { return nil, err } - for _, n := range neighbors { - nodes, ok := nodeids[n.ID] - if !ok { - return nil, fmt.Errorf(`unexpected foreign-key "subject_subject_digests" returned %v`, n.ID) - } - for i := range nodes { - nodes[i].Edges.Subject = n - } - } } - for i := range sdq.loadTotal { if err := sdq.loadTotal[i](ctx, nodes); err != nil { return nil, err @@ -425,6 +400,36 @@ func (sdq *SubjectDigestQuery) sqlAll(ctx context.Context, hooks ...queryHook) ( return nodes, nil } +func (sdq *SubjectDigestQuery) loadSubject(ctx context.Context, query *SubjectQuery, nodes []*SubjectDigest, init func(*SubjectDigest), assign func(*SubjectDigest, *Subject)) error { + ids := make([]int, 0, len(nodes)) + nodeids := make(map[int][]*SubjectDigest) + for i := range nodes { + if nodes[i].subject_subject_digests == nil { + continue + } + fk := *nodes[i].subject_subject_digests + if _, ok := nodeids[fk]; !ok { + ids = append(ids, fk) + } + nodeids[fk] = append(nodeids[fk], nodes[i]) + } + query.Where(subject.IDIn(ids...)) + neighbors, err := query.All(ctx) + if err != nil { + return err + } + for _, n := range neighbors { + nodes, ok := nodeids[n.ID] + if !ok { + return fmt.Errorf(`unexpected foreign-key "subject_subject_digests" returned %v`, n.ID) + } + for i := range nodes { + assign(nodes[i], n) + } + } + return nil +} + func (sdq *SubjectDigestQuery) sqlCount(ctx context.Context) (int, error) { _spec := sdq.querySpec() if len(sdq.modifiers) > 0 { @@ -438,11 +443,14 @@ func (sdq *SubjectDigestQuery) sqlCount(ctx context.Context) (int, error) { } func (sdq *SubjectDigestQuery) sqlExist(ctx context.Context) (bool, error) { - n, err := sdq.sqlCount(ctx) - if err != nil { + switch _, err := sdq.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 (sdq *SubjectDigestQuery) querySpec() *sqlgraph.QuerySpec { @@ -543,7 +551,7 @@ func (sdgb *SubjectDigestGroupBy) Aggregate(fns ...AggregateFunc) *SubjectDigest } // Scan applies the group-by query and scans the result into the given value. -func (sdgb *SubjectDigestGroupBy) Scan(ctx context.Context, v interface{}) error { +func (sdgb *SubjectDigestGroupBy) Scan(ctx context.Context, v any) error { query, err := sdgb.path(ctx) if err != nil { return err @@ -552,7 +560,7 @@ func (sdgb *SubjectDigestGroupBy) Scan(ctx context.Context, v interface{}) error return sdgb.sqlScan(ctx, v) } -func (sdgb *SubjectDigestGroupBy) sqlScan(ctx context.Context, v interface{}) error { +func (sdgb *SubjectDigestGroupBy) sqlScan(ctx context.Context, v any) error { for _, f := range sdgb.fields { if !subjectdigest.ValidColumn(f) { return &ValidationError{Name: f, err: fmt.Errorf("invalid field %q for group-by", f)} @@ -599,7 +607,7 @@ type SubjectDigestSelect struct { } // Scan applies the selector query and scans the result into the given value. -func (sds *SubjectDigestSelect) Scan(ctx context.Context, v interface{}) error { +func (sds *SubjectDigestSelect) Scan(ctx context.Context, v any) error { if err := sds.prepareQuery(ctx); err != nil { return err } @@ -607,7 +615,7 @@ func (sds *SubjectDigestSelect) Scan(ctx context.Context, v interface{}) error { return sds.sqlScan(ctx, v) } -func (sds *SubjectDigestSelect) sqlScan(ctx context.Context, v interface{}) error { +func (sds *SubjectDigestSelect) sqlScan(ctx context.Context, v any) error { rows := &sql.Rows{} query, args := sds.sql.Query() if err := sds.driver.Query(ctx, query, args, rows); err != nil { diff --git a/ent/subjectdigest_update.go b/ent/subjectdigest_update.go index 6d2fccf1..7ce42c4f 100644 --- a/ent/subjectdigest_update.go +++ b/ent/subjectdigest_update.go @@ -1,4 +1,4 @@ -// Code generated by entc, DO NOT EDIT. +// Code generated by ent, DO NOT EDIT. package ent @@ -216,7 +216,7 @@ func (sdu *SubjectDigestUpdate) sqlSave(ctx context.Context) (n int, err error) if _, ok := err.(*sqlgraph.NotFoundError); ok { err = &NotFoundError{subjectdigest.Label} } else if sqlgraph.IsConstraintError(err) { - err = &ConstraintError{err.Error(), err} + err = &ConstraintError{msg: err.Error(), wrap: err} } return 0, err } @@ -452,7 +452,7 @@ func (sduo *SubjectDigestUpdateOne) sqlSave(ctx context.Context) (_node *Subject if _, ok := err.(*sqlgraph.NotFoundError); ok { err = &NotFoundError{subjectdigest.Label} } else if sqlgraph.IsConstraintError(err) { - err = &ConstraintError{err.Error(), err} + err = &ConstraintError{msg: err.Error(), wrap: err} } return nil, err } diff --git a/ent/tx.go b/ent/tx.go index 09c1a03e..6c45c6ea 100644 --- a/ent/tx.go +++ b/ent/tx.go @@ -1,4 +1,4 @@ -// Code generated by entc, DO NOT EDIT. +// Code generated by ent, DO NOT EDIT. package ent @@ -219,12 +219,12 @@ func (*txDriver) Commit() error { return nil } func (*txDriver) Rollback() error { return nil } // Exec calls tx.Exec. -func (tx *txDriver) Exec(ctx context.Context, query string, args, v interface{}) error { +func (tx *txDriver) Exec(ctx context.Context, query string, args, v any) error { return tx.tx.Exec(ctx, query, args, v) } // Query calls tx.Query. -func (tx *txDriver) Query(ctx context.Context, query string, args, v interface{}) error { +func (tx *txDriver) Query(ctx context.Context, query string, args, v any) error { return tx.tx.Query(ctx, query, args, v) } diff --git a/go.mod b/go.mod index 7c9eff03..1ef139c0 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.19 require ( ariga.io/sqlcomment v0.0.0-20211020114721-6bb67a62a61a entgo.io/contrib v0.3.0 - entgo.io/ent v0.10.2-0.20220528091257-0917701f9114 + entgo.io/ent v0.11.3 github.com/99designs/gqlgen v0.17.5-0.20220428154617-9250f9ac1f90 github.com/antonfisher/nested-logrus-formatter v1.3.1 github.com/edwarnicke/gitoid v0.0.0-20220710194850-1be5bfda1f9d @@ -26,7 +26,7 @@ require ( ) require ( - ariga.io/atlas v0.4.2-0.20220524161107-b5b3f75b1034 // indirect + ariga.io/atlas v0.7.2-0.20220927111110-867ee0cca56a // indirect github.com/agext/levenshtein v1.2.1 // indirect github.com/agnivade/levenshtein v1.1.1 // indirect github.com/apparentlymart/go-textseg/v13 v13.0.0 // indirect @@ -44,7 +44,7 @@ require ( github.com/grpc-ecosystem/grpc-gateway/v2 v2.11.3 // indirect github.com/hashicorp/errwrap v1.1.0 // indirect github.com/hashicorp/golang-lru v0.5.4 // indirect - github.com/hashicorp/hcl/v2 v2.10.0 // indirect + github.com/hashicorp/hcl/v2 v2.13.0 // indirect github.com/inconshreveable/mousetrap v1.0.0 // indirect github.com/mitchellh/go-homedir v1.1.0 // indirect github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7 // indirect @@ -70,7 +70,7 @@ require ( golang.org/x/net v0.0.0-20220907135653-1e95f45603a7 // indirect golang.org/x/sys v0.0.0-20220908164124-27713097b956 // indirect golang.org/x/text v0.3.8-0.20211004125949-5bd84dd9b33b // indirect - golang.org/x/tools v0.1.12 // indirect + golang.org/x/tools v0.1.13-0.20220804200503-81c7dc4e4efa // indirect google.golang.org/genproto v0.0.0-20220908141613-51c1cc9bc6d0 // indirect google.golang.org/grpc v1.49.0 // indirect google.golang.org/protobuf v1.28.1 // indirect diff --git a/go.sum b/go.sum index a082dd09..6d9d3675 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,5 @@ -ariga.io/atlas v0.4.2-0.20220524161107-b5b3f75b1034 h1:cjqJPtwk6LhJdYaFgLHI0OuZyEspkxodoCLKeLdhJPk= -ariga.io/atlas v0.4.2-0.20220524161107-b5b3f75b1034/go.mod h1:CKqqlJeTdRfEmnHaCcNPHg8DD6GPx1TxNPZ1NFknKHU= +ariga.io/atlas v0.7.2-0.20220927111110-867ee0cca56a h1:6/nt4DODfgxzHTTg3tYy7YkVzruGQGZ/kRvXpA45KUo= +ariga.io/atlas v0.7.2-0.20220927111110-867ee0cca56a/go.mod h1:ft47uSh5hWGDCmQC9DsztZg6Xk+KagM5Ts/mZYKb9JE= ariga.io/sqlcomment v0.0.0-20211020114721-6bb67a62a61a h1:rF33ixWgZAVi2wg4oNljORY954kdaZxjhD2IStWr1JA= ariga.io/sqlcomment v0.0.0-20211020114721-6bb67a62a61a/go.mod h1:K6ubZj0yR5JIrCkzfKmZjz44O/dsCClLW8Yb5pttjzo= cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= @@ -37,8 +37,8 @@ cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9 dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= entgo.io/contrib v0.3.0 h1:dcWQAQkPVmOhYgZz20e18sgh3hkW8TV+0Y5QrFjFAsA= entgo.io/contrib v0.3.0/go.mod h1:mc3iYCB4aKIL3rcnrXN5C/+N4pKoOVnVUPlZvTbcdNk= -entgo.io/ent v0.10.2-0.20220528091257-0917701f9114 h1:BJ3c7WialDUYIM+lzdbON5UO8nWAgcccWde6AaqlK68= -entgo.io/ent v0.10.2-0.20220528091257-0917701f9114/go.mod h1:pevBAz5Fo4vFd4Glgi+XcNlviNLesimIjtR9QkZWBJ4= +entgo.io/ent v0.11.3 h1:F5FBGAWiDCGder7YT+lqMnyzXl6d0xU3xMBM/SO3CMc= +entgo.io/ent v0.11.3/go.mod h1:mvDhvynOzAsOe7anH7ynPPtMjA/eeXP96kAfweevyxc= github.com/99designs/gqlgen v0.17.5-0.20220428154617-9250f9ac1f90 h1:nGGP+sUJ6D3guzjVBgoH1PrZxoU4lUdfR/Q8THYrAJI= github.com/99designs/gqlgen v0.17.5-0.20220428154617-9250f9ac1f90/go.mod h1:SNpLVzaF37rRLSAXtu8FKVp5I4zycneMmFX6NT4XGSU= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= @@ -55,8 +55,6 @@ github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883/go.mod h1:rCTlJbsFo github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY= github.com/antonfisher/nested-logrus-formatter v1.3.1 h1:NFJIr+pzwv5QLHTPyKz9UMEoHck02Q9L0FP13b/xSbQ= github.com/antonfisher/nested-logrus-formatter v1.3.1/go.mod h1:6WTfyWFkBc9+zyBaKIqRrg/KwMqBbodBjgbHjDz7zjA= -github.com/apparentlymart/go-dump v0.0.0-20180507223929-23540a00eaa3/go.mod h1:oL81AME2rN47vu18xqj1S1jPIPuN7afo62yKTNn3XMM= -github.com/apparentlymart/go-textseg v1.0.0/go.mod h1:z96Txxhf3xSFMPmb5X/1W05FF/Nj9VFpLOpjS5yuumk= github.com/apparentlymart/go-textseg/v13 v13.0.0 h1:Y+KvPE1NYz0xl601PVImeQfFyEy6iT90AvPUL1NNfNw= github.com/apparentlymart/go-textseg/v13 v13.0.0/go.mod h1:ZK2fH7c4NqDTLtiYLvIkEghdlcqw7yxLeM89kiTRPUo= github.com/arbovm/levenshtein v0.0.0-20160628152529-48b4e1c0c4d0 h1:jfIu9sQUG6Ig+0+Ap1h4unLjW6YQJpKZVmUzxsD4E/Q= @@ -113,7 +111,6 @@ github.com/go-openapi/inflect v0.19.0/go.mod h1:lHpZVlpIQqLyKwJ4N+YSc9hchQy/i12f github.com/go-sql-driver/mysql v1.6.0 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfCHuOE= github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= github.com/go-test/deep v1.0.3 h1:ZrJSEWsXzPOxaZnFteGEfooLba+ju3FYIbOrS+rQd68= -github.com/go-test/deep v1.0.3/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= github.com/golang/glog v1.0.0 h1:nfP3RFugxnNRyKgeWd4oI1nYvXpxrx8ck8ZrcizshdQ= github.com/golang/glog v1.0.0/go.mod h1:EWib/APOK0SL3dFbYqvxE3UYd8E6s1ouQ7iEp/0LWV4= @@ -129,7 +126,6 @@ github.com/golang/mock v1.4.0/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt github.com/golang/mock v1.4.1/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw= github.com/golang/mock v1.4.3/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw= github.com/golang/mock v1.4.4/go.mod h1:l3mdAwkq5BuhzHwde/uurv3sEJeZMXNpwsxVWU71h+4= -github.com/golang/protobuf v1.1.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= @@ -195,8 +191,8 @@ github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hashicorp/golang-lru v0.5.4 h1:YDjusn29QI/Das2iO9M0BHnIbxPeyuCHsjMW+lJfyTc= github.com/hashicorp/golang-lru v0.5.4/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4= -github.com/hashicorp/hcl/v2 v2.10.0 h1:1S1UnuhDGlv3gRFV4+0EdwB+znNP5HmcGbIqwnSCByg= -github.com/hashicorp/hcl/v2 v2.10.0/go.mod h1:FwWsfWEjyV/CMj8s/gqAuiviY72rJ1/oayI9WftqcKg= +github.com/hashicorp/hcl/v2 v2.13.0 h1:0Apadu1w6M11dyGFxWnmhhcMjkbAiKCv7G1r/2QgCNc= +github.com/hashicorp/hcl/v2 v2.13.0/go.mod h1:e4z5nxYlWNPdDSNYX+ph14EvWYMFm3eP0zIUqPc2jr0= github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM= github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= @@ -212,7 +208,6 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kylelemons/godebug v0.0.0-20170820004349-d65d576e9348 h1:MtvEpTB6LX3vkb4ax0b5D2DHbNAUsen0Gx5wZoq3lV4= -github.com/kylelemons/godebug v0.0.0-20170820004349-d65d576e9348/go.mod h1:B69LEHPfb2qLo0BaaOLcbitczOKLWTsrBG9LczfCD4k= github.com/logrusorgru/aurora/v3 v3.0.0/go.mod h1:vsR12bk5grlLvLXAYrBsb5Oc/N+LxAlxggSjiwMnCUc= github.com/matryer/moq v0.2.7/go.mod h1:kITsx543GOENm48TUAQyJ9+SAvFSr7iGQXPoth/VUBk= github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4= @@ -237,7 +232,6 @@ github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1: github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= -github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo= github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM= github.com/sergi/go-diff v1.2.0 h1:XU+rvMAioB0UC3q1MFrIQy4Vo5/4VsRDQQXHsEya6xQ= github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0= @@ -245,12 +239,10 @@ github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVs github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= github.com/spf13/cobra v1.5.0 h1:X+jTBEBqF0bHN+9cSMgmfuvv2VHJ9ezmFNf9Y/XstYU= github.com/spf13/cobra v1.5.0/go.mod h1:dWXEIy2H428czQCjInthrTRUg7yKbok+2Qi/yBIJoUM= -github.com/spf13/pflag v1.0.2/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/objx v0.2.0 h1:Hbg2NidpLE8veEBkEZTL3CvlkUIVzuU9jDplZO54c48= -github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +github.com/stretchr/objx v0.4.0 h1:M2gUjqZET1qApGOWNSnZ49BAIMX4F/1plDv3+l31EJ4= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= @@ -265,7 +257,6 @@ github.com/urfave/cli/v2 v2.4.0/go.mod h1:NX9W0zmTvedE5oDoOMs2RTC8RvdK98NTYZE5Lb github.com/vektah/gqlparser/v2 v2.4.2/go.mod h1:flJWIR04IMQPGz+BXLrORkrARBxv/rtyIAFvd/MceW0= github.com/vektah/gqlparser/v2 v2.4.7 h1:yub2WLoSIr+chP1zMv6bjrsgTasfubxGZJeC8ISEpgE= github.com/vektah/gqlparser/v2 v2.4.7/go.mod h1:flJWIR04IMQPGz+BXLrORkrARBxv/rtyIAFvd/MceW0= -github.com/vmihailenco/msgpack v3.3.3+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk= github.com/vmihailenco/msgpack/v4 v4.3.12/go.mod h1:gborTTJjAo/GWTqqRjrLCn9pgNN+NXzzngzBKDPIqw4= github.com/vmihailenco/msgpack/v5 v5.0.0-beta.9 h1:iBRIniTnWOo0kqkg3k3XR8Vn6OCkVlIuZNo0UoBrKx4= github.com/vmihailenco/msgpack/v5 v5.0.0-beta.9/go.mod h1:HVxBVPUK/+fZMonk4bi1islLa8V3cfnBug0+4dykPzo= @@ -276,11 +267,8 @@ github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9de github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= -github.com/zclconf/go-cty v1.2.0/go.mod h1:hOPWgoHbaTUnI5k4D2ld+GRpFJSCe6bCM7m1q/N4PQ8= -github.com/zclconf/go-cty v1.8.0/go.mod h1:vVKLxnk3puL4qRAv72AO+W99LUD4da90g3uUAzyuvAk= github.com/zclconf/go-cty v1.10.0 h1:mp9ZXQeIcN8kAwuqorjH+Q+njbJKjLrvB2yIh4q7U+0= github.com/zclconf/go-cty v1.10.0/go.mod h1:vVKLxnk3puL4qRAv72AO+W99LUD4da90g3uUAzyuvAk= -github.com/zclconf/go-cty-debug v0.0.0-20191215020915-b22d67c1ba0b/go.mod h1:ZRKQfBXbGkpdV6QMzT3rU1kSTAnfu1dO8dPKjYprgj8= go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8= go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= @@ -313,7 +301,6 @@ go.opentelemetry.io/proto/otlp v0.19.0 h1:IVN6GR+mhC4s5yfcTbmzHYODqvWAp3ZedA2SJP go.opentelemetry.io/proto/otlp v0.19.0/go.mod h1:H7XAot3MsfNsj7EXtrA2q5xSNQ10UqI405h3+duxN4U= go.uber.org/goleak v1.1.12 h1:gZAh5/EyT/HQwlpkCy6wTpqfH9H8Lz8zbm3dZh+OyzA= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20190426145343-a29dc8fdc734/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= @@ -356,7 +343,6 @@ golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3/go.mod h1:3p9vT2HGsQu2 golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 h1:6zppjxzCulZykYSLyVDYbneBfbaBIQPYMevg0bEwv2s= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20180811021610-c39426892332/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -410,7 +396,6 @@ golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5h golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190502175342-a43fa875dd82/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -499,8 +484,8 @@ golang.org/x/tools v0.0.0-20200804011535-6c149bb5ef0d/go.mod h1:njjCfa9FT2d7l9Bc golang.org/x/tools v0.0.0-20200825202427-b303f430e36d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= golang.org/x/tools v0.1.9/go.mod h1:nABZi5QlRsZVlzPpHl034qft6wpY4eDcsTt5AaioBiU= golang.org/x/tools v0.1.10/go.mod h1:Uh6Zz+xoGYZom868N8YTex3t7RhtHDBrE8Gzo9bV56E= -golang.org/x/tools v0.1.12 h1:VveCTK38A2rkS8ZqFY25HIDFscX5X9OoEhJd3quQmXU= -golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= +golang.org/x/tools v0.1.13-0.20220804200503-81c7dc4e4efa h1:uKcci2q7Qtp6nMTC/AAvfNUAldFtJuHWV9/5QWiypts= +golang.org/x/tools v0.1.13-0.20220804200503-81c7dc4e4efa/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=