property.go•6.28 kB
// Code generated by ent, DO NOT EDIT.
package ent
import (
"fmt"
"strings"
"time"
"entgo.io/ent"
"entgo.io/ent/dialect/sql"
"github.com/Southclaws/storyden/internal/ent/node"
"github.com/Southclaws/storyden/internal/ent/property"
"github.com/Southclaws/storyden/internal/ent/propertyschemafield"
"github.com/rs/xid"
)
// Property is the model entity for the Property schema.
type Property struct {
config `json:"-"`
// ID of the ent.
ID xid.ID `json:"id,omitempty"`
// CreatedAt holds the value of the "created_at" field.
CreatedAt time.Time `json:"created_at,omitempty"`
// NodeID holds the value of the "node_id" field.
NodeID xid.ID `json:"node_id,omitempty"`
// FieldID holds the value of the "field_id" field.
FieldID xid.ID `json:"field_id,omitempty"`
// Value holds the value of the "value" field.
Value string `json:"value,omitempty"`
// Edges holds the relations/edges for other nodes in the graph.
// The values are being populated by the PropertyQuery when eager-loading is set.
Edges PropertyEdges `json:"edges"`
selectValues sql.SelectValues
}
// PropertyEdges holds the relations/edges for other nodes in the graph.
type PropertyEdges struct {
// Node holds the value of the node edge.
Node *Node `json:"node,omitempty"`
// Schema holds the value of the schema edge.
Schema *PropertySchemaField `json:"schema,omitempty"`
// loadedTypes holds the information for reporting if a
// type was loaded (or requested) in eager-loading or not.
loadedTypes [2]bool
}
// NodeOrErr returns the Node value or an error if the edge
// was not loaded in eager-loading, or loaded but was not found.
func (e PropertyEdges) NodeOrErr() (*Node, error) {
if e.Node != nil {
return e.Node, nil
} else if e.loadedTypes[0] {
return nil, &NotFoundError{label: node.Label}
}
return nil, &NotLoadedError{edge: "node"}
}
// 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 PropertyEdges) SchemaOrErr() (*PropertySchemaField, error) {
if e.Schema != nil {
return e.Schema, nil
} else if e.loadedTypes[1] {
return nil, &NotFoundError{label: propertyschemafield.Label}
}
return nil, &NotLoadedError{edge: "schema"}
}
// scanValues returns the types for scanning values from sql.Rows.
func (*Property) scanValues(columns []string) ([]any, error) {
values := make([]any, len(columns))
for i := range columns {
switch columns[i] {
case property.FieldValue:
values[i] = new(sql.NullString)
case property.FieldCreatedAt:
values[i] = new(sql.NullTime)
case property.FieldID, property.FieldNodeID, property.FieldFieldID:
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 Property fields.
func (_m *Property) 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 property.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 property.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 {
_m.CreatedAt = value.Time
}
case property.FieldNodeID:
if value, ok := values[i].(*xid.ID); !ok {
return fmt.Errorf("unexpected type %T for field node_id", values[i])
} else if value != nil {
_m.NodeID = *value
}
case property.FieldFieldID:
if value, ok := values[i].(*xid.ID); !ok {
return fmt.Errorf("unexpected type %T for field field_id", values[i])
} else if value != nil {
_m.FieldID = *value
}
case property.FieldValue:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field value", values[i])
} else if value.Valid {
_m.Value = value.String
}
default:
_m.selectValues.Set(columns[i], values[i])
}
}
return nil
}
// GetValue returns the ent.Value that was dynamically selected and assigned to the Property.
// This includes values selected through modifiers, order, etc.
func (_m *Property) GetValue(name string) (ent.Value, error) {
return _m.selectValues.Get(name)
}
// QueryNode queries the "node" edge of the Property entity.
func (_m *Property) QueryNode() *NodeQuery {
return NewPropertyClient(_m.config).QueryNode(_m)
}
// QuerySchema queries the "schema" edge of the Property entity.
func (_m *Property) QuerySchema() *PropertySchemaFieldQuery {
return NewPropertyClient(_m.config).QuerySchema(_m)
}
// Update returns a builder for updating this Property.
// Note that you need to call Property.Unwrap() before calling this method if this Property
// was returned from a transaction, and the transaction was committed or rolled back.
func (_m *Property) Update() *PropertyUpdateOne {
return NewPropertyClient(_m.config).UpdateOne(_m)
}
// Unwrap unwraps the Property 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 *Property) Unwrap() *Property {
_tx, ok := _m.config.driver.(*txDriver)
if !ok {
panic("ent: Property is not a transactional entity")
}
_m.config.driver = _tx.drv
return _m
}
// String implements the fmt.Stringer.
func (_m *Property) String() string {
var builder strings.Builder
builder.WriteString("Property(")
builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID))
builder.WriteString("created_at=")
builder.WriteString(_m.CreatedAt.Format(time.ANSIC))
builder.WriteString(", ")
builder.WriteString("node_id=")
builder.WriteString(fmt.Sprintf("%v", _m.NodeID))
builder.WriteString(", ")
builder.WriteString("field_id=")
builder.WriteString(fmt.Sprintf("%v", _m.FieldID))
builder.WriteString(", ")
builder.WriteString("value=")
builder.WriteString(_m.Value)
builder.WriteByte(')')
return builder.String()
}
// Properties is a parsable slice of Property.
type Properties []*Property