/
company.go
425 lines (384 loc) · 13.4 KB
/
company.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
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
// Copyright 2019-present Facebook
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Code generated by entc, DO NOT EDIT.
package ent
import (
"fmt"
"strings"
"entgo.io/ent/dialect/sql"
"github.com/diazoxide/entrefine/examples/ent-project/ent/company"
"github.com/diazoxide/entrefine/examples/ent-project/ent/image"
"github.com/google/uuid"
)
// Company is the model entity for the Company schema.
type Company 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"`
// Description holds the value of the "description" field.
Description string `json:"description,omitempty"`
// Edges holds the relations/edges for other nodes in the graph.
// The values are being populated by the CompanyQuery when eager-loading is set.
Edges CompanyEdges `json:"edges"`
}
// CompanyEdges holds the relations/edges for other nodes in the graph.
type CompanyEdges struct {
// Countries holds the value of the countries edge.
Countries []*Country `json:"countries,omitempty"`
// Phones holds the value of the phones edge.
Phones []*Phone `json:"phones,omitempty"`
// Emails holds the value of the emails edge.
Emails []*Email `json:"emails,omitempty"`
// Websites holds the value of the websites edge.
Websites []*Website `json:"websites,omitempty"`
// Locations holds the value of the locations edge.
Locations []*Location `json:"locations,omitempty"`
// LogoImage holds the value of the logo_image edge.
LogoImage *Image `json:"logo_image,omitempty"`
// CoverImage holds the value of the cover_image edge.
CoverImage *Image `json:"cover_image,omitempty"`
// GalleryImages holds the value of the gallery_images edge.
GalleryImages []*Image `json:"gallery_images,omitempty"`
// loadedTypes holds the information for reporting if a
// type was loaded (or requested) in eager-loading or not.
loadedTypes [8]bool
// totalCount holds the count of the edges above.
totalCount [8]map[string]int
namedCountries map[string][]*Country
namedPhones map[string][]*Phone
namedEmails map[string][]*Email
namedWebsites map[string][]*Website
namedLocations map[string][]*Location
namedGalleryImages map[string][]*Image
}
// CountriesOrErr returns the Countries value or an error if the edge
// was not loaded in eager-loading.
func (e CompanyEdges) CountriesOrErr() ([]*Country, error) {
if e.loadedTypes[0] {
return e.Countries, nil
}
return nil, &NotLoadedError{edge: "countries"}
}
// PhonesOrErr returns the Phones value or an error if the edge
// was not loaded in eager-loading.
func (e CompanyEdges) PhonesOrErr() ([]*Phone, error) {
if e.loadedTypes[1] {
return e.Phones, nil
}
return nil, &NotLoadedError{edge: "phones"}
}
// EmailsOrErr returns the Emails value or an error if the edge
// was not loaded in eager-loading.
func (e CompanyEdges) EmailsOrErr() ([]*Email, error) {
if e.loadedTypes[2] {
return e.Emails, nil
}
return nil, &NotLoadedError{edge: "emails"}
}
// WebsitesOrErr returns the Websites value or an error if the edge
// was not loaded in eager-loading.
func (e CompanyEdges) WebsitesOrErr() ([]*Website, error) {
if e.loadedTypes[3] {
return e.Websites, nil
}
return nil, &NotLoadedError{edge: "websites"}
}
// LocationsOrErr returns the Locations value or an error if the edge
// was not loaded in eager-loading.
func (e CompanyEdges) LocationsOrErr() ([]*Location, error) {
if e.loadedTypes[4] {
return e.Locations, nil
}
return nil, &NotLoadedError{edge: "locations"}
}
// LogoImageOrErr returns the LogoImage value or an error if the edge
// was not loaded in eager-loading, or loaded but was not found.
func (e CompanyEdges) LogoImageOrErr() (*Image, error) {
if e.loadedTypes[5] {
if e.LogoImage == nil {
// Edge was loaded but was not found.
return nil, &NotFoundError{label: image.Label}
}
return e.LogoImage, nil
}
return nil, &NotLoadedError{edge: "logo_image"}
}
// CoverImageOrErr returns the CoverImage value or an error if the edge
// was not loaded in eager-loading, or loaded but was not found.
func (e CompanyEdges) CoverImageOrErr() (*Image, error) {
if e.loadedTypes[6] {
if e.CoverImage == nil {
// Edge was loaded but was not found.
return nil, &NotFoundError{label: image.Label}
}
return e.CoverImage, nil
}
return nil, &NotLoadedError{edge: "cover_image"}
}
// GalleryImagesOrErr returns the GalleryImages value or an error if the edge
// was not loaded in eager-loading.
func (e CompanyEdges) GalleryImagesOrErr() ([]*Image, error) {
if e.loadedTypes[7] {
return e.GalleryImages, nil
}
return nil, &NotLoadedError{edge: "gallery_images"}
}
// scanValues returns the types for scanning values from sql.Rows.
func (*Company) scanValues(columns []string) ([]any, error) {
values := make([]any, len(columns))
for i := range columns {
switch columns[i] {
case company.FieldName, company.FieldDescription:
values[i] = new(sql.NullString)
case company.FieldID:
values[i] = new(uuid.UUID)
default:
return nil, fmt.Errorf("unexpected column %q for type Company", columns[i])
}
}
return values, nil
}
// assignValues assigns the values that were returned from sql.Rows (after scanning)
// to the Company fields.
func (c *Company) 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 company.FieldID:
if value, ok := values[i].(*uuid.UUID); !ok {
return fmt.Errorf("unexpected type %T for field id", values[i])
} else if value != nil {
c.ID = *value
}
case company.FieldName:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field name", values[i])
} else if value.Valid {
c.Name = value.String
}
case company.FieldDescription:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field description", values[i])
} else if value.Valid {
c.Description = value.String
}
}
}
return nil
}
// QueryCountries queries the "countries" edge of the Company entity.
func (c *Company) QueryCountries() *CountryQuery {
return NewCompanyClient(c.config).QueryCountries(c)
}
// QueryPhones queries the "phones" edge of the Company entity.
func (c *Company) QueryPhones() *PhoneQuery {
return NewCompanyClient(c.config).QueryPhones(c)
}
// QueryEmails queries the "emails" edge of the Company entity.
func (c *Company) QueryEmails() *EmailQuery {
return NewCompanyClient(c.config).QueryEmails(c)
}
// QueryWebsites queries the "websites" edge of the Company entity.
func (c *Company) QueryWebsites() *WebsiteQuery {
return NewCompanyClient(c.config).QueryWebsites(c)
}
// QueryLocations queries the "locations" edge of the Company entity.
func (c *Company) QueryLocations() *LocationQuery {
return NewCompanyClient(c.config).QueryLocations(c)
}
// QueryLogoImage queries the "logo_image" edge of the Company entity.
func (c *Company) QueryLogoImage() *ImageQuery {
return NewCompanyClient(c.config).QueryLogoImage(c)
}
// QueryCoverImage queries the "cover_image" edge of the Company entity.
func (c *Company) QueryCoverImage() *ImageQuery {
return NewCompanyClient(c.config).QueryCoverImage(c)
}
// QueryGalleryImages queries the "gallery_images" edge of the Company entity.
func (c *Company) QueryGalleryImages() *ImageQuery {
return NewCompanyClient(c.config).QueryGalleryImages(c)
}
// Update returns a builder for updating this Company.
// Note that you need to call Company.Unwrap() before calling this method if this Company
// was returned from a transaction, and the transaction was committed or rolled back.
func (c *Company) Update() *CompanyUpdateOne {
return NewCompanyClient(c.config).UpdateOne(c)
}
// Unwrap unwraps the Company 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 (c *Company) Unwrap() *Company {
_tx, ok := c.config.driver.(*txDriver)
if !ok {
panic("ent: Company is not a transactional entity")
}
c.config.driver = _tx.drv
return c
}
// String implements the fmt.Stringer.
func (c *Company) String() string {
var builder strings.Builder
builder.WriteString("Company(")
builder.WriteString(fmt.Sprintf("id=%v, ", c.ID))
builder.WriteString("name=")
builder.WriteString(c.Name)
builder.WriteString(", ")
builder.WriteString("description=")
builder.WriteString(c.Description)
builder.WriteByte(')')
return builder.String()
}
// NamedCountries returns the Countries named value or an error if the edge was not
// loaded in eager-loading with this name.
func (c *Company) NamedCountries(name string) ([]*Country, error) {
if c.Edges.namedCountries == nil {
return nil, &NotLoadedError{edge: name}
}
nodes, ok := c.Edges.namedCountries[name]
if !ok {
return nil, &NotLoadedError{edge: name}
}
return nodes, nil
}
func (c *Company) appendNamedCountries(name string, edges ...*Country) {
if c.Edges.namedCountries == nil {
c.Edges.namedCountries = make(map[string][]*Country)
}
if len(edges) == 0 {
c.Edges.namedCountries[name] = []*Country{}
} else {
c.Edges.namedCountries[name] = append(c.Edges.namedCountries[name], edges...)
}
}
// NamedPhones returns the Phones named value or an error if the edge was not
// loaded in eager-loading with this name.
func (c *Company) NamedPhones(name string) ([]*Phone, error) {
if c.Edges.namedPhones == nil {
return nil, &NotLoadedError{edge: name}
}
nodes, ok := c.Edges.namedPhones[name]
if !ok {
return nil, &NotLoadedError{edge: name}
}
return nodes, nil
}
func (c *Company) appendNamedPhones(name string, edges ...*Phone) {
if c.Edges.namedPhones == nil {
c.Edges.namedPhones = make(map[string][]*Phone)
}
if len(edges) == 0 {
c.Edges.namedPhones[name] = []*Phone{}
} else {
c.Edges.namedPhones[name] = append(c.Edges.namedPhones[name], edges...)
}
}
// NamedEmails returns the Emails named value or an error if the edge was not
// loaded in eager-loading with this name.
func (c *Company) NamedEmails(name string) ([]*Email, error) {
if c.Edges.namedEmails == nil {
return nil, &NotLoadedError{edge: name}
}
nodes, ok := c.Edges.namedEmails[name]
if !ok {
return nil, &NotLoadedError{edge: name}
}
return nodes, nil
}
func (c *Company) appendNamedEmails(name string, edges ...*Email) {
if c.Edges.namedEmails == nil {
c.Edges.namedEmails = make(map[string][]*Email)
}
if len(edges) == 0 {
c.Edges.namedEmails[name] = []*Email{}
} else {
c.Edges.namedEmails[name] = append(c.Edges.namedEmails[name], edges...)
}
}
// NamedWebsites returns the Websites named value or an error if the edge was not
// loaded in eager-loading with this name.
func (c *Company) NamedWebsites(name string) ([]*Website, error) {
if c.Edges.namedWebsites == nil {
return nil, &NotLoadedError{edge: name}
}
nodes, ok := c.Edges.namedWebsites[name]
if !ok {
return nil, &NotLoadedError{edge: name}
}
return nodes, nil
}
func (c *Company) appendNamedWebsites(name string, edges ...*Website) {
if c.Edges.namedWebsites == nil {
c.Edges.namedWebsites = make(map[string][]*Website)
}
if len(edges) == 0 {
c.Edges.namedWebsites[name] = []*Website{}
} else {
c.Edges.namedWebsites[name] = append(c.Edges.namedWebsites[name], edges...)
}
}
// NamedLocations returns the Locations named value or an error if the edge was not
// loaded in eager-loading with this name.
func (c *Company) NamedLocations(name string) ([]*Location, error) {
if c.Edges.namedLocations == nil {
return nil, &NotLoadedError{edge: name}
}
nodes, ok := c.Edges.namedLocations[name]
if !ok {
return nil, &NotLoadedError{edge: name}
}
return nodes, nil
}
func (c *Company) appendNamedLocations(name string, edges ...*Location) {
if c.Edges.namedLocations == nil {
c.Edges.namedLocations = make(map[string][]*Location)
}
if len(edges) == 0 {
c.Edges.namedLocations[name] = []*Location{}
} else {
c.Edges.namedLocations[name] = append(c.Edges.namedLocations[name], edges...)
}
}
// NamedGalleryImages returns the GalleryImages named value or an error if the edge was not
// loaded in eager-loading with this name.
func (c *Company) NamedGalleryImages(name string) ([]*Image, error) {
if c.Edges.namedGalleryImages == nil {
return nil, &NotLoadedError{edge: name}
}
nodes, ok := c.Edges.namedGalleryImages[name]
if !ok {
return nil, &NotLoadedError{edge: name}
}
return nodes, nil
}
func (c *Company) appendNamedGalleryImages(name string, edges ...*Image) {
if c.Edges.namedGalleryImages == nil {
c.Edges.namedGalleryImages = make(map[string][]*Image)
}
if len(edges) == 0 {
c.Edges.namedGalleryImages[name] = []*Image{}
} else {
c.Edges.namedGalleryImages[name] = append(c.Edges.namedGalleryImages[name], edges...)
}
}
// Companies is a parsable slice of Company.
type Companies []*Company
func (c Companies) config(cfg config) {
for _i := range c {
c[_i].config = cfg
}
}