Add files via upload
This commit is contained in:
@@ -0,0 +1,382 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"home-vue-go/internal/ent/predicate"
|
||||
"home-vue-go/internal/ent/visit"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// VisitUpdate is the builder for updating Visit entities.
|
||||
type VisitUpdate struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *VisitMutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the VisitUpdate builder.
|
||||
func (_u *VisitUpdate) Where(ps ...predicate.Visit) *VisitUpdate {
|
||||
_u.mutation.Where(ps...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetPath sets the "path" field.
|
||||
func (_u *VisitUpdate) SetPath(v string) *VisitUpdate {
|
||||
_u.mutation.SetPath(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillablePath sets the "path" field if the given value is not nil.
|
||||
func (_u *VisitUpdate) SetNillablePath(v *string) *VisitUpdate {
|
||||
if v != nil {
|
||||
_u.SetPath(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetIP sets the "ip" field.
|
||||
func (_u *VisitUpdate) SetIP(v string) *VisitUpdate {
|
||||
_u.mutation.SetIP(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableIP sets the "ip" field if the given value is not nil.
|
||||
func (_u *VisitUpdate) SetNillableIP(v *string) *VisitUpdate {
|
||||
if v != nil {
|
||||
_u.SetIP(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetUserAgent sets the "user_agent" field.
|
||||
func (_u *VisitUpdate) SetUserAgent(v string) *VisitUpdate {
|
||||
_u.mutation.SetUserAgent(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableUserAgent sets the "user_agent" field if the given value is not nil.
|
||||
func (_u *VisitUpdate) SetNillableUserAgent(v *string) *VisitUpdate {
|
||||
if v != nil {
|
||||
_u.SetUserAgent(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearUserAgent clears the value of the "user_agent" field.
|
||||
func (_u *VisitUpdate) ClearUserAgent() *VisitUpdate {
|
||||
_u.mutation.ClearUserAgent()
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetReferer sets the "referer" field.
|
||||
func (_u *VisitUpdate) SetReferer(v string) *VisitUpdate {
|
||||
_u.mutation.SetReferer(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableReferer sets the "referer" field if the given value is not nil.
|
||||
func (_u *VisitUpdate) SetNillableReferer(v *string) *VisitUpdate {
|
||||
if v != nil {
|
||||
_u.SetReferer(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearReferer clears the value of the "referer" field.
|
||||
func (_u *VisitUpdate) ClearReferer() *VisitUpdate {
|
||||
_u.mutation.ClearReferer()
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetVisitTime sets the "visit_time" field.
|
||||
func (_u *VisitUpdate) SetVisitTime(v time.Time) *VisitUpdate {
|
||||
_u.mutation.SetVisitTime(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableVisitTime sets the "visit_time" field if the given value is not nil.
|
||||
func (_u *VisitUpdate) SetNillableVisitTime(v *time.Time) *VisitUpdate {
|
||||
if v != nil {
|
||||
_u.SetVisitTime(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// Mutation returns the VisitMutation object of the builder.
|
||||
func (_u *VisitUpdate) Mutation() *VisitMutation {
|
||||
return _u.mutation
|
||||
}
|
||||
|
||||
// Save executes the query and returns the number of nodes affected by the update operation.
|
||||
func (_u *VisitUpdate) Save(ctx context.Context) (int, error) {
|
||||
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (_u *VisitUpdate) SaveX(ctx context.Context) int {
|
||||
affected, err := _u.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return affected
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (_u *VisitUpdate) Exec(ctx context.Context) error {
|
||||
_, err := _u.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_u *VisitUpdate) ExecX(ctx context.Context) {
|
||||
if err := _u.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (_u *VisitUpdate) sqlSave(ctx context.Context) (_node int, err error) {
|
||||
_spec := sqlgraph.NewUpdateSpec(visit.Table, visit.Columns, sqlgraph.NewFieldSpec(visit.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.Path(); ok {
|
||||
_spec.SetField(visit.FieldPath, field.TypeString, value)
|
||||
}
|
||||
if value, ok := _u.mutation.IP(); ok {
|
||||
_spec.SetField(visit.FieldIP, field.TypeString, value)
|
||||
}
|
||||
if value, ok := _u.mutation.UserAgent(); ok {
|
||||
_spec.SetField(visit.FieldUserAgent, field.TypeString, value)
|
||||
}
|
||||
if _u.mutation.UserAgentCleared() {
|
||||
_spec.ClearField(visit.FieldUserAgent, field.TypeString)
|
||||
}
|
||||
if value, ok := _u.mutation.Referer(); ok {
|
||||
_spec.SetField(visit.FieldReferer, field.TypeString, value)
|
||||
}
|
||||
if _u.mutation.RefererCleared() {
|
||||
_spec.ClearField(visit.FieldReferer, field.TypeString)
|
||||
}
|
||||
if value, ok := _u.mutation.VisitTime(); ok {
|
||||
_spec.SetField(visit.FieldVisitTime, field.TypeTime, value)
|
||||
}
|
||||
if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{visit.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return 0, err
|
||||
}
|
||||
_u.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
|
||||
// VisitUpdateOne is the builder for updating a single Visit entity.
|
||||
type VisitUpdateOne struct {
|
||||
config
|
||||
fields []string
|
||||
hooks []Hook
|
||||
mutation *VisitMutation
|
||||
}
|
||||
|
||||
// SetPath sets the "path" field.
|
||||
func (_u *VisitUpdateOne) SetPath(v string) *VisitUpdateOne {
|
||||
_u.mutation.SetPath(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillablePath sets the "path" field if the given value is not nil.
|
||||
func (_u *VisitUpdateOne) SetNillablePath(v *string) *VisitUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetPath(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetIP sets the "ip" field.
|
||||
func (_u *VisitUpdateOne) SetIP(v string) *VisitUpdateOne {
|
||||
_u.mutation.SetIP(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableIP sets the "ip" field if the given value is not nil.
|
||||
func (_u *VisitUpdateOne) SetNillableIP(v *string) *VisitUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetIP(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetUserAgent sets the "user_agent" field.
|
||||
func (_u *VisitUpdateOne) SetUserAgent(v string) *VisitUpdateOne {
|
||||
_u.mutation.SetUserAgent(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableUserAgent sets the "user_agent" field if the given value is not nil.
|
||||
func (_u *VisitUpdateOne) SetNillableUserAgent(v *string) *VisitUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetUserAgent(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearUserAgent clears the value of the "user_agent" field.
|
||||
func (_u *VisitUpdateOne) ClearUserAgent() *VisitUpdateOne {
|
||||
_u.mutation.ClearUserAgent()
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetReferer sets the "referer" field.
|
||||
func (_u *VisitUpdateOne) SetReferer(v string) *VisitUpdateOne {
|
||||
_u.mutation.SetReferer(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableReferer sets the "referer" field if the given value is not nil.
|
||||
func (_u *VisitUpdateOne) SetNillableReferer(v *string) *VisitUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetReferer(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearReferer clears the value of the "referer" field.
|
||||
func (_u *VisitUpdateOne) ClearReferer() *VisitUpdateOne {
|
||||
_u.mutation.ClearReferer()
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetVisitTime sets the "visit_time" field.
|
||||
func (_u *VisitUpdateOne) SetVisitTime(v time.Time) *VisitUpdateOne {
|
||||
_u.mutation.SetVisitTime(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableVisitTime sets the "visit_time" field if the given value is not nil.
|
||||
func (_u *VisitUpdateOne) SetNillableVisitTime(v *time.Time) *VisitUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetVisitTime(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// Mutation returns the VisitMutation object of the builder.
|
||||
func (_u *VisitUpdateOne) Mutation() *VisitMutation {
|
||||
return _u.mutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the VisitUpdate builder.
|
||||
func (_u *VisitUpdateOne) Where(ps ...predicate.Visit) *VisitUpdateOne {
|
||||
_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 *VisitUpdateOne) Select(field string, fields ...string) *VisitUpdateOne {
|
||||
_u.fields = append([]string{field}, fields...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// Save executes the query and returns the updated Visit entity.
|
||||
func (_u *VisitUpdateOne) Save(ctx context.Context) (*Visit, error) {
|
||||
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (_u *VisitUpdateOne) SaveX(ctx context.Context) *Visit {
|
||||
node, err := _u.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// Exec executes the query on the entity.
|
||||
func (_u *VisitUpdateOne) Exec(ctx context.Context) error {
|
||||
_, err := _u.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_u *VisitUpdateOne) ExecX(ctx context.Context) {
|
||||
if err := _u.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (_u *VisitUpdateOne) sqlSave(ctx context.Context) (_node *Visit, err error) {
|
||||
_spec := sqlgraph.NewUpdateSpec(visit.Table, visit.Columns, sqlgraph.NewFieldSpec(visit.FieldID, field.TypeInt))
|
||||
id, ok := _u.mutation.ID()
|
||||
if !ok {
|
||||
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Visit.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, visit.FieldID)
|
||||
for _, f := range fields {
|
||||
if !visit.ValidColumn(f) {
|
||||
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||||
}
|
||||
if f != visit.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.Path(); ok {
|
||||
_spec.SetField(visit.FieldPath, field.TypeString, value)
|
||||
}
|
||||
if value, ok := _u.mutation.IP(); ok {
|
||||
_spec.SetField(visit.FieldIP, field.TypeString, value)
|
||||
}
|
||||
if value, ok := _u.mutation.UserAgent(); ok {
|
||||
_spec.SetField(visit.FieldUserAgent, field.TypeString, value)
|
||||
}
|
||||
if _u.mutation.UserAgentCleared() {
|
||||
_spec.ClearField(visit.FieldUserAgent, field.TypeString)
|
||||
}
|
||||
if value, ok := _u.mutation.Referer(); ok {
|
||||
_spec.SetField(visit.FieldReferer, field.TypeString, value)
|
||||
}
|
||||
if _u.mutation.RefererCleared() {
|
||||
_spec.ClearField(visit.FieldReferer, field.TypeString)
|
||||
}
|
||||
if value, ok := _u.mutation.VisitTime(); ok {
|
||||
_spec.SetField(visit.FieldVisitTime, field.TypeTime, value)
|
||||
}
|
||||
_node = &Visit{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{visit.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
_u.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
Reference in New Issue
Block a user