123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274 |
- // Code generated by ent, DO NOT EDIT.
- package ent
- import (
- "fmt"
- "strings"
- "time"
- "wechat-api/ent/agent"
- "entgo.io/ent"
- "entgo.io/ent/dialect/sql"
- )
- // Agent is the model entity for the Agent schema.
- type Agent struct {
- config `json:"-"`
- // ID of the ent.
- ID uint64 `json:"id,omitempty"`
- // Create Time | 创建日期
- CreatedAt time.Time `json:"created_at,omitempty"`
- // Update Time | 修改日期
- UpdatedAt time.Time `json:"updated_at,omitempty"`
- // Delete Time | 删除日期
- DeletedAt time.Time `json:"deleted_at,omitempty"`
- // name | 角色名称
- Name string `json:"name,omitempty"`
- // role | 角色设定
- Role string `json:"role,omitempty"`
- // status | 状态 1-正常 2-禁用
- Status int `json:"status,omitempty"`
- // background | 背景介绍
- Background string `json:"background,omitempty"`
- // examples | 对话案例
- Examples string `json:"examples,omitempty"`
- // organization_id | 租户ID
- OrganizationID uint64 `json:"organization_id,omitempty"`
- // dataset_id | 知识库ID
- DatasetID string `json:"dataset_id,omitempty"`
- // collection_id | 集合ID
- CollectionID string `json:"collection_id,omitempty"`
- // Edges holds the relations/edges for other nodes in the graph.
- // The values are being populated by the AgentQuery when eager-loading is set.
- Edges AgentEdges `json:"edges"`
- selectValues sql.SelectValues
- }
- // AgentEdges holds the relations/edges for other nodes in the graph.
- type AgentEdges struct {
- // WxAgent holds the value of the wx_agent edge.
- WxAgent []*Wx `json:"wx_agent,omitempty"`
- // TokenAgent holds the value of the token_agent edge.
- TokenAgent []*Token `json:"token_agent,omitempty"`
- // WaAgent holds the value of the wa_agent edge.
- WaAgent []*Whatsapp `json:"wa_agent,omitempty"`
- // loadedTypes holds the information for reporting if a
- // type was loaded (or requested) in eager-loading or not.
- loadedTypes [3]bool
- }
- // WxAgentOrErr returns the WxAgent value or an error if the edge
- // was not loaded in eager-loading.
- func (e AgentEdges) WxAgentOrErr() ([]*Wx, error) {
- if e.loadedTypes[0] {
- return e.WxAgent, nil
- }
- return nil, &NotLoadedError{edge: "wx_agent"}
- }
- // TokenAgentOrErr returns the TokenAgent value or an error if the edge
- // was not loaded in eager-loading.
- func (e AgentEdges) TokenAgentOrErr() ([]*Token, error) {
- if e.loadedTypes[1] {
- return e.TokenAgent, nil
- }
- return nil, &NotLoadedError{edge: "token_agent"}
- }
- // WaAgentOrErr returns the WaAgent value or an error if the edge
- // was not loaded in eager-loading.
- func (e AgentEdges) WaAgentOrErr() ([]*Whatsapp, error) {
- if e.loadedTypes[2] {
- return e.WaAgent, nil
- }
- return nil, &NotLoadedError{edge: "wa_agent"}
- }
- // scanValues returns the types for scanning values from sql.Rows.
- func (*Agent) scanValues(columns []string) ([]any, error) {
- values := make([]any, len(columns))
- for i := range columns {
- switch columns[i] {
- case agent.FieldID, agent.FieldStatus, agent.FieldOrganizationID:
- values[i] = new(sql.NullInt64)
- case agent.FieldName, agent.FieldRole, agent.FieldBackground, agent.FieldExamples, agent.FieldDatasetID, agent.FieldCollectionID:
- values[i] = new(sql.NullString)
- case agent.FieldCreatedAt, agent.FieldUpdatedAt, agent.FieldDeletedAt:
- values[i] = new(sql.NullTime)
- default:
- values[i] = new(sql.UnknownType)
- }
- }
- return values, nil
- }
- // assignValues assigns the values that were returned from sql.Rows (after scanning)
- // to the Agent fields.
- func (a *Agent) 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 agent.FieldID:
- value, ok := values[i].(*sql.NullInt64)
- if !ok {
- return fmt.Errorf("unexpected type %T for field id", value)
- }
- a.ID = uint64(value.Int64)
- case agent.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 {
- a.CreatedAt = value.Time
- }
- case agent.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 {
- a.UpdatedAt = value.Time
- }
- case agent.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 {
- a.DeletedAt = value.Time
- }
- case agent.FieldName:
- if value, ok := values[i].(*sql.NullString); !ok {
- return fmt.Errorf("unexpected type %T for field name", values[i])
- } else if value.Valid {
- a.Name = value.String
- }
- case agent.FieldRole:
- if value, ok := values[i].(*sql.NullString); !ok {
- return fmt.Errorf("unexpected type %T for field role", values[i])
- } else if value.Valid {
- a.Role = value.String
- }
- case agent.FieldStatus:
- if value, ok := values[i].(*sql.NullInt64); !ok {
- return fmt.Errorf("unexpected type %T for field status", values[i])
- } else if value.Valid {
- a.Status = int(value.Int64)
- }
- case agent.FieldBackground:
- if value, ok := values[i].(*sql.NullString); !ok {
- return fmt.Errorf("unexpected type %T for field background", values[i])
- } else if value.Valid {
- a.Background = value.String
- }
- case agent.FieldExamples:
- if value, ok := values[i].(*sql.NullString); !ok {
- return fmt.Errorf("unexpected type %T for field examples", values[i])
- } else if value.Valid {
- a.Examples = value.String
- }
- case agent.FieldOrganizationID:
- if value, ok := values[i].(*sql.NullInt64); !ok {
- return fmt.Errorf("unexpected type %T for field organization_id", values[i])
- } else if value.Valid {
- a.OrganizationID = uint64(value.Int64)
- }
- case agent.FieldDatasetID:
- if value, ok := values[i].(*sql.NullString); !ok {
- return fmt.Errorf("unexpected type %T for field dataset_id", values[i])
- } else if value.Valid {
- a.DatasetID = value.String
- }
- case agent.FieldCollectionID:
- if value, ok := values[i].(*sql.NullString); !ok {
- return fmt.Errorf("unexpected type %T for field collection_id", values[i])
- } else if value.Valid {
- a.CollectionID = value.String
- }
- default:
- a.selectValues.Set(columns[i], values[i])
- }
- }
- return nil
- }
- // Value returns the ent.Value that was dynamically selected and assigned to the Agent.
- // This includes values selected through modifiers, order, etc.
- func (a *Agent) Value(name string) (ent.Value, error) {
- return a.selectValues.Get(name)
- }
- // QueryWxAgent queries the "wx_agent" edge of the Agent entity.
- func (a *Agent) QueryWxAgent() *WxQuery {
- return NewAgentClient(a.config).QueryWxAgent(a)
- }
- // QueryTokenAgent queries the "token_agent" edge of the Agent entity.
- func (a *Agent) QueryTokenAgent() *TokenQuery {
- return NewAgentClient(a.config).QueryTokenAgent(a)
- }
- // QueryWaAgent queries the "wa_agent" edge of the Agent entity.
- func (a *Agent) QueryWaAgent() *WhatsappQuery {
- return NewAgentClient(a.config).QueryWaAgent(a)
- }
- // Update returns a builder for updating this Agent.
- // Note that you need to call Agent.Unwrap() before calling this method if this Agent
- // was returned from a transaction, and the transaction was committed or rolled back.
- func (a *Agent) Update() *AgentUpdateOne {
- return NewAgentClient(a.config).UpdateOne(a)
- }
- // Unwrap unwraps the Agent 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 (a *Agent) Unwrap() *Agent {
- _tx, ok := a.config.driver.(*txDriver)
- if !ok {
- panic("ent: Agent is not a transactional entity")
- }
- a.config.driver = _tx.drv
- return a
- }
- // String implements the fmt.Stringer.
- func (a *Agent) String() string {
- var builder strings.Builder
- builder.WriteString("Agent(")
- builder.WriteString(fmt.Sprintf("id=%v, ", a.ID))
- builder.WriteString("created_at=")
- builder.WriteString(a.CreatedAt.Format(time.ANSIC))
- builder.WriteString(", ")
- builder.WriteString("updated_at=")
- builder.WriteString(a.UpdatedAt.Format(time.ANSIC))
- builder.WriteString(", ")
- builder.WriteString("deleted_at=")
- builder.WriteString(a.DeletedAt.Format(time.ANSIC))
- builder.WriteString(", ")
- builder.WriteString("name=")
- builder.WriteString(a.Name)
- builder.WriteString(", ")
- builder.WriteString("role=")
- builder.WriteString(a.Role)
- builder.WriteString(", ")
- builder.WriteString("status=")
- builder.WriteString(fmt.Sprintf("%v", a.Status))
- builder.WriteString(", ")
- builder.WriteString("background=")
- builder.WriteString(a.Background)
- builder.WriteString(", ")
- builder.WriteString("examples=")
- builder.WriteString(a.Examples)
- builder.WriteString(", ")
- builder.WriteString("organization_id=")
- builder.WriteString(fmt.Sprintf("%v", a.OrganizationID))
- builder.WriteString(", ")
- builder.WriteString("dataset_id=")
- builder.WriteString(a.DatasetID)
- builder.WriteString(", ")
- builder.WriteString("collection_id=")
- builder.WriteString(a.CollectionID)
- builder.WriteByte(')')
- return builder.String()
- }
- // Agents is a parsable slice of Agent.
- type Agents []*Agent
|