propertyschemafield.go•6.55 kB
// Code generated by ent, DO NOT EDIT.
package ent
import (
"fmt"
"strings"
"entgo.io/ent"
"entgo.io/ent/dialect/sql"
"github.com/Southclaws/storyden/internal/ent/propertyschema"
"github.com/Southclaws/storyden/internal/ent/propertyschemafield"
"github.com/rs/xid"
)
// PropertySchemaField is the model entity for the PropertySchemaField schema.
type PropertySchemaField struct {
config `json:"-"`
// ID of the ent.
ID xid.ID `json:"id,omitempty"`
// Name holds the value of the "name" field.
Name string `json:"name,omitempty"`
// Type holds the value of the "type" field.
Type string `json:"type,omitempty"`
// Sort holds the value of the "sort" field.
Sort string `json:"sort,omitempty"`
// SchemaID holds the value of the "schema_id" field.
SchemaID xid.ID `json:"schema_id,omitempty"`
// Edges holds the relations/edges for other nodes in the graph.
// The values are being populated by the PropertySchemaFieldQuery when eager-loading is set.
Edges PropertySchemaFieldEdges `json:"edges"`
selectValues sql.SelectValues
}
// PropertySchemaFieldEdges holds the relations/edges for other nodes in the graph.
type PropertySchemaFieldEdges struct {
// Schema holds the value of the schema edge.
Schema *PropertySchema `json:"schema,omitempty"`
// Properties holds the value of the properties edge.
Properties []*Property `json:"properties,omitempty"`
// loadedTypes holds the information for reporting if a
// type was loaded (or requested) in eager-loading or not.
loadedTypes [2]bool
}
// SchemaOrErr returns the Schema value or an error if the edge
// was not loaded in eager-loading, or loaded but was not found.
func (e PropertySchemaFieldEdges) SchemaOrErr() (*PropertySchema, error) {
if e.Schema != nil {
return e.Schema, nil
} else if e.loadedTypes[0] {
return nil, &NotFoundError{label: propertyschema.Label}
}
return nil, &NotLoadedError{edge: "schema"}
}
// PropertiesOrErr returns the Properties value or an error if the edge
// was not loaded in eager-loading.
func (e PropertySchemaFieldEdges) PropertiesOrErr() ([]*Property, error) {
if e.loadedTypes[1] {
return e.Properties, nil
}
return nil, &NotLoadedError{edge: "properties"}
}
// scanValues returns the types for scanning values from sql.Rows.
func (*PropertySchemaField) scanValues(columns []string) ([]any, error) {
values := make([]any, len(columns))
for i := range columns {
switch columns[i] {
case propertyschemafield.FieldName, propertyschemafield.FieldType, propertyschemafield.FieldSort:
values[i] = new(sql.NullString)
case propertyschemafield.FieldID, propertyschemafield.FieldSchemaID:
values[i] = new(xid.ID)
default:
values[i] = new(sql.UnknownType)
}
}
return values, nil
}
// assignValues assigns the values that were returned from sql.Rows (after scanning)
// to the PropertySchemaField fields.
func (_m *PropertySchemaField) 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 propertyschemafield.FieldID:
if value, ok := values[i].(*xid.ID); !ok {
return fmt.Errorf("unexpected type %T for field id", values[i])
} else if value != nil {
_m.ID = *value
}
case propertyschemafield.FieldName:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field name", values[i])
} else if value.Valid {
_m.Name = value.String
}
case propertyschemafield.FieldType:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field type", values[i])
} else if value.Valid {
_m.Type = value.String
}
case propertyschemafield.FieldSort:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field sort", values[i])
} else if value.Valid {
_m.Sort = value.String
}
case propertyschemafield.FieldSchemaID:
if value, ok := values[i].(*xid.ID); !ok {
return fmt.Errorf("unexpected type %T for field schema_id", values[i])
} else if value != nil {
_m.SchemaID = *value
}
default:
_m.selectValues.Set(columns[i], values[i])
}
}
return nil
}
// Value returns the ent.Value that was dynamically selected and assigned to the PropertySchemaField.
// This includes values selected through modifiers, order, etc.
func (_m *PropertySchemaField) Value(name string) (ent.Value, error) {
return _m.selectValues.Get(name)
}
// QuerySchema queries the "schema" edge of the PropertySchemaField entity.
func (_m *PropertySchemaField) QuerySchema() *PropertySchemaQuery {
return NewPropertySchemaFieldClient(_m.config).QuerySchema(_m)
}
// QueryProperties queries the "properties" edge of the PropertySchemaField entity.
func (_m *PropertySchemaField) QueryProperties() *PropertyQuery {
return NewPropertySchemaFieldClient(_m.config).QueryProperties(_m)
}
// Update returns a builder for updating this PropertySchemaField.
// Note that you need to call PropertySchemaField.Unwrap() before calling this method if this PropertySchemaField
// was returned from a transaction, and the transaction was committed or rolled back.
func (_m *PropertySchemaField) Update() *PropertySchemaFieldUpdateOne {
return NewPropertySchemaFieldClient(_m.config).UpdateOne(_m)
}
// Unwrap unwraps the PropertySchemaField 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 *PropertySchemaField) Unwrap() *PropertySchemaField {
_tx, ok := _m.config.driver.(*txDriver)
if !ok {
panic("ent: PropertySchemaField is not a transactional entity")
}
_m.config.driver = _tx.drv
return _m
}
// String implements the fmt.Stringer.
func (_m *PropertySchemaField) String() string {
var builder strings.Builder
builder.WriteString("PropertySchemaField(")
builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID))
builder.WriteString("name=")
builder.WriteString(_m.Name)
builder.WriteString(", ")
builder.WriteString("type=")
builder.WriteString(_m.Type)
builder.WriteString(", ")
builder.WriteString("sort=")
builder.WriteString(_m.Sort)
builder.WriteString(", ")
builder.WriteString("schema_id=")
builder.WriteString(fmt.Sprintf("%v", _m.SchemaID))
builder.WriteByte(')')
return builder.String()
}
// PropertySchemaFields is a parsable slice of PropertySchemaField.
type PropertySchemaFields []*PropertySchemaField