/
country.go
343 lines (310 loc) · 10.5 KB
/
country.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
// 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/country"
"github.com/google/uuid"
)
// Country is the model entity for the Country schema.
type Country 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"`
// Code holds the value of the "code" field.
Code string `json:"code,omitempty"`
// Edges holds the relations/edges for other nodes in the graph.
// The values are being populated by the CountryQuery when eager-loading is set.
Edges CountryEdges `json:"edges"`
}
// CountryEdges holds the relations/edges for other nodes in the graph.
type CountryEdges struct {
// Companies holds the value of the companies edge.
Companies []*Company `json:"companies,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"`
// loadedTypes holds the information for reporting if a
// type was loaded (or requested) in eager-loading or not.
loadedTypes [5]bool
// totalCount holds the count of the edges above.
totalCount [5]map[string]int
namedCompanies map[string][]*Company
namedPhones map[string][]*Phone
namedEmails map[string][]*Email
namedWebsites map[string][]*Website
namedLocations map[string][]*Location
}
// CompaniesOrErr returns the Companies value or an error if the edge
// was not loaded in eager-loading.
func (e CountryEdges) CompaniesOrErr() ([]*Company, error) {
if e.loadedTypes[0] {
return e.Companies, nil
}
return nil, &NotLoadedError{edge: "companies"}
}
// PhonesOrErr returns the Phones value or an error if the edge
// was not loaded in eager-loading.
func (e CountryEdges) 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 CountryEdges) 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 CountryEdges) 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 CountryEdges) LocationsOrErr() ([]*Location, error) {
if e.loadedTypes[4] {
return e.Locations, nil
}
return nil, &NotLoadedError{edge: "locations"}
}
// scanValues returns the types for scanning values from sql.Rows.
func (*Country) scanValues(columns []string) ([]any, error) {
values := make([]any, len(columns))
for i := range columns {
switch columns[i] {
case country.FieldName, country.FieldCode:
values[i] = new(sql.NullString)
case country.FieldID:
values[i] = new(uuid.UUID)
default:
return nil, fmt.Errorf("unexpected column %q for type Country", columns[i])
}
}
return values, nil
}
// assignValues assigns the values that were returned from sql.Rows (after scanning)
// to the Country fields.
func (c *Country) 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 country.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 country.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 country.FieldCode:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field code", values[i])
} else if value.Valid {
c.Code = value.String
}
}
}
return nil
}
// QueryCompanies queries the "companies" edge of the Country entity.
func (c *Country) QueryCompanies() *CompanyQuery {
return NewCountryClient(c.config).QueryCompanies(c)
}
// QueryPhones queries the "phones" edge of the Country entity.
func (c *Country) QueryPhones() *PhoneQuery {
return NewCountryClient(c.config).QueryPhones(c)
}
// QueryEmails queries the "emails" edge of the Country entity.
func (c *Country) QueryEmails() *EmailQuery {
return NewCountryClient(c.config).QueryEmails(c)
}
// QueryWebsites queries the "websites" edge of the Country entity.
func (c *Country) QueryWebsites() *WebsiteQuery {
return NewCountryClient(c.config).QueryWebsites(c)
}
// QueryLocations queries the "locations" edge of the Country entity.
func (c *Country) QueryLocations() *LocationQuery {
return NewCountryClient(c.config).QueryLocations(c)
}
// Update returns a builder for updating this Country.
// Note that you need to call Country.Unwrap() before calling this method if this Country
// was returned from a transaction, and the transaction was committed or rolled back.
func (c *Country) Update() *CountryUpdateOne {
return NewCountryClient(c.config).UpdateOne(c)
}
// Unwrap unwraps the Country 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 *Country) Unwrap() *Country {
_tx, ok := c.config.driver.(*txDriver)
if !ok {
panic("ent: Country is not a transactional entity")
}
c.config.driver = _tx.drv
return c
}
// String implements the fmt.Stringer.
func (c *Country) String() string {
var builder strings.Builder
builder.WriteString("Country(")
builder.WriteString(fmt.Sprintf("id=%v, ", c.ID))
builder.WriteString("name=")
builder.WriteString(c.Name)
builder.WriteString(", ")
builder.WriteString("code=")
builder.WriteString(c.Code)
builder.WriteByte(')')
return builder.String()
}
// NamedCompanies returns the Companies named value or an error if the edge was not
// loaded in eager-loading with this name.
func (c *Country) NamedCompanies(name string) ([]*Company, error) {
if c.Edges.namedCompanies == nil {
return nil, &NotLoadedError{edge: name}
}
nodes, ok := c.Edges.namedCompanies[name]
if !ok {
return nil, &NotLoadedError{edge: name}
}
return nodes, nil
}
func (c *Country) appendNamedCompanies(name string, edges ...*Company) {
if c.Edges.namedCompanies == nil {
c.Edges.namedCompanies = make(map[string][]*Company)
}
if len(edges) == 0 {
c.Edges.namedCompanies[name] = []*Company{}
} else {
c.Edges.namedCompanies[name] = append(c.Edges.namedCompanies[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 *Country) 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 *Country) 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 *Country) 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 *Country) 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 *Country) 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 *Country) 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 *Country) 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 *Country) 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...)
}
}
// Countries is a parsable slice of Country.
type Countries []*Country
func (c Countries) config(cfg config) {
for _i := range c {
c[_i].config = cfg
}
}