// 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/user" ) // User is the model entity for the User schema. type User 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"` // UpdatedAt holds the value of the "updated_at" field. UpdatedAt time.Time `json:"updatedAt"` // Email holds the value of the "email" field. Email string `json:"email,omitempty"` // EmailVerified holds the value of the "email_verified" field. EmailVerified bool `json:"email_verified,omitempty"` // Phone holds the value of the "phone" field. Phone string `json:"phone,omitempty"` // PhoneVerified holds the value of the "phone_verified" field. PhoneVerified bool `json:"phone_verified,omitempty"` // PwdSalt holds the value of the "pwd_salt" field. PwdSalt string `json:"pwd_salt,omitempty"` // PwdHash holds the value of the "pwd_hash" field. PwdHash string `json:"pwd_hash,omitempty"` // LoginFailedCount holds the value of the "login_failed_count" field. LoginFailedCount uint8 `json:"login_failed_count,omitempty"` // LoginAttemptOn holds the value of the "login_attempt_on" field. LoginAttemptOn *time.Time `json:"login_attempt_on,omitempty"` // LoginLockedUntil holds the value of the "login_locked_until" field. LoginLockedUntil *time.Time `json:"login_locked_until,omitempty"` // FirstName holds the value of the "first_name" field. FirstName string `json:"first_name,omitempty"` // MiddleName holds the value of the "middle_name" field. MiddleName *string `json:"middle_name,omitempty"` // LastName holds the value of the "last_name" field. LastName string `json:"last_name,omitempty"` // Status holds the value of the "status" field. Status user.Status `json:"status,omitempty"` // Edges holds the relations/edges for other nodes in the graph. // The values are being populated by the UserQuery when eager-loading is set. Edges UserEdges `json:"edges"` selectValues sql.SelectValues } // UserEdges holds the relations/edges for other nodes in the graph. type UserEdges struct { // Sessions holds the value of the sessions edge. Sessions []*UserSession `json:"sessions,omitempty"` // AuditLogs holds the value of the audit_logs edge. AuditLogs []*Audit `json:"audit_logs,omitempty"` // loadedTypes holds the information for reporting if a // type was loaded (or requested) in eager-loading or not. loadedTypes [2]bool } // SessionsOrErr returns the Sessions value or an error if the edge // was not loaded in eager-loading. func (e UserEdges) SessionsOrErr() ([]*UserSession, error) { if e.loadedTypes[0] { return e.Sessions, nil } return nil, &NotLoadedError{edge: "sessions"} } // AuditLogsOrErr returns the AuditLogs value or an error if the edge // was not loaded in eager-loading. func (e UserEdges) AuditLogsOrErr() ([]*Audit, error) { if e.loadedTypes[1] { return e.AuditLogs, nil } return nil, &NotLoadedError{edge: "audit_logs"} } // scanValues returns the types for scanning values from sql.Rows. func (*User) scanValues(columns []string) ([]any, error) { values := make([]any, len(columns)) for i := range columns { switch columns[i] { case user.FieldEmailVerified, user.FieldPhoneVerified: values[i] = new(sql.NullBool) case user.FieldID, user.FieldLoginFailedCount: values[i] = new(sql.NullInt64) case user.FieldEmail, user.FieldPhone, user.FieldPwdSalt, user.FieldPwdHash, user.FieldFirstName, user.FieldMiddleName, user.FieldLastName, user.FieldStatus: values[i] = new(sql.NullString) case user.FieldCreatedAt, user.FieldUpdatedAt, user.FieldLoginAttemptOn, user.FieldLoginLockedUntil: values[i] = new(sql.NullTime) default: values[i] = new(sql.UnknownType) } } return values, nil } // assignValues assigns the values that were returned from sql.Rows (after scanning) // to the User fields. func (u *User) 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 user.FieldID: value, ok := values[i].(*sql.NullInt64) if !ok { return fmt.Errorf("unexpected type %T for field id", value) } u.ID = int64(value.Int64) case user.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 { u.CreatedAt = value.Time } case user.FieldUpdatedAt: if value, ok := values[i].(*sql.NullTime); !ok { return fmt.Errorf("unexpected type %T for field updated_at", values[i]) } else if value.Valid { u.UpdatedAt = value.Time } case user.FieldEmail: if value, ok := values[i].(*sql.NullString); !ok { return fmt.Errorf("unexpected type %T for field email", values[i]) } else if value.Valid { u.Email = value.String } case user.FieldEmailVerified: if value, ok := values[i].(*sql.NullBool); !ok { return fmt.Errorf("unexpected type %T for field email_verified", values[i]) } else if value.Valid { u.EmailVerified = value.Bool } case user.FieldPhone: if value, ok := values[i].(*sql.NullString); !ok { return fmt.Errorf("unexpected type %T for field phone", values[i]) } else if value.Valid { u.Phone = value.String } case user.FieldPhoneVerified: if value, ok := values[i].(*sql.NullBool); !ok { return fmt.Errorf("unexpected type %T for field phone_verified", values[i]) } else if value.Valid { u.PhoneVerified = value.Bool } case user.FieldPwdSalt: if value, ok := values[i].(*sql.NullString); !ok { return fmt.Errorf("unexpected type %T for field pwd_salt", values[i]) } else if value.Valid { u.PwdSalt = value.String } case user.FieldPwdHash: if value, ok := values[i].(*sql.NullString); !ok { return fmt.Errorf("unexpected type %T for field pwd_hash", values[i]) } else if value.Valid { u.PwdHash = value.String } case user.FieldLoginFailedCount: if value, ok := values[i].(*sql.NullInt64); !ok { return fmt.Errorf("unexpected type %T for field login_failed_count", values[i]) } else if value.Valid { u.LoginFailedCount = uint8(value.Int64) } case user.FieldLoginAttemptOn: if value, ok := values[i].(*sql.NullTime); !ok { return fmt.Errorf("unexpected type %T for field login_attempt_on", values[i]) } else if value.Valid { u.LoginAttemptOn = new(time.Time) *u.LoginAttemptOn = value.Time } case user.FieldLoginLockedUntil: if value, ok := values[i].(*sql.NullTime); !ok { return fmt.Errorf("unexpected type %T for field login_locked_until", values[i]) } else if value.Valid { u.LoginLockedUntil = new(time.Time) *u.LoginLockedUntil = value.Time } case user.FieldFirstName: if value, ok := values[i].(*sql.NullString); !ok { return fmt.Errorf("unexpected type %T for field first_name", values[i]) } else if value.Valid { u.FirstName = value.String } case user.FieldMiddleName: if value, ok := values[i].(*sql.NullString); !ok { return fmt.Errorf("unexpected type %T for field middle_name", values[i]) } else if value.Valid { u.MiddleName = new(string) *u.MiddleName = value.String } case user.FieldLastName: if value, ok := values[i].(*sql.NullString); !ok { return fmt.Errorf("unexpected type %T for field last_name", values[i]) } else if value.Valid { u.LastName = value.String } case user.FieldStatus: if value, ok := values[i].(*sql.NullString); !ok { return fmt.Errorf("unexpected type %T for field status", values[i]) } else if value.Valid { u.Status = user.Status(value.String) } default: u.selectValues.Set(columns[i], values[i]) } } return nil } // Value returns the ent.Value that was dynamically selected and assigned to the User. // This includes values selected through modifiers, order, etc. func (u *User) Value(name string) (ent.Value, error) { return u.selectValues.Get(name) } // QuerySessions queries the "sessions" edge of the User entity. func (u *User) QuerySessions() *UserSessionQuery { return NewUserClient(u.config).QuerySessions(u) } // QueryAuditLogs queries the "audit_logs" edge of the User entity. func (u *User) QueryAuditLogs() *AuditQuery { return NewUserClient(u.config).QueryAuditLogs(u) } // Update returns a builder for updating this User. // Note that you need to call User.Unwrap() before calling this method if this User // was returned from a transaction, and the transaction was committed or rolled back. func (u *User) Update() *UserUpdateOne { return NewUserClient(u.config).UpdateOne(u) } // Unwrap unwraps the User 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 (u *User) Unwrap() *User { _tx, ok := u.config.driver.(*txDriver) if !ok { panic("ent: User is not a transactional entity") } u.config.driver = _tx.drv return u } // String implements the fmt.Stringer. func (u *User) String() string { var builder strings.Builder builder.WriteString("User(") builder.WriteString(fmt.Sprintf("id=%v, ", u.ID)) builder.WriteString("created_at=") builder.WriteString(u.CreatedAt.Format(time.ANSIC)) builder.WriteString(", ") builder.WriteString("updated_at=") builder.WriteString(u.UpdatedAt.Format(time.ANSIC)) builder.WriteString(", ") builder.WriteString("email=") builder.WriteString(u.Email) builder.WriteString(", ") builder.WriteString("email_verified=") builder.WriteString(fmt.Sprintf("%v", u.EmailVerified)) builder.WriteString(", ") builder.WriteString("phone=") builder.WriteString(u.Phone) builder.WriteString(", ") builder.WriteString("phone_verified=") builder.WriteString(fmt.Sprintf("%v", u.PhoneVerified)) builder.WriteString(", ") builder.WriteString("pwd_salt=") builder.WriteString(u.PwdSalt) builder.WriteString(", ") builder.WriteString("pwd_hash=") builder.WriteString(u.PwdHash) builder.WriteString(", ") builder.WriteString("login_failed_count=") builder.WriteString(fmt.Sprintf("%v", u.LoginFailedCount)) builder.WriteString(", ") if v := u.LoginAttemptOn; v != nil { builder.WriteString("login_attempt_on=") builder.WriteString(v.Format(time.ANSIC)) } builder.WriteString(", ") if v := u.LoginLockedUntil; v != nil { builder.WriteString("login_locked_until=") builder.WriteString(v.Format(time.ANSIC)) } builder.WriteString(", ") builder.WriteString("first_name=") builder.WriteString(u.FirstName) builder.WriteString(", ") if v := u.MiddleName; v != nil { builder.WriteString("middle_name=") builder.WriteString(*v) } builder.WriteString(", ") builder.WriteString("last_name=") builder.WriteString(u.LastName) builder.WriteString(", ") builder.WriteString("status=") builder.WriteString(fmt.Sprintf("%v", u.Status)) builder.WriteByte(')') return builder.String() } // Users is a parsable slice of User. type Users []*User