htmgo/examples/todo-list/ent/task.go

170 lines
5.3 KiB
Go

// Code generated by ent, DO NOT EDIT.
package ent
import (
"encoding/json"
"fmt"
"strings"
"time"
"todolist/ent/task"
"entgo.io/ent"
"entgo.io/ent/dialect/sql"
"github.com/google/uuid"
)
// Task is the model entity for the Task schema.
type Task struct {
config `json:"-"`
// ID of the ent.
ID uuid.UUID `json:"id,omitempty"`
// Name holds the value of the "name" field.
Name string `json:"name,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"`
// CompletedAt holds the value of the "completed_at" field.
CompletedAt *time.Time `json:"completed_at,omitempty"`
// Tags holds the value of the "tags" field.
Tags []string `json:"tags,omitempty"`
// IPAddress holds the value of the "ip_address" field.
IPAddress string `json:"ip_address,omitempty"`
selectValues sql.SelectValues
}
// scanValues returns the types for scanning values from sql.Rows.
func (*Task) scanValues(columns []string) ([]any, error) {
values := make([]any, len(columns))
for i := range columns {
switch columns[i] {
case task.FieldTags:
values[i] = new([]byte)
case task.FieldName, task.FieldIPAddress:
values[i] = new(sql.NullString)
case task.FieldCreatedAt, task.FieldUpdatedAt, task.FieldCompletedAt:
values[i] = new(sql.NullTime)
case task.FieldID:
values[i] = new(uuid.UUID)
default:
values[i] = new(sql.UnknownType)
}
}
return values, nil
}
// assignValues assigns the values that were returned from sql.Rows (after scanning)
// to the Task fields.
func (t *Task) 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 task.FieldID:
if value, ok := values[i].(*uuid.UUID); !ok {
return fmt.Errorf("unexpected type %T for field id", values[i])
} else if value != nil {
t.ID = *value
}
case task.FieldName:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field name", values[i])
} else if value.Valid {
t.Name = value.String
}
case task.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 {
t.CreatedAt = value.Time
}
case task.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 {
t.UpdatedAt = value.Time
}
case task.FieldCompletedAt:
if value, ok := values[i].(*sql.NullTime); !ok {
return fmt.Errorf("unexpected type %T for field completed_at", values[i])
} else if value.Valid {
t.CompletedAt = new(time.Time)
*t.CompletedAt = value.Time
}
case task.FieldTags:
if value, ok := values[i].(*[]byte); !ok {
return fmt.Errorf("unexpected type %T for field tags", values[i])
} else if value != nil && len(*value) > 0 {
if err := json.Unmarshal(*value, &t.Tags); err != nil {
return fmt.Errorf("unmarshal field tags: %w", err)
}
}
case task.FieldIPAddress:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field ip_address", values[i])
} else if value.Valid {
t.IPAddress = value.String
}
default:
t.selectValues.Set(columns[i], values[i])
}
}
return nil
}
// Value returns the ent.Value that was dynamically selected and assigned to the Task.
// This includes values selected through modifiers, order, etc.
func (t *Task) Value(name string) (ent.Value, error) {
return t.selectValues.Get(name)
}
// Update returns a builder for updating this Task.
// Note that you need to call Task.Unwrap() before calling this method if this Task
// was returned from a transaction, and the transaction was committed or rolled back.
func (t *Task) Update() *TaskUpdateOne {
return NewTaskClient(t.config).UpdateOne(t)
}
// Unwrap unwraps the Task 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 (t *Task) Unwrap() *Task {
_tx, ok := t.config.driver.(*txDriver)
if !ok {
panic("ent: Task is not a transactional entity")
}
t.config.driver = _tx.drv
return t
}
// String implements the fmt.Stringer.
func (t *Task) String() string {
var builder strings.Builder
builder.WriteString("Task(")
builder.WriteString(fmt.Sprintf("id=%v, ", t.ID))
builder.WriteString("name=")
builder.WriteString(t.Name)
builder.WriteString(", ")
builder.WriteString("created_at=")
builder.WriteString(t.CreatedAt.Format(time.ANSIC))
builder.WriteString(", ")
builder.WriteString("updated_at=")
builder.WriteString(t.UpdatedAt.Format(time.ANSIC))
builder.WriteString(", ")
if v := t.CompletedAt; v != nil {
builder.WriteString("completed_at=")
builder.WriteString(v.Format(time.ANSIC))
}
builder.WriteString(", ")
builder.WriteString("tags=")
builder.WriteString(fmt.Sprintf("%v", t.Tags))
builder.WriteString(", ")
builder.WriteString("ip_address=")
builder.WriteString(t.IPAddress)
builder.WriteByte(')')
return builder.String()
}
// Tasks is a parsable slice of Task.
type Tasks []*Task