mirror of
https://github.com/chaitin/MonkeyCode.git
synced 2026-11-23 20:39:32 +08:00
297 lines
10 KiB
Go
297 lines
10 KiB
Go
// Code generated by ent, DO NOT EDIT.
|
|
|
|
package db
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"strings"
|
|
"time"
|
|
|
|
"entgo.io/ent"
|
|
"entgo.io/ent/dialect/sql"
|
|
"github.com/chaitin/MonkeyCode/backend/db/mcptool"
|
|
"github.com/chaitin/MonkeyCode/backend/db/mcpupstream"
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
// MCPTool is the model entity for the MCPTool schema.
|
|
type MCPTool struct {
|
|
config `json:"-"`
|
|
// ID of the ent.
|
|
ID uuid.UUID `json:"id,omitempty"`
|
|
// DeletedAt holds the value of the "deleted_at" field.
|
|
DeletedAt time.Time `json:"deleted_at,omitempty"`
|
|
// UpstreamID holds the value of the "upstream_id" field.
|
|
UpstreamID uuid.UUID `json:"upstream_id,omitempty"`
|
|
// Name holds the value of the "name" field.
|
|
Name string `json:"name,omitempty"`
|
|
// NamespacedName holds the value of the "namespaced_name" field.
|
|
NamespacedName string `json:"namespaced_name,omitempty"`
|
|
// Scope holds the value of the "scope" field.
|
|
Scope mcptool.Scope `json:"scope,omitempty"`
|
|
// UserID holds the value of the "user_id" field.
|
|
UserID *uuid.UUID `json:"user_id,omitempty"`
|
|
// Description holds the value of the "description" field.
|
|
Description string `json:"description,omitempty"`
|
|
// InputSchema holds the value of the "input_schema" field.
|
|
InputSchema map[string]interface{} `json:"input_schema,omitempty"`
|
|
// Price holds the value of the "price" field.
|
|
Price int64 `json:"price,omitempty"`
|
|
// Enabled holds the value of the "enabled" field.
|
|
Enabled bool `json:"enabled,omitempty"`
|
|
// VersionHash holds the value of the "version_hash" field.
|
|
VersionHash string `json:"version_hash,omitempty"`
|
|
// SyncedAt holds the value of the "synced_at" field.
|
|
SyncedAt *time.Time `json:"synced_at,omitempty"`
|
|
// CreatedAt holds the value of the "created_at" field.
|
|
CreatedAt time.Time `json:"created_at,omitempty"`
|
|
// UpdatedAt holds the value of the "updated_at" field.
|
|
UpdatedAt time.Time `json:"updated_at,omitempty"`
|
|
// Edges holds the relations/edges for other nodes in the graph.
|
|
// The values are being populated by the MCPToolQuery when eager-loading is set.
|
|
Edges MCPToolEdges `json:"edges"`
|
|
selectValues sql.SelectValues
|
|
}
|
|
|
|
// MCPToolEdges holds the relations/edges for other nodes in the graph.
|
|
type MCPToolEdges struct {
|
|
// Upstream holds the value of the upstream edge.
|
|
Upstream *MCPUpstream `json:"upstream,omitempty"`
|
|
// loadedTypes holds the information for reporting if a
|
|
// type was loaded (or requested) in eager-loading or not.
|
|
loadedTypes [1]bool
|
|
}
|
|
|
|
// UpstreamOrErr returns the Upstream value or an error if the edge
|
|
// was not loaded in eager-loading, or loaded but was not found.
|
|
func (e MCPToolEdges) UpstreamOrErr() (*MCPUpstream, error) {
|
|
if e.Upstream != nil {
|
|
return e.Upstream, nil
|
|
} else if e.loadedTypes[0] {
|
|
return nil, &NotFoundError{label: mcpupstream.Label}
|
|
}
|
|
return nil, &NotLoadedError{edge: "upstream"}
|
|
}
|
|
|
|
// scanValues returns the types for scanning values from sql.Rows.
|
|
func (*MCPTool) scanValues(columns []string) ([]any, error) {
|
|
values := make([]any, len(columns))
|
|
for i := range columns {
|
|
switch columns[i] {
|
|
case mcptool.FieldUserID:
|
|
values[i] = &sql.NullScanner{S: new(uuid.UUID)}
|
|
case mcptool.FieldInputSchema:
|
|
values[i] = new([]byte)
|
|
case mcptool.FieldEnabled:
|
|
values[i] = new(sql.NullBool)
|
|
case mcptool.FieldPrice:
|
|
values[i] = new(sql.NullInt64)
|
|
case mcptool.FieldName, mcptool.FieldNamespacedName, mcptool.FieldScope, mcptool.FieldDescription, mcptool.FieldVersionHash:
|
|
values[i] = new(sql.NullString)
|
|
case mcptool.FieldDeletedAt, mcptool.FieldSyncedAt, mcptool.FieldCreatedAt, mcptool.FieldUpdatedAt:
|
|
values[i] = new(sql.NullTime)
|
|
case mcptool.FieldID, mcptool.FieldUpstreamID:
|
|
values[i] = new(uuid.UUID)
|
|
default:
|
|
values[i] = new(sql.UnknownType)
|
|
}
|
|
}
|
|
return values, nil
|
|
}
|
|
|
|
// assignValues assigns the values that were returned from sql.Rows (after scanning)
|
|
// to the MCPTool fields.
|
|
func (_m *MCPTool) 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 mcptool.FieldID:
|
|
if value, ok := values[i].(*uuid.UUID); !ok {
|
|
return fmt.Errorf("unexpected type %T for field id", values[i])
|
|
} else if value != nil {
|
|
_m.ID = *value
|
|
}
|
|
case mcptool.FieldDeletedAt:
|
|
if value, ok := values[i].(*sql.NullTime); !ok {
|
|
return fmt.Errorf("unexpected type %T for field deleted_at", values[i])
|
|
} else if value.Valid {
|
|
_m.DeletedAt = value.Time
|
|
}
|
|
case mcptool.FieldUpstreamID:
|
|
if value, ok := values[i].(*uuid.UUID); !ok {
|
|
return fmt.Errorf("unexpected type %T for field upstream_id", values[i])
|
|
} else if value != nil {
|
|
_m.UpstreamID = *value
|
|
}
|
|
case mcptool.FieldName:
|
|
if value, ok := values[i].(*sql.NullString); !ok {
|
|
return fmt.Errorf("unexpected type %T for field name", values[i])
|
|
} else if value.Valid {
|
|
_m.Name = value.String
|
|
}
|
|
case mcptool.FieldNamespacedName:
|
|
if value, ok := values[i].(*sql.NullString); !ok {
|
|
return fmt.Errorf("unexpected type %T for field namespaced_name", values[i])
|
|
} else if value.Valid {
|
|
_m.NamespacedName = value.String
|
|
}
|
|
case mcptool.FieldScope:
|
|
if value, ok := values[i].(*sql.NullString); !ok {
|
|
return fmt.Errorf("unexpected type %T for field scope", values[i])
|
|
} else if value.Valid {
|
|
_m.Scope = mcptool.Scope(value.String)
|
|
}
|
|
case mcptool.FieldUserID:
|
|
if value, ok := values[i].(*sql.NullScanner); !ok {
|
|
return fmt.Errorf("unexpected type %T for field user_id", values[i])
|
|
} else if value.Valid {
|
|
_m.UserID = new(uuid.UUID)
|
|
*_m.UserID = *value.S.(*uuid.UUID)
|
|
}
|
|
case mcptool.FieldDescription:
|
|
if value, ok := values[i].(*sql.NullString); !ok {
|
|
return fmt.Errorf("unexpected type %T for field description", values[i])
|
|
} else if value.Valid {
|
|
_m.Description = value.String
|
|
}
|
|
case mcptool.FieldInputSchema:
|
|
if value, ok := values[i].(*[]byte); !ok {
|
|
return fmt.Errorf("unexpected type %T for field input_schema", values[i])
|
|
} else if value != nil && len(*value) > 0 {
|
|
if err := json.Unmarshal(*value, &_m.InputSchema); err != nil {
|
|
return fmt.Errorf("unmarshal field input_schema: %w", err)
|
|
}
|
|
}
|
|
case mcptool.FieldPrice:
|
|
if value, ok := values[i].(*sql.NullInt64); !ok {
|
|
return fmt.Errorf("unexpected type %T for field price", values[i])
|
|
} else if value.Valid {
|
|
_m.Price = value.Int64
|
|
}
|
|
case mcptool.FieldEnabled:
|
|
if value, ok := values[i].(*sql.NullBool); !ok {
|
|
return fmt.Errorf("unexpected type %T for field enabled", values[i])
|
|
} else if value.Valid {
|
|
_m.Enabled = value.Bool
|
|
}
|
|
case mcptool.FieldVersionHash:
|
|
if value, ok := values[i].(*sql.NullString); !ok {
|
|
return fmt.Errorf("unexpected type %T for field version_hash", values[i])
|
|
} else if value.Valid {
|
|
_m.VersionHash = value.String
|
|
}
|
|
case mcptool.FieldSyncedAt:
|
|
if value, ok := values[i].(*sql.NullTime); !ok {
|
|
return fmt.Errorf("unexpected type %T for field synced_at", values[i])
|
|
} else if value.Valid {
|
|
_m.SyncedAt = new(time.Time)
|
|
*_m.SyncedAt = value.Time
|
|
}
|
|
case mcptool.FieldCreatedAt:
|
|
if value, ok := values[i].(*sql.NullTime); !ok {
|
|
return fmt.Errorf("unexpected type %T for field created_at", values[i])
|
|
} else if value.Valid {
|
|
_m.CreatedAt = value.Time
|
|
}
|
|
case mcptool.FieldUpdatedAt:
|
|
if value, ok := values[i].(*sql.NullTime); !ok {
|
|
return fmt.Errorf("unexpected type %T for field updated_at", values[i])
|
|
} else if value.Valid {
|
|
_m.UpdatedAt = value.Time
|
|
}
|
|
default:
|
|
_m.selectValues.Set(columns[i], values[i])
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// Value returns the ent.Value that was dynamically selected and assigned to the MCPTool.
|
|
// This includes values selected through modifiers, order, etc.
|
|
func (_m *MCPTool) Value(name string) (ent.Value, error) {
|
|
return _m.selectValues.Get(name)
|
|
}
|
|
|
|
// QueryUpstream queries the "upstream" edge of the MCPTool entity.
|
|
func (_m *MCPTool) QueryUpstream() *MCPUpstreamQuery {
|
|
return NewMCPToolClient(_m.config).QueryUpstream(_m)
|
|
}
|
|
|
|
// Update returns a builder for updating this MCPTool.
|
|
// Note that you need to call MCPTool.Unwrap() before calling this method if this MCPTool
|
|
// was returned from a transaction, and the transaction was committed or rolled back.
|
|
func (_m *MCPTool) Update() *MCPToolUpdateOne {
|
|
return NewMCPToolClient(_m.config).UpdateOne(_m)
|
|
}
|
|
|
|
// Unwrap unwraps the MCPTool 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 (_m *MCPTool) Unwrap() *MCPTool {
|
|
_tx, ok := _m.config.driver.(*txDriver)
|
|
if !ok {
|
|
panic("db: MCPTool is not a transactional entity")
|
|
}
|
|
_m.config.driver = _tx.drv
|
|
return _m
|
|
}
|
|
|
|
// String implements the fmt.Stringer.
|
|
func (_m *MCPTool) String() string {
|
|
var builder strings.Builder
|
|
builder.WriteString("MCPTool(")
|
|
builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID))
|
|
builder.WriteString("deleted_at=")
|
|
builder.WriteString(_m.DeletedAt.Format(time.ANSIC))
|
|
builder.WriteString(", ")
|
|
builder.WriteString("upstream_id=")
|
|
builder.WriteString(fmt.Sprintf("%v", _m.UpstreamID))
|
|
builder.WriteString(", ")
|
|
builder.WriteString("name=")
|
|
builder.WriteString(_m.Name)
|
|
builder.WriteString(", ")
|
|
builder.WriteString("namespaced_name=")
|
|
builder.WriteString(_m.NamespacedName)
|
|
builder.WriteString(", ")
|
|
builder.WriteString("scope=")
|
|
builder.WriteString(fmt.Sprintf("%v", _m.Scope))
|
|
builder.WriteString(", ")
|
|
if v := _m.UserID; v != nil {
|
|
builder.WriteString("user_id=")
|
|
builder.WriteString(fmt.Sprintf("%v", *v))
|
|
}
|
|
builder.WriteString(", ")
|
|
builder.WriteString("description=")
|
|
builder.WriteString(_m.Description)
|
|
builder.WriteString(", ")
|
|
builder.WriteString("input_schema=")
|
|
builder.WriteString(fmt.Sprintf("%v", _m.InputSchema))
|
|
builder.WriteString(", ")
|
|
builder.WriteString("price=")
|
|
builder.WriteString(fmt.Sprintf("%v", _m.Price))
|
|
builder.WriteString(", ")
|
|
builder.WriteString("enabled=")
|
|
builder.WriteString(fmt.Sprintf("%v", _m.Enabled))
|
|
builder.WriteString(", ")
|
|
builder.WriteString("version_hash=")
|
|
builder.WriteString(_m.VersionHash)
|
|
builder.WriteString(", ")
|
|
if v := _m.SyncedAt; v != nil {
|
|
builder.WriteString("synced_at=")
|
|
builder.WriteString(v.Format(time.ANSIC))
|
|
}
|
|
builder.WriteString(", ")
|
|
builder.WriteString("created_at=")
|
|
builder.WriteString(_m.CreatedAt.Format(time.ANSIC))
|
|
builder.WriteString(", ")
|
|
builder.WriteString("updated_at=")
|
|
builder.WriteString(_m.UpdatedAt.Format(time.ANSIC))
|
|
builder.WriteByte(')')
|
|
return builder.String()
|
|
}
|
|
|
|
// MCPTools is a parsable slice of MCPTool.
|
|
type MCPTools []*MCPTool
|