523 lines
14 KiB
Go
523 lines
14 KiB
Go
// Code generated by ent, DO NOT EDIT.
|
|
|
|
package ent
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
"time"
|
|
|
|
"entgo.io/ent/dialect/sql"
|
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
|
"entgo.io/ent/schema/field"
|
|
"kanhole/pkg/db/ent/frpcclient"
|
|
"kanhole/pkg/db/ent/predicate"
|
|
)
|
|
|
|
// FrpcClientUpdate is the builder for updating FrpcClient entities.
|
|
type FrpcClientUpdate struct {
|
|
config
|
|
hooks []Hook
|
|
mutation *FrpcClientMutation
|
|
}
|
|
|
|
// Where appends a list predicates to the FrpcClientUpdate builder.
|
|
func (_u *FrpcClientUpdate) Where(ps ...predicate.FrpcClient) *FrpcClientUpdate {
|
|
_u.mutation.Where(ps...)
|
|
return _u
|
|
}
|
|
|
|
// SetName sets the "name" field.
|
|
func (_u *FrpcClientUpdate) SetName(v string) *FrpcClientUpdate {
|
|
_u.mutation.SetName(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableName sets the "name" field if the given value is not nil.
|
|
func (_u *FrpcClientUpdate) SetNillableName(v *string) *FrpcClientUpdate {
|
|
if v != nil {
|
|
_u.SetName(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetKey sets the "key" field.
|
|
func (_u *FrpcClientUpdate) SetKey(v string) *FrpcClientUpdate {
|
|
_u.mutation.SetKey(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableKey sets the "key" field if the given value is not nil.
|
|
func (_u *FrpcClientUpdate) SetNillableKey(v *string) *FrpcClientUpdate {
|
|
if v != nil {
|
|
_u.SetKey(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetAddr sets the "addr" field.
|
|
func (_u *FrpcClientUpdate) SetAddr(v string) *FrpcClientUpdate {
|
|
_u.mutation.SetAddr(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableAddr sets the "addr" field if the given value is not nil.
|
|
func (_u *FrpcClientUpdate) SetNillableAddr(v *string) *FrpcClientUpdate {
|
|
if v != nil {
|
|
_u.SetAddr(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetPort sets the "port" field.
|
|
func (_u *FrpcClientUpdate) SetPort(v int) *FrpcClientUpdate {
|
|
_u.mutation.ResetPort()
|
|
_u.mutation.SetPort(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillablePort sets the "port" field if the given value is not nil.
|
|
func (_u *FrpcClientUpdate) SetNillablePort(v *int) *FrpcClientUpdate {
|
|
if v != nil {
|
|
_u.SetPort(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// AddPort adds value to the "port" field.
|
|
func (_u *FrpcClientUpdate) AddPort(v int) *FrpcClientUpdate {
|
|
_u.mutation.AddPort(v)
|
|
return _u
|
|
}
|
|
|
|
// SetStatus sets the "status" field.
|
|
func (_u *FrpcClientUpdate) SetStatus(v string) *FrpcClientUpdate {
|
|
_u.mutation.SetStatus(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableStatus sets the "status" field if the given value is not nil.
|
|
func (_u *FrpcClientUpdate) SetNillableStatus(v *string) *FrpcClientUpdate {
|
|
if v != nil {
|
|
_u.SetStatus(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetMetadata sets the "metadata" field.
|
|
func (_u *FrpcClientUpdate) SetMetadata(v string) *FrpcClientUpdate {
|
|
_u.mutation.SetMetadata(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableMetadata sets the "metadata" field if the given value is not nil.
|
|
func (_u *FrpcClientUpdate) SetNillableMetadata(v *string) *FrpcClientUpdate {
|
|
if v != nil {
|
|
_u.SetMetadata(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (_u *FrpcClientUpdate) SetCreatedAt(v time.Time) *FrpcClientUpdate {
|
|
_u.mutation.SetCreatedAt(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
|
func (_u *FrpcClientUpdate) SetNillableCreatedAt(v *time.Time) *FrpcClientUpdate {
|
|
if v != nil {
|
|
_u.SetCreatedAt(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetUpdatedAt sets the "updated_at" field.
|
|
func (_u *FrpcClientUpdate) SetUpdatedAt(v time.Time) *FrpcClientUpdate {
|
|
_u.mutation.SetUpdatedAt(v)
|
|
return _u
|
|
}
|
|
|
|
// SetLastSeen sets the "last_seen" field.
|
|
func (_u *FrpcClientUpdate) SetLastSeen(v time.Time) *FrpcClientUpdate {
|
|
_u.mutation.SetLastSeen(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableLastSeen sets the "last_seen" field if the given value is not nil.
|
|
func (_u *FrpcClientUpdate) SetNillableLastSeen(v *time.Time) *FrpcClientUpdate {
|
|
if v != nil {
|
|
_u.SetLastSeen(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// ClearLastSeen clears the value of the "last_seen" field.
|
|
func (_u *FrpcClientUpdate) ClearLastSeen() *FrpcClientUpdate {
|
|
_u.mutation.ClearLastSeen()
|
|
return _u
|
|
}
|
|
|
|
// Mutation returns the FrpcClientMutation object of the builder.
|
|
func (_u *FrpcClientUpdate) Mutation() *FrpcClientMutation {
|
|
return _u.mutation
|
|
}
|
|
|
|
// Save executes the query and returns the number of nodes affected by the update operation.
|
|
func (_u *FrpcClientUpdate) Save(ctx context.Context) (int, error) {
|
|
_u.defaults()
|
|
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
|
}
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
func (_u *FrpcClientUpdate) SaveX(ctx context.Context) int {
|
|
affected, err := _u.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return affected
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (_u *FrpcClientUpdate) Exec(ctx context.Context) error {
|
|
_, err := _u.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_u *FrpcClientUpdate) ExecX(ctx context.Context) {
|
|
if err := _u.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
// defaults sets the default values of the builder before save.
|
|
func (_u *FrpcClientUpdate) defaults() {
|
|
if _, ok := _u.mutation.UpdatedAt(); !ok {
|
|
v := frpcclient.UpdateDefaultUpdatedAt()
|
|
_u.mutation.SetUpdatedAt(v)
|
|
}
|
|
}
|
|
|
|
func (_u *FrpcClientUpdate) sqlSave(ctx context.Context) (_node int, err error) {
|
|
_spec := sqlgraph.NewUpdateSpec(frpcclient.Table, frpcclient.Columns, sqlgraph.NewFieldSpec(frpcclient.FieldID, field.TypeInt))
|
|
if ps := _u.mutation.predicates; len(ps) > 0 {
|
|
_spec.Predicate = func(selector *sql.Selector) {
|
|
for i := range ps {
|
|
ps[i](selector)
|
|
}
|
|
}
|
|
}
|
|
if value, ok := _u.mutation.Name(); ok {
|
|
_spec.SetField(frpcclient.FieldName, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Key(); ok {
|
|
_spec.SetField(frpcclient.FieldKey, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Addr(); ok {
|
|
_spec.SetField(frpcclient.FieldAddr, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Port(); ok {
|
|
_spec.SetField(frpcclient.FieldPort, field.TypeInt, value)
|
|
}
|
|
if value, ok := _u.mutation.AddedPort(); ok {
|
|
_spec.AddField(frpcclient.FieldPort, field.TypeInt, value)
|
|
}
|
|
if value, ok := _u.mutation.Status(); ok {
|
|
_spec.SetField(frpcclient.FieldStatus, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Metadata(); ok {
|
|
_spec.SetField(frpcclient.FieldMetadata, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.CreatedAt(); ok {
|
|
_spec.SetField(frpcclient.FieldCreatedAt, field.TypeTime, value)
|
|
}
|
|
if value, ok := _u.mutation.UpdatedAt(); ok {
|
|
_spec.SetField(frpcclient.FieldUpdatedAt, field.TypeTime, value)
|
|
}
|
|
if value, ok := _u.mutation.LastSeen(); ok {
|
|
_spec.SetField(frpcclient.FieldLastSeen, field.TypeTime, value)
|
|
}
|
|
if _u.mutation.LastSeenCleared() {
|
|
_spec.ClearField(frpcclient.FieldLastSeen, field.TypeTime)
|
|
}
|
|
if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
|
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
|
err = &NotFoundError{frpcclient.Label}
|
|
} else if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
return 0, err
|
|
}
|
|
_u.mutation.done = true
|
|
return _node, nil
|
|
}
|
|
|
|
// FrpcClientUpdateOne is the builder for updating a single FrpcClient entity.
|
|
type FrpcClientUpdateOne struct {
|
|
config
|
|
fields []string
|
|
hooks []Hook
|
|
mutation *FrpcClientMutation
|
|
}
|
|
|
|
// SetName sets the "name" field.
|
|
func (_u *FrpcClientUpdateOne) SetName(v string) *FrpcClientUpdateOne {
|
|
_u.mutation.SetName(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableName sets the "name" field if the given value is not nil.
|
|
func (_u *FrpcClientUpdateOne) SetNillableName(v *string) *FrpcClientUpdateOne {
|
|
if v != nil {
|
|
_u.SetName(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetKey sets the "key" field.
|
|
func (_u *FrpcClientUpdateOne) SetKey(v string) *FrpcClientUpdateOne {
|
|
_u.mutation.SetKey(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableKey sets the "key" field if the given value is not nil.
|
|
func (_u *FrpcClientUpdateOne) SetNillableKey(v *string) *FrpcClientUpdateOne {
|
|
if v != nil {
|
|
_u.SetKey(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetAddr sets the "addr" field.
|
|
func (_u *FrpcClientUpdateOne) SetAddr(v string) *FrpcClientUpdateOne {
|
|
_u.mutation.SetAddr(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableAddr sets the "addr" field if the given value is not nil.
|
|
func (_u *FrpcClientUpdateOne) SetNillableAddr(v *string) *FrpcClientUpdateOne {
|
|
if v != nil {
|
|
_u.SetAddr(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetPort sets the "port" field.
|
|
func (_u *FrpcClientUpdateOne) SetPort(v int) *FrpcClientUpdateOne {
|
|
_u.mutation.ResetPort()
|
|
_u.mutation.SetPort(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillablePort sets the "port" field if the given value is not nil.
|
|
func (_u *FrpcClientUpdateOne) SetNillablePort(v *int) *FrpcClientUpdateOne {
|
|
if v != nil {
|
|
_u.SetPort(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// AddPort adds value to the "port" field.
|
|
func (_u *FrpcClientUpdateOne) AddPort(v int) *FrpcClientUpdateOne {
|
|
_u.mutation.AddPort(v)
|
|
return _u
|
|
}
|
|
|
|
// SetStatus sets the "status" field.
|
|
func (_u *FrpcClientUpdateOne) SetStatus(v string) *FrpcClientUpdateOne {
|
|
_u.mutation.SetStatus(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableStatus sets the "status" field if the given value is not nil.
|
|
func (_u *FrpcClientUpdateOne) SetNillableStatus(v *string) *FrpcClientUpdateOne {
|
|
if v != nil {
|
|
_u.SetStatus(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetMetadata sets the "metadata" field.
|
|
func (_u *FrpcClientUpdateOne) SetMetadata(v string) *FrpcClientUpdateOne {
|
|
_u.mutation.SetMetadata(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableMetadata sets the "metadata" field if the given value is not nil.
|
|
func (_u *FrpcClientUpdateOne) SetNillableMetadata(v *string) *FrpcClientUpdateOne {
|
|
if v != nil {
|
|
_u.SetMetadata(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (_u *FrpcClientUpdateOne) SetCreatedAt(v time.Time) *FrpcClientUpdateOne {
|
|
_u.mutation.SetCreatedAt(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
|
func (_u *FrpcClientUpdateOne) SetNillableCreatedAt(v *time.Time) *FrpcClientUpdateOne {
|
|
if v != nil {
|
|
_u.SetCreatedAt(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetUpdatedAt sets the "updated_at" field.
|
|
func (_u *FrpcClientUpdateOne) SetUpdatedAt(v time.Time) *FrpcClientUpdateOne {
|
|
_u.mutation.SetUpdatedAt(v)
|
|
return _u
|
|
}
|
|
|
|
// SetLastSeen sets the "last_seen" field.
|
|
func (_u *FrpcClientUpdateOne) SetLastSeen(v time.Time) *FrpcClientUpdateOne {
|
|
_u.mutation.SetLastSeen(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableLastSeen sets the "last_seen" field if the given value is not nil.
|
|
func (_u *FrpcClientUpdateOne) SetNillableLastSeen(v *time.Time) *FrpcClientUpdateOne {
|
|
if v != nil {
|
|
_u.SetLastSeen(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// ClearLastSeen clears the value of the "last_seen" field.
|
|
func (_u *FrpcClientUpdateOne) ClearLastSeen() *FrpcClientUpdateOne {
|
|
_u.mutation.ClearLastSeen()
|
|
return _u
|
|
}
|
|
|
|
// Mutation returns the FrpcClientMutation object of the builder.
|
|
func (_u *FrpcClientUpdateOne) Mutation() *FrpcClientMutation {
|
|
return _u.mutation
|
|
}
|
|
|
|
// Where appends a list predicates to the FrpcClientUpdate builder.
|
|
func (_u *FrpcClientUpdateOne) Where(ps ...predicate.FrpcClient) *FrpcClientUpdateOne {
|
|
_u.mutation.Where(ps...)
|
|
return _u
|
|
}
|
|
|
|
// Select allows selecting one or more fields (columns) of the returned entity.
|
|
// The default is selecting all fields defined in the entity schema.
|
|
func (_u *FrpcClientUpdateOne) Select(field string, fields ...string) *FrpcClientUpdateOne {
|
|
_u.fields = append([]string{field}, fields...)
|
|
return _u
|
|
}
|
|
|
|
// Save executes the query and returns the updated FrpcClient entity.
|
|
func (_u *FrpcClientUpdateOne) Save(ctx context.Context) (*FrpcClient, error) {
|
|
_u.defaults()
|
|
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
|
}
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
func (_u *FrpcClientUpdateOne) SaveX(ctx context.Context) *FrpcClient {
|
|
node, err := _u.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return node
|
|
}
|
|
|
|
// Exec executes the query on the entity.
|
|
func (_u *FrpcClientUpdateOne) Exec(ctx context.Context) error {
|
|
_, err := _u.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_u *FrpcClientUpdateOne) ExecX(ctx context.Context) {
|
|
if err := _u.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
// defaults sets the default values of the builder before save.
|
|
func (_u *FrpcClientUpdateOne) defaults() {
|
|
if _, ok := _u.mutation.UpdatedAt(); !ok {
|
|
v := frpcclient.UpdateDefaultUpdatedAt()
|
|
_u.mutation.SetUpdatedAt(v)
|
|
}
|
|
}
|
|
|
|
func (_u *FrpcClientUpdateOne) sqlSave(ctx context.Context) (_node *FrpcClient, err error) {
|
|
_spec := sqlgraph.NewUpdateSpec(frpcclient.Table, frpcclient.Columns, sqlgraph.NewFieldSpec(frpcclient.FieldID, field.TypeInt))
|
|
id, ok := _u.mutation.ID()
|
|
if !ok {
|
|
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "FrpcClient.id" for update`)}
|
|
}
|
|
_spec.Node.ID.Value = id
|
|
if fields := _u.fields; len(fields) > 0 {
|
|
_spec.Node.Columns = make([]string, 0, len(fields))
|
|
_spec.Node.Columns = append(_spec.Node.Columns, frpcclient.FieldID)
|
|
for _, f := range fields {
|
|
if !frpcclient.ValidColumn(f) {
|
|
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
|
}
|
|
if f != frpcclient.FieldID {
|
|
_spec.Node.Columns = append(_spec.Node.Columns, f)
|
|
}
|
|
}
|
|
}
|
|
if ps := _u.mutation.predicates; len(ps) > 0 {
|
|
_spec.Predicate = func(selector *sql.Selector) {
|
|
for i := range ps {
|
|
ps[i](selector)
|
|
}
|
|
}
|
|
}
|
|
if value, ok := _u.mutation.Name(); ok {
|
|
_spec.SetField(frpcclient.FieldName, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Key(); ok {
|
|
_spec.SetField(frpcclient.FieldKey, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Addr(); ok {
|
|
_spec.SetField(frpcclient.FieldAddr, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Port(); ok {
|
|
_spec.SetField(frpcclient.FieldPort, field.TypeInt, value)
|
|
}
|
|
if value, ok := _u.mutation.AddedPort(); ok {
|
|
_spec.AddField(frpcclient.FieldPort, field.TypeInt, value)
|
|
}
|
|
if value, ok := _u.mutation.Status(); ok {
|
|
_spec.SetField(frpcclient.FieldStatus, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Metadata(); ok {
|
|
_spec.SetField(frpcclient.FieldMetadata, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.CreatedAt(); ok {
|
|
_spec.SetField(frpcclient.FieldCreatedAt, field.TypeTime, value)
|
|
}
|
|
if value, ok := _u.mutation.UpdatedAt(); ok {
|
|
_spec.SetField(frpcclient.FieldUpdatedAt, field.TypeTime, value)
|
|
}
|
|
if value, ok := _u.mutation.LastSeen(); ok {
|
|
_spec.SetField(frpcclient.FieldLastSeen, field.TypeTime, value)
|
|
}
|
|
if _u.mutation.LastSeenCleared() {
|
|
_spec.ClearField(frpcclient.FieldLastSeen, field.TypeTime)
|
|
}
|
|
_node = &FrpcClient{config: _u.config}
|
|
_spec.Assign = _node.assignValues
|
|
_spec.ScanValues = _node.scanValues
|
|
if err = sqlgraph.UpdateNode(ctx, _u.driver, _spec); err != nil {
|
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
|
err = &NotFoundError{frpcclient.Label}
|
|
} else if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
return nil, err
|
|
}
|
|
_u.mutation.done = true
|
|
return _node, nil
|
|
}
|