/
dope.go
269 lines (247 loc) · 8.71 KB
/
dope.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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
// Code generated by entc, DO NOT EDIT.
package ent
import (
"fmt"
"strings"
"entgo.io/ent/dialect/sql"
"github.com/dopedao/dope-monorepo/packages/api/internal/ent/dope"
"github.com/dopedao/dope-monorepo/packages/api/internal/ent/listing"
"github.com/dopedao/dope-monorepo/packages/api/internal/ent/search"
"github.com/dopedao/dope-monorepo/packages/api/internal/ent/wallet"
)
// Dope is the model entity for the Dope schema.
type Dope struct {
config `json:"-"`
// ID of the ent.
ID string `json:"id,omitempty"`
// Claimed holds the value of the "claimed" field.
Claimed bool `json:"claimed,omitempty"`
// Opened holds the value of the "opened" field.
Opened bool `json:"opened,omitempty"`
// Score holds the value of the "score" field.
Score int `json:"score,omitempty"`
// Rank holds the value of the "rank" field.
Rank int `json:"rank,omitempty"`
// Order holds the value of the "order" field.
Order int `json:"order,omitempty"`
// Edges holds the relations/edges for other nodes in the graph.
// The values are being populated by the DopeQuery when eager-loading is set.
Edges DopeEdges `json:"edges"`
listing_dope_lastsales *string
wallet_dopes *string
}
// DopeEdges holds the relations/edges for other nodes in the graph.
type DopeEdges struct {
// Wallet holds the value of the wallet edge.
Wallet *Wallet `json:"wallet,omitempty"`
// LastSale holds the value of the last_sale edge.
LastSale *Listing `json:"last_sale,omitempty"`
// Listings holds the value of the listings edge.
Listings []*Listing `json:"listings,omitempty"`
// Items holds the value of the items edge.
Items []*Item `json:"items,omitempty"`
// Index holds the value of the index edge.
Index *Search `json:"index,omitempty"`
// loadedTypes holds the information for reporting if a
// type was loaded (or requested) in eager-loading or not.
loadedTypes [5]bool
}
// WalletOrErr returns the Wallet value or an error if the edge
// was not loaded in eager-loading, or loaded but was not found.
func (e DopeEdges) WalletOrErr() (*Wallet, error) {
if e.loadedTypes[0] {
if e.Wallet == nil {
// The edge wallet was loaded in eager-loading,
// but was not found.
return nil, &NotFoundError{label: wallet.Label}
}
return e.Wallet, nil
}
return nil, &NotLoadedError{edge: "wallet"}
}
// LastSaleOrErr returns the LastSale value or an error if the edge
// was not loaded in eager-loading, or loaded but was not found.
func (e DopeEdges) LastSaleOrErr() (*Listing, error) {
if e.loadedTypes[1] {
if e.LastSale == nil {
// The edge last_sale was loaded in eager-loading,
// but was not found.
return nil, &NotFoundError{label: listing.Label}
}
return e.LastSale, nil
}
return nil, &NotLoadedError{edge: "last_sale"}
}
// ListingsOrErr returns the Listings value or an error if the edge
// was not loaded in eager-loading.
func (e DopeEdges) ListingsOrErr() ([]*Listing, error) {
if e.loadedTypes[2] {
return e.Listings, nil
}
return nil, &NotLoadedError{edge: "listings"}
}
// ItemsOrErr returns the Items value or an error if the edge
// was not loaded in eager-loading.
func (e DopeEdges) ItemsOrErr() ([]*Item, error) {
if e.loadedTypes[3] {
return e.Items, nil
}
return nil, &NotLoadedError{edge: "items"}
}
// IndexOrErr returns the Index value or an error if the edge
// was not loaded in eager-loading, or loaded but was not found.
func (e DopeEdges) IndexOrErr() (*Search, error) {
if e.loadedTypes[4] {
if e.Index == nil {
// The edge index was loaded in eager-loading,
// but was not found.
return nil, &NotFoundError{label: search.Label}
}
return e.Index, nil
}
return nil, &NotLoadedError{edge: "index"}
}
// scanValues returns the types for scanning values from sql.Rows.
func (*Dope) scanValues(columns []string) ([]interface{}, error) {
values := make([]interface{}, len(columns))
for i := range columns {
switch columns[i] {
case dope.FieldClaimed, dope.FieldOpened:
values[i] = new(sql.NullBool)
case dope.FieldScore, dope.FieldRank, dope.FieldOrder:
values[i] = new(sql.NullInt64)
case dope.FieldID:
values[i] = new(sql.NullString)
case dope.ForeignKeys[0]: // listing_dope_lastsales
values[i] = new(sql.NullString)
case dope.ForeignKeys[1]: // wallet_dopes
values[i] = new(sql.NullString)
default:
return nil, fmt.Errorf("unexpected column %q for type Dope", columns[i])
}
}
return values, nil
}
// assignValues assigns the values that were returned from sql.Rows (after scanning)
// to the Dope fields.
func (d *Dope) assignValues(columns []string, values []interface{}) 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 dope.FieldID:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field id", values[i])
} else if value.Valid {
d.ID = value.String
}
case dope.FieldClaimed:
if value, ok := values[i].(*sql.NullBool); !ok {
return fmt.Errorf("unexpected type %T for field claimed", values[i])
} else if value.Valid {
d.Claimed = value.Bool
}
case dope.FieldOpened:
if value, ok := values[i].(*sql.NullBool); !ok {
return fmt.Errorf("unexpected type %T for field opened", values[i])
} else if value.Valid {
d.Opened = value.Bool
}
case dope.FieldScore:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field score", values[i])
} else if value.Valid {
d.Score = int(value.Int64)
}
case dope.FieldRank:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field rank", values[i])
} else if value.Valid {
d.Rank = int(value.Int64)
}
case dope.FieldOrder:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field order", values[i])
} else if value.Valid {
d.Order = int(value.Int64)
}
case dope.ForeignKeys[0]:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field listing_dope_lastsales", values[i])
} else if value.Valid {
d.listing_dope_lastsales = new(string)
*d.listing_dope_lastsales = value.String
}
case dope.ForeignKeys[1]:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field wallet_dopes", values[i])
} else if value.Valid {
d.wallet_dopes = new(string)
*d.wallet_dopes = value.String
}
}
}
return nil
}
// QueryWallet queries the "wallet" edge of the Dope entity.
func (d *Dope) QueryWallet() *WalletQuery {
return (&DopeClient{config: d.config}).QueryWallet(d)
}
// QueryLastSale queries the "last_sale" edge of the Dope entity.
func (d *Dope) QueryLastSale() *ListingQuery {
return (&DopeClient{config: d.config}).QueryLastSale(d)
}
// QueryListings queries the "listings" edge of the Dope entity.
func (d *Dope) QueryListings() *ListingQuery {
return (&DopeClient{config: d.config}).QueryListings(d)
}
// QueryItems queries the "items" edge of the Dope entity.
func (d *Dope) QueryItems() *ItemQuery {
return (&DopeClient{config: d.config}).QueryItems(d)
}
// QueryIndex queries the "index" edge of the Dope entity.
func (d *Dope) QueryIndex() *SearchQuery {
return (&DopeClient{config: d.config}).QueryIndex(d)
}
// Update returns a builder for updating this Dope.
// Note that you need to call Dope.Unwrap() before calling this method if this Dope
// was returned from a transaction, and the transaction was committed or rolled back.
func (d *Dope) Update() *DopeUpdateOne {
return (&DopeClient{config: d.config}).UpdateOne(d)
}
// Unwrap unwraps the Dope 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 (d *Dope) Unwrap() *Dope {
tx, ok := d.config.driver.(*txDriver)
if !ok {
panic("ent: Dope is not a transactional entity")
}
d.config.driver = tx.drv
return d
}
// String implements the fmt.Stringer.
func (d *Dope) String() string {
var builder strings.Builder
builder.WriteString("Dope(")
builder.WriteString(fmt.Sprintf("id=%v", d.ID))
builder.WriteString(", claimed=")
builder.WriteString(fmt.Sprintf("%v", d.Claimed))
builder.WriteString(", opened=")
builder.WriteString(fmt.Sprintf("%v", d.Opened))
builder.WriteString(", score=")
builder.WriteString(fmt.Sprintf("%v", d.Score))
builder.WriteString(", rank=")
builder.WriteString(fmt.Sprintf("%v", d.Rank))
builder.WriteString(", order=")
builder.WriteString(fmt.Sprintf("%v", d.Order))
builder.WriteByte(')')
return builder.String()
}
// Dopes is a parsable slice of Dope.
type Dopes []*Dope
func (d Dopes) config(cfg config) {
for _i := range d {
d[_i].config = cfg
}
}