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