Files

252 lines
9.1 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/consts"
"github.com/chaitin/MonkeyCode/backend/db/notifychannel"
"github.com/google/uuid"
)
// NotifyChannel is the model entity for the NotifyChannel schema.
type NotifyChannel 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"`
// OwnerID holds the value of the "owner_id" field.
OwnerID uuid.UUID `json:"owner_id,omitempty"`
// OwnerType holds the value of the "owner_type" field.
OwnerType consts.NotifyOwnerType `json:"owner_type,omitempty"`
// Name holds the value of the "name" field.
Name string `json:"name,omitempty"`
// Kind holds the value of the "kind" field.
Kind consts.NotifyChannelKind `json:"kind,omitempty"`
// WebhookURL holds the value of the "webhook_url" field.
WebhookURL string `json:"webhook_url,omitempty"`
// Secret holds the value of the "secret" field.
Secret string `json:"secret,omitempty"`
// Headers holds the value of the "headers" field.
Headers map[string]string `json:"headers,omitempty"`
// Enabled holds the value of the "enabled" field.
Enabled bool `json:"enabled,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 NotifyChannelQuery when eager-loading is set.
Edges NotifyChannelEdges `json:"edges"`
selectValues sql.SelectValues
}
// NotifyChannelEdges holds the relations/edges for other nodes in the graph.
type NotifyChannelEdges struct {
// Subscriptions holds the value of the subscriptions edge.
Subscriptions []*NotifySubscription `json:"subscriptions,omitempty"`
// loadedTypes holds the information for reporting if a
// type was loaded (or requested) in eager-loading or not.
loadedTypes [1]bool
}
// SubscriptionsOrErr returns the Subscriptions value or an error if the edge
// was not loaded in eager-loading.
func (e NotifyChannelEdges) SubscriptionsOrErr() ([]*NotifySubscription, error) {
if e.loadedTypes[0] {
return e.Subscriptions, nil
}
return nil, &NotLoadedError{edge: "subscriptions"}
}
// scanValues returns the types for scanning values from sql.Rows.
func (*NotifyChannel) scanValues(columns []string) ([]any, error) {
values := make([]any, len(columns))
for i := range columns {
switch columns[i] {
case notifychannel.FieldHeaders:
values[i] = new([]byte)
case notifychannel.FieldEnabled:
values[i] = new(sql.NullBool)
case notifychannel.FieldOwnerType, notifychannel.FieldName, notifychannel.FieldKind, notifychannel.FieldWebhookURL, notifychannel.FieldSecret:
values[i] = new(sql.NullString)
case notifychannel.FieldDeletedAt, notifychannel.FieldCreatedAt, notifychannel.FieldUpdatedAt:
values[i] = new(sql.NullTime)
case notifychannel.FieldID, notifychannel.FieldOwnerID:
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 NotifyChannel fields.
func (_m *NotifyChannel) 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 notifychannel.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 notifychannel.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 notifychannel.FieldOwnerID:
if value, ok := values[i].(*uuid.UUID); !ok {
return fmt.Errorf("unexpected type %T for field owner_id", values[i])
} else if value != nil {
_m.OwnerID = *value
}
case notifychannel.FieldOwnerType:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field owner_type", values[i])
} else if value.Valid {
_m.OwnerType = consts.NotifyOwnerType(value.String)
}
case notifychannel.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 notifychannel.FieldKind:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field kind", values[i])
} else if value.Valid {
_m.Kind = consts.NotifyChannelKind(value.String)
}
case notifychannel.FieldWebhookURL:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field webhook_url", values[i])
} else if value.Valid {
_m.WebhookURL = value.String
}
case notifychannel.FieldSecret:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field secret", values[i])
} else if value.Valid {
_m.Secret = value.String
}
case notifychannel.FieldHeaders:
if value, ok := values[i].(*[]byte); !ok {
return fmt.Errorf("unexpected type %T for field headers", values[i])
} else if value != nil && len(*value) > 0 {
if err := json.Unmarshal(*value, &_m.Headers); err != nil {
return fmt.Errorf("unmarshal field headers: %w", err)
}
}
case notifychannel.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 notifychannel.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 notifychannel.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 NotifyChannel.
// This includes values selected through modifiers, order, etc.
func (_m *NotifyChannel) Value(name string) (ent.Value, error) {
return _m.selectValues.Get(name)
}
// QuerySubscriptions queries the "subscriptions" edge of the NotifyChannel entity.
func (_m *NotifyChannel) QuerySubscriptions() *NotifySubscriptionQuery {
return NewNotifyChannelClient(_m.config).QuerySubscriptions(_m)
}
// Update returns a builder for updating this NotifyChannel.
// Note that you need to call NotifyChannel.Unwrap() before calling this method if this NotifyChannel
// was returned from a transaction, and the transaction was committed or rolled back.
func (_m *NotifyChannel) Update() *NotifyChannelUpdateOne {
return NewNotifyChannelClient(_m.config).UpdateOne(_m)
}
// Unwrap unwraps the NotifyChannel 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 *NotifyChannel) Unwrap() *NotifyChannel {
_tx, ok := _m.config.driver.(*txDriver)
if !ok {
panic("db: NotifyChannel is not a transactional entity")
}
_m.config.driver = _tx.drv
return _m
}
// String implements the fmt.Stringer.
func (_m *NotifyChannel) String() string {
var builder strings.Builder
builder.WriteString("NotifyChannel(")
builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID))
builder.WriteString("deleted_at=")
builder.WriteString(_m.DeletedAt.Format(time.ANSIC))
builder.WriteString(", ")
builder.WriteString("owner_id=")
builder.WriteString(fmt.Sprintf("%v", _m.OwnerID))
builder.WriteString(", ")
builder.WriteString("owner_type=")
builder.WriteString(fmt.Sprintf("%v", _m.OwnerType))
builder.WriteString(", ")
builder.WriteString("name=")
builder.WriteString(_m.Name)
builder.WriteString(", ")
builder.WriteString("kind=")
builder.WriteString(fmt.Sprintf("%v", _m.Kind))
builder.WriteString(", ")
builder.WriteString("webhook_url=")
builder.WriteString(_m.WebhookURL)
builder.WriteString(", ")
builder.WriteString("secret=")
builder.WriteString(_m.Secret)
builder.WriteString(", ")
builder.WriteString("headers=")
builder.WriteString(fmt.Sprintf("%v", _m.Headers))
builder.WriteString(", ")
builder.WriteString("enabled=")
builder.WriteString(fmt.Sprintf("%v", _m.Enabled))
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()
}
// NotifyChannels is a parsable slice of NotifyChannel.
type NotifyChannels []*NotifyChannel