Debian Codegraph @

ent/statement.go

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