Debian Codegraph @

ent/subject.go

raw
1 // Code generated by ent, DO NOT EDIT.
2
3 package ent
4
5 import (
6 "fmt"
7 "strings"
8 "time"
9
10 "entgo.io/ent"
11 "entgo.io/ent/dialect/sql"
12 "github.com/google/uuid"
13 "github.com/in-toto/archivista/ent/statement"
14 "github.com/in-toto/archivista/ent/subject"
15 )
16
17 // Subject is the model entity for the Subject schema.
18 type Subject struct {
19 config `json:"-"`
20 // ID of the ent.
21 ID uuid.UUID `json:"id,omitempty"`
22 // CreatedAt holds the value of the "created_at" field.
23 CreatedAt *time.Time `json:"created_at,omitempty"`
24 // Name holds the value of the "name" field.
25 Name string `json:"name,omitempty"`
26 // Edges holds the relations/edges for other nodes in the graph.
27 // The values are being populated by the SubjectQuery when eager-loading is set.
28 Edges SubjectEdges `json:"edges"`
29 statement_subjects *uuid.UUID
30 selectValues sql.SelectValues
31 }
32
33 // SubjectEdges holds the relations/edges for other nodes in the graph.
34 type SubjectEdges struct {
35 // SubjectDigests holds the value of the subject_digests edge.
36 SubjectDigests []*SubjectDigest `json:"subject_digests,omitempty"`
37 // Statement holds the value of the statement edge.
38 Statement *Statement `json:"statement,omitempty"`
39 // loadedTypes holds the information for reporting if a
40 // type was loaded (or requested) in eager-loading or not.
41 loadedTypes [2]bool
42 // totalCount holds the count of the edges above.
43 totalCount [2]map[string]int
44
45 namedSubjectDigests map[string][]*SubjectDigest
46 }
47
48 // SubjectDigestsOrErr returns the SubjectDigests value or an error if the edge
49 // was not loaded in eager-loading.
50 func (e SubjectEdges) SubjectDigestsOrErr() ([]*SubjectDigest, error) {
51 if e.loadedTypes[0] {
52 return e.SubjectDigests, nil
53 }
54 return nil, &NotLoadedError{edge: "subject_digests"}
55 }
56
57 // StatementOrErr returns the Statement value or an error if the edge
58 // was not loaded in eager-loading, or loaded but was not found.
59 func (e SubjectEdges) StatementOrErr() (*Statement, error) {
60 if e.Statement != nil {
61 return e.Statement, nil
62 } else if e.loadedTypes[1] {
63 return nil, &NotFoundError{label: statement.Label}
64 }
65 return nil, &NotLoadedError{edge: "statement"}
66 }
67
68 // scanValues returns the types for scanning values from sql.Rows.
69 func (*Subject) scanValues(columns []string) ([]any, error) {
70 values := make([]any, len(columns))
71 for i := range columns {
72 switch columns[i] {
73 case subject.FieldName:
74 values[i] = new(sql.NullString)
75 case subject.FieldCreatedAt:
76 values[i] = new(sql.NullTime)
77 case subject.FieldID:
78 values[i] = new(uuid.UUID)
79 case subject.ForeignKeys[0]: // statement_subjects
80 values[i] = &sql.NullScanner{S: new(uuid.UUID)}
81 default:
82 values[i] = new(sql.UnknownType)
83 }
84 }
85 return values, nil
86 }
87
88 // assignValues assigns the values that were returned from sql.Rows (after scanning)
89 // to the Subject fields.
90 func (_m *Subject) assignValues(columns []string, values []any) error {
91 if m, n := len(values), len(columns); m < n {
92 return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
93 }
94 for i := range columns {
95 switch columns[i] {
96 case subject.FieldID:
97 if value, ok := values[i].(*uuid.UUID); !ok {
98 return fmt.Errorf("unexpected type %T for field id", values[i])
99 } else if value != nil {
100 _m.ID = *value
101 }
102 case subject.FieldCreatedAt:
103 if value, ok := values[i].(*sql.NullTime); !ok {
104 return fmt.Errorf("unexpected type %T for field created_at", values[i])
105 } else if value.Valid {
106 _m.CreatedAt = new(time.Time)
107 *_m.CreatedAt = value.Time
108 }
109 case subject.FieldName:
110 if value, ok := values[i].(*sql.NullString); !ok {
111 return fmt.Errorf("unexpected type %T for field name", values[i])
112 } else if value.Valid {
113 _m.Name = value.String
114 }
115 case subject.ForeignKeys[0]:
116 if value, ok := values[i].(*sql.NullScanner); !ok {
117 return fmt.Errorf("unexpected type %T for field statement_subjects", values[i])
118 } else if value.Valid {
119 _m.statement_subjects = new(uuid.UUID)
120 *_m.statement_subjects = *value.S.(*uuid.UUID)
121 }
122 default:
123 _m.selectValues.Set(columns[i], values[i])
124 }
125 }
126 return nil
127 }
128
129 // Value returns the ent.Value that was dynamically selected and assigned to the Subject.
130 // This includes values selected through modifiers, order, etc.
131 func (_m *Subject) Value(name string) (ent.Value, error) {
132 return _m.selectValues.Get(name)
133 }
134
135 // QuerySubjectDigests queries the "subject_digests" edge of the Subject entity.
136 func (_m *Subject) QuerySubjectDigests() *SubjectDigestQuery {
137 return NewSubjectClient(_m.config).QuerySubjectDigests(_m)
138 }
139
140 // QueryStatement queries the "statement" edge of the Subject entity.
141 func (_m *Subject) QueryStatement() *StatementQuery {
142 return NewSubjectClient(_m.config).QueryStatement(_m)
143 }
144
145 // Update returns a builder for updating this Subject.
146 // Note that you need to call Subject.Unwrap() before calling this method if this Subject
147 // was returned from a transaction, and the transaction was committed or rolled back.
148 func (_m *Subject) Update() *SubjectUpdateOne {
149 return NewSubjectClient(_m.config).UpdateOne(_m)
150 }
151
152 // Unwrap unwraps the Subject entity that was returned from a transaction after it was closed,
153 // so that all future queries will be executed through the driver which created the transaction.
154 func (_m *Subject) Unwrap() *Subject {
155 _tx, ok := _m.config.driver.(*txDriver)
156 if !ok {
157 panic("ent: Subject is not a transactional entity")
158 }
159 _m.config.driver = _tx.drv
160 return _m
161 }
162
163 // String implements the fmt.Stringer.
164 func (_m *Subject) String() string {
165 var builder strings.Builder
166 builder.WriteString("Subject(")
167 builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID))
168 if v := _m.CreatedAt; v != nil {
169 builder.WriteString("created_at=")
170 builder.WriteString(v.Format(time.ANSIC))
171 }
172 builder.WriteString(", ")
173 builder.WriteString("name=")
174 builder.WriteString(_m.Name)
175 builder.WriteByte(')')
176 return builder.String()
177 }
178
179 // NamedSubjectDigests returns the SubjectDigests named value or an error if the edge was not
180 // loaded in eager-loading with this name.
181 func (_m *Subject) NamedSubjectDigests(name string) ([]*SubjectDigest, error) {
182 if _m.Edges.namedSubjectDigests == nil {
183 return nil, &NotLoadedError{edge: name}
184 }
185 nodes, ok := _m.Edges.namedSubjectDigests[name]
186 if !ok {
187 return nil, &NotLoadedError{edge: name}
188 }
189 return nodes, nil
190 }
191
192 func (_m *Subject) appendNamedSubjectDigests(name string, edges ...*SubjectDigest) {
193 if _m.Edges.namedSubjectDigests == nil {
194 _m.Edges.namedSubjectDigests = make(map[string][]*SubjectDigest)
195 }
196 if len(edges) == 0 {
197 _m.Edges.namedSubjectDigests[name] = []*SubjectDigest{}
198 } else {
199 _m.Edges.namedSubjectDigests[name] = append(_m.Edges.namedSubjectDigests[name], edges...)
200 }
201 }
202
203 // Subjects is a parsable slice of Subject.
204 type Subjects []*Subject