mirror of
https://github.com/chaitin/MonkeyCode.git
synced 2026-11-22 19:39:31 +08:00
547 lines
15 KiB
Go
547 lines
15 KiB
Go
// Code generated by ent, DO NOT EDIT.
|
|
|
|
package db
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
"time"
|
|
|
|
"entgo.io/ent/dialect/sql"
|
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
|
"entgo.io/ent/schema/field"
|
|
"github.com/chaitin/MonkeyCode/backend/db/audit"
|
|
"github.com/chaitin/MonkeyCode/backend/db/predicate"
|
|
"github.com/chaitin/MonkeyCode/backend/db/user"
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
// AuditUpdate is the builder for updating Audit entities.
|
|
type AuditUpdate struct {
|
|
config
|
|
hooks []Hook
|
|
mutation *AuditMutation
|
|
modifiers []func(*sql.UpdateBuilder)
|
|
}
|
|
|
|
// Where appends a list predicates to the AuditUpdate builder.
|
|
func (_u *AuditUpdate) Where(ps ...predicate.Audit) *AuditUpdate {
|
|
_u.mutation.Where(ps...)
|
|
return _u
|
|
}
|
|
|
|
// SetUserID sets the "user_id" field.
|
|
func (_u *AuditUpdate) SetUserID(v uuid.UUID) *AuditUpdate {
|
|
_u.mutation.SetUserID(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableUserID sets the "user_id" field if the given value is not nil.
|
|
func (_u *AuditUpdate) SetNillableUserID(v *uuid.UUID) *AuditUpdate {
|
|
if v != nil {
|
|
_u.SetUserID(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetOperation sets the "operation" field.
|
|
func (_u *AuditUpdate) SetOperation(v string) *AuditUpdate {
|
|
_u.mutation.SetOperation(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableOperation sets the "operation" field if the given value is not nil.
|
|
func (_u *AuditUpdate) SetNillableOperation(v *string) *AuditUpdate {
|
|
if v != nil {
|
|
_u.SetOperation(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetSourceIP sets the "source_ip" field.
|
|
func (_u *AuditUpdate) SetSourceIP(v string) *AuditUpdate {
|
|
_u.mutation.SetSourceIP(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableSourceIP sets the "source_ip" field if the given value is not nil.
|
|
func (_u *AuditUpdate) SetNillableSourceIP(v *string) *AuditUpdate {
|
|
if v != nil {
|
|
_u.SetSourceIP(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetUserAgent sets the "user_agent" field.
|
|
func (_u *AuditUpdate) SetUserAgent(v string) *AuditUpdate {
|
|
_u.mutation.SetUserAgent(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableUserAgent sets the "user_agent" field if the given value is not nil.
|
|
func (_u *AuditUpdate) SetNillableUserAgent(v *string) *AuditUpdate {
|
|
if v != nil {
|
|
_u.SetUserAgent(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetRequest sets the "request" field.
|
|
func (_u *AuditUpdate) SetRequest(v string) *AuditUpdate {
|
|
_u.mutation.SetRequest(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableRequest sets the "request" field if the given value is not nil.
|
|
func (_u *AuditUpdate) SetNillableRequest(v *string) *AuditUpdate {
|
|
if v != nil {
|
|
_u.SetRequest(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetResponse sets the "response" field.
|
|
func (_u *AuditUpdate) SetResponse(v string) *AuditUpdate {
|
|
_u.mutation.SetResponse(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableResponse sets the "response" field if the given value is not nil.
|
|
func (_u *AuditUpdate) SetNillableResponse(v *string) *AuditUpdate {
|
|
if v != nil {
|
|
_u.SetResponse(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// ClearResponse clears the value of the "response" field.
|
|
func (_u *AuditUpdate) ClearResponse() *AuditUpdate {
|
|
_u.mutation.ClearResponse()
|
|
return _u
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (_u *AuditUpdate) SetCreatedAt(v time.Time) *AuditUpdate {
|
|
_u.mutation.SetCreatedAt(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
|
func (_u *AuditUpdate) SetNillableCreatedAt(v *time.Time) *AuditUpdate {
|
|
if v != nil {
|
|
_u.SetCreatedAt(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetUser sets the "user" edge to the User entity.
|
|
func (_u *AuditUpdate) SetUser(v *User) *AuditUpdate {
|
|
return _u.SetUserID(v.ID)
|
|
}
|
|
|
|
// Mutation returns the AuditMutation object of the builder.
|
|
func (_u *AuditUpdate) Mutation() *AuditMutation {
|
|
return _u.mutation
|
|
}
|
|
|
|
// ClearUser clears the "user" edge to the User entity.
|
|
func (_u *AuditUpdate) ClearUser() *AuditUpdate {
|
|
_u.mutation.ClearUser()
|
|
return _u
|
|
}
|
|
|
|
// Save executes the query and returns the number of nodes affected by the update operation.
|
|
func (_u *AuditUpdate) 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 *AuditUpdate) SaveX(ctx context.Context) int {
|
|
affected, err := _u.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return affected
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (_u *AuditUpdate) Exec(ctx context.Context) error {
|
|
_, err := _u.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_u *AuditUpdate) ExecX(ctx context.Context) {
|
|
if err := _u.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
// check runs all checks and user-defined validators on the builder.
|
|
func (_u *AuditUpdate) check() error {
|
|
if _u.mutation.UserCleared() && len(_u.mutation.UserIDs()) > 0 {
|
|
return errors.New(`db: clearing a required unique edge "Audit.user"`)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
|
|
func (_u *AuditUpdate) Modify(modifiers ...func(u *sql.UpdateBuilder)) *AuditUpdate {
|
|
_u.modifiers = append(_u.modifiers, modifiers...)
|
|
return _u
|
|
}
|
|
|
|
func (_u *AuditUpdate) sqlSave(ctx context.Context) (_node int, err error) {
|
|
if err := _u.check(); err != nil {
|
|
return _node, err
|
|
}
|
|
_spec := sqlgraph.NewUpdateSpec(audit.Table, audit.Columns, sqlgraph.NewFieldSpec(audit.FieldID, field.TypeUUID))
|
|
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.Operation(); ok {
|
|
_spec.SetField(audit.FieldOperation, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.SourceIP(); ok {
|
|
_spec.SetField(audit.FieldSourceIP, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.UserAgent(); ok {
|
|
_spec.SetField(audit.FieldUserAgent, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Request(); ok {
|
|
_spec.SetField(audit.FieldRequest, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Response(); ok {
|
|
_spec.SetField(audit.FieldResponse, field.TypeString, value)
|
|
}
|
|
if _u.mutation.ResponseCleared() {
|
|
_spec.ClearField(audit.FieldResponse, field.TypeString)
|
|
}
|
|
if value, ok := _u.mutation.CreatedAt(); ok {
|
|
_spec.SetField(audit.FieldCreatedAt, field.TypeTime, value)
|
|
}
|
|
if _u.mutation.UserCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: true,
|
|
Table: audit.UserTable,
|
|
Columns: []string{audit.UserColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID),
|
|
},
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := _u.mutation.UserIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: true,
|
|
Table: audit.UserTable,
|
|
Columns: []string{audit.UserColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
|
}
|
|
_spec.AddModifiers(_u.modifiers...)
|
|
if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
|
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
|
err = &NotFoundError{audit.Label}
|
|
} else if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
return 0, err
|
|
}
|
|
_u.mutation.done = true
|
|
return _node, nil
|
|
}
|
|
|
|
// AuditUpdateOne is the builder for updating a single Audit entity.
|
|
type AuditUpdateOne struct {
|
|
config
|
|
fields []string
|
|
hooks []Hook
|
|
mutation *AuditMutation
|
|
modifiers []func(*sql.UpdateBuilder)
|
|
}
|
|
|
|
// SetUserID sets the "user_id" field.
|
|
func (_u *AuditUpdateOne) SetUserID(v uuid.UUID) *AuditUpdateOne {
|
|
_u.mutation.SetUserID(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableUserID sets the "user_id" field if the given value is not nil.
|
|
func (_u *AuditUpdateOne) SetNillableUserID(v *uuid.UUID) *AuditUpdateOne {
|
|
if v != nil {
|
|
_u.SetUserID(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetOperation sets the "operation" field.
|
|
func (_u *AuditUpdateOne) SetOperation(v string) *AuditUpdateOne {
|
|
_u.mutation.SetOperation(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableOperation sets the "operation" field if the given value is not nil.
|
|
func (_u *AuditUpdateOne) SetNillableOperation(v *string) *AuditUpdateOne {
|
|
if v != nil {
|
|
_u.SetOperation(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetSourceIP sets the "source_ip" field.
|
|
func (_u *AuditUpdateOne) SetSourceIP(v string) *AuditUpdateOne {
|
|
_u.mutation.SetSourceIP(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableSourceIP sets the "source_ip" field if the given value is not nil.
|
|
func (_u *AuditUpdateOne) SetNillableSourceIP(v *string) *AuditUpdateOne {
|
|
if v != nil {
|
|
_u.SetSourceIP(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetUserAgent sets the "user_agent" field.
|
|
func (_u *AuditUpdateOne) SetUserAgent(v string) *AuditUpdateOne {
|
|
_u.mutation.SetUserAgent(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableUserAgent sets the "user_agent" field if the given value is not nil.
|
|
func (_u *AuditUpdateOne) SetNillableUserAgent(v *string) *AuditUpdateOne {
|
|
if v != nil {
|
|
_u.SetUserAgent(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetRequest sets the "request" field.
|
|
func (_u *AuditUpdateOne) SetRequest(v string) *AuditUpdateOne {
|
|
_u.mutation.SetRequest(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableRequest sets the "request" field if the given value is not nil.
|
|
func (_u *AuditUpdateOne) SetNillableRequest(v *string) *AuditUpdateOne {
|
|
if v != nil {
|
|
_u.SetRequest(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetResponse sets the "response" field.
|
|
func (_u *AuditUpdateOne) SetResponse(v string) *AuditUpdateOne {
|
|
_u.mutation.SetResponse(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableResponse sets the "response" field if the given value is not nil.
|
|
func (_u *AuditUpdateOne) SetNillableResponse(v *string) *AuditUpdateOne {
|
|
if v != nil {
|
|
_u.SetResponse(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// ClearResponse clears the value of the "response" field.
|
|
func (_u *AuditUpdateOne) ClearResponse() *AuditUpdateOne {
|
|
_u.mutation.ClearResponse()
|
|
return _u
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (_u *AuditUpdateOne) SetCreatedAt(v time.Time) *AuditUpdateOne {
|
|
_u.mutation.SetCreatedAt(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
|
func (_u *AuditUpdateOne) SetNillableCreatedAt(v *time.Time) *AuditUpdateOne {
|
|
if v != nil {
|
|
_u.SetCreatedAt(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetUser sets the "user" edge to the User entity.
|
|
func (_u *AuditUpdateOne) SetUser(v *User) *AuditUpdateOne {
|
|
return _u.SetUserID(v.ID)
|
|
}
|
|
|
|
// Mutation returns the AuditMutation object of the builder.
|
|
func (_u *AuditUpdateOne) Mutation() *AuditMutation {
|
|
return _u.mutation
|
|
}
|
|
|
|
// ClearUser clears the "user" edge to the User entity.
|
|
func (_u *AuditUpdateOne) ClearUser() *AuditUpdateOne {
|
|
_u.mutation.ClearUser()
|
|
return _u
|
|
}
|
|
|
|
// Where appends a list predicates to the AuditUpdate builder.
|
|
func (_u *AuditUpdateOne) Where(ps ...predicate.Audit) *AuditUpdateOne {
|
|
_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 *AuditUpdateOne) Select(field string, fields ...string) *AuditUpdateOne {
|
|
_u.fields = append([]string{field}, fields...)
|
|
return _u
|
|
}
|
|
|
|
// Save executes the query and returns the updated Audit entity.
|
|
func (_u *AuditUpdateOne) Save(ctx context.Context) (*Audit, error) {
|
|
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
|
}
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
func (_u *AuditUpdateOne) SaveX(ctx context.Context) *Audit {
|
|
node, err := _u.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return node
|
|
}
|
|
|
|
// Exec executes the query on the entity.
|
|
func (_u *AuditUpdateOne) Exec(ctx context.Context) error {
|
|
_, err := _u.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_u *AuditUpdateOne) ExecX(ctx context.Context) {
|
|
if err := _u.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
// check runs all checks and user-defined validators on the builder.
|
|
func (_u *AuditUpdateOne) check() error {
|
|
if _u.mutation.UserCleared() && len(_u.mutation.UserIDs()) > 0 {
|
|
return errors.New(`db: clearing a required unique edge "Audit.user"`)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
|
|
func (_u *AuditUpdateOne) Modify(modifiers ...func(u *sql.UpdateBuilder)) *AuditUpdateOne {
|
|
_u.modifiers = append(_u.modifiers, modifiers...)
|
|
return _u
|
|
}
|
|
|
|
func (_u *AuditUpdateOne) sqlSave(ctx context.Context) (_node *Audit, err error) {
|
|
if err := _u.check(); err != nil {
|
|
return _node, err
|
|
}
|
|
_spec := sqlgraph.NewUpdateSpec(audit.Table, audit.Columns, sqlgraph.NewFieldSpec(audit.FieldID, field.TypeUUID))
|
|
id, ok := _u.mutation.ID()
|
|
if !ok {
|
|
return nil, &ValidationError{Name: "id", err: errors.New(`db: missing "Audit.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, audit.FieldID)
|
|
for _, f := range fields {
|
|
if !audit.ValidColumn(f) {
|
|
return nil, &ValidationError{Name: f, err: fmt.Errorf("db: invalid field %q for query", f)}
|
|
}
|
|
if f != audit.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.Operation(); ok {
|
|
_spec.SetField(audit.FieldOperation, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.SourceIP(); ok {
|
|
_spec.SetField(audit.FieldSourceIP, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.UserAgent(); ok {
|
|
_spec.SetField(audit.FieldUserAgent, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Request(); ok {
|
|
_spec.SetField(audit.FieldRequest, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Response(); ok {
|
|
_spec.SetField(audit.FieldResponse, field.TypeString, value)
|
|
}
|
|
if _u.mutation.ResponseCleared() {
|
|
_spec.ClearField(audit.FieldResponse, field.TypeString)
|
|
}
|
|
if value, ok := _u.mutation.CreatedAt(); ok {
|
|
_spec.SetField(audit.FieldCreatedAt, field.TypeTime, value)
|
|
}
|
|
if _u.mutation.UserCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: true,
|
|
Table: audit.UserTable,
|
|
Columns: []string{audit.UserColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID),
|
|
},
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := _u.mutation.UserIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: true,
|
|
Table: audit.UserTable,
|
|
Columns: []string{audit.UserColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
|
}
|
|
_spec.AddModifiers(_u.modifiers...)
|
|
_node = &Audit{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{audit.Label}
|
|
} else if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
return nil, err
|
|
}
|
|
_u.mutation.done = true
|
|
return _node, nil
|
|
}
|