zkt24/z2/backend/ent/key.go
2024-04-25 13:51:47 +02:00

174 lines
5.4 KiB
Go

// Code generated by ent, DO NOT EDIT.
package ent
import (
"fmt"
"strings"
"thesis/ent/key"
"entgo.io/ent"
"entgo.io/ent/dialect/sql"
)
// Key is the model entity for the Key schema.
type Key struct {
config `json:"-"`
// ID of the ent.
ID int `json:"id,omitempty"`
// PublicKey holds the value of the "publicKey" field.
PublicKey string `json:"publicKey,omitempty"`
// Owner holds the value of the "Owner" field.
Owner string `json:"Owner,omitempty"`
// TrustScore holds the value of the "trustScore" field.
TrustScore float64 `json:"trustScore,omitempty"`
// Edges holds the relations/edges for other nodes in the graph.
// The values are being populated by the KeyQuery when eager-loading is set.
Edges KeyEdges `json:"edges"`
validators_key *int
white_list_account *int
selectValues sql.SelectValues
}
// KeyEdges holds the relations/edges for other nodes in the graph.
type KeyEdges struct {
// Signed holds the value of the Signed edge.
Signed []*Transactions `json:"Signed,omitempty"`
// loadedTypes holds the information for reporting if a
// type was loaded (or requested) in eager-loading or not.
loadedTypes [1]bool
}
// SignedOrErr returns the Signed value or an error if the edge
// was not loaded in eager-loading.
func (e KeyEdges) SignedOrErr() ([]*Transactions, error) {
if e.loadedTypes[0] {
return e.Signed, nil
}
return nil, &NotLoadedError{edge: "Signed"}
}
// scanValues returns the types for scanning values from sql.Rows.
func (*Key) scanValues(columns []string) ([]any, error) {
values := make([]any, len(columns))
for i := range columns {
switch columns[i] {
case key.FieldTrustScore:
values[i] = new(sql.NullFloat64)
case key.FieldID:
values[i] = new(sql.NullInt64)
case key.FieldPublicKey, key.FieldOwner:
values[i] = new(sql.NullString)
case key.ForeignKeys[0]: // validators_key
values[i] = new(sql.NullInt64)
case key.ForeignKeys[1]: // white_list_account
values[i] = new(sql.NullInt64)
default:
values[i] = new(sql.UnknownType)
}
}
return values, nil
}
// assignValues assigns the values that were returned from sql.Rows (after scanning)
// to the Key fields.
func (k *Key) assignValues(columns []string, values []any) error {
if m, n := len(values), len(columns); m < n {
return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
}
for i := range columns {
switch columns[i] {
case key.FieldID:
value, ok := values[i].(*sql.NullInt64)
if !ok {
return fmt.Errorf("unexpected type %T for field id", value)
}
k.ID = int(value.Int64)
case key.FieldPublicKey:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field publicKey", values[i])
} else if value.Valid {
k.PublicKey = value.String
}
case key.FieldOwner:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field Owner", values[i])
} else if value.Valid {
k.Owner = value.String
}
case key.FieldTrustScore:
if value, ok := values[i].(*sql.NullFloat64); !ok {
return fmt.Errorf("unexpected type %T for field trustScore", values[i])
} else if value.Valid {
k.TrustScore = value.Float64
}
case key.ForeignKeys[0]:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for edge-field validators_key", value)
} else if value.Valid {
k.validators_key = new(int)
*k.validators_key = int(value.Int64)
}
case key.ForeignKeys[1]:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for edge-field white_list_account", value)
} else if value.Valid {
k.white_list_account = new(int)
*k.white_list_account = int(value.Int64)
}
default:
k.selectValues.Set(columns[i], values[i])
}
}
return nil
}
// Value returns the ent.Value that was dynamically selected and assigned to the Key.
// This includes values selected through modifiers, order, etc.
func (k *Key) Value(name string) (ent.Value, error) {
return k.selectValues.Get(name)
}
// QuerySigned queries the "Signed" edge of the Key entity.
func (k *Key) QuerySigned() *TransactionsQuery {
return NewKeyClient(k.config).QuerySigned(k)
}
// Update returns a builder for updating this Key.
// Note that you need to call Key.Unwrap() before calling this method if this Key
// was returned from a transaction, and the transaction was committed or rolled back.
func (k *Key) Update() *KeyUpdateOne {
return NewKeyClient(k.config).UpdateOne(k)
}
// Unwrap unwraps the Key entity that was returned from a transaction after it was closed,
// so that all future queries will be executed through the driver which created the transaction.
func (k *Key) Unwrap() *Key {
_tx, ok := k.config.driver.(*txDriver)
if !ok {
panic("ent: Key is not a transactional entity")
}
k.config.driver = _tx.drv
return k
}
// String implements the fmt.Stringer.
func (k *Key) String() string {
var builder strings.Builder
builder.WriteString("Key(")
builder.WriteString(fmt.Sprintf("id=%v, ", k.ID))
builder.WriteString("publicKey=")
builder.WriteString(k.PublicKey)
builder.WriteString(", ")
builder.WriteString("Owner=")
builder.WriteString(k.Owner)
builder.WriteString(", ")
builder.WriteString("trustScore=")
builder.WriteString(fmt.Sprintf("%v", k.TrustScore))
builder.WriteByte(')')
return builder.String()
}
// Keys is a parsable slice of Key.
type Keys []*Key