// Code generated by ent, DO NOT EDIT. package ent import ( "fmt" "strings" "time" "code.icod.de/dalu/ka/ent/profile" "entgo.io/ent" "entgo.io/ent/dialect/sql" "github.com/google/uuid" ) // Profile is the model entity for the Profile schema. type Profile struct { config `json:"-"` // ID of the ent. ID uuid.UUID `json:"id,omitempty"` // CreatedAt holds the value of the "created_at" field. CreatedAt time.Time `json:"created_at,omitempty"` // UpdatedAt holds the value of the "updated_at" field. UpdatedAt time.Time `json:"updated_at,omitempty"` // Name holds the value of the "name" field. Name string `json:"name,omitempty"` // Address holds the value of the "address" field. Address string `json:"address,omitempty"` // Phone holds the value of the "phone" field. Phone string `json:"phone,omitempty"` // Edges holds the relations/edges for other nodes in the graph. // The values are being populated by the ProfileQuery when eager-loading is set. Edges ProfileEdges `json:"edges"` selectValues sql.SelectValues } // ProfileEdges holds the relations/edges for other nodes in the graph. type ProfileEdges struct { // Posts holds the value of the posts edge. Posts []*Post `json:"posts,omitempty"` // loadedTypes holds the information for reporting if a // type was loaded (or requested) in eager-loading or not. loadedTypes [1]bool // totalCount holds the count of the edges above. totalCount [1]map[string]int namedPosts map[string][]*Post } // PostsOrErr returns the Posts value or an error if the edge // was not loaded in eager-loading. func (e ProfileEdges) PostsOrErr() ([]*Post, error) { if e.loadedTypes[0] { return e.Posts, nil } return nil, &NotLoadedError{edge: "posts"} } // scanValues returns the types for scanning values from sql.Rows. func (*Profile) scanValues(columns []string) ([]any, error) { values := make([]any, len(columns)) for i := range columns { switch columns[i] { case profile.FieldName, profile.FieldAddress, profile.FieldPhone: values[i] = new(sql.NullString) case profile.FieldCreatedAt, profile.FieldUpdatedAt: values[i] = new(sql.NullTime) case profile.FieldID: 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 Profile fields. func (pr *Profile) 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 profile.FieldID: if value, ok := values[i].(*uuid.UUID); !ok { return fmt.Errorf("unexpected type %T for field id", values[i]) } else if value != nil { pr.ID = *value } case profile.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 { pr.CreatedAt = value.Time } case profile.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 { pr.UpdatedAt = value.Time } case profile.FieldName: if value, ok := values[i].(*sql.NullString); !ok { return fmt.Errorf("unexpected type %T for field name", values[i]) } else if value.Valid { pr.Name = value.String } case profile.FieldAddress: if value, ok := values[i].(*sql.NullString); !ok { return fmt.Errorf("unexpected type %T for field address", values[i]) } else if value.Valid { pr.Address = value.String } case profile.FieldPhone: if value, ok := values[i].(*sql.NullString); !ok { return fmt.Errorf("unexpected type %T for field phone", values[i]) } else if value.Valid { pr.Phone = value.String } default: pr.selectValues.Set(columns[i], values[i]) } } return nil } // Value returns the ent.Value that was dynamically selected and assigned to the Profile. // This includes values selected through modifiers, order, etc. func (pr *Profile) Value(name string) (ent.Value, error) { return pr.selectValues.Get(name) } // QueryPosts queries the "posts" edge of the Profile entity. func (pr *Profile) QueryPosts() *PostQuery { return NewProfileClient(pr.config).QueryPosts(pr) } // Update returns a builder for updating this Profile. // Note that you need to call Profile.Unwrap() before calling this method if this Profile // was returned from a transaction, and the transaction was committed or rolled back. func (pr *Profile) Update() *ProfileUpdateOne { return NewProfileClient(pr.config).UpdateOne(pr) } // Unwrap unwraps the Profile 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 (pr *Profile) Unwrap() *Profile { _tx, ok := pr.config.driver.(*txDriver) if !ok { panic("ent: Profile is not a transactional entity") } pr.config.driver = _tx.drv return pr } // String implements the fmt.Stringer. func (pr *Profile) String() string { var builder strings.Builder builder.WriteString("Profile(") builder.WriteString(fmt.Sprintf("id=%v, ", pr.ID)) builder.WriteString("created_at=") builder.WriteString(pr.CreatedAt.Format(time.ANSIC)) builder.WriteString(", ") builder.WriteString("updated_at=") builder.WriteString(pr.UpdatedAt.Format(time.ANSIC)) builder.WriteString(", ") builder.WriteString("name=") builder.WriteString(pr.Name) builder.WriteString(", ") builder.WriteString("address=") builder.WriteString(pr.Address) builder.WriteString(", ") builder.WriteString("phone=") builder.WriteString(pr.Phone) builder.WriteByte(')') return builder.String() } // NamedPosts returns the Posts named value or an error if the edge was not // loaded in eager-loading with this name. func (pr *Profile) NamedPosts(name string) ([]*Post, error) { if pr.Edges.namedPosts == nil { return nil, &NotLoadedError{edge: name} } nodes, ok := pr.Edges.namedPosts[name] if !ok { return nil, &NotLoadedError{edge: name} } return nodes, nil } func (pr *Profile) appendNamedPosts(name string, edges ...*Post) { if pr.Edges.namedPosts == nil { pr.Edges.namedPosts = make(map[string][]*Post) } if len(edges) == 0 { pr.Edges.namedPosts[name] = []*Post{} } else { pr.Edges.namedPosts[name] = append(pr.Edges.namedPosts[name], edges...) } } // Profiles is a parsable slice of Profile. type Profiles []*Profile