pcmt/ent/searchquery_update.go
surtur 74546f996b
All checks were successful
continuous-integration/drone/push Build is passing
ent: add/extend entities, tests, validation
2023-08-19 04:52:15 +02:00

198 lines
5.9 KiB
Go

// Code generated by ent, DO NOT EDIT.
package ent
import (
"context"
"errors"
"fmt"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
"git.dotya.ml/mirre-mt/pcmt/ent/predicate"
"git.dotya.ml/mirre-mt/pcmt/ent/searchquery"
)
// SearchQueryUpdate is the builder for updating SearchQuery entities.
type SearchQueryUpdate struct {
config
hooks []Hook
mutation *SearchQueryMutation
}
// Where appends a list predicates to the SearchQueryUpdate builder.
func (squ *SearchQueryUpdate) Where(ps ...predicate.SearchQuery) *SearchQueryUpdate {
squ.mutation.Where(ps...)
return squ
}
// Mutation returns the SearchQueryMutation object of the builder.
func (squ *SearchQueryUpdate) Mutation() *SearchQueryMutation {
return squ.mutation
}
// Save executes the query and returns the number of nodes affected by the update operation.
func (squ *SearchQueryUpdate) Save(ctx context.Context) (int, error) {
return withHooks(ctx, squ.sqlSave, squ.mutation, squ.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (squ *SearchQueryUpdate) SaveX(ctx context.Context) int {
affected, err := squ.Save(ctx)
if err != nil {
panic(err)
}
return affected
}
// Exec executes the query.
func (squ *SearchQueryUpdate) Exec(ctx context.Context) error {
_, err := squ.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (squ *SearchQueryUpdate) ExecX(ctx context.Context) {
if err := squ.Exec(ctx); err != nil {
panic(err)
}
}
// check runs all checks and user-defined validators on the builder.
func (squ *SearchQueryUpdate) check() error {
if _, ok := squ.mutation.UserID(); squ.mutation.UserCleared() && !ok {
return errors.New(`ent: clearing a required unique edge "SearchQuery.user"`)
}
return nil
}
func (squ *SearchQueryUpdate) sqlSave(ctx context.Context) (n int, err error) {
if err := squ.check(); err != nil {
return n, err
}
_spec := sqlgraph.NewUpdateSpec(searchquery.Table, searchquery.Columns, sqlgraph.NewFieldSpec(searchquery.FieldID, field.TypeUUID))
if ps := squ.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if n, err = sqlgraph.UpdateNodes(ctx, squ.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{searchquery.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return 0, err
}
squ.mutation.done = true
return n, nil
}
// SearchQueryUpdateOne is the builder for updating a single SearchQuery entity.
type SearchQueryUpdateOne struct {
config
fields []string
hooks []Hook
mutation *SearchQueryMutation
}
// Mutation returns the SearchQueryMutation object of the builder.
func (squo *SearchQueryUpdateOne) Mutation() *SearchQueryMutation {
return squo.mutation
}
// Where appends a list predicates to the SearchQueryUpdate builder.
func (squo *SearchQueryUpdateOne) Where(ps ...predicate.SearchQuery) *SearchQueryUpdateOne {
squo.mutation.Where(ps...)
return squo
}
// Select allows selecting one or more fields (columns) of the returned entity.
// The default is selecting all fields defined in the entity schema.
func (squo *SearchQueryUpdateOne) Select(field string, fields ...string) *SearchQueryUpdateOne {
squo.fields = append([]string{field}, fields...)
return squo
}
// Save executes the query and returns the updated SearchQuery entity.
func (squo *SearchQueryUpdateOne) Save(ctx context.Context) (*SearchQuery, error) {
return withHooks(ctx, squo.sqlSave, squo.mutation, squo.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (squo *SearchQueryUpdateOne) SaveX(ctx context.Context) *SearchQuery {
node, err := squo.Save(ctx)
if err != nil {
panic(err)
}
return node
}
// Exec executes the query on the entity.
func (squo *SearchQueryUpdateOne) Exec(ctx context.Context) error {
_, err := squo.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (squo *SearchQueryUpdateOne) ExecX(ctx context.Context) {
if err := squo.Exec(ctx); err != nil {
panic(err)
}
}
// check runs all checks and user-defined validators on the builder.
func (squo *SearchQueryUpdateOne) check() error {
if _, ok := squo.mutation.UserID(); squo.mutation.UserCleared() && !ok {
return errors.New(`ent: clearing a required unique edge "SearchQuery.user"`)
}
return nil
}
func (squo *SearchQueryUpdateOne) sqlSave(ctx context.Context) (_node *SearchQuery, err error) {
if err := squo.check(); err != nil {
return _node, err
}
_spec := sqlgraph.NewUpdateSpec(searchquery.Table, searchquery.Columns, sqlgraph.NewFieldSpec(searchquery.FieldID, field.TypeUUID))
id, ok := squo.mutation.ID()
if !ok {
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "SearchQuery.id" for update`)}
}
_spec.Node.ID.Value = id
if fields := squo.fields; len(fields) > 0 {
_spec.Node.Columns = make([]string, 0, len(fields))
_spec.Node.Columns = append(_spec.Node.Columns, searchquery.FieldID)
for _, f := range fields {
if !searchquery.ValidColumn(f) {
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
}
if f != searchquery.FieldID {
_spec.Node.Columns = append(_spec.Node.Columns, f)
}
}
}
if ps := squo.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
_node = &SearchQuery{config: squo.config}
_spec.Assign = _node.assignValues
_spec.ScanValues = _node.scanValues
if err = sqlgraph.UpdateNode(ctx, squo.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{searchquery.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return nil, err
}
squo.mutation.done = true
return _node, nil
}