// Copyright 2019-present Facebook Inc. All rights reserved. // This source code is licensed under the Apache 2.0 license found // in the LICENSE file in the root directory of this source tree. // Code generated by ent, DO NOT EDIT. package ent import ( "fmt" "strings" "entgo.io/ent" "entgo.io/ent/dialect/sql" "entgo.io/ent/entc/integration/edgefield/ent/metadata" "entgo.io/ent/entc/integration/edgefield/ent/user" ) // Metadata is the model entity for the Metadata schema. type Metadata struct { config `json:"-"` // ID of the ent. ID int `json:"id,omitempty"` // Age holds the value of the "age" field. Age int `json:"age,omitempty"` // ParentID holds the value of the "parent_id" field. ParentID int `json:"parent_id,omitempty"` // Edges holds the relations/edges for other nodes in the graph. // The values are being populated by the MetadataQuery when eager-loading is set. Edges MetadataEdges `json:"edges"` selectValues sql.SelectValues } // MetadataEdges holds the relations/edges for other nodes in the graph. type MetadataEdges struct { // User holds the value of the user edge. User *User `json:"user,omitempty"` // Children holds the value of the children edge. Children []*Metadata `json:"children,omitempty"` // Parent holds the value of the parent edge. Parent *Metadata `json:"parent,omitempty"` // loadedTypes holds the information for reporting if a // type was loaded (or requested) in eager-loading or not. loadedTypes [3]bool namedChildren map[string][]*Metadata } // 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 MetadataEdges) 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"} } // ChildrenOrErr returns the Children value or an error if the edge // was not loaded in eager-loading. func (e MetadataEdges) ChildrenOrErr() ([]*Metadata, error) { if e.loadedTypes[1] { return e.Children, nil } return nil, &NotLoadedError{edge: "children"} } // ParentOrErr returns the Parent value or an error if the edge // was not loaded in eager-loading, or loaded but was not found. func (e MetadataEdges) ParentOrErr() (*Metadata, error) { if e.Parent != nil { return e.Parent, nil } else if e.loadedTypes[2] { return nil, &NotFoundError{label: metadata.Label} } return nil, &NotLoadedError{edge: "parent"} } // scanValues returns the types for scanning values from sql.Rows. func (*Metadata) scanValues(columns []string) ([]any, error) { values := make([]any, len(columns)) for i := range columns { switch columns[i] { case metadata.FieldID, metadata.FieldAge, metadata.FieldParentID: 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 Metadata fields. func (_m *Metadata) 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 metadata.FieldID: value, ok := values[i].(*sql.NullInt64) if !ok { return fmt.Errorf("unexpected type %T for field id", value) } _m.ID = int(value.Int64) case metadata.FieldAge: if value, ok := values[i].(*sql.NullInt64); !ok { return fmt.Errorf("unexpected type %T for field age", values[i]) } else if value.Valid { _m.Age = int(value.Int64) } case metadata.FieldParentID: if value, ok := values[i].(*sql.NullInt64); !ok { return fmt.Errorf("unexpected type %T for field parent_id", values[i]) } else if value.Valid { _m.ParentID = int(value.Int64) } default: _m.selectValues.Set(columns[i], values[i]) } } return nil } // Value returns the ent.Value that was dynamically selected and assigned to the Metadata. // This includes values selected through modifiers, order, etc. func (_m *Metadata) Value(name string) (ent.Value, error) { return _m.selectValues.Get(name) } // QueryUser queries the "user" edge of the Metadata entity. func (_m *Metadata) QueryUser() *UserQuery { return NewMetadataClient(_m.config).QueryUser(_m) } // QueryChildren queries the "children" edge of the Metadata entity. func (_m *Metadata) QueryChildren() *MetadataQuery { return NewMetadataClient(_m.config).QueryChildren(_m) } // QueryParent queries the "parent" edge of the Metadata entity. func (_m *Metadata) QueryParent() *MetadataQuery { return NewMetadataClient(_m.config).QueryParent(_m) } // Update returns a builder for updating this Metadata. // Note that you need to call Metadata.Unwrap() before calling this method if this Metadata // was returned from a transaction, and the transaction was committed or rolled back. func (_m *Metadata) Update() *MetadataUpdateOne { return NewMetadataClient(_m.config).UpdateOne(_m) } // Unwrap unwraps the Metadata 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 *Metadata) Unwrap() *Metadata { _tx, ok := _m.config.driver.(*txDriver) if !ok { panic("ent: Metadata is not a transactional entity") } _m.config.driver = _tx.drv return _m } // String implements the fmt.Stringer. func (_m *Metadata) String() string { var builder strings.Builder builder.WriteString("Metadata(") builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID)) builder.WriteString("age=") builder.WriteString(fmt.Sprintf("%v", _m.Age)) builder.WriteString(", ") builder.WriteString("parent_id=") builder.WriteString(fmt.Sprintf("%v", _m.ParentID)) builder.WriteByte(')') return builder.String() } // NamedChildren returns the Children named value or an error if the edge was not // loaded in eager-loading with this name. func (_m *Metadata) NamedChildren(name string) ([]*Metadata, error) { if _m.Edges.namedChildren == nil { return nil, &NotLoadedError{edge: name} } nodes, ok := _m.Edges.namedChildren[name] if !ok { return nil, &NotLoadedError{edge: name} } return nodes, nil } func (_m *Metadata) appendNamedChildren(name string, edges ...*Metadata) { if _m.Edges.namedChildren == nil { _m.Edges.namedChildren = make(map[string][]*Metadata) } if len(edges) == 0 { _m.Edges.namedChildren[name] = []*Metadata{} } else { _m.Edges.namedChildren[name] = append(_m.Edges.namedChildren[name], edges...) } } // MetadataSlice is a parsable slice of Metadata. type MetadataSlice []*Metadata