/
repository.go
342 lines (311 loc) · 11.7 KB
/
repository.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
// Code generated by ent, DO NOT EDIT.
package ent
import (
"fmt"
"strings"
"entgo.io/ent/dialect/sql"
"github.com/fogo-sh/grackdb/ent/githubaccount"
"github.com/fogo-sh/grackdb/ent/githuborganization"
"github.com/fogo-sh/grackdb/ent/project"
"github.com/fogo-sh/grackdb/ent/repository"
)
// Repository is the model entity for the Repository schema.
type Repository struct {
config `json:"-"`
// ID of the ent.
ID int `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 RepositoryQuery when eager-loading is set.
Edges RepositoryEdges `json:"edges"`
github_account_repositories *int
github_organization_repositories *int
project_repositories *int
}
// RepositoryEdges holds the relations/edges for other nodes in the graph.
type RepositoryEdges struct {
// Project holds the value of the project edge.
Project *Project `json:"project,omitempty"`
// GithubAccount holds the value of the github_account edge.
GithubAccount *GithubAccount `json:"github_account,omitempty"`
// GithubOrganization holds the value of the github_organization edge.
GithubOrganization *GithubOrganization `json:"github_organization,omitempty"`
// DiscordBots holds the value of the discord_bots edge.
DiscordBots []*DiscordBot `json:"discord_bots,omitempty"`
// Sites holds the value of the sites edge.
Sites []*Site `json:"sites,omitempty"`
// Technologies holds the value of the technologies edge.
Technologies []*RepositoryTechnology `json:"technologies,omitempty"`
// loadedTypes holds the information for reporting if a
// type was loaded (or requested) in eager-loading or not.
loadedTypes [6]bool
// totalCount holds the count of the edges above.
totalCount [6]map[string]int
namedDiscordBots map[string][]*DiscordBot
namedSites map[string][]*Site
namedTechnologies map[string][]*RepositoryTechnology
}
// ProjectOrErr returns the Project value or an error if the edge
// was not loaded in eager-loading, or loaded but was not found.
func (e RepositoryEdges) ProjectOrErr() (*Project, error) {
if e.loadedTypes[0] {
if e.Project == nil {
// Edge was loaded but was not found.
return nil, &NotFoundError{label: project.Label}
}
return e.Project, nil
}
return nil, &NotLoadedError{edge: "project"}
}
// GithubAccountOrErr returns the GithubAccount value or an error if the edge
// was not loaded in eager-loading, or loaded but was not found.
func (e RepositoryEdges) GithubAccountOrErr() (*GithubAccount, error) {
if e.loadedTypes[1] {
if e.GithubAccount == nil {
// Edge was loaded but was not found.
return nil, &NotFoundError{label: githubaccount.Label}
}
return e.GithubAccount, nil
}
return nil, &NotLoadedError{edge: "github_account"}
}
// GithubOrganizationOrErr returns the GithubOrganization value or an error if the edge
// was not loaded in eager-loading, or loaded but was not found.
func (e RepositoryEdges) GithubOrganizationOrErr() (*GithubOrganization, error) {
if e.loadedTypes[2] {
if e.GithubOrganization == nil {
// Edge was loaded but was not found.
return nil, &NotFoundError{label: githuborganization.Label}
}
return e.GithubOrganization, nil
}
return nil, &NotLoadedError{edge: "github_organization"}
}
// DiscordBotsOrErr returns the DiscordBots value or an error if the edge
// was not loaded in eager-loading.
func (e RepositoryEdges) DiscordBotsOrErr() ([]*DiscordBot, error) {
if e.loadedTypes[3] {
return e.DiscordBots, nil
}
return nil, &NotLoadedError{edge: "discord_bots"}
}
// SitesOrErr returns the Sites value or an error if the edge
// was not loaded in eager-loading.
func (e RepositoryEdges) SitesOrErr() ([]*Site, error) {
if e.loadedTypes[4] {
return e.Sites, nil
}
return nil, &NotLoadedError{edge: "sites"}
}
// TechnologiesOrErr returns the Technologies value or an error if the edge
// was not loaded in eager-loading.
func (e RepositoryEdges) TechnologiesOrErr() ([]*RepositoryTechnology, error) {
if e.loadedTypes[5] {
return e.Technologies, nil
}
return nil, &NotLoadedError{edge: "technologies"}
}
// scanValues returns the types for scanning values from sql.Rows.
func (*Repository) scanValues(columns []string) ([]interface{}, error) {
values := make([]interface{}, len(columns))
for i := range columns {
switch columns[i] {
case repository.FieldID:
values[i] = new(sql.NullInt64)
case repository.FieldName, repository.FieldDescription:
values[i] = new(sql.NullString)
case repository.ForeignKeys[0]: // github_account_repositories
values[i] = new(sql.NullInt64)
case repository.ForeignKeys[1]: // github_organization_repositories
values[i] = new(sql.NullInt64)
case repository.ForeignKeys[2]: // project_repositories
values[i] = new(sql.NullInt64)
default:
return nil, fmt.Errorf("unexpected column %q for type Repository", columns[i])
}
}
return values, nil
}
// assignValues assigns the values that were returned from sql.Rows (after scanning)
// to the Repository fields.
func (r *Repository) 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 repository.FieldID:
value, ok := values[i].(*sql.NullInt64)
if !ok {
return fmt.Errorf("unexpected type %T for field id", value)
}
r.ID = int(value.Int64)
case repository.FieldName:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field name", values[i])
} else if value.Valid {
r.Name = value.String
}
case repository.FieldDescription:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field description", values[i])
} else if value.Valid {
r.Description = new(string)
*r.Description = value.String
}
case repository.ForeignKeys[0]:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for edge-field github_account_repositories", value)
} else if value.Valid {
r.github_account_repositories = new(int)
*r.github_account_repositories = int(value.Int64)
}
case repository.ForeignKeys[1]:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for edge-field github_organization_repositories", value)
} else if value.Valid {
r.github_organization_repositories = new(int)
*r.github_organization_repositories = int(value.Int64)
}
case repository.ForeignKeys[2]:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for edge-field project_repositories", value)
} else if value.Valid {
r.project_repositories = new(int)
*r.project_repositories = int(value.Int64)
}
}
}
return nil
}
// QueryProject queries the "project" edge of the Repository entity.
func (r *Repository) QueryProject() *ProjectQuery {
return (&RepositoryClient{config: r.config}).QueryProject(r)
}
// QueryGithubAccount queries the "github_account" edge of the Repository entity.
func (r *Repository) QueryGithubAccount() *GithubAccountQuery {
return (&RepositoryClient{config: r.config}).QueryGithubAccount(r)
}
// QueryGithubOrganization queries the "github_organization" edge of the Repository entity.
func (r *Repository) QueryGithubOrganization() *GithubOrganizationQuery {
return (&RepositoryClient{config: r.config}).QueryGithubOrganization(r)
}
// QueryDiscordBots queries the "discord_bots" edge of the Repository entity.
func (r *Repository) QueryDiscordBots() *DiscordBotQuery {
return (&RepositoryClient{config: r.config}).QueryDiscordBots(r)
}
// QuerySites queries the "sites" edge of the Repository entity.
func (r *Repository) QuerySites() *SiteQuery {
return (&RepositoryClient{config: r.config}).QuerySites(r)
}
// QueryTechnologies queries the "technologies" edge of the Repository entity.
func (r *Repository) QueryTechnologies() *RepositoryTechnologyQuery {
return (&RepositoryClient{config: r.config}).QueryTechnologies(r)
}
// Update returns a builder for updating this Repository.
// Note that you need to call Repository.Unwrap() before calling this method if this Repository
// was returned from a transaction, and the transaction was committed or rolled back.
func (r *Repository) Update() *RepositoryUpdateOne {
return (&RepositoryClient{config: r.config}).UpdateOne(r)
}
// Unwrap unwraps the Repository 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 (r *Repository) Unwrap() *Repository {
_tx, ok := r.config.driver.(*txDriver)
if !ok {
panic("ent: Repository is not a transactional entity")
}
r.config.driver = _tx.drv
return r
}
// String implements the fmt.Stringer.
func (r *Repository) String() string {
var builder strings.Builder
builder.WriteString("Repository(")
builder.WriteString(fmt.Sprintf("id=%v, ", r.ID))
builder.WriteString("name=")
builder.WriteString(r.Name)
builder.WriteString(", ")
if v := r.Description; v != nil {
builder.WriteString("description=")
builder.WriteString(*v)
}
builder.WriteByte(')')
return builder.String()
}
// NamedDiscordBots returns the DiscordBots named value or an error if the edge was not
// loaded in eager-loading with this name.
func (r *Repository) NamedDiscordBots(name string) ([]*DiscordBot, error) {
if r.Edges.namedDiscordBots == nil {
return nil, &NotLoadedError{edge: name}
}
nodes, ok := r.Edges.namedDiscordBots[name]
if !ok {
return nil, &NotLoadedError{edge: name}
}
return nodes, nil
}
func (r *Repository) appendNamedDiscordBots(name string, edges ...*DiscordBot) {
if r.Edges.namedDiscordBots == nil {
r.Edges.namedDiscordBots = make(map[string][]*DiscordBot)
}
if len(edges) == 0 {
r.Edges.namedDiscordBots[name] = []*DiscordBot{}
} else {
r.Edges.namedDiscordBots[name] = append(r.Edges.namedDiscordBots[name], edges...)
}
}
// NamedSites returns the Sites named value or an error if the edge was not
// loaded in eager-loading with this name.
func (r *Repository) NamedSites(name string) ([]*Site, error) {
if r.Edges.namedSites == nil {
return nil, &NotLoadedError{edge: name}
}
nodes, ok := r.Edges.namedSites[name]
if !ok {
return nil, &NotLoadedError{edge: name}
}
return nodes, nil
}
func (r *Repository) appendNamedSites(name string, edges ...*Site) {
if r.Edges.namedSites == nil {
r.Edges.namedSites = make(map[string][]*Site)
}
if len(edges) == 0 {
r.Edges.namedSites[name] = []*Site{}
} else {
r.Edges.namedSites[name] = append(r.Edges.namedSites[name], edges...)
}
}
// NamedTechnologies returns the Technologies named value or an error if the edge was not
// loaded in eager-loading with this name.
func (r *Repository) NamedTechnologies(name string) ([]*RepositoryTechnology, error) {
if r.Edges.namedTechnologies == nil {
return nil, &NotLoadedError{edge: name}
}
nodes, ok := r.Edges.namedTechnologies[name]
if !ok {
return nil, &NotLoadedError{edge: name}
}
return nodes, nil
}
func (r *Repository) appendNamedTechnologies(name string, edges ...*RepositoryTechnology) {
if r.Edges.namedTechnologies == nil {
r.Edges.namedTechnologies = make(map[string][]*RepositoryTechnology)
}
if len(edges) == 0 {
r.Edges.namedTechnologies[name] = []*RepositoryTechnology{}
} else {
r.Edges.namedTechnologies[name] = append(r.Edges.namedTechnologies[name], edges...)
}
}
// Repositories is a parsable slice of Repository.
type Repositories []*Repository
func (r Repositories) config(cfg config) {
for _i := range r {
r[_i].config = cfg
}
}