/
notifyflowsource.go
215 lines (199 loc) · 8.5 KB
/
notifyflowsource.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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
// Code generated by ent, DO NOT EDIT.
package ent
import (
"encoding/json"
"fmt"
"strings"
"time"
"entgo.io/ent"
"entgo.io/ent/dialect/sql"
"github.com/tuihub/librarian/app/sephirah/internal/data/internal/ent/feedconfig"
"github.com/tuihub/librarian/app/sephirah/internal/data/internal/ent/notifyflow"
"github.com/tuihub/librarian/app/sephirah/internal/data/internal/ent/notifyflowsource"
"github.com/tuihub/librarian/internal/model"
)
// NotifyFlowSource is the model entity for the NotifyFlowSource schema.
type NotifyFlowSource struct {
config `json:"-"`
// ID of the ent.
ID int `json:"id,omitempty"`
// NotifyFlowID holds the value of the "notify_flow_id" field.
NotifyFlowID model.InternalID `json:"notify_flow_id,omitempty"`
// NotifySourceID holds the value of the "notify_source_id" field.
NotifySourceID model.InternalID `json:"notify_source_id,omitempty"`
// FilterIncludeKeywords holds the value of the "filter_include_keywords" field.
FilterIncludeKeywords []string `json:"filter_include_keywords,omitempty"`
// FilterExcludeKeywords holds the value of the "filter_exclude_keywords" field.
FilterExcludeKeywords []string `json:"filter_exclude_keywords,omitempty"`
// UpdatedAt holds the value of the "updated_at" field.
UpdatedAt time.Time `json:"updated_at,omitempty"`
// CreatedAt holds the value of the "created_at" field.
CreatedAt time.Time `json:"created_at,omitempty"`
// Edges holds the relations/edges for other nodes in the graph.
// The values are being populated by the NotifyFlowSourceQuery when eager-loading is set.
Edges NotifyFlowSourceEdges `json:"edges"`
selectValues sql.SelectValues
}
// NotifyFlowSourceEdges holds the relations/edges for other nodes in the graph.
type NotifyFlowSourceEdges struct {
// NotifyFlow holds the value of the notify_flow edge.
NotifyFlow *NotifyFlow `json:"notify_flow,omitempty"`
// NotifySource holds the value of the notify_source edge.
NotifySource *FeedConfig `json:"notify_source,omitempty"`
// loadedTypes holds the information for reporting if a
// type was loaded (or requested) in eager-loading or not.
loadedTypes [2]bool
}
// NotifyFlowOrErr returns the NotifyFlow value or an error if the edge
// was not loaded in eager-loading, or loaded but was not found.
func (e NotifyFlowSourceEdges) NotifyFlowOrErr() (*NotifyFlow, error) {
if e.NotifyFlow != nil {
return e.NotifyFlow, nil
} else if e.loadedTypes[0] {
return nil, &NotFoundError{label: notifyflow.Label}
}
return nil, &NotLoadedError{edge: "notify_flow"}
}
// NotifySourceOrErr returns the NotifySource value or an error if the edge
// was not loaded in eager-loading, or loaded but was not found.
func (e NotifyFlowSourceEdges) NotifySourceOrErr() (*FeedConfig, error) {
if e.NotifySource != nil {
return e.NotifySource, nil
} else if e.loadedTypes[1] {
return nil, &NotFoundError{label: feedconfig.Label}
}
return nil, &NotLoadedError{edge: "notify_source"}
}
// scanValues returns the types for scanning values from sql.Rows.
func (*NotifyFlowSource) scanValues(columns []string) ([]any, error) {
values := make([]any, len(columns))
for i := range columns {
switch columns[i] {
case notifyflowsource.FieldFilterIncludeKeywords, notifyflowsource.FieldFilterExcludeKeywords:
values[i] = new([]byte)
case notifyflowsource.FieldID, notifyflowsource.FieldNotifyFlowID, notifyflowsource.FieldNotifySourceID:
values[i] = new(sql.NullInt64)
case notifyflowsource.FieldUpdatedAt, notifyflowsource.FieldCreatedAt:
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 NotifyFlowSource fields.
func (nfs *NotifyFlowSource) 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 notifyflowsource.FieldID:
value, ok := values[i].(*sql.NullInt64)
if !ok {
return fmt.Errorf("unexpected type %T for field id", value)
}
nfs.ID = int(value.Int64)
case notifyflowsource.FieldNotifyFlowID:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field notify_flow_id", values[i])
} else if value.Valid {
nfs.NotifyFlowID = model.InternalID(value.Int64)
}
case notifyflowsource.FieldNotifySourceID:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field notify_source_id", values[i])
} else if value.Valid {
nfs.NotifySourceID = model.InternalID(value.Int64)
}
case notifyflowsource.FieldFilterIncludeKeywords:
if value, ok := values[i].(*[]byte); !ok {
return fmt.Errorf("unexpected type %T for field filter_include_keywords", values[i])
} else if value != nil && len(*value) > 0 {
if err := json.Unmarshal(*value, &nfs.FilterIncludeKeywords); err != nil {
return fmt.Errorf("unmarshal field filter_include_keywords: %w", err)
}
}
case notifyflowsource.FieldFilterExcludeKeywords:
if value, ok := values[i].(*[]byte); !ok {
return fmt.Errorf("unexpected type %T for field filter_exclude_keywords", values[i])
} else if value != nil && len(*value) > 0 {
if err := json.Unmarshal(*value, &nfs.FilterExcludeKeywords); err != nil {
return fmt.Errorf("unmarshal field filter_exclude_keywords: %w", err)
}
}
case notifyflowsource.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 {
nfs.UpdatedAt = value.Time
}
case notifyflowsource.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 {
nfs.CreatedAt = value.Time
}
default:
nfs.selectValues.Set(columns[i], values[i])
}
}
return nil
}
// Value returns the ent.Value that was dynamically selected and assigned to the NotifyFlowSource.
// This includes values selected through modifiers, order, etc.
func (nfs *NotifyFlowSource) Value(name string) (ent.Value, error) {
return nfs.selectValues.Get(name)
}
// QueryNotifyFlow queries the "notify_flow" edge of the NotifyFlowSource entity.
func (nfs *NotifyFlowSource) QueryNotifyFlow() *NotifyFlowQuery {
return NewNotifyFlowSourceClient(nfs.config).QueryNotifyFlow(nfs)
}
// QueryNotifySource queries the "notify_source" edge of the NotifyFlowSource entity.
func (nfs *NotifyFlowSource) QueryNotifySource() *FeedConfigQuery {
return NewNotifyFlowSourceClient(nfs.config).QueryNotifySource(nfs)
}
// Update returns a builder for updating this NotifyFlowSource.
// Note that you need to call NotifyFlowSource.Unwrap() before calling this method if this NotifyFlowSource
// was returned from a transaction, and the transaction was committed or rolled back.
func (nfs *NotifyFlowSource) Update() *NotifyFlowSourceUpdateOne {
return NewNotifyFlowSourceClient(nfs.config).UpdateOne(nfs)
}
// Unwrap unwraps the NotifyFlowSource 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 (nfs *NotifyFlowSource) Unwrap() *NotifyFlowSource {
_tx, ok := nfs.config.driver.(*txDriver)
if !ok {
panic("ent: NotifyFlowSource is not a transactional entity")
}
nfs.config.driver = _tx.drv
return nfs
}
// String implements the fmt.Stringer.
func (nfs *NotifyFlowSource) String() string {
var builder strings.Builder
builder.WriteString("NotifyFlowSource(")
builder.WriteString(fmt.Sprintf("id=%v, ", nfs.ID))
builder.WriteString("notify_flow_id=")
builder.WriteString(fmt.Sprintf("%v", nfs.NotifyFlowID))
builder.WriteString(", ")
builder.WriteString("notify_source_id=")
builder.WriteString(fmt.Sprintf("%v", nfs.NotifySourceID))
builder.WriteString(", ")
builder.WriteString("filter_include_keywords=")
builder.WriteString(fmt.Sprintf("%v", nfs.FilterIncludeKeywords))
builder.WriteString(", ")
builder.WriteString("filter_exclude_keywords=")
builder.WriteString(fmt.Sprintf("%v", nfs.FilterExcludeKeywords))
builder.WriteString(", ")
builder.WriteString("updated_at=")
builder.WriteString(nfs.UpdatedAt.Format(time.ANSIC))
builder.WriteString(", ")
builder.WriteString("created_at=")
builder.WriteString(nfs.CreatedAt.Format(time.ANSIC))
builder.WriteByte(')')
return builder.String()
}
// NotifyFlowSources is a parsable slice of NotifyFlowSource.
type NotifyFlowSources []*NotifyFlowSource