// Code generated by ent, DO NOT EDIT. package ent import ( "fmt" "strings" "time" "tss-rocks-be/ent/contributor" "tss-rocks-be/ent/user" "entgo.io/ent" "entgo.io/ent/dialect/sql" ) // Contributor is the model entity for the Contributor schema. type Contributor struct { config `json:"-"` // ID of the ent. ID int `json:"id,omitempty"` // Name holds the value of the "name" field. Name string `json:"name,omitempty"` // AvatarURL holds the value of the "avatar_url" field. AvatarURL string `json:"avatar_url,omitempty"` // Bio holds the value of the "bio" field. Bio string `json:"bio,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"` // Edges holds the relations/edges for other nodes in the graph. // The values are being populated by the ContributorQuery when eager-loading is set. Edges ContributorEdges `json:"edges"` user_contributors *int selectValues sql.SelectValues } // ContributorEdges holds the relations/edges for other nodes in the graph. type ContributorEdges struct { // User holds the value of the user edge. User *User `json:"user,omitempty"` // SocialLinks holds the value of the social_links edge. SocialLinks []*ContributorSocialLink `json:"social_links,omitempty"` // Posts holds the value of the posts edge. Posts []*PostContributor `json:"posts,omitempty"` // loadedTypes holds the information for reporting if a // type was loaded (or requested) in eager-loading or not. loadedTypes [3]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 ContributorEdges) 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"} } // SocialLinksOrErr returns the SocialLinks value or an error if the edge // was not loaded in eager-loading. func (e ContributorEdges) SocialLinksOrErr() ([]*ContributorSocialLink, error) { if e.loadedTypes[1] { return e.SocialLinks, nil } return nil, &NotLoadedError{edge: "social_links"} } // PostsOrErr returns the Posts value or an error if the edge // was not loaded in eager-loading. func (e ContributorEdges) PostsOrErr() ([]*PostContributor, error) { if e.loadedTypes[2] { return e.Posts, nil } return nil, &NotLoadedError{edge: "posts"} } // scanValues returns the types for scanning values from sql.Rows. func (*Contributor) scanValues(columns []string) ([]any, error) { values := make([]any, len(columns)) for i := range columns { switch columns[i] { case contributor.FieldID: values[i] = new(sql.NullInt64) case contributor.FieldName, contributor.FieldAvatarURL, contributor.FieldBio: values[i] = new(sql.NullString) case contributor.FieldCreatedAt, contributor.FieldUpdatedAt: values[i] = new(sql.NullTime) case contributor.ForeignKeys[0]: // user_contributors 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 Contributor fields. func (c *Contributor) 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 contributor.FieldID: value, ok := values[i].(*sql.NullInt64) if !ok { return fmt.Errorf("unexpected type %T for field id", value) } c.ID = int(value.Int64) case contributor.FieldName: if value, ok := values[i].(*sql.NullString); !ok { return fmt.Errorf("unexpected type %T for field name", values[i]) } else if value.Valid { c.Name = value.String } case contributor.FieldAvatarURL: if value, ok := values[i].(*sql.NullString); !ok { return fmt.Errorf("unexpected type %T for field avatar_url", values[i]) } else if value.Valid { c.AvatarURL = value.String } case contributor.FieldBio: if value, ok := values[i].(*sql.NullString); !ok { return fmt.Errorf("unexpected type %T for field bio", values[i]) } else if value.Valid { c.Bio = value.String } case contributor.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 { c.CreatedAt = value.Time } case contributor.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 { c.UpdatedAt = value.Time } case contributor.ForeignKeys[0]: if value, ok := values[i].(*sql.NullInt64); !ok { return fmt.Errorf("unexpected type %T for edge-field user_contributors", value) } else if value.Valid { c.user_contributors = new(int) *c.user_contributors = int(value.Int64) } default: c.selectValues.Set(columns[i], values[i]) } } return nil } // Value returns the ent.Value that was dynamically selected and assigned to the Contributor. // This includes values selected through modifiers, order, etc. func (c *Contributor) Value(name string) (ent.Value, error) { return c.selectValues.Get(name) } // QueryUser queries the "user" edge of the Contributor entity. func (c *Contributor) QueryUser() *UserQuery { return NewContributorClient(c.config).QueryUser(c) } // QuerySocialLinks queries the "social_links" edge of the Contributor entity. func (c *Contributor) QuerySocialLinks() *ContributorSocialLinkQuery { return NewContributorClient(c.config).QuerySocialLinks(c) } // QueryPosts queries the "posts" edge of the Contributor entity. func (c *Contributor) QueryPosts() *PostContributorQuery { return NewContributorClient(c.config).QueryPosts(c) } // Update returns a builder for updating this Contributor. // Note that you need to call Contributor.Unwrap() before calling this method if this Contributor // was returned from a transaction, and the transaction was committed or rolled back. func (c *Contributor) Update() *ContributorUpdateOne { return NewContributorClient(c.config).UpdateOne(c) } // Unwrap unwraps the Contributor 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 (c *Contributor) Unwrap() *Contributor { _tx, ok := c.config.driver.(*txDriver) if !ok { panic("ent: Contributor is not a transactional entity") } c.config.driver = _tx.drv return c } // String implements the fmt.Stringer. func (c *Contributor) String() string { var builder strings.Builder builder.WriteString("Contributor(") builder.WriteString(fmt.Sprintf("id=%v, ", c.ID)) builder.WriteString("name=") builder.WriteString(c.Name) builder.WriteString(", ") builder.WriteString("avatar_url=") builder.WriteString(c.AvatarURL) builder.WriteString(", ") builder.WriteString("bio=") builder.WriteString(c.Bio) builder.WriteString(", ") builder.WriteString("created_at=") builder.WriteString(c.CreatedAt.Format(time.ANSIC)) builder.WriteString(", ") builder.WriteString("updated_at=") builder.WriteString(c.UpdatedAt.Format(time.ANSIC)) builder.WriteByte(')') return builder.String() } // Contributors is a parsable slice of Contributor. type Contributors []*Contributor