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