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

168 lines
5.2 KiB
Go

// Code generated by ent, DO NOT EDIT.
package ent
import (
"fmt"
"strings"
"thesis/ent/blocks"
"entgo.io/ent"
"entgo.io/ent/dialect/sql"
)
// Blocks is the model entity for the Blocks schema.
type Blocks struct {
config `json:"-"`
// ID of the ent.
ID int `json:"id,omitempty"`
// Hash holds the value of the "hash" field.
Hash string `json:"hash,omitempty"`
// Length holds the value of the "length" field.
Length int `json:"length,omitempty"`
// PreviousHash holds the value of the "previousHash" field.
PreviousHash string `json:"previousHash,omitempty"`
// Edges holds the relations/edges for other nodes in the graph.
// The values are being populated by the BlocksQuery when eager-loading is set.
Edges BlocksEdges `json:"edges"`
selectValues sql.SelectValues
}
// BlocksEdges holds the relations/edges for other nodes in the graph.
type BlocksEdges struct {
// Caster holds the value of the Caster edge.
Caster []*Validators `json:"Caster,omitempty"`
// MinedTxs holds the value of the MinedTxs edge.
MinedTxs []*Transactions `json:"MinedTxs,omitempty"`
// loadedTypes holds the information for reporting if a
// type was loaded (or requested) in eager-loading or not.
loadedTypes [2]bool
}
// CasterOrErr returns the Caster value or an error if the edge
// was not loaded in eager-loading.
func (e BlocksEdges) CasterOrErr() ([]*Validators, error) {
if e.loadedTypes[0] {
return e.Caster, nil
}
return nil, &NotLoadedError{edge: "Caster"}
}
// MinedTxsOrErr returns the MinedTxs value or an error if the edge
// was not loaded in eager-loading.
func (e BlocksEdges) MinedTxsOrErr() ([]*Transactions, error) {
if e.loadedTypes[1] {
return e.MinedTxs, nil
}
return nil, &NotLoadedError{edge: "MinedTxs"}
}
// scanValues returns the types for scanning values from sql.Rows.
func (*Blocks) scanValues(columns []string) ([]any, error) {
values := make([]any, len(columns))
for i := range columns {
switch columns[i] {
case blocks.FieldID, blocks.FieldLength:
values[i] = new(sql.NullInt64)
case blocks.FieldHash, blocks.FieldPreviousHash:
values[i] = new(sql.NullString)
default:
values[i] = new(sql.UnknownType)
}
}
return values, nil
}
// assignValues assigns the values that were returned from sql.Rows (after scanning)
// to the Blocks fields.
func (b *Blocks) 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 blocks.FieldID:
value, ok := values[i].(*sql.NullInt64)
if !ok {
return fmt.Errorf("unexpected type %T for field id", value)
}
b.ID = int(value.Int64)
case blocks.FieldHash:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field hash", values[i])
} else if value.Valid {
b.Hash = value.String
}
case blocks.FieldLength:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field length", values[i])
} else if value.Valid {
b.Length = int(value.Int64)
}
case blocks.FieldPreviousHash:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field previousHash", values[i])
} else if value.Valid {
b.PreviousHash = value.String
}
default:
b.selectValues.Set(columns[i], values[i])
}
}
return nil
}
// Value returns the ent.Value that was dynamically selected and assigned to the Blocks.
// This includes values selected through modifiers, order, etc.
func (b *Blocks) Value(name string) (ent.Value, error) {
return b.selectValues.Get(name)
}
// QueryCaster queries the "Caster" edge of the Blocks entity.
func (b *Blocks) QueryCaster() *ValidatorsQuery {
return NewBlocksClient(b.config).QueryCaster(b)
}
// QueryMinedTxs queries the "MinedTxs" edge of the Blocks entity.
func (b *Blocks) QueryMinedTxs() *TransactionsQuery {
return NewBlocksClient(b.config).QueryMinedTxs(b)
}
// Update returns a builder for updating this Blocks.
// Note that you need to call Blocks.Unwrap() before calling this method if this Blocks
// was returned from a transaction, and the transaction was committed or rolled back.
func (b *Blocks) Update() *BlocksUpdateOne {
return NewBlocksClient(b.config).UpdateOne(b)
}
// Unwrap unwraps the Blocks 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 (b *Blocks) Unwrap() *Blocks {
_tx, ok := b.config.driver.(*txDriver)
if !ok {
panic("ent: Blocks is not a transactional entity")
}
b.config.driver = _tx.drv
return b
}
// String implements the fmt.Stringer.
func (b *Blocks) String() string {
var builder strings.Builder
builder.WriteString("Blocks(")
builder.WriteString(fmt.Sprintf("id=%v, ", b.ID))
builder.WriteString("hash=")
builder.WriteString(b.Hash)
builder.WriteString(", ")
builder.WriteString("length=")
builder.WriteString(fmt.Sprintf("%v", b.Length))
builder.WriteString(", ")
builder.WriteString("previousHash=")
builder.WriteString(b.PreviousHash)
builder.WriteByte(')')
return builder.String()
}
// BlocksSlice is a parsable slice of Blocks.
type BlocksSlice []*Blocks