/
todo.go
executable file
·160 lines (149 loc) · 5.03 KB
/
todo.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
// Code generated by ent, DO NOT EDIT.
package ent
import (
"fmt"
"strings"
"time"
"entgo.io/ent/dialect/sql"
"github.com/dev-hyunsang/golang-jwt-redis/ent/todo"
"github.com/google/uuid"
)
// ToDo is the model entity for the ToDo schema.
type ToDo struct {
config `json:"-"`
// ID of the ent.
ID int `json:"id,omitempty"`
// TodoUUID holds the value of the "todo_uuid" field.
TodoUUID uuid.UUID `json:"todo_uuid,omitempty"`
// UserUUID holds the value of the "user_uuid" field.
UserUUID uuid.UUID `json:"user_uuid,omitempty"`
// TodoTitle holds the value of the "todo_title" field.
TodoTitle string `json:"todo_title,omitempty"`
// TodoContext holds the value of the "todo_context" field.
TodoContext string `json:"todo_context,omitempty"`
// UpdatedAt holds the value of the "updated_at" field.
UpdatedAt time.Time `json:"updated_at,omitempty"`
// CratedAt holds the value of the "crated_at" field.
CratedAt time.Time `json:"crated_at,omitempty"`
}
// scanValues returns the types for scanning values from sql.Rows.
func (*ToDo) scanValues(columns []string) ([]any, error) {
values := make([]any, len(columns))
for i := range columns {
switch columns[i] {
case todo.FieldID:
values[i] = new(sql.NullInt64)
case todo.FieldTodoTitle, todo.FieldTodoContext:
values[i] = new(sql.NullString)
case todo.FieldUpdatedAt, todo.FieldCratedAt:
values[i] = new(sql.NullTime)
case todo.FieldTodoUUID, todo.FieldUserUUID:
values[i] = new(uuid.UUID)
default:
return nil, fmt.Errorf("unexpected column %q for type ToDo", columns[i])
}
}
return values, nil
}
// assignValues assigns the values that were returned from sql.Rows (after scanning)
// to the ToDo fields.
func (td *ToDo) 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 todo.FieldID:
value, ok := values[i].(*sql.NullInt64)
if !ok {
return fmt.Errorf("unexpected type %T for field id", value)
}
td.ID = int(value.Int64)
case todo.FieldTodoUUID:
if value, ok := values[i].(*uuid.UUID); !ok {
return fmt.Errorf("unexpected type %T for field todo_uuid", values[i])
} else if value != nil {
td.TodoUUID = *value
}
case todo.FieldUserUUID:
if value, ok := values[i].(*uuid.UUID); !ok {
return fmt.Errorf("unexpected type %T for field user_uuid", values[i])
} else if value != nil {
td.UserUUID = *value
}
case todo.FieldTodoTitle:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field todo_title", values[i])
} else if value.Valid {
td.TodoTitle = value.String
}
case todo.FieldTodoContext:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field todo_context", values[i])
} else if value.Valid {
td.TodoContext = value.String
}
case todo.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 {
td.UpdatedAt = value.Time
}
case todo.FieldCratedAt:
if value, ok := values[i].(*sql.NullTime); !ok {
return fmt.Errorf("unexpected type %T for field crated_at", values[i])
} else if value.Valid {
td.CratedAt = value.Time
}
}
}
return nil
}
// Update returns a builder for updating this ToDo.
// Note that you need to call ToDo.Unwrap() before calling this method if this ToDo
// was returned from a transaction, and the transaction was committed or rolled back.
func (td *ToDo) Update() *ToDoUpdateOne {
return (&ToDoClient{config: td.config}).UpdateOne(td)
}
// Unwrap unwraps the ToDo 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 (td *ToDo) Unwrap() *ToDo {
_tx, ok := td.config.driver.(*txDriver)
if !ok {
panic("ent: ToDo is not a transactional entity")
}
td.config.driver = _tx.drv
return td
}
// String implements the fmt.Stringer.
func (td *ToDo) String() string {
var builder strings.Builder
builder.WriteString("ToDo(")
builder.WriteString(fmt.Sprintf("id=%v, ", td.ID))
builder.WriteString("todo_uuid=")
builder.WriteString(fmt.Sprintf("%v", td.TodoUUID))
builder.WriteString(", ")
builder.WriteString("user_uuid=")
builder.WriteString(fmt.Sprintf("%v", td.UserUUID))
builder.WriteString(", ")
builder.WriteString("todo_title=")
builder.WriteString(td.TodoTitle)
builder.WriteString(", ")
builder.WriteString("todo_context=")
builder.WriteString(td.TodoContext)
builder.WriteString(", ")
builder.WriteString("updated_at=")
builder.WriteString(td.UpdatedAt.Format(time.ANSIC))
builder.WriteString(", ")
builder.WriteString("crated_at=")
builder.WriteString(td.CratedAt.Format(time.ANSIC))
builder.WriteByte(')')
return builder.String()
}
// ToDos is a parsable slice of ToDo.
type ToDos []*ToDo
func (td ToDos) config(cfg config) {
for _i := range td {
td[_i].config = cfg
}
}