// Code generated by ent, DO NOT EDIT. package ent import ( "encoding/json" "fmt" "online-order/ent/business" "online-order/ent/domain" "online-order/ent/user" "strings" "time" "entgo.io/ent" "entgo.io/ent/dialect/sql" ) // Domain is the model entity for the Domain schema. type Domain struct { config `json:"-"` // ID of the ent. ID int `json:"id,omitempty"` // Domain holds the value of the "domain" field. Domain string `json:"domain,omitempty"` // BusinessID holds the value of the "business_id" field. BusinessID *int `json:"business_id,omitempty"` // UserID holds the value of the "user_id" field. UserID *int `json:"user_id,omitempty"` // Config holds the value of the "config" field. Config []string `json:"config,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 DomainQuery when eager-loading is set. Edges DomainEdges `json:"edges"` selectValues sql.SelectValues } // DomainEdges holds the relations/edges for other nodes in the graph. type DomainEdges struct { // Businesses holds the value of the businesses edge. Businesses *Business `json:"businesses,omitempty"` // Users holds the value of the users edge. Users *User `json:"users,omitempty"` // loadedTypes holds the information for reporting if a // type was loaded (or requested) in eager-loading or not. loadedTypes [2]bool } // BusinessesOrErr returns the Businesses value or an error if the edge // was not loaded in eager-loading, or loaded but was not found. func (e DomainEdges) BusinessesOrErr() (*Business, error) { if e.loadedTypes[0] { if e.Businesses == nil { // Edge was loaded but was not found. return nil, &NotFoundError{label: business.Label} } return e.Businesses, nil } return nil, &NotLoadedError{edge: "businesses"} } // UsersOrErr returns the Users value or an error if the edge // was not loaded in eager-loading, or loaded but was not found. func (e DomainEdges) UsersOrErr() (*User, error) { if e.loadedTypes[1] { if e.Users == nil { // Edge was loaded but was not found. return nil, &NotFoundError{label: user.Label} } return e.Users, nil } return nil, &NotLoadedError{edge: "users"} } // scanValues returns the types for scanning values from sql.Rows. func (*Domain) scanValues(columns []string) ([]any, error) { values := make([]any, len(columns)) for i := range columns { switch columns[i] { case domain.FieldConfig: values[i] = new([]byte) case domain.FieldID, domain.FieldBusinessID, domain.FieldUserID: values[i] = new(sql.NullInt64) case domain.FieldDomain: values[i] = new(sql.NullString) case domain.FieldCreatedAt, domain.FieldUpdatedAt: 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 Domain fields. func (d *Domain) 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 domain.FieldID: value, ok := values[i].(*sql.NullInt64) if !ok { return fmt.Errorf("unexpected type %T for field id", value) } d.ID = int(value.Int64) case domain.FieldDomain: if value, ok := values[i].(*sql.NullString); !ok { return fmt.Errorf("unexpected type %T for field domain", values[i]) } else if value.Valid { d.Domain = value.String } case domain.FieldBusinessID: if value, ok := values[i].(*sql.NullInt64); !ok { return fmt.Errorf("unexpected type %T for field business_id", values[i]) } else if value.Valid { d.BusinessID = new(int) *d.BusinessID = int(value.Int64) } case domain.FieldUserID: if value, ok := values[i].(*sql.NullInt64); !ok { return fmt.Errorf("unexpected type %T for field user_id", values[i]) } else if value.Valid { d.UserID = new(int) *d.UserID = int(value.Int64) } case domain.FieldConfig: if value, ok := values[i].(*[]byte); !ok { return fmt.Errorf("unexpected type %T for field config", values[i]) } else if value != nil && len(*value) > 0 { if err := json.Unmarshal(*value, &d.Config); err != nil { return fmt.Errorf("unmarshal field config: %w", err) } } case domain.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 { d.CreatedAt = value.Time } case domain.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 { d.UpdatedAt = value.Time } default: d.selectValues.Set(columns[i], values[i]) } } return nil } // Value returns the ent.Value that was dynamically selected and assigned to the Domain. // This includes values selected through modifiers, order, etc. func (d *Domain) Value(name string) (ent.Value, error) { return d.selectValues.Get(name) } // QueryBusinesses queries the "businesses" edge of the Domain entity. func (d *Domain) QueryBusinesses() *BusinessQuery { return NewDomainClient(d.config).QueryBusinesses(d) } // QueryUsers queries the "users" edge of the Domain entity. func (d *Domain) QueryUsers() *UserQuery { return NewDomainClient(d.config).QueryUsers(d) } // Update returns a builder for updating this Domain. // Note that you need to call Domain.Unwrap() before calling this method if this Domain // was returned from a transaction, and the transaction was committed or rolled back. func (d *Domain) Update() *DomainUpdateOne { return NewDomainClient(d.config).UpdateOne(d) } // Unwrap unwraps the Domain 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 (d *Domain) Unwrap() *Domain { _tx, ok := d.config.driver.(*txDriver) if !ok { panic("ent: Domain is not a transactional entity") } d.config.driver = _tx.drv return d } // String implements the fmt.Stringer. func (d *Domain) String() string { var builder strings.Builder builder.WriteString("Domain(") builder.WriteString(fmt.Sprintf("id=%v, ", d.ID)) builder.WriteString("domain=") builder.WriteString(d.Domain) builder.WriteString(", ") if v := d.BusinessID; v != nil { builder.WriteString("business_id=") builder.WriteString(fmt.Sprintf("%v", *v)) } builder.WriteString(", ") if v := d.UserID; v != nil { builder.WriteString("user_id=") builder.WriteString(fmt.Sprintf("%v", *v)) } builder.WriteString(", ") builder.WriteString("config=") builder.WriteString(fmt.Sprintf("%v", d.Config)) builder.WriteString(", ") builder.WriteString("created_at=") builder.WriteString(d.CreatedAt.Format(time.ANSIC)) builder.WriteString(", ") builder.WriteString("updated_at=") builder.WriteString(d.UpdatedAt.Format(time.ANSIC)) builder.WriteByte(')') return builder.String() } // Domains is a parsable slice of Domain. type Domains []*Domain