Debian Codegraph @

ent/dsse.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/dsse"
14 "github.com/in-toto/archivista/ent/statement"
15 )
16
17 // Dsse is the model entity for the Dsse schema.
18 type Dsse 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 // GitoidSha256 holds the value of the "gitoid_sha256" field.
25 GitoidSha256 string `json:"gitoid_sha256,omitempty"`
26 // PayloadType holds the value of the "payload_type" field.
27 PayloadType string `json:"payload_type,omitempty"`
28 // Edges holds the relations/edges for other nodes in the graph.
29 // The values are being populated by the DsseQuery when eager-loading is set.
30 Edges DsseEdges `json:"edges"`
31 dsse_statement *uuid.UUID
32 selectValues sql.SelectValues
33 }
34
35 // DsseEdges holds the relations/edges for other nodes in the graph.
36 type DsseEdges struct {
37 // Statement holds the value of the statement edge.
38 Statement *Statement `json:"statement,omitempty"`
39 // Signatures holds the value of the signatures edge.
40 Signatures []*Signature `json:"signatures,omitempty"`
41 // PayloadDigests holds the value of the payload_digests edge.
42 PayloadDigests []*PayloadDigest `json:"payload_digests,omitempty"`
43 // loadedTypes holds the information for reporting if a
44 // type was loaded (or requested) in eager-loading or not.
45 loadedTypes [3]bool
46 // totalCount holds the count of the edges above.
47 totalCount [3]map[string]int
48
49 namedSignatures map[string][]*Signature
50 namedPayloadDigests map[string][]*PayloadDigest
51 }
52
53 // StatementOrErr returns the Statement value or an error if the edge
54 // was not loaded in eager-loading, or loaded but was not found.
55 func (e DsseEdges) StatementOrErr() (*Statement, error) {
56 if e.Statement != nil {
57 return e.Statement, nil
58 } else if e.loadedTypes[0] {
59 return nil, &NotFoundError{label: statement.Label}
60 }
61 return nil, &NotLoadedError{edge: "statement"}
62 }
63
64 // SignaturesOrErr returns the Signatures value or an error if the edge
65 // was not loaded in eager-loading.
66 func (e DsseEdges) SignaturesOrErr() ([]*Signature, error) {
67 if e.loadedTypes[1] {
68 return e.Signatures, nil
69 }
70 return nil, &NotLoadedError{edge: "signatures"}
71 }
72
73 // PayloadDigestsOrErr returns the PayloadDigests value or an error if the edge
74 // was not loaded in eager-loading.
75 func (e DsseEdges) PayloadDigestsOrErr() ([]*PayloadDigest, error) {
76 if e.loadedTypes[2] {
77 return e.PayloadDigests, nil
78 }
79 return nil, &NotLoadedError{edge: "payload_digests"}
80 }
81
82 // scanValues returns the types for scanning values from sql.Rows.
83 func (*Dsse) scanValues(columns []string) ([]any, error) {
84 values := make([]any, len(columns))
85 for i := range columns {
86 switch columns[i] {
87 case dsse.FieldGitoidSha256, dsse.FieldPayloadType:
88 values[i] = new(sql.NullString)
89 case dsse.FieldCreatedAt:
90 values[i] = new(sql.NullTime)
91 case dsse.FieldID:
92 values[i] = new(uuid.UUID)
93 case dsse.ForeignKeys[0]: // dsse_statement
94 values[i] = &sql.NullScanner{S: new(uuid.UUID)}
95 default:
96 values[i] = new(sql.UnknownType)
97 }
98 }
99 return values, nil
100 }
101
102 // assignValues assigns the values that were returned from sql.Rows (after scanning)
103 // to the Dsse fields.
104 func (_m *Dsse) assignValues(columns []string, values []any) error {
105 if m, n := len(values), len(columns); m < n {
106 return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
107 }
108 for i := range columns {
109 switch columns[i] {
110 case dsse.FieldID:
111 if value, ok := values[i].(*uuid.UUID); !ok {
112 return fmt.Errorf("unexpected type %T for field id", values[i])
113 } else if value != nil {
114 _m.ID = *value
115 }
116 case dsse.FieldCreatedAt:
117 if value, ok := values[i].(*sql.NullTime); !ok {
118 return fmt.Errorf("unexpected type %T for field created_at", values[i])
119 } else if value.Valid {
120 _m.CreatedAt = new(time.Time)
121 *_m.CreatedAt = value.Time
122 }
123 case dsse.FieldGitoidSha256:
124 if value, ok := values[i].(*sql.NullString); !ok {
125 return fmt.Errorf("unexpected type %T for field gitoid_sha256", values[i])
126 } else if value.Valid {
127 _m.GitoidSha256 = value.String
128 }
129 case dsse.FieldPayloadType:
130 if value, ok := values[i].(*sql.NullString); !ok {
131 return fmt.Errorf("unexpected type %T for field payload_type", values[i])
132 } else if value.Valid {
133 _m.PayloadType = value.String
134 }
135 case dsse.ForeignKeys[0]:
136 if value, ok := values[i].(*sql.NullScanner); !ok {
137 return fmt.Errorf("unexpected type %T for field dsse_statement", values[i])
138 } else if value.Valid {
139 _m.dsse_statement = new(uuid.UUID)
140 *_m.dsse_statement = *value.S.(*uuid.UUID)
141 }
142 default:
143 _m.selectValues.Set(columns[i], values[i])
144 }
145 }
146 return nil
147 }
148
149 // Value returns the ent.Value that was dynamically selected and assigned to the Dsse.
150 // This includes values selected through modifiers, order, etc.
151 func (_m *Dsse) Value(name string) (ent.Value, error) {
152 return _m.selectValues.Get(name)
153 }
154
155 // QueryStatement queries the "statement" edge of the Dsse entity.
156 func (_m *Dsse) QueryStatement() *StatementQuery {
157 return NewDsseClient(_m.config).QueryStatement(_m)
158 }
159
160 // QuerySignatures queries the "signatures" edge of the Dsse entity.
161 func (_m *Dsse) QuerySignatures() *SignatureQuery {
162 return NewDsseClient(_m.config).QuerySignatures(_m)
163 }
164
165 // QueryPayloadDigests queries the "payload_digests" edge of the Dsse entity.
166 func (_m *Dsse) QueryPayloadDigests() *PayloadDigestQuery {
167 return NewDsseClient(_m.config).QueryPayloadDigests(_m)
168 }
169
170 // Update returns a builder for updating this Dsse.
171 // Note that you need to call Dsse.Unwrap() before calling this method if this Dsse
172 // was returned from a transaction, and the transaction was committed or rolled back.
173 func (_m *Dsse) Update() *DsseUpdateOne {
174 return NewDsseClient(_m.config).UpdateOne(_m)
175 }
176
177 // Unwrap unwraps the Dsse entity that was returned from a transaction after it was closed,
178 // so that all future queries will be executed through the driver which created the transaction.
179 func (_m *Dsse) Unwrap() *Dsse {
180 _tx, ok := _m.config.driver.(*txDriver)
181 if !ok {
182 panic("ent: Dsse is not a transactional entity")
183 }
184 _m.config.driver = _tx.drv
185 return _m
186 }
187
188 // String implements the fmt.Stringer.
189 func (_m *Dsse) String() string {
190 var builder strings.Builder
191 builder.WriteString("Dsse(")
192 builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID))
193 if v := _m.CreatedAt; v != nil {
194 builder.WriteString("created_at=")
195 builder.WriteString(v.Format(time.ANSIC))
196 }
197 builder.WriteString(", ")
198 builder.WriteString("gitoid_sha256=")
199 builder.WriteString(_m.GitoidSha256)
200 builder.WriteString(", ")
201 builder.WriteString("payload_type=")
202 builder.WriteString(_m.PayloadType)
203 builder.WriteByte(')')
204 return builder.String()
205 }
206
207 // NamedSignatures returns the Signatures named value or an error if the edge was not
208 // loaded in eager-loading with this name.
209 func (_m *Dsse) NamedSignatures(name string) ([]*Signature, error) {
210 if _m.Edges.namedSignatures == nil {
211 return nil, &NotLoadedError{edge: name}
212 }
213 nodes, ok := _m.Edges.namedSignatures[name]
214 if !ok {
215 return nil, &NotLoadedError{edge: name}
216 }
217 return nodes, nil
218 }
219
220 func (_m *Dsse) appendNamedSignatures(name string, edges ...*Signature) {
221 if _m.Edges.namedSignatures == nil {
222 _m.Edges.namedSignatures = make(map[string][]*Signature)
223 }
224 if len(edges) == 0 {
225 _m.Edges.namedSignatures[name] = []*Signature{}
226 } else {
227 _m.Edges.namedSignatures[name] = append(_m.Edges.namedSignatures[name], edges...)
228 }
229 }
230
231 // NamedPayloadDigests returns the PayloadDigests named value or an error if the edge was not
232 // loaded in eager-loading with this name.
233 func (_m *Dsse) NamedPayloadDigests(name string) ([]*PayloadDigest, error) {
234 if _m.Edges.namedPayloadDigests == nil {
235 return nil, &NotLoadedError{edge: name}
236 }
237 nodes, ok := _m.Edges.namedPayloadDigests[name]
238 if !ok {
239 return nil, &NotLoadedError{edge: name}
240 }
241 return nodes, nil
242 }
243
244 func (_m *Dsse) appendNamedPayloadDigests(name string, edges ...*PayloadDigest) {
245 if _m.Edges.namedPayloadDigests == nil {
246 _m.Edges.namedPayloadDigests = make(map[string][]*PayloadDigest)
247 }
248 if len(edges) == 0 {
249 _m.Edges.namedPayloadDigests[name] = []*PayloadDigest{}
250 } else {
251 _m.Edges.namedPayloadDigests[name] = append(_m.Edges.namedPayloadDigests[name], edges...)
252 }
253 }
254
255 // Dsses is a parsable slice of Dsse.
256 type Dsses []*Dsse