// Code generated by ent, DO NOT EDIT. package ent import ( "fmt" "strings" "time" "entgo.io/ent" "entgo.io/ent/dialect/sql" "gitserver.in/patialtech/rano/db/ent/audit" "gitserver.in/patialtech/rano/db/ent/user" ) // Audit is the model entity for the Audit schema. type Audit struct { config `json:"-"` // ID of the ent. ID int64 `json:"id,omitempty"` // CreatedAt holds the value of the "created_at" field. CreatedAt time.Time `json:"createdAt"` // EntName holds the value of the "ent_name" field. EntName string `json:"ent_name,omitempty"` // EntID holds the value of the "ent_id" field. EntID int64 `json:"ent_id,omitempty"` // Operation holds the value of the "operation" field. Operation audit.Operation `json:"operation,omitempty"` // Description holds the value of the "description" field. Description string `json:"description,omitempty"` // IP holds the value of the "ip" field. IP string `json:"ip,omitempty"` // UserName holds the value of the "user_name" field. UserName string `json:"user_name,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"` user_id *int64 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.FieldID, audit.FieldEntID: values[i] = new(sql.NullInt64) case audit.FieldEntName, audit.FieldOperation, audit.FieldDescription, audit.FieldIP, audit.FieldUserName: values[i] = new(sql.NullString) case audit.FieldCreatedAt: values[i] = new(sql.NullTime) case audit.ForeignKeys[0]: // user_id values[i] = new(sql.NullInt64) 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 (a *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: value, ok := values[i].(*sql.NullInt64) if !ok { return fmt.Errorf("unexpected type %T for field id", value) } a.ID = int64(value.Int64) 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 { a.CreatedAt = value.Time } case audit.FieldEntName: if value, ok := values[i].(*sql.NullString); !ok { return fmt.Errorf("unexpected type %T for field ent_name", values[i]) } else if value.Valid { a.EntName = value.String } case audit.FieldEntID: if value, ok := values[i].(*sql.NullInt64); !ok { return fmt.Errorf("unexpected type %T for field ent_id", values[i]) } else if value.Valid { a.EntID = value.Int64 } 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 { a.Operation = audit.Operation(value.String) } case audit.FieldDescription: if value, ok := values[i].(*sql.NullString); !ok { return fmt.Errorf("unexpected type %T for field description", values[i]) } else if value.Valid { a.Description = value.String } case audit.FieldIP: if value, ok := values[i].(*sql.NullString); !ok { return fmt.Errorf("unexpected type %T for field ip", values[i]) } else if value.Valid { a.IP = value.String } case audit.FieldUserName: if value, ok := values[i].(*sql.NullString); !ok { return fmt.Errorf("unexpected type %T for field user_name", values[i]) } else if value.Valid { a.UserName = value.String } case audit.ForeignKeys[0]: if value, ok := values[i].(*sql.NullInt64); !ok { return fmt.Errorf("unexpected type %T for edge-field user_id", value) } else if value.Valid { a.user_id = new(int64) *a.user_id = int64(value.Int64) } default: a.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 (a *Audit) Value(name string) (ent.Value, error) { return a.selectValues.Get(name) } // QueryUser queries the "user" edge of the Audit entity. func (a *Audit) QueryUser() *UserQuery { return NewAuditClient(a.config).QueryUser(a) } // 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 (a *Audit) Update() *AuditUpdateOne { return NewAuditClient(a.config).UpdateOne(a) } // 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 (a *Audit) Unwrap() *Audit { _tx, ok := a.config.driver.(*txDriver) if !ok { panic("ent: Audit is not a transactional entity") } a.config.driver = _tx.drv return a } // String implements the fmt.Stringer. func (a *Audit) String() string { var builder strings.Builder builder.WriteString("Audit(") builder.WriteString(fmt.Sprintf("id=%v, ", a.ID)) builder.WriteString("created_at=") builder.WriteString(a.CreatedAt.Format(time.ANSIC)) builder.WriteString(", ") builder.WriteString("ent_name=") builder.WriteString(a.EntName) builder.WriteString(", ") builder.WriteString("ent_id=") builder.WriteString(fmt.Sprintf("%v", a.EntID)) builder.WriteString(", ") builder.WriteString("operation=") builder.WriteString(fmt.Sprintf("%v", a.Operation)) builder.WriteString(", ") builder.WriteString("description=") builder.WriteString(a.Description) builder.WriteString(", ") builder.WriteString("ip=") builder.WriteString(a.IP) builder.WriteString(", ") builder.WriteString("user_name=") builder.WriteString(a.UserName) builder.WriteByte(')') return builder.String() } // Audits is a parsable slice of Audit. type Audits []*Audit