// Code generated by ent, DO NOT EDIT. package db import ( "fmt" "strings" "time" "entgo.io/ent" "entgo.io/ent/dialect/sql" "github.com/chaitin/MonkeyCode/backend/db/audit" "github.com/chaitin/MonkeyCode/backend/db/user" "github.com/google/uuid" ) // Audit is the model entity for the Audit schema. type Audit struct { config `json:"-"` // ID of the ent. ID uuid.UUID `json:"id,omitempty"` // UserID holds the value of the "user_id" field. UserID uuid.UUID `json:"user_id,omitempty"` // Operation holds the value of the "operation" field. Operation string `json:"operation,omitempty"` // SourceIP holds the value of the "source_ip" field. SourceIP string `json:"source_ip,omitempty"` // UserAgent holds the value of the "user_agent" field. UserAgent string `json:"user_agent,omitempty"` // Request holds the value of the "request" field. Request string `json:"request,omitempty"` // Response holds the value of the "response" field. Response string `json:"response,omitempty"` // CreatedAt holds the value of the "created_at" field. CreatedAt time.Time `json:"created_at,omitempty"` // Edges holds the relations/edges for other nodes in the graph. // The values are being populated by the AuditQuery when eager-loading is set. Edges AuditEdges `json:"edges"` selectValues sql.SelectValues } // AuditEdges holds the relations/edges for other nodes in the graph. type AuditEdges struct { // User holds the value of the user edge. User *User `json:"user,omitempty"` // loadedTypes holds the information for reporting if a // type was loaded (or requested) in eager-loading or not. loadedTypes [1]bool } // UserOrErr returns the User value or an error if the edge // was not loaded in eager-loading, or loaded but was not found. func (e AuditEdges) UserOrErr() (*User, error) { if e.User != nil { return e.User, nil } else if e.loadedTypes[0] { return nil, &NotFoundError{label: user.Label} } return nil, &NotLoadedError{edge: "user"} } // scanValues returns the types for scanning values from sql.Rows. func (*Audit) scanValues(columns []string) ([]any, error) { values := make([]any, len(columns)) for i := range columns { switch columns[i] { case audit.FieldOperation, audit.FieldSourceIP, audit.FieldUserAgent, audit.FieldRequest, audit.FieldResponse: values[i] = new(sql.NullString) case audit.FieldCreatedAt: values[i] = new(sql.NullTime) case audit.FieldID, audit.FieldUserID: values[i] = new(uuid.UUID) default: values[i] = new(sql.UnknownType) } } return values, nil } // assignValues assigns the values that were returned from sql.Rows (after scanning) // to the Audit fields. func (_m *Audit) 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) } for i := range columns { switch columns[i] { case audit.FieldID: if value, ok := values[i].(*uuid.UUID); !ok { return fmt.Errorf("unexpected type %T for field id", values[i]) } else if value != nil { _m.ID = *value } case audit.FieldUserID: if value, ok := values[i].(*uuid.UUID); !ok { return fmt.Errorf("unexpected type %T for field user_id", values[i]) } else if value != nil { _m.UserID = *value } case audit.FieldOperation: if value, ok := values[i].(*sql.NullString); !ok { return fmt.Errorf("unexpected type %T for field operation", values[i]) } else if value.Valid { _m.Operation = value.String } case audit.FieldSourceIP: if value, ok := values[i].(*sql.NullString); !ok { return fmt.Errorf("unexpected type %T for field source_ip", values[i]) } else if value.Valid { _m.SourceIP = value.String } case audit.FieldUserAgent: if value, ok := values[i].(*sql.NullString); !ok { return fmt.Errorf("unexpected type %T for field user_agent", values[i]) } else if value.Valid { _m.UserAgent = value.String } case audit.FieldRequest: if value, ok := values[i].(*sql.NullString); !ok { return fmt.Errorf("unexpected type %T for field request", values[i]) } else if value.Valid { _m.Request = value.String } case audit.FieldResponse: if value, ok := values[i].(*sql.NullString); !ok { return fmt.Errorf("unexpected type %T for field response", values[i]) } else if value.Valid { _m.Response = value.String } case audit.FieldCreatedAt: if value, ok := values[i].(*sql.NullTime); !ok { return fmt.Errorf("unexpected type %T for field created_at", values[i]) } else if value.Valid { _m.CreatedAt = value.Time } default: _m.selectValues.Set(columns[i], values[i]) } } return nil } // Value returns the ent.Value that was dynamically selected and assigned to the Audit. // This includes values selected through modifiers, order, etc. func (_m *Audit) Value(name string) (ent.Value, error) { return _m.selectValues.Get(name) } // QueryUser queries the "user" edge of the Audit entity. func (_m *Audit) QueryUser() *UserQuery { return NewAuditClient(_m.config).QueryUser(_m) } // Update returns a builder for updating this Audit. // Note that you need to call Audit.Unwrap() before calling this method if this Audit // was returned from a transaction, and the transaction was committed or rolled back. func (_m *Audit) Update() *AuditUpdateOne { return NewAuditClient(_m.config).UpdateOne(_m) } // Unwrap unwraps the Audit 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 (_m *Audit) Unwrap() *Audit { _tx, ok := _m.config.driver.(*txDriver) if !ok { panic("db: Audit is not a transactional entity") } _m.config.driver = _tx.drv return _m } // String implements the fmt.Stringer. func (_m *Audit) String() string { var builder strings.Builder builder.WriteString("Audit(") builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID)) builder.WriteString("user_id=") builder.WriteString(fmt.Sprintf("%v", _m.UserID)) builder.WriteString(", ") builder.WriteString("operation=") builder.WriteString(_m.Operation) builder.WriteString(", ") builder.WriteString("source_ip=") builder.WriteString(_m.SourceIP) builder.WriteString(", ") builder.WriteString("user_agent=") builder.WriteString(_m.UserAgent) builder.WriteString(", ") builder.WriteString("request=") builder.WriteString(_m.Request) builder.WriteString(", ") builder.WriteString("response=") builder.WriteString(_m.Response) builder.WriteString(", ") builder.WriteString("created_at=") builder.WriteString(_m.CreatedAt.Format(time.ANSIC)) builder.WriteByte(')') return builder.String() } // Audits is a parsable slice of Audit. type Audits []*Audit