2795 lines
81 KiB
Go
2795 lines
81 KiB
Go
// Code generated by ent, DO NOT EDIT.
|
|
|
|
package ent
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
"sync"
|
|
"time"
|
|
|
|
"entgo.io/ent"
|
|
"entgo.io/ent/dialect/sql"
|
|
"github.com/fatedier/frp/pkg/db/ent/frpcclient"
|
|
"github.com/fatedier/frp/pkg/db/ent/predicate"
|
|
"github.com/fatedier/frp/pkg/db/ent/proxy"
|
|
"github.com/fatedier/frp/pkg/db/ent/serverconfig"
|
|
"github.com/fatedier/frp/pkg/db/ent/user"
|
|
)
|
|
|
|
const (
|
|
// Operation types.
|
|
OpCreate = ent.OpCreate
|
|
OpDelete = ent.OpDelete
|
|
OpDeleteOne = ent.OpDeleteOne
|
|
OpUpdate = ent.OpUpdate
|
|
OpUpdateOne = ent.OpUpdateOne
|
|
|
|
// Node types.
|
|
TypeFrpcClient = "FrpcClient"
|
|
TypeProxy = "Proxy"
|
|
TypeServerConfig = "ServerConfig"
|
|
TypeUser = "User"
|
|
)
|
|
|
|
// FrpcClientMutation represents an operation that mutates the FrpcClient nodes in the graph.
|
|
type FrpcClientMutation struct {
|
|
config
|
|
op Op
|
|
typ string
|
|
id *int
|
|
name *string
|
|
key *string
|
|
addr *string
|
|
port *int
|
|
addport *int
|
|
status *string
|
|
metadata *string
|
|
created_at *time.Time
|
|
updated_at *time.Time
|
|
last_seen *time.Time
|
|
clearedFields map[string]struct{}
|
|
done bool
|
|
oldValue func(context.Context) (*FrpcClient, error)
|
|
predicates []predicate.FrpcClient
|
|
}
|
|
|
|
var _ ent.Mutation = (*FrpcClientMutation)(nil)
|
|
|
|
// frpcclientOption allows management of the mutation configuration using functional options.
|
|
type frpcclientOption func(*FrpcClientMutation)
|
|
|
|
// newFrpcClientMutation creates new mutation for the FrpcClient entity.
|
|
func newFrpcClientMutation(c config, op Op, opts ...frpcclientOption) *FrpcClientMutation {
|
|
m := &FrpcClientMutation{
|
|
config: c,
|
|
op: op,
|
|
typ: TypeFrpcClient,
|
|
clearedFields: make(map[string]struct{}),
|
|
}
|
|
for _, opt := range opts {
|
|
opt(m)
|
|
}
|
|
return m
|
|
}
|
|
|
|
// withFrpcClientID sets the ID field of the mutation.
|
|
func withFrpcClientID(id int) frpcclientOption {
|
|
return func(m *FrpcClientMutation) {
|
|
var (
|
|
err error
|
|
once sync.Once
|
|
value *FrpcClient
|
|
)
|
|
m.oldValue = func(ctx context.Context) (*FrpcClient, error) {
|
|
once.Do(func() {
|
|
if m.done {
|
|
err = errors.New("querying old values post mutation is not allowed")
|
|
} else {
|
|
value, err = m.Client().FrpcClient.Get(ctx, id)
|
|
}
|
|
})
|
|
return value, err
|
|
}
|
|
m.id = &id
|
|
}
|
|
}
|
|
|
|
// withFrpcClient sets the old FrpcClient of the mutation.
|
|
func withFrpcClient(node *FrpcClient) frpcclientOption {
|
|
return func(m *FrpcClientMutation) {
|
|
m.oldValue = func(context.Context) (*FrpcClient, error) {
|
|
return node, nil
|
|
}
|
|
m.id = &node.ID
|
|
}
|
|
}
|
|
|
|
// Client returns a new `ent.Client` from the mutation. If the mutation was
|
|
// executed in a transaction (ent.Tx), a transactional client is returned.
|
|
func (m FrpcClientMutation) Client() *Client {
|
|
client := &Client{config: m.config}
|
|
client.init()
|
|
return client
|
|
}
|
|
|
|
// Tx returns an `ent.Tx` for mutations that were executed in transactions;
|
|
// it returns an error otherwise.
|
|
func (m FrpcClientMutation) Tx() (*Tx, error) {
|
|
if _, ok := m.driver.(*txDriver); !ok {
|
|
return nil, errors.New("ent: mutation is not running in a transaction")
|
|
}
|
|
tx := &Tx{config: m.config}
|
|
tx.init()
|
|
return tx, nil
|
|
}
|
|
|
|
// ID returns the ID value in the mutation. Note that the ID is only available
|
|
// if it was provided to the builder or after it was returned from the database.
|
|
func (m *FrpcClientMutation) ID() (id int, exists bool) {
|
|
if m.id == nil {
|
|
return
|
|
}
|
|
return *m.id, true
|
|
}
|
|
|
|
// IDs queries the database and returns the entity ids that match the mutation's predicate.
|
|
// That means, if the mutation is applied within a transaction with an isolation level such
|
|
// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated
|
|
// or updated by the mutation.
|
|
func (m *FrpcClientMutation) IDs(ctx context.Context) ([]int, error) {
|
|
switch {
|
|
case m.op.Is(OpUpdateOne | OpDeleteOne):
|
|
id, exists := m.ID()
|
|
if exists {
|
|
return []int{id}, nil
|
|
}
|
|
fallthrough
|
|
case m.op.Is(OpUpdate | OpDelete):
|
|
return m.Client().FrpcClient.Query().Where(m.predicates...).IDs(ctx)
|
|
default:
|
|
return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
|
|
}
|
|
}
|
|
|
|
// SetName sets the "name" field.
|
|
func (m *FrpcClientMutation) SetName(s string) {
|
|
m.name = &s
|
|
}
|
|
|
|
// Name returns the value of the "name" field in the mutation.
|
|
func (m *FrpcClientMutation) Name() (r string, exists bool) {
|
|
v := m.name
|
|
if v == nil {
|
|
return
|
|
}
|
|
return *v, true
|
|
}
|
|
|
|
// OldName returns the old "name" field's value of the FrpcClient entity.
|
|
// If the FrpcClient object wasn't provided to the builder, the object is fetched from the database.
|
|
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
|
func (m *FrpcClientMutation) OldName(ctx context.Context) (v string, err error) {
|
|
if !m.op.Is(OpUpdateOne) {
|
|
return v, errors.New("OldName is only allowed on UpdateOne operations")
|
|
}
|
|
if m.id == nil || m.oldValue == nil {
|
|
return v, errors.New("OldName requires an ID field in the mutation")
|
|
}
|
|
oldValue, err := m.oldValue(ctx)
|
|
if err != nil {
|
|
return v, fmt.Errorf("querying old value for OldName: %w", err)
|
|
}
|
|
return oldValue.Name, nil
|
|
}
|
|
|
|
// ResetName resets all changes to the "name" field.
|
|
func (m *FrpcClientMutation) ResetName() {
|
|
m.name = nil
|
|
}
|
|
|
|
// SetKey sets the "key" field.
|
|
func (m *FrpcClientMutation) SetKey(s string) {
|
|
m.key = &s
|
|
}
|
|
|
|
// Key returns the value of the "key" field in the mutation.
|
|
func (m *FrpcClientMutation) Key() (r string, exists bool) {
|
|
v := m.key
|
|
if v == nil {
|
|
return
|
|
}
|
|
return *v, true
|
|
}
|
|
|
|
// OldKey returns the old "key" field's value of the FrpcClient entity.
|
|
// If the FrpcClient object wasn't provided to the builder, the object is fetched from the database.
|
|
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
|
func (m *FrpcClientMutation) OldKey(ctx context.Context) (v string, err error) {
|
|
if !m.op.Is(OpUpdateOne) {
|
|
return v, errors.New("OldKey is only allowed on UpdateOne operations")
|
|
}
|
|
if m.id == nil || m.oldValue == nil {
|
|
return v, errors.New("OldKey requires an ID field in the mutation")
|
|
}
|
|
oldValue, err := m.oldValue(ctx)
|
|
if err != nil {
|
|
return v, fmt.Errorf("querying old value for OldKey: %w", err)
|
|
}
|
|
return oldValue.Key, nil
|
|
}
|
|
|
|
// ResetKey resets all changes to the "key" field.
|
|
func (m *FrpcClientMutation) ResetKey() {
|
|
m.key = nil
|
|
}
|
|
|
|
// SetAddr sets the "addr" field.
|
|
func (m *FrpcClientMutation) SetAddr(s string) {
|
|
m.addr = &s
|
|
}
|
|
|
|
// Addr returns the value of the "addr" field in the mutation.
|
|
func (m *FrpcClientMutation) Addr() (r string, exists bool) {
|
|
v := m.addr
|
|
if v == nil {
|
|
return
|
|
}
|
|
return *v, true
|
|
}
|
|
|
|
// OldAddr returns the old "addr" field's value of the FrpcClient entity.
|
|
// If the FrpcClient object wasn't provided to the builder, the object is fetched from the database.
|
|
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
|
func (m *FrpcClientMutation) OldAddr(ctx context.Context) (v string, err error) {
|
|
if !m.op.Is(OpUpdateOne) {
|
|
return v, errors.New("OldAddr is only allowed on UpdateOne operations")
|
|
}
|
|
if m.id == nil || m.oldValue == nil {
|
|
return v, errors.New("OldAddr requires an ID field in the mutation")
|
|
}
|
|
oldValue, err := m.oldValue(ctx)
|
|
if err != nil {
|
|
return v, fmt.Errorf("querying old value for OldAddr: %w", err)
|
|
}
|
|
return oldValue.Addr, nil
|
|
}
|
|
|
|
// ResetAddr resets all changes to the "addr" field.
|
|
func (m *FrpcClientMutation) ResetAddr() {
|
|
m.addr = nil
|
|
}
|
|
|
|
// SetPort sets the "port" field.
|
|
func (m *FrpcClientMutation) SetPort(i int) {
|
|
m.port = &i
|
|
m.addport = nil
|
|
}
|
|
|
|
// Port returns the value of the "port" field in the mutation.
|
|
func (m *FrpcClientMutation) Port() (r int, exists bool) {
|
|
v := m.port
|
|
if v == nil {
|
|
return
|
|
}
|
|
return *v, true
|
|
}
|
|
|
|
// OldPort returns the old "port" field's value of the FrpcClient entity.
|
|
// If the FrpcClient object wasn't provided to the builder, the object is fetched from the database.
|
|
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
|
func (m *FrpcClientMutation) OldPort(ctx context.Context) (v int, err error) {
|
|
if !m.op.Is(OpUpdateOne) {
|
|
return v, errors.New("OldPort is only allowed on UpdateOne operations")
|
|
}
|
|
if m.id == nil || m.oldValue == nil {
|
|
return v, errors.New("OldPort requires an ID field in the mutation")
|
|
}
|
|
oldValue, err := m.oldValue(ctx)
|
|
if err != nil {
|
|
return v, fmt.Errorf("querying old value for OldPort: %w", err)
|
|
}
|
|
return oldValue.Port, nil
|
|
}
|
|
|
|
// AddPort adds i to the "port" field.
|
|
func (m *FrpcClientMutation) AddPort(i int) {
|
|
if m.addport != nil {
|
|
*m.addport += i
|
|
} else {
|
|
m.addport = &i
|
|
}
|
|
}
|
|
|
|
// AddedPort returns the value that was added to the "port" field in this mutation.
|
|
func (m *FrpcClientMutation) AddedPort() (r int, exists bool) {
|
|
v := m.addport
|
|
if v == nil {
|
|
return
|
|
}
|
|
return *v, true
|
|
}
|
|
|
|
// ResetPort resets all changes to the "port" field.
|
|
func (m *FrpcClientMutation) ResetPort() {
|
|
m.port = nil
|
|
m.addport = nil
|
|
}
|
|
|
|
// SetStatus sets the "status" field.
|
|
func (m *FrpcClientMutation) SetStatus(s string) {
|
|
m.status = &s
|
|
}
|
|
|
|
// Status returns the value of the "status" field in the mutation.
|
|
func (m *FrpcClientMutation) Status() (r string, exists bool) {
|
|
v := m.status
|
|
if v == nil {
|
|
return
|
|
}
|
|
return *v, true
|
|
}
|
|
|
|
// OldStatus returns the old "status" field's value of the FrpcClient entity.
|
|
// If the FrpcClient object wasn't provided to the builder, the object is fetched from the database.
|
|
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
|
func (m *FrpcClientMutation) OldStatus(ctx context.Context) (v string, err error) {
|
|
if !m.op.Is(OpUpdateOne) {
|
|
return v, errors.New("OldStatus is only allowed on UpdateOne operations")
|
|
}
|
|
if m.id == nil || m.oldValue == nil {
|
|
return v, errors.New("OldStatus requires an ID field in the mutation")
|
|
}
|
|
oldValue, err := m.oldValue(ctx)
|
|
if err != nil {
|
|
return v, fmt.Errorf("querying old value for OldStatus: %w", err)
|
|
}
|
|
return oldValue.Status, nil
|
|
}
|
|
|
|
// ResetStatus resets all changes to the "status" field.
|
|
func (m *FrpcClientMutation) ResetStatus() {
|
|
m.status = nil
|
|
}
|
|
|
|
// SetMetadata sets the "metadata" field.
|
|
func (m *FrpcClientMutation) SetMetadata(s string) {
|
|
m.metadata = &s
|
|
}
|
|
|
|
// Metadata returns the value of the "metadata" field in the mutation.
|
|
func (m *FrpcClientMutation) Metadata() (r string, exists bool) {
|
|
v := m.metadata
|
|
if v == nil {
|
|
return
|
|
}
|
|
return *v, true
|
|
}
|
|
|
|
// OldMetadata returns the old "metadata" field's value of the FrpcClient entity.
|
|
// If the FrpcClient object wasn't provided to the builder, the object is fetched from the database.
|
|
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
|
func (m *FrpcClientMutation) OldMetadata(ctx context.Context) (v string, err error) {
|
|
if !m.op.Is(OpUpdateOne) {
|
|
return v, errors.New("OldMetadata is only allowed on UpdateOne operations")
|
|
}
|
|
if m.id == nil || m.oldValue == nil {
|
|
return v, errors.New("OldMetadata requires an ID field in the mutation")
|
|
}
|
|
oldValue, err := m.oldValue(ctx)
|
|
if err != nil {
|
|
return v, fmt.Errorf("querying old value for OldMetadata: %w", err)
|
|
}
|
|
return oldValue.Metadata, nil
|
|
}
|
|
|
|
// ResetMetadata resets all changes to the "metadata" field.
|
|
func (m *FrpcClientMutation) ResetMetadata() {
|
|
m.metadata = nil
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (m *FrpcClientMutation) SetCreatedAt(t time.Time) {
|
|
m.created_at = &t
|
|
}
|
|
|
|
// CreatedAt returns the value of the "created_at" field in the mutation.
|
|
func (m *FrpcClientMutation) CreatedAt() (r time.Time, exists bool) {
|
|
v := m.created_at
|
|
if v == nil {
|
|
return
|
|
}
|
|
return *v, true
|
|
}
|
|
|
|
// OldCreatedAt returns the old "created_at" field's value of the FrpcClient entity.
|
|
// If the FrpcClient object wasn't provided to the builder, the object is fetched from the database.
|
|
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
|
func (m *FrpcClientMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) {
|
|
if !m.op.Is(OpUpdateOne) {
|
|
return v, errors.New("OldCreatedAt is only allowed on UpdateOne operations")
|
|
}
|
|
if m.id == nil || m.oldValue == nil {
|
|
return v, errors.New("OldCreatedAt requires an ID field in the mutation")
|
|
}
|
|
oldValue, err := m.oldValue(ctx)
|
|
if err != nil {
|
|
return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err)
|
|
}
|
|
return oldValue.CreatedAt, nil
|
|
}
|
|
|
|
// ResetCreatedAt resets all changes to the "created_at" field.
|
|
func (m *FrpcClientMutation) ResetCreatedAt() {
|
|
m.created_at = nil
|
|
}
|
|
|
|
// SetUpdatedAt sets the "updated_at" field.
|
|
func (m *FrpcClientMutation) SetUpdatedAt(t time.Time) {
|
|
m.updated_at = &t
|
|
}
|
|
|
|
// UpdatedAt returns the value of the "updated_at" field in the mutation.
|
|
func (m *FrpcClientMutation) UpdatedAt() (r time.Time, exists bool) {
|
|
v := m.updated_at
|
|
if v == nil {
|
|
return
|
|
}
|
|
return *v, true
|
|
}
|
|
|
|
// OldUpdatedAt returns the old "updated_at" field's value of the FrpcClient entity.
|
|
// If the FrpcClient object wasn't provided to the builder, the object is fetched from the database.
|
|
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
|
func (m *FrpcClientMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) {
|
|
if !m.op.Is(OpUpdateOne) {
|
|
return v, errors.New("OldUpdatedAt is only allowed on UpdateOne operations")
|
|
}
|
|
if m.id == nil || m.oldValue == nil {
|
|
return v, errors.New("OldUpdatedAt requires an ID field in the mutation")
|
|
}
|
|
oldValue, err := m.oldValue(ctx)
|
|
if err != nil {
|
|
return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err)
|
|
}
|
|
return oldValue.UpdatedAt, nil
|
|
}
|
|
|
|
// ResetUpdatedAt resets all changes to the "updated_at" field.
|
|
func (m *FrpcClientMutation) ResetUpdatedAt() {
|
|
m.updated_at = nil
|
|
}
|
|
|
|
// SetLastSeen sets the "last_seen" field.
|
|
func (m *FrpcClientMutation) SetLastSeen(t time.Time) {
|
|
m.last_seen = &t
|
|
}
|
|
|
|
// LastSeen returns the value of the "last_seen" field in the mutation.
|
|
func (m *FrpcClientMutation) LastSeen() (r time.Time, exists bool) {
|
|
v := m.last_seen
|
|
if v == nil {
|
|
return
|
|
}
|
|
return *v, true
|
|
}
|
|
|
|
// OldLastSeen returns the old "last_seen" field's value of the FrpcClient entity.
|
|
// If the FrpcClient object wasn't provided to the builder, the object is fetched from the database.
|
|
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
|
func (m *FrpcClientMutation) OldLastSeen(ctx context.Context) (v time.Time, err error) {
|
|
if !m.op.Is(OpUpdateOne) {
|
|
return v, errors.New("OldLastSeen is only allowed on UpdateOne operations")
|
|
}
|
|
if m.id == nil || m.oldValue == nil {
|
|
return v, errors.New("OldLastSeen requires an ID field in the mutation")
|
|
}
|
|
oldValue, err := m.oldValue(ctx)
|
|
if err != nil {
|
|
return v, fmt.Errorf("querying old value for OldLastSeen: %w", err)
|
|
}
|
|
return oldValue.LastSeen, nil
|
|
}
|
|
|
|
// ClearLastSeen clears the value of the "last_seen" field.
|
|
func (m *FrpcClientMutation) ClearLastSeen() {
|
|
m.last_seen = nil
|
|
m.clearedFields[frpcclient.FieldLastSeen] = struct{}{}
|
|
}
|
|
|
|
// LastSeenCleared returns if the "last_seen" field was cleared in this mutation.
|
|
func (m *FrpcClientMutation) LastSeenCleared() bool {
|
|
_, ok := m.clearedFields[frpcclient.FieldLastSeen]
|
|
return ok
|
|
}
|
|
|
|
// ResetLastSeen resets all changes to the "last_seen" field.
|
|
func (m *FrpcClientMutation) ResetLastSeen() {
|
|
m.last_seen = nil
|
|
delete(m.clearedFields, frpcclient.FieldLastSeen)
|
|
}
|
|
|
|
// Where appends a list predicates to the FrpcClientMutation builder.
|
|
func (m *FrpcClientMutation) Where(ps ...predicate.FrpcClient) {
|
|
m.predicates = append(m.predicates, ps...)
|
|
}
|
|
|
|
// WhereP appends storage-level predicates to the FrpcClientMutation builder. Using this method,
|
|
// users can use type-assertion to append predicates that do not depend on any generated package.
|
|
func (m *FrpcClientMutation) WhereP(ps ...func(*sql.Selector)) {
|
|
p := make([]predicate.FrpcClient, len(ps))
|
|
for i := range ps {
|
|
p[i] = ps[i]
|
|
}
|
|
m.Where(p...)
|
|
}
|
|
|
|
// Op returns the operation name.
|
|
func (m *FrpcClientMutation) Op() Op {
|
|
return m.op
|
|
}
|
|
|
|
// SetOp allows setting the mutation operation.
|
|
func (m *FrpcClientMutation) SetOp(op Op) {
|
|
m.op = op
|
|
}
|
|
|
|
// Type returns the node type of this mutation (FrpcClient).
|
|
func (m *FrpcClientMutation) Type() string {
|
|
return m.typ
|
|
}
|
|
|
|
// Fields returns all fields that were changed during this mutation. Note that in
|
|
// order to get all numeric fields that were incremented/decremented, call
|
|
// AddedFields().
|
|
func (m *FrpcClientMutation) Fields() []string {
|
|
fields := make([]string, 0, 9)
|
|
if m.name != nil {
|
|
fields = append(fields, frpcclient.FieldName)
|
|
}
|
|
if m.key != nil {
|
|
fields = append(fields, frpcclient.FieldKey)
|
|
}
|
|
if m.addr != nil {
|
|
fields = append(fields, frpcclient.FieldAddr)
|
|
}
|
|
if m.port != nil {
|
|
fields = append(fields, frpcclient.FieldPort)
|
|
}
|
|
if m.status != nil {
|
|
fields = append(fields, frpcclient.FieldStatus)
|
|
}
|
|
if m.metadata != nil {
|
|
fields = append(fields, frpcclient.FieldMetadata)
|
|
}
|
|
if m.created_at != nil {
|
|
fields = append(fields, frpcclient.FieldCreatedAt)
|
|
}
|
|
if m.updated_at != nil {
|
|
fields = append(fields, frpcclient.FieldUpdatedAt)
|
|
}
|
|
if m.last_seen != nil {
|
|
fields = append(fields, frpcclient.FieldLastSeen)
|
|
}
|
|
return fields
|
|
}
|
|
|
|
// Field returns the value of a field with the given name. The second boolean
|
|
// return value indicates that this field was not set, or was not defined in the
|
|
// schema.
|
|
func (m *FrpcClientMutation) Field(name string) (ent.Value, bool) {
|
|
switch name {
|
|
case frpcclient.FieldName:
|
|
return m.Name()
|
|
case frpcclient.FieldKey:
|
|
return m.Key()
|
|
case frpcclient.FieldAddr:
|
|
return m.Addr()
|
|
case frpcclient.FieldPort:
|
|
return m.Port()
|
|
case frpcclient.FieldStatus:
|
|
return m.Status()
|
|
case frpcclient.FieldMetadata:
|
|
return m.Metadata()
|
|
case frpcclient.FieldCreatedAt:
|
|
return m.CreatedAt()
|
|
case frpcclient.FieldUpdatedAt:
|
|
return m.UpdatedAt()
|
|
case frpcclient.FieldLastSeen:
|
|
return m.LastSeen()
|
|
}
|
|
return nil, false
|
|
}
|
|
|
|
// OldField returns the old value of the field from the database. An error is
|
|
// returned if the mutation operation is not UpdateOne, or the query to the
|
|
// database failed.
|
|
func (m *FrpcClientMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
|
|
switch name {
|
|
case frpcclient.FieldName:
|
|
return m.OldName(ctx)
|
|
case frpcclient.FieldKey:
|
|
return m.OldKey(ctx)
|
|
case frpcclient.FieldAddr:
|
|
return m.OldAddr(ctx)
|
|
case frpcclient.FieldPort:
|
|
return m.OldPort(ctx)
|
|
case frpcclient.FieldStatus:
|
|
return m.OldStatus(ctx)
|
|
case frpcclient.FieldMetadata:
|
|
return m.OldMetadata(ctx)
|
|
case frpcclient.FieldCreatedAt:
|
|
return m.OldCreatedAt(ctx)
|
|
case frpcclient.FieldUpdatedAt:
|
|
return m.OldUpdatedAt(ctx)
|
|
case frpcclient.FieldLastSeen:
|
|
return m.OldLastSeen(ctx)
|
|
}
|
|
return nil, fmt.Errorf("unknown FrpcClient field %s", name)
|
|
}
|
|
|
|
// SetField sets the value of a field with the given name. It returns an error if
|
|
// the field is not defined in the schema, or if the type mismatched the field
|
|
// type.
|
|
func (m *FrpcClientMutation) SetField(name string, value ent.Value) error {
|
|
switch name {
|
|
case frpcclient.FieldName:
|
|
v, ok := value.(string)
|
|
if !ok {
|
|
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
|
}
|
|
m.SetName(v)
|
|
return nil
|
|
case frpcclient.FieldKey:
|
|
v, ok := value.(string)
|
|
if !ok {
|
|
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
|
}
|
|
m.SetKey(v)
|
|
return nil
|
|
case frpcclient.FieldAddr:
|
|
v, ok := value.(string)
|
|
if !ok {
|
|
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
|
}
|
|
m.SetAddr(v)
|
|
return nil
|
|
case frpcclient.FieldPort:
|
|
v, ok := value.(int)
|
|
if !ok {
|
|
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
|
}
|
|
m.SetPort(v)
|
|
return nil
|
|
case frpcclient.FieldStatus:
|
|
v, ok := value.(string)
|
|
if !ok {
|
|
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
|
}
|
|
m.SetStatus(v)
|
|
return nil
|
|
case frpcclient.FieldMetadata:
|
|
v, ok := value.(string)
|
|
if !ok {
|
|
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
|
}
|
|
m.SetMetadata(v)
|
|
return nil
|
|
case frpcclient.FieldCreatedAt:
|
|
v, ok := value.(time.Time)
|
|
if !ok {
|
|
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
|
}
|
|
m.SetCreatedAt(v)
|
|
return nil
|
|
case frpcclient.FieldUpdatedAt:
|
|
v, ok := value.(time.Time)
|
|
if !ok {
|
|
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
|
}
|
|
m.SetUpdatedAt(v)
|
|
return nil
|
|
case frpcclient.FieldLastSeen:
|
|
v, ok := value.(time.Time)
|
|
if !ok {
|
|
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
|
}
|
|
m.SetLastSeen(v)
|
|
return nil
|
|
}
|
|
return fmt.Errorf("unknown FrpcClient field %s", name)
|
|
}
|
|
|
|
// AddedFields returns all numeric fields that were incremented/decremented during
|
|
// this mutation.
|
|
func (m *FrpcClientMutation) AddedFields() []string {
|
|
var fields []string
|
|
if m.addport != nil {
|
|
fields = append(fields, frpcclient.FieldPort)
|
|
}
|
|
return fields
|
|
}
|
|
|
|
// AddedField returns the numeric value that was incremented/decremented on a field
|
|
// with the given name. The second boolean return value indicates that this field
|
|
// was not set, or was not defined in the schema.
|
|
func (m *FrpcClientMutation) AddedField(name string) (ent.Value, bool) {
|
|
switch name {
|
|
case frpcclient.FieldPort:
|
|
return m.AddedPort()
|
|
}
|
|
return nil, false
|
|
}
|
|
|
|
// AddField adds the value to the field with the given name. It returns an error if
|
|
// the field is not defined in the schema, or if the type mismatched the field
|
|
// type.
|
|
func (m *FrpcClientMutation) AddField(name string, value ent.Value) error {
|
|
switch name {
|
|
case frpcclient.FieldPort:
|
|
v, ok := value.(int)
|
|
if !ok {
|
|
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
|
}
|
|
m.AddPort(v)
|
|
return nil
|
|
}
|
|
return fmt.Errorf("unknown FrpcClient numeric field %s", name)
|
|
}
|
|
|
|
// ClearedFields returns all nullable fields that were cleared during this
|
|
// mutation.
|
|
func (m *FrpcClientMutation) ClearedFields() []string {
|
|
var fields []string
|
|
if m.FieldCleared(frpcclient.FieldLastSeen) {
|
|
fields = append(fields, frpcclient.FieldLastSeen)
|
|
}
|
|
return fields
|
|
}
|
|
|
|
// FieldCleared returns a boolean indicating if a field with the given name was
|
|
// cleared in this mutation.
|
|
func (m *FrpcClientMutation) FieldCleared(name string) bool {
|
|
_, ok := m.clearedFields[name]
|
|
return ok
|
|
}
|
|
|
|
// ClearField clears the value of the field with the given name. It returns an
|
|
// error if the field is not defined in the schema.
|
|
func (m *FrpcClientMutation) ClearField(name string) error {
|
|
switch name {
|
|
case frpcclient.FieldLastSeen:
|
|
m.ClearLastSeen()
|
|
return nil
|
|
}
|
|
return fmt.Errorf("unknown FrpcClient nullable field %s", name)
|
|
}
|
|
|
|
// ResetField resets all changes in the mutation for the field with the given name.
|
|
// It returns an error if the field is not defined in the schema.
|
|
func (m *FrpcClientMutation) ResetField(name string) error {
|
|
switch name {
|
|
case frpcclient.FieldName:
|
|
m.ResetName()
|
|
return nil
|
|
case frpcclient.FieldKey:
|
|
m.ResetKey()
|
|
return nil
|
|
case frpcclient.FieldAddr:
|
|
m.ResetAddr()
|
|
return nil
|
|
case frpcclient.FieldPort:
|
|
m.ResetPort()
|
|
return nil
|
|
case frpcclient.FieldStatus:
|
|
m.ResetStatus()
|
|
return nil
|
|
case frpcclient.FieldMetadata:
|
|
m.ResetMetadata()
|
|
return nil
|
|
case frpcclient.FieldCreatedAt:
|
|
m.ResetCreatedAt()
|
|
return nil
|
|
case frpcclient.FieldUpdatedAt:
|
|
m.ResetUpdatedAt()
|
|
return nil
|
|
case frpcclient.FieldLastSeen:
|
|
m.ResetLastSeen()
|
|
return nil
|
|
}
|
|
return fmt.Errorf("unknown FrpcClient field %s", name)
|
|
}
|
|
|
|
// AddedEdges returns all edge names that were set/added in this mutation.
|
|
func (m *FrpcClientMutation) AddedEdges() []string {
|
|
edges := make([]string, 0, 0)
|
|
return edges
|
|
}
|
|
|
|
// AddedIDs returns all IDs (to other nodes) that were added for the given edge
|
|
// name in this mutation.
|
|
func (m *FrpcClientMutation) AddedIDs(name string) []ent.Value {
|
|
return nil
|
|
}
|
|
|
|
// RemovedEdges returns all edge names that were removed in this mutation.
|
|
func (m *FrpcClientMutation) RemovedEdges() []string {
|
|
edges := make([]string, 0, 0)
|
|
return edges
|
|
}
|
|
|
|
// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
|
|
// the given name in this mutation.
|
|
func (m *FrpcClientMutation) RemovedIDs(name string) []ent.Value {
|
|
return nil
|
|
}
|
|
|
|
// ClearedEdges returns all edge names that were cleared in this mutation.
|
|
func (m *FrpcClientMutation) ClearedEdges() []string {
|
|
edges := make([]string, 0, 0)
|
|
return edges
|
|
}
|
|
|
|
// EdgeCleared returns a boolean which indicates if the edge with the given name
|
|
// was cleared in this mutation.
|
|
func (m *FrpcClientMutation) EdgeCleared(name string) bool {
|
|
return false
|
|
}
|
|
|
|
// ClearEdge clears the value of the edge with the given name. It returns an error
|
|
// if that edge is not defined in the schema.
|
|
func (m *FrpcClientMutation) ClearEdge(name string) error {
|
|
return fmt.Errorf("unknown FrpcClient unique edge %s", name)
|
|
}
|
|
|
|
// ResetEdge resets all changes to the edge with the given name in this mutation.
|
|
// It returns an error if the edge is not defined in the schema.
|
|
func (m *FrpcClientMutation) ResetEdge(name string) error {
|
|
return fmt.Errorf("unknown FrpcClient edge %s", name)
|
|
}
|
|
|
|
// ProxyMutation represents an operation that mutates the Proxy nodes in the graph.
|
|
type ProxyMutation struct {
|
|
config
|
|
op Op
|
|
typ string
|
|
id *int
|
|
name *string
|
|
proxy_type *string
|
|
local_ip *string
|
|
local_port *int
|
|
addlocal_port *int
|
|
remote_port *int
|
|
addremote_port *int
|
|
status *string
|
|
custom_domains *string
|
|
metadata *string
|
|
client_id *int
|
|
addclient_id *int
|
|
created_at *time.Time
|
|
updated_at *time.Time
|
|
clearedFields map[string]struct{}
|
|
done bool
|
|
oldValue func(context.Context) (*Proxy, error)
|
|
predicates []predicate.Proxy
|
|
}
|
|
|
|
var _ ent.Mutation = (*ProxyMutation)(nil)
|
|
|
|
// proxyOption allows management of the mutation configuration using functional options.
|
|
type proxyOption func(*ProxyMutation)
|
|
|
|
// newProxyMutation creates new mutation for the Proxy entity.
|
|
func newProxyMutation(c config, op Op, opts ...proxyOption) *ProxyMutation {
|
|
m := &ProxyMutation{
|
|
config: c,
|
|
op: op,
|
|
typ: TypeProxy,
|
|
clearedFields: make(map[string]struct{}),
|
|
}
|
|
for _, opt := range opts {
|
|
opt(m)
|
|
}
|
|
return m
|
|
}
|
|
|
|
// withProxyID sets the ID field of the mutation.
|
|
func withProxyID(id int) proxyOption {
|
|
return func(m *ProxyMutation) {
|
|
var (
|
|
err error
|
|
once sync.Once
|
|
value *Proxy
|
|
)
|
|
m.oldValue = func(ctx context.Context) (*Proxy, error) {
|
|
once.Do(func() {
|
|
if m.done {
|
|
err = errors.New("querying old values post mutation is not allowed")
|
|
} else {
|
|
value, err = m.Client().Proxy.Get(ctx, id)
|
|
}
|
|
})
|
|
return value, err
|
|
}
|
|
m.id = &id
|
|
}
|
|
}
|
|
|
|
// withProxy sets the old Proxy of the mutation.
|
|
func withProxy(node *Proxy) proxyOption {
|
|
return func(m *ProxyMutation) {
|
|
m.oldValue = func(context.Context) (*Proxy, error) {
|
|
return node, nil
|
|
}
|
|
m.id = &node.ID
|
|
}
|
|
}
|
|
|
|
// Client returns a new `ent.Client` from the mutation. If the mutation was
|
|
// executed in a transaction (ent.Tx), a transactional client is returned.
|
|
func (m ProxyMutation) Client() *Client {
|
|
client := &Client{config: m.config}
|
|
client.init()
|
|
return client
|
|
}
|
|
|
|
// Tx returns an `ent.Tx` for mutations that were executed in transactions;
|
|
// it returns an error otherwise.
|
|
func (m ProxyMutation) Tx() (*Tx, error) {
|
|
if _, ok := m.driver.(*txDriver); !ok {
|
|
return nil, errors.New("ent: mutation is not running in a transaction")
|
|
}
|
|
tx := &Tx{config: m.config}
|
|
tx.init()
|
|
return tx, nil
|
|
}
|
|
|
|
// ID returns the ID value in the mutation. Note that the ID is only available
|
|
// if it was provided to the builder or after it was returned from the database.
|
|
func (m *ProxyMutation) ID() (id int, exists bool) {
|
|
if m.id == nil {
|
|
return
|
|
}
|
|
return *m.id, true
|
|
}
|
|
|
|
// IDs queries the database and returns the entity ids that match the mutation's predicate.
|
|
// That means, if the mutation is applied within a transaction with an isolation level such
|
|
// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated
|
|
// or updated by the mutation.
|
|
func (m *ProxyMutation) IDs(ctx context.Context) ([]int, error) {
|
|
switch {
|
|
case m.op.Is(OpUpdateOne | OpDeleteOne):
|
|
id, exists := m.ID()
|
|
if exists {
|
|
return []int{id}, nil
|
|
}
|
|
fallthrough
|
|
case m.op.Is(OpUpdate | OpDelete):
|
|
return m.Client().Proxy.Query().Where(m.predicates...).IDs(ctx)
|
|
default:
|
|
return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
|
|
}
|
|
}
|
|
|
|
// SetName sets the "name" field.
|
|
func (m *ProxyMutation) SetName(s string) {
|
|
m.name = &s
|
|
}
|
|
|
|
// Name returns the value of the "name" field in the mutation.
|
|
func (m *ProxyMutation) Name() (r string, exists bool) {
|
|
v := m.name
|
|
if v == nil {
|
|
return
|
|
}
|
|
return *v, true
|
|
}
|
|
|
|
// OldName returns the old "name" field's value of the Proxy entity.
|
|
// If the Proxy object wasn't provided to the builder, the object is fetched from the database.
|
|
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
|
func (m *ProxyMutation) OldName(ctx context.Context) (v string, err error) {
|
|
if !m.op.Is(OpUpdateOne) {
|
|
return v, errors.New("OldName is only allowed on UpdateOne operations")
|
|
}
|
|
if m.id == nil || m.oldValue == nil {
|
|
return v, errors.New("OldName requires an ID field in the mutation")
|
|
}
|
|
oldValue, err := m.oldValue(ctx)
|
|
if err != nil {
|
|
return v, fmt.Errorf("querying old value for OldName: %w", err)
|
|
}
|
|
return oldValue.Name, nil
|
|
}
|
|
|
|
// ResetName resets all changes to the "name" field.
|
|
func (m *ProxyMutation) ResetName() {
|
|
m.name = nil
|
|
}
|
|
|
|
// SetProxyType sets the "proxy_type" field.
|
|
func (m *ProxyMutation) SetProxyType(s string) {
|
|
m.proxy_type = &s
|
|
}
|
|
|
|
// ProxyType returns the value of the "proxy_type" field in the mutation.
|
|
func (m *ProxyMutation) ProxyType() (r string, exists bool) {
|
|
v := m.proxy_type
|
|
if v == nil {
|
|
return
|
|
}
|
|
return *v, true
|
|
}
|
|
|
|
// OldProxyType returns the old "proxy_type" field's value of the Proxy entity.
|
|
// If the Proxy object wasn't provided to the builder, the object is fetched from the database.
|
|
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
|
func (m *ProxyMutation) OldProxyType(ctx context.Context) (v string, err error) {
|
|
if !m.op.Is(OpUpdateOne) {
|
|
return v, errors.New("OldProxyType is only allowed on UpdateOne operations")
|
|
}
|
|
if m.id == nil || m.oldValue == nil {
|
|
return v, errors.New("OldProxyType requires an ID field in the mutation")
|
|
}
|
|
oldValue, err := m.oldValue(ctx)
|
|
if err != nil {
|
|
return v, fmt.Errorf("querying old value for OldProxyType: %w", err)
|
|
}
|
|
return oldValue.ProxyType, nil
|
|
}
|
|
|
|
// ResetProxyType resets all changes to the "proxy_type" field.
|
|
func (m *ProxyMutation) ResetProxyType() {
|
|
m.proxy_type = nil
|
|
}
|
|
|
|
// SetLocalIP sets the "local_ip" field.
|
|
func (m *ProxyMutation) SetLocalIP(s string) {
|
|
m.local_ip = &s
|
|
}
|
|
|
|
// LocalIP returns the value of the "local_ip" field in the mutation.
|
|
func (m *ProxyMutation) LocalIP() (r string, exists bool) {
|
|
v := m.local_ip
|
|
if v == nil {
|
|
return
|
|
}
|
|
return *v, true
|
|
}
|
|
|
|
// OldLocalIP returns the old "local_ip" field's value of the Proxy entity.
|
|
// If the Proxy object wasn't provided to the builder, the object is fetched from the database.
|
|
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
|
func (m *ProxyMutation) OldLocalIP(ctx context.Context) (v string, err error) {
|
|
if !m.op.Is(OpUpdateOne) {
|
|
return v, errors.New("OldLocalIP is only allowed on UpdateOne operations")
|
|
}
|
|
if m.id == nil || m.oldValue == nil {
|
|
return v, errors.New("OldLocalIP requires an ID field in the mutation")
|
|
}
|
|
oldValue, err := m.oldValue(ctx)
|
|
if err != nil {
|
|
return v, fmt.Errorf("querying old value for OldLocalIP: %w", err)
|
|
}
|
|
return oldValue.LocalIP, nil
|
|
}
|
|
|
|
// ResetLocalIP resets all changes to the "local_ip" field.
|
|
func (m *ProxyMutation) ResetLocalIP() {
|
|
m.local_ip = nil
|
|
}
|
|
|
|
// SetLocalPort sets the "local_port" field.
|
|
func (m *ProxyMutation) SetLocalPort(i int) {
|
|
m.local_port = &i
|
|
m.addlocal_port = nil
|
|
}
|
|
|
|
// LocalPort returns the value of the "local_port" field in the mutation.
|
|
func (m *ProxyMutation) LocalPort() (r int, exists bool) {
|
|
v := m.local_port
|
|
if v == nil {
|
|
return
|
|
}
|
|
return *v, true
|
|
}
|
|
|
|
// OldLocalPort returns the old "local_port" field's value of the Proxy entity.
|
|
// If the Proxy object wasn't provided to the builder, the object is fetched from the database.
|
|
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
|
func (m *ProxyMutation) OldLocalPort(ctx context.Context) (v int, err error) {
|
|
if !m.op.Is(OpUpdateOne) {
|
|
return v, errors.New("OldLocalPort is only allowed on UpdateOne operations")
|
|
}
|
|
if m.id == nil || m.oldValue == nil {
|
|
return v, errors.New("OldLocalPort requires an ID field in the mutation")
|
|
}
|
|
oldValue, err := m.oldValue(ctx)
|
|
if err != nil {
|
|
return v, fmt.Errorf("querying old value for OldLocalPort: %w", err)
|
|
}
|
|
return oldValue.LocalPort, nil
|
|
}
|
|
|
|
// AddLocalPort adds i to the "local_port" field.
|
|
func (m *ProxyMutation) AddLocalPort(i int) {
|
|
if m.addlocal_port != nil {
|
|
*m.addlocal_port += i
|
|
} else {
|
|
m.addlocal_port = &i
|
|
}
|
|
}
|
|
|
|
// AddedLocalPort returns the value that was added to the "local_port" field in this mutation.
|
|
func (m *ProxyMutation) AddedLocalPort() (r int, exists bool) {
|
|
v := m.addlocal_port
|
|
if v == nil {
|
|
return
|
|
}
|
|
return *v, true
|
|
}
|
|
|
|
// ResetLocalPort resets all changes to the "local_port" field.
|
|
func (m *ProxyMutation) ResetLocalPort() {
|
|
m.local_port = nil
|
|
m.addlocal_port = nil
|
|
}
|
|
|
|
// SetRemotePort sets the "remote_port" field.
|
|
func (m *ProxyMutation) SetRemotePort(i int) {
|
|
m.remote_port = &i
|
|
m.addremote_port = nil
|
|
}
|
|
|
|
// RemotePort returns the value of the "remote_port" field in the mutation.
|
|
func (m *ProxyMutation) RemotePort() (r int, exists bool) {
|
|
v := m.remote_port
|
|
if v == nil {
|
|
return
|
|
}
|
|
return *v, true
|
|
}
|
|
|
|
// OldRemotePort returns the old "remote_port" field's value of the Proxy entity.
|
|
// If the Proxy object wasn't provided to the builder, the object is fetched from the database.
|
|
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
|
func (m *ProxyMutation) OldRemotePort(ctx context.Context) (v int, err error) {
|
|
if !m.op.Is(OpUpdateOne) {
|
|
return v, errors.New("OldRemotePort is only allowed on UpdateOne operations")
|
|
}
|
|
if m.id == nil || m.oldValue == nil {
|
|
return v, errors.New("OldRemotePort requires an ID field in the mutation")
|
|
}
|
|
oldValue, err := m.oldValue(ctx)
|
|
if err != nil {
|
|
return v, fmt.Errorf("querying old value for OldRemotePort: %w", err)
|
|
}
|
|
return oldValue.RemotePort, nil
|
|
}
|
|
|
|
// AddRemotePort adds i to the "remote_port" field.
|
|
func (m *ProxyMutation) AddRemotePort(i int) {
|
|
if m.addremote_port != nil {
|
|
*m.addremote_port += i
|
|
} else {
|
|
m.addremote_port = &i
|
|
}
|
|
}
|
|
|
|
// AddedRemotePort returns the value that was added to the "remote_port" field in this mutation.
|
|
func (m *ProxyMutation) AddedRemotePort() (r int, exists bool) {
|
|
v := m.addremote_port
|
|
if v == nil {
|
|
return
|
|
}
|
|
return *v, true
|
|
}
|
|
|
|
// ResetRemotePort resets all changes to the "remote_port" field.
|
|
func (m *ProxyMutation) ResetRemotePort() {
|
|
m.remote_port = nil
|
|
m.addremote_port = nil
|
|
}
|
|
|
|
// SetStatus sets the "status" field.
|
|
func (m *ProxyMutation) SetStatus(s string) {
|
|
m.status = &s
|
|
}
|
|
|
|
// Status returns the value of the "status" field in the mutation.
|
|
func (m *ProxyMutation) Status() (r string, exists bool) {
|
|
v := m.status
|
|
if v == nil {
|
|
return
|
|
}
|
|
return *v, true
|
|
}
|
|
|
|
// OldStatus returns the old "status" field's value of the Proxy entity.
|
|
// If the Proxy object wasn't provided to the builder, the object is fetched from the database.
|
|
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
|
func (m *ProxyMutation) OldStatus(ctx context.Context) (v string, err error) {
|
|
if !m.op.Is(OpUpdateOne) {
|
|
return v, errors.New("OldStatus is only allowed on UpdateOne operations")
|
|
}
|
|
if m.id == nil || m.oldValue == nil {
|
|
return v, errors.New("OldStatus requires an ID field in the mutation")
|
|
}
|
|
oldValue, err := m.oldValue(ctx)
|
|
if err != nil {
|
|
return v, fmt.Errorf("querying old value for OldStatus: %w", err)
|
|
}
|
|
return oldValue.Status, nil
|
|
}
|
|
|
|
// ResetStatus resets all changes to the "status" field.
|
|
func (m *ProxyMutation) ResetStatus() {
|
|
m.status = nil
|
|
}
|
|
|
|
// SetCustomDomains sets the "custom_domains" field.
|
|
func (m *ProxyMutation) SetCustomDomains(s string) {
|
|
m.custom_domains = &s
|
|
}
|
|
|
|
// CustomDomains returns the value of the "custom_domains" field in the mutation.
|
|
func (m *ProxyMutation) CustomDomains() (r string, exists bool) {
|
|
v := m.custom_domains
|
|
if v == nil {
|
|
return
|
|
}
|
|
return *v, true
|
|
}
|
|
|
|
// OldCustomDomains returns the old "custom_domains" field's value of the Proxy entity.
|
|
// If the Proxy object wasn't provided to the builder, the object is fetched from the database.
|
|
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
|
func (m *ProxyMutation) OldCustomDomains(ctx context.Context) (v string, err error) {
|
|
if !m.op.Is(OpUpdateOne) {
|
|
return v, errors.New("OldCustomDomains is only allowed on UpdateOne operations")
|
|
}
|
|
if m.id == nil || m.oldValue == nil {
|
|
return v, errors.New("OldCustomDomains requires an ID field in the mutation")
|
|
}
|
|
oldValue, err := m.oldValue(ctx)
|
|
if err != nil {
|
|
return v, fmt.Errorf("querying old value for OldCustomDomains: %w", err)
|
|
}
|
|
return oldValue.CustomDomains, nil
|
|
}
|
|
|
|
// ResetCustomDomains resets all changes to the "custom_domains" field.
|
|
func (m *ProxyMutation) ResetCustomDomains() {
|
|
m.custom_domains = nil
|
|
}
|
|
|
|
// SetMetadata sets the "metadata" field.
|
|
func (m *ProxyMutation) SetMetadata(s string) {
|
|
m.metadata = &s
|
|
}
|
|
|
|
// Metadata returns the value of the "metadata" field in the mutation.
|
|
func (m *ProxyMutation) Metadata() (r string, exists bool) {
|
|
v := m.metadata
|
|
if v == nil {
|
|
return
|
|
}
|
|
return *v, true
|
|
}
|
|
|
|
// OldMetadata returns the old "metadata" field's value of the Proxy entity.
|
|
// If the Proxy object wasn't provided to the builder, the object is fetched from the database.
|
|
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
|
func (m *ProxyMutation) OldMetadata(ctx context.Context) (v string, err error) {
|
|
if !m.op.Is(OpUpdateOne) {
|
|
return v, errors.New("OldMetadata is only allowed on UpdateOne operations")
|
|
}
|
|
if m.id == nil || m.oldValue == nil {
|
|
return v, errors.New("OldMetadata requires an ID field in the mutation")
|
|
}
|
|
oldValue, err := m.oldValue(ctx)
|
|
if err != nil {
|
|
return v, fmt.Errorf("querying old value for OldMetadata: %w", err)
|
|
}
|
|
return oldValue.Metadata, nil
|
|
}
|
|
|
|
// ResetMetadata resets all changes to the "metadata" field.
|
|
func (m *ProxyMutation) ResetMetadata() {
|
|
m.metadata = nil
|
|
}
|
|
|
|
// SetClientID sets the "client_id" field.
|
|
func (m *ProxyMutation) SetClientID(i int) {
|
|
m.client_id = &i
|
|
m.addclient_id = nil
|
|
}
|
|
|
|
// ClientID returns the value of the "client_id" field in the mutation.
|
|
func (m *ProxyMutation) ClientID() (r int, exists bool) {
|
|
v := m.client_id
|
|
if v == nil {
|
|
return
|
|
}
|
|
return *v, true
|
|
}
|
|
|
|
// OldClientID returns the old "client_id" field's value of the Proxy entity.
|
|
// If the Proxy object wasn't provided to the builder, the object is fetched from the database.
|
|
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
|
func (m *ProxyMutation) OldClientID(ctx context.Context) (v int, err error) {
|
|
if !m.op.Is(OpUpdateOne) {
|
|
return v, errors.New("OldClientID is only allowed on UpdateOne operations")
|
|
}
|
|
if m.id == nil || m.oldValue == nil {
|
|
return v, errors.New("OldClientID requires an ID field in the mutation")
|
|
}
|
|
oldValue, err := m.oldValue(ctx)
|
|
if err != nil {
|
|
return v, fmt.Errorf("querying old value for OldClientID: %w", err)
|
|
}
|
|
return oldValue.ClientID, nil
|
|
}
|
|
|
|
// AddClientID adds i to the "client_id" field.
|
|
func (m *ProxyMutation) AddClientID(i int) {
|
|
if m.addclient_id != nil {
|
|
*m.addclient_id += i
|
|
} else {
|
|
m.addclient_id = &i
|
|
}
|
|
}
|
|
|
|
// AddedClientID returns the value that was added to the "client_id" field in this mutation.
|
|
func (m *ProxyMutation) AddedClientID() (r int, exists bool) {
|
|
v := m.addclient_id
|
|
if v == nil {
|
|
return
|
|
}
|
|
return *v, true
|
|
}
|
|
|
|
// ResetClientID resets all changes to the "client_id" field.
|
|
func (m *ProxyMutation) ResetClientID() {
|
|
m.client_id = nil
|
|
m.addclient_id = nil
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (m *ProxyMutation) SetCreatedAt(t time.Time) {
|
|
m.created_at = &t
|
|
}
|
|
|
|
// CreatedAt returns the value of the "created_at" field in the mutation.
|
|
func (m *ProxyMutation) CreatedAt() (r time.Time, exists bool) {
|
|
v := m.created_at
|
|
if v == nil {
|
|
return
|
|
}
|
|
return *v, true
|
|
}
|
|
|
|
// OldCreatedAt returns the old "created_at" field's value of the Proxy entity.
|
|
// If the Proxy object wasn't provided to the builder, the object is fetched from the database.
|
|
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
|
func (m *ProxyMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) {
|
|
if !m.op.Is(OpUpdateOne) {
|
|
return v, errors.New("OldCreatedAt is only allowed on UpdateOne operations")
|
|
}
|
|
if m.id == nil || m.oldValue == nil {
|
|
return v, errors.New("OldCreatedAt requires an ID field in the mutation")
|
|
}
|
|
oldValue, err := m.oldValue(ctx)
|
|
if err != nil {
|
|
return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err)
|
|
}
|
|
return oldValue.CreatedAt, nil
|
|
}
|
|
|
|
// ResetCreatedAt resets all changes to the "created_at" field.
|
|
func (m *ProxyMutation) ResetCreatedAt() {
|
|
m.created_at = nil
|
|
}
|
|
|
|
// SetUpdatedAt sets the "updated_at" field.
|
|
func (m *ProxyMutation) SetUpdatedAt(t time.Time) {
|
|
m.updated_at = &t
|
|
}
|
|
|
|
// UpdatedAt returns the value of the "updated_at" field in the mutation.
|
|
func (m *ProxyMutation) UpdatedAt() (r time.Time, exists bool) {
|
|
v := m.updated_at
|
|
if v == nil {
|
|
return
|
|
}
|
|
return *v, true
|
|
}
|
|
|
|
// OldUpdatedAt returns the old "updated_at" field's value of the Proxy entity.
|
|
// If the Proxy object wasn't provided to the builder, the object is fetched from the database.
|
|
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
|
func (m *ProxyMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) {
|
|
if !m.op.Is(OpUpdateOne) {
|
|
return v, errors.New("OldUpdatedAt is only allowed on UpdateOne operations")
|
|
}
|
|
if m.id == nil || m.oldValue == nil {
|
|
return v, errors.New("OldUpdatedAt requires an ID field in the mutation")
|
|
}
|
|
oldValue, err := m.oldValue(ctx)
|
|
if err != nil {
|
|
return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err)
|
|
}
|
|
return oldValue.UpdatedAt, nil
|
|
}
|
|
|
|
// ResetUpdatedAt resets all changes to the "updated_at" field.
|
|
func (m *ProxyMutation) ResetUpdatedAt() {
|
|
m.updated_at = nil
|
|
}
|
|
|
|
// Where appends a list predicates to the ProxyMutation builder.
|
|
func (m *ProxyMutation) Where(ps ...predicate.Proxy) {
|
|
m.predicates = append(m.predicates, ps...)
|
|
}
|
|
|
|
// WhereP appends storage-level predicates to the ProxyMutation builder. Using this method,
|
|
// users can use type-assertion to append predicates that do not depend on any generated package.
|
|
func (m *ProxyMutation) WhereP(ps ...func(*sql.Selector)) {
|
|
p := make([]predicate.Proxy, len(ps))
|
|
for i := range ps {
|
|
p[i] = ps[i]
|
|
}
|
|
m.Where(p...)
|
|
}
|
|
|
|
// Op returns the operation name.
|
|
func (m *ProxyMutation) Op() Op {
|
|
return m.op
|
|
}
|
|
|
|
// SetOp allows setting the mutation operation.
|
|
func (m *ProxyMutation) SetOp(op Op) {
|
|
m.op = op
|
|
}
|
|
|
|
// Type returns the node type of this mutation (Proxy).
|
|
func (m *ProxyMutation) Type() string {
|
|
return m.typ
|
|
}
|
|
|
|
// Fields returns all fields that were changed during this mutation. Note that in
|
|
// order to get all numeric fields that were incremented/decremented, call
|
|
// AddedFields().
|
|
func (m *ProxyMutation) Fields() []string {
|
|
fields := make([]string, 0, 11)
|
|
if m.name != nil {
|
|
fields = append(fields, proxy.FieldName)
|
|
}
|
|
if m.proxy_type != nil {
|
|
fields = append(fields, proxy.FieldProxyType)
|
|
}
|
|
if m.local_ip != nil {
|
|
fields = append(fields, proxy.FieldLocalIP)
|
|
}
|
|
if m.local_port != nil {
|
|
fields = append(fields, proxy.FieldLocalPort)
|
|
}
|
|
if m.remote_port != nil {
|
|
fields = append(fields, proxy.FieldRemotePort)
|
|
}
|
|
if m.status != nil {
|
|
fields = append(fields, proxy.FieldStatus)
|
|
}
|
|
if m.custom_domains != nil {
|
|
fields = append(fields, proxy.FieldCustomDomains)
|
|
}
|
|
if m.metadata != nil {
|
|
fields = append(fields, proxy.FieldMetadata)
|
|
}
|
|
if m.client_id != nil {
|
|
fields = append(fields, proxy.FieldClientID)
|
|
}
|
|
if m.created_at != nil {
|
|
fields = append(fields, proxy.FieldCreatedAt)
|
|
}
|
|
if m.updated_at != nil {
|
|
fields = append(fields, proxy.FieldUpdatedAt)
|
|
}
|
|
return fields
|
|
}
|
|
|
|
// Field returns the value of a field with the given name. The second boolean
|
|
// return value indicates that this field was not set, or was not defined in the
|
|
// schema.
|
|
func (m *ProxyMutation) Field(name string) (ent.Value, bool) {
|
|
switch name {
|
|
case proxy.FieldName:
|
|
return m.Name()
|
|
case proxy.FieldProxyType:
|
|
return m.ProxyType()
|
|
case proxy.FieldLocalIP:
|
|
return m.LocalIP()
|
|
case proxy.FieldLocalPort:
|
|
return m.LocalPort()
|
|
case proxy.FieldRemotePort:
|
|
return m.RemotePort()
|
|
case proxy.FieldStatus:
|
|
return m.Status()
|
|
case proxy.FieldCustomDomains:
|
|
return m.CustomDomains()
|
|
case proxy.FieldMetadata:
|
|
return m.Metadata()
|
|
case proxy.FieldClientID:
|
|
return m.ClientID()
|
|
case proxy.FieldCreatedAt:
|
|
return m.CreatedAt()
|
|
case proxy.FieldUpdatedAt:
|
|
return m.UpdatedAt()
|
|
}
|
|
return nil, false
|
|
}
|
|
|
|
// OldField returns the old value of the field from the database. An error is
|
|
// returned if the mutation operation is not UpdateOne, or the query to the
|
|
// database failed.
|
|
func (m *ProxyMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
|
|
switch name {
|
|
case proxy.FieldName:
|
|
return m.OldName(ctx)
|
|
case proxy.FieldProxyType:
|
|
return m.OldProxyType(ctx)
|
|
case proxy.FieldLocalIP:
|
|
return m.OldLocalIP(ctx)
|
|
case proxy.FieldLocalPort:
|
|
return m.OldLocalPort(ctx)
|
|
case proxy.FieldRemotePort:
|
|
return m.OldRemotePort(ctx)
|
|
case proxy.FieldStatus:
|
|
return m.OldStatus(ctx)
|
|
case proxy.FieldCustomDomains:
|
|
return m.OldCustomDomains(ctx)
|
|
case proxy.FieldMetadata:
|
|
return m.OldMetadata(ctx)
|
|
case proxy.FieldClientID:
|
|
return m.OldClientID(ctx)
|
|
case proxy.FieldCreatedAt:
|
|
return m.OldCreatedAt(ctx)
|
|
case proxy.FieldUpdatedAt:
|
|
return m.OldUpdatedAt(ctx)
|
|
}
|
|
return nil, fmt.Errorf("unknown Proxy field %s", name)
|
|
}
|
|
|
|
// SetField sets the value of a field with the given name. It returns an error if
|
|
// the field is not defined in the schema, or if the type mismatched the field
|
|
// type.
|
|
func (m *ProxyMutation) SetField(name string, value ent.Value) error {
|
|
switch name {
|
|
case proxy.FieldName:
|
|
v, ok := value.(string)
|
|
if !ok {
|
|
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
|
}
|
|
m.SetName(v)
|
|
return nil
|
|
case proxy.FieldProxyType:
|
|
v, ok := value.(string)
|
|
if !ok {
|
|
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
|
}
|
|
m.SetProxyType(v)
|
|
return nil
|
|
case proxy.FieldLocalIP:
|
|
v, ok := value.(string)
|
|
if !ok {
|
|
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
|
}
|
|
m.SetLocalIP(v)
|
|
return nil
|
|
case proxy.FieldLocalPort:
|
|
v, ok := value.(int)
|
|
if !ok {
|
|
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
|
}
|
|
m.SetLocalPort(v)
|
|
return nil
|
|
case proxy.FieldRemotePort:
|
|
v, ok := value.(int)
|
|
if !ok {
|
|
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
|
}
|
|
m.SetRemotePort(v)
|
|
return nil
|
|
case proxy.FieldStatus:
|
|
v, ok := value.(string)
|
|
if !ok {
|
|
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
|
}
|
|
m.SetStatus(v)
|
|
return nil
|
|
case proxy.FieldCustomDomains:
|
|
v, ok := value.(string)
|
|
if !ok {
|
|
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
|
}
|
|
m.SetCustomDomains(v)
|
|
return nil
|
|
case proxy.FieldMetadata:
|
|
v, ok := value.(string)
|
|
if !ok {
|
|
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
|
}
|
|
m.SetMetadata(v)
|
|
return nil
|
|
case proxy.FieldClientID:
|
|
v, ok := value.(int)
|
|
if !ok {
|
|
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
|
}
|
|
m.SetClientID(v)
|
|
return nil
|
|
case proxy.FieldCreatedAt:
|
|
v, ok := value.(time.Time)
|
|
if !ok {
|
|
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
|
}
|
|
m.SetCreatedAt(v)
|
|
return nil
|
|
case proxy.FieldUpdatedAt:
|
|
v, ok := value.(time.Time)
|
|
if !ok {
|
|
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
|
}
|
|
m.SetUpdatedAt(v)
|
|
return nil
|
|
}
|
|
return fmt.Errorf("unknown Proxy field %s", name)
|
|
}
|
|
|
|
// AddedFields returns all numeric fields that were incremented/decremented during
|
|
// this mutation.
|
|
func (m *ProxyMutation) AddedFields() []string {
|
|
var fields []string
|
|
if m.addlocal_port != nil {
|
|
fields = append(fields, proxy.FieldLocalPort)
|
|
}
|
|
if m.addremote_port != nil {
|
|
fields = append(fields, proxy.FieldRemotePort)
|
|
}
|
|
if m.addclient_id != nil {
|
|
fields = append(fields, proxy.FieldClientID)
|
|
}
|
|
return fields
|
|
}
|
|
|
|
// AddedField returns the numeric value that was incremented/decremented on a field
|
|
// with the given name. The second boolean return value indicates that this field
|
|
// was not set, or was not defined in the schema.
|
|
func (m *ProxyMutation) AddedField(name string) (ent.Value, bool) {
|
|
switch name {
|
|
case proxy.FieldLocalPort:
|
|
return m.AddedLocalPort()
|
|
case proxy.FieldRemotePort:
|
|
return m.AddedRemotePort()
|
|
case proxy.FieldClientID:
|
|
return m.AddedClientID()
|
|
}
|
|
return nil, false
|
|
}
|
|
|
|
// AddField adds the value to the field with the given name. It returns an error if
|
|
// the field is not defined in the schema, or if the type mismatched the field
|
|
// type.
|
|
func (m *ProxyMutation) AddField(name string, value ent.Value) error {
|
|
switch name {
|
|
case proxy.FieldLocalPort:
|
|
v, ok := value.(int)
|
|
if !ok {
|
|
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
|
}
|
|
m.AddLocalPort(v)
|
|
return nil
|
|
case proxy.FieldRemotePort:
|
|
v, ok := value.(int)
|
|
if !ok {
|
|
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
|
}
|
|
m.AddRemotePort(v)
|
|
return nil
|
|
case proxy.FieldClientID:
|
|
v, ok := value.(int)
|
|
if !ok {
|
|
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
|
}
|
|
m.AddClientID(v)
|
|
return nil
|
|
}
|
|
return fmt.Errorf("unknown Proxy numeric field %s", name)
|
|
}
|
|
|
|
// ClearedFields returns all nullable fields that were cleared during this
|
|
// mutation.
|
|
func (m *ProxyMutation) ClearedFields() []string {
|
|
return nil
|
|
}
|
|
|
|
// FieldCleared returns a boolean indicating if a field with the given name was
|
|
// cleared in this mutation.
|
|
func (m *ProxyMutation) FieldCleared(name string) bool {
|
|
_, ok := m.clearedFields[name]
|
|
return ok
|
|
}
|
|
|
|
// ClearField clears the value of the field with the given name. It returns an
|
|
// error if the field is not defined in the schema.
|
|
func (m *ProxyMutation) ClearField(name string) error {
|
|
return fmt.Errorf("unknown Proxy nullable field %s", name)
|
|
}
|
|
|
|
// ResetField resets all changes in the mutation for the field with the given name.
|
|
// It returns an error if the field is not defined in the schema.
|
|
func (m *ProxyMutation) ResetField(name string) error {
|
|
switch name {
|
|
case proxy.FieldName:
|
|
m.ResetName()
|
|
return nil
|
|
case proxy.FieldProxyType:
|
|
m.ResetProxyType()
|
|
return nil
|
|
case proxy.FieldLocalIP:
|
|
m.ResetLocalIP()
|
|
return nil
|
|
case proxy.FieldLocalPort:
|
|
m.ResetLocalPort()
|
|
return nil
|
|
case proxy.FieldRemotePort:
|
|
m.ResetRemotePort()
|
|
return nil
|
|
case proxy.FieldStatus:
|
|
m.ResetStatus()
|
|
return nil
|
|
case proxy.FieldCustomDomains:
|
|
m.ResetCustomDomains()
|
|
return nil
|
|
case proxy.FieldMetadata:
|
|
m.ResetMetadata()
|
|
return nil
|
|
case proxy.FieldClientID:
|
|
m.ResetClientID()
|
|
return nil
|
|
case proxy.FieldCreatedAt:
|
|
m.ResetCreatedAt()
|
|
return nil
|
|
case proxy.FieldUpdatedAt:
|
|
m.ResetUpdatedAt()
|
|
return nil
|
|
}
|
|
return fmt.Errorf("unknown Proxy field %s", name)
|
|
}
|
|
|
|
// AddedEdges returns all edge names that were set/added in this mutation.
|
|
func (m *ProxyMutation) AddedEdges() []string {
|
|
edges := make([]string, 0, 0)
|
|
return edges
|
|
}
|
|
|
|
// AddedIDs returns all IDs (to other nodes) that were added for the given edge
|
|
// name in this mutation.
|
|
func (m *ProxyMutation) AddedIDs(name string) []ent.Value {
|
|
return nil
|
|
}
|
|
|
|
// RemovedEdges returns all edge names that were removed in this mutation.
|
|
func (m *ProxyMutation) RemovedEdges() []string {
|
|
edges := make([]string, 0, 0)
|
|
return edges
|
|
}
|
|
|
|
// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
|
|
// the given name in this mutation.
|
|
func (m *ProxyMutation) RemovedIDs(name string) []ent.Value {
|
|
return nil
|
|
}
|
|
|
|
// ClearedEdges returns all edge names that were cleared in this mutation.
|
|
func (m *ProxyMutation) ClearedEdges() []string {
|
|
edges := make([]string, 0, 0)
|
|
return edges
|
|
}
|
|
|
|
// EdgeCleared returns a boolean which indicates if the edge with the given name
|
|
// was cleared in this mutation.
|
|
func (m *ProxyMutation) EdgeCleared(name string) bool {
|
|
return false
|
|
}
|
|
|
|
// ClearEdge clears the value of the edge with the given name. It returns an error
|
|
// if that edge is not defined in the schema.
|
|
func (m *ProxyMutation) ClearEdge(name string) error {
|
|
return fmt.Errorf("unknown Proxy unique edge %s", name)
|
|
}
|
|
|
|
// ResetEdge resets all changes to the edge with the given name in this mutation.
|
|
// It returns an error if the edge is not defined in the schema.
|
|
func (m *ProxyMutation) ResetEdge(name string) error {
|
|
return fmt.Errorf("unknown Proxy edge %s", name)
|
|
}
|
|
|
|
// ServerConfigMutation represents an operation that mutates the ServerConfig nodes in the graph.
|
|
type ServerConfigMutation struct {
|
|
config
|
|
op Op
|
|
typ string
|
|
id *int
|
|
key *string
|
|
value *string
|
|
clearedFields map[string]struct{}
|
|
done bool
|
|
oldValue func(context.Context) (*ServerConfig, error)
|
|
predicates []predicate.ServerConfig
|
|
}
|
|
|
|
var _ ent.Mutation = (*ServerConfigMutation)(nil)
|
|
|
|
// serverconfigOption allows management of the mutation configuration using functional options.
|
|
type serverconfigOption func(*ServerConfigMutation)
|
|
|
|
// newServerConfigMutation creates new mutation for the ServerConfig entity.
|
|
func newServerConfigMutation(c config, op Op, opts ...serverconfigOption) *ServerConfigMutation {
|
|
m := &ServerConfigMutation{
|
|
config: c,
|
|
op: op,
|
|
typ: TypeServerConfig,
|
|
clearedFields: make(map[string]struct{}),
|
|
}
|
|
for _, opt := range opts {
|
|
opt(m)
|
|
}
|
|
return m
|
|
}
|
|
|
|
// withServerConfigID sets the ID field of the mutation.
|
|
func withServerConfigID(id int) serverconfigOption {
|
|
return func(m *ServerConfigMutation) {
|
|
var (
|
|
err error
|
|
once sync.Once
|
|
value *ServerConfig
|
|
)
|
|
m.oldValue = func(ctx context.Context) (*ServerConfig, error) {
|
|
once.Do(func() {
|
|
if m.done {
|
|
err = errors.New("querying old values post mutation is not allowed")
|
|
} else {
|
|
value, err = m.Client().ServerConfig.Get(ctx, id)
|
|
}
|
|
})
|
|
return value, err
|
|
}
|
|
m.id = &id
|
|
}
|
|
}
|
|
|
|
// withServerConfig sets the old ServerConfig of the mutation.
|
|
func withServerConfig(node *ServerConfig) serverconfigOption {
|
|
return func(m *ServerConfigMutation) {
|
|
m.oldValue = func(context.Context) (*ServerConfig, error) {
|
|
return node, nil
|
|
}
|
|
m.id = &node.ID
|
|
}
|
|
}
|
|
|
|
// Client returns a new `ent.Client` from the mutation. If the mutation was
|
|
// executed in a transaction (ent.Tx), a transactional client is returned.
|
|
func (m ServerConfigMutation) Client() *Client {
|
|
client := &Client{config: m.config}
|
|
client.init()
|
|
return client
|
|
}
|
|
|
|
// Tx returns an `ent.Tx` for mutations that were executed in transactions;
|
|
// it returns an error otherwise.
|
|
func (m ServerConfigMutation) Tx() (*Tx, error) {
|
|
if _, ok := m.driver.(*txDriver); !ok {
|
|
return nil, errors.New("ent: mutation is not running in a transaction")
|
|
}
|
|
tx := &Tx{config: m.config}
|
|
tx.init()
|
|
return tx, nil
|
|
}
|
|
|
|
// ID returns the ID value in the mutation. Note that the ID is only available
|
|
// if it was provided to the builder or after it was returned from the database.
|
|
func (m *ServerConfigMutation) ID() (id int, exists bool) {
|
|
if m.id == nil {
|
|
return
|
|
}
|
|
return *m.id, true
|
|
}
|
|
|
|
// IDs queries the database and returns the entity ids that match the mutation's predicate.
|
|
// That means, if the mutation is applied within a transaction with an isolation level such
|
|
// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated
|
|
// or updated by the mutation.
|
|
func (m *ServerConfigMutation) IDs(ctx context.Context) ([]int, error) {
|
|
switch {
|
|
case m.op.Is(OpUpdateOne | OpDeleteOne):
|
|
id, exists := m.ID()
|
|
if exists {
|
|
return []int{id}, nil
|
|
}
|
|
fallthrough
|
|
case m.op.Is(OpUpdate | OpDelete):
|
|
return m.Client().ServerConfig.Query().Where(m.predicates...).IDs(ctx)
|
|
default:
|
|
return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
|
|
}
|
|
}
|
|
|
|
// SetKey sets the "key" field.
|
|
func (m *ServerConfigMutation) SetKey(s string) {
|
|
m.key = &s
|
|
}
|
|
|
|
// Key returns the value of the "key" field in the mutation.
|
|
func (m *ServerConfigMutation) Key() (r string, exists bool) {
|
|
v := m.key
|
|
if v == nil {
|
|
return
|
|
}
|
|
return *v, true
|
|
}
|
|
|
|
// OldKey returns the old "key" field's value of the ServerConfig entity.
|
|
// If the ServerConfig object wasn't provided to the builder, the object is fetched from the database.
|
|
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
|
func (m *ServerConfigMutation) OldKey(ctx context.Context) (v string, err error) {
|
|
if !m.op.Is(OpUpdateOne) {
|
|
return v, errors.New("OldKey is only allowed on UpdateOne operations")
|
|
}
|
|
if m.id == nil || m.oldValue == nil {
|
|
return v, errors.New("OldKey requires an ID field in the mutation")
|
|
}
|
|
oldValue, err := m.oldValue(ctx)
|
|
if err != nil {
|
|
return v, fmt.Errorf("querying old value for OldKey: %w", err)
|
|
}
|
|
return oldValue.Key, nil
|
|
}
|
|
|
|
// ResetKey resets all changes to the "key" field.
|
|
func (m *ServerConfigMutation) ResetKey() {
|
|
m.key = nil
|
|
}
|
|
|
|
// SetValue sets the "value" field.
|
|
func (m *ServerConfigMutation) SetValue(s string) {
|
|
m.value = &s
|
|
}
|
|
|
|
// Value returns the value of the "value" field in the mutation.
|
|
func (m *ServerConfigMutation) Value() (r string, exists bool) {
|
|
v := m.value
|
|
if v == nil {
|
|
return
|
|
}
|
|
return *v, true
|
|
}
|
|
|
|
// OldValue returns the old "value" field's value of the ServerConfig entity.
|
|
// If the ServerConfig object wasn't provided to the builder, the object is fetched from the database.
|
|
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
|
func (m *ServerConfigMutation) OldValue(ctx context.Context) (v string, err error) {
|
|
if !m.op.Is(OpUpdateOne) {
|
|
return v, errors.New("OldValue is only allowed on UpdateOne operations")
|
|
}
|
|
if m.id == nil || m.oldValue == nil {
|
|
return v, errors.New("OldValue requires an ID field in the mutation")
|
|
}
|
|
oldValue, err := m.oldValue(ctx)
|
|
if err != nil {
|
|
return v, fmt.Errorf("querying old value for OldValue: %w", err)
|
|
}
|
|
return oldValue.Value, nil
|
|
}
|
|
|
|
// ResetValue resets all changes to the "value" field.
|
|
func (m *ServerConfigMutation) ResetValue() {
|
|
m.value = nil
|
|
}
|
|
|
|
// Where appends a list predicates to the ServerConfigMutation builder.
|
|
func (m *ServerConfigMutation) Where(ps ...predicate.ServerConfig) {
|
|
m.predicates = append(m.predicates, ps...)
|
|
}
|
|
|
|
// WhereP appends storage-level predicates to the ServerConfigMutation builder. Using this method,
|
|
// users can use type-assertion to append predicates that do not depend on any generated package.
|
|
func (m *ServerConfigMutation) WhereP(ps ...func(*sql.Selector)) {
|
|
p := make([]predicate.ServerConfig, len(ps))
|
|
for i := range ps {
|
|
p[i] = ps[i]
|
|
}
|
|
m.Where(p...)
|
|
}
|
|
|
|
// Op returns the operation name.
|
|
func (m *ServerConfigMutation) Op() Op {
|
|
return m.op
|
|
}
|
|
|
|
// SetOp allows setting the mutation operation.
|
|
func (m *ServerConfigMutation) SetOp(op Op) {
|
|
m.op = op
|
|
}
|
|
|
|
// Type returns the node type of this mutation (ServerConfig).
|
|
func (m *ServerConfigMutation) Type() string {
|
|
return m.typ
|
|
}
|
|
|
|
// Fields returns all fields that were changed during this mutation. Note that in
|
|
// order to get all numeric fields that were incremented/decremented, call
|
|
// AddedFields().
|
|
func (m *ServerConfigMutation) Fields() []string {
|
|
fields := make([]string, 0, 2)
|
|
if m.key != nil {
|
|
fields = append(fields, serverconfig.FieldKey)
|
|
}
|
|
if m.value != nil {
|
|
fields = append(fields, serverconfig.FieldValue)
|
|
}
|
|
return fields
|
|
}
|
|
|
|
// Field returns the value of a field with the given name. The second boolean
|
|
// return value indicates that this field was not set, or was not defined in the
|
|
// schema.
|
|
func (m *ServerConfigMutation) Field(name string) (ent.Value, bool) {
|
|
switch name {
|
|
case serverconfig.FieldKey:
|
|
return m.Key()
|
|
case serverconfig.FieldValue:
|
|
return m.Value()
|
|
}
|
|
return nil, false
|
|
}
|
|
|
|
// OldField returns the old value of the field from the database. An error is
|
|
// returned if the mutation operation is not UpdateOne, or the query to the
|
|
// database failed.
|
|
func (m *ServerConfigMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
|
|
switch name {
|
|
case serverconfig.FieldKey:
|
|
return m.OldKey(ctx)
|
|
case serverconfig.FieldValue:
|
|
return m.OldValue(ctx)
|
|
}
|
|
return nil, fmt.Errorf("unknown ServerConfig field %s", name)
|
|
}
|
|
|
|
// SetField sets the value of a field with the given name. It returns an error if
|
|
// the field is not defined in the schema, or if the type mismatched the field
|
|
// type.
|
|
func (m *ServerConfigMutation) SetField(name string, value ent.Value) error {
|
|
switch name {
|
|
case serverconfig.FieldKey:
|
|
v, ok := value.(string)
|
|
if !ok {
|
|
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
|
}
|
|
m.SetKey(v)
|
|
return nil
|
|
case serverconfig.FieldValue:
|
|
v, ok := value.(string)
|
|
if !ok {
|
|
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
|
}
|
|
m.SetValue(v)
|
|
return nil
|
|
}
|
|
return fmt.Errorf("unknown ServerConfig field %s", name)
|
|
}
|
|
|
|
// AddedFields returns all numeric fields that were incremented/decremented during
|
|
// this mutation.
|
|
func (m *ServerConfigMutation) AddedFields() []string {
|
|
return nil
|
|
}
|
|
|
|
// AddedField returns the numeric value that was incremented/decremented on a field
|
|
// with the given name. The second boolean return value indicates that this field
|
|
// was not set, or was not defined in the schema.
|
|
func (m *ServerConfigMutation) AddedField(name string) (ent.Value, bool) {
|
|
return nil, false
|
|
}
|
|
|
|
// AddField adds the value to the field with the given name. It returns an error if
|
|
// the field is not defined in the schema, or if the type mismatched the field
|
|
// type.
|
|
func (m *ServerConfigMutation) AddField(name string, value ent.Value) error {
|
|
switch name {
|
|
}
|
|
return fmt.Errorf("unknown ServerConfig numeric field %s", name)
|
|
}
|
|
|
|
// ClearedFields returns all nullable fields that were cleared during this
|
|
// mutation.
|
|
func (m *ServerConfigMutation) ClearedFields() []string {
|
|
return nil
|
|
}
|
|
|
|
// FieldCleared returns a boolean indicating if a field with the given name was
|
|
// cleared in this mutation.
|
|
func (m *ServerConfigMutation) FieldCleared(name string) bool {
|
|
_, ok := m.clearedFields[name]
|
|
return ok
|
|
}
|
|
|
|
// ClearField clears the value of the field with the given name. It returns an
|
|
// error if the field is not defined in the schema.
|
|
func (m *ServerConfigMutation) ClearField(name string) error {
|
|
return fmt.Errorf("unknown ServerConfig nullable field %s", name)
|
|
}
|
|
|
|
// ResetField resets all changes in the mutation for the field with the given name.
|
|
// It returns an error if the field is not defined in the schema.
|
|
func (m *ServerConfigMutation) ResetField(name string) error {
|
|
switch name {
|
|
case serverconfig.FieldKey:
|
|
m.ResetKey()
|
|
return nil
|
|
case serverconfig.FieldValue:
|
|
m.ResetValue()
|
|
return nil
|
|
}
|
|
return fmt.Errorf("unknown ServerConfig field %s", name)
|
|
}
|
|
|
|
// AddedEdges returns all edge names that were set/added in this mutation.
|
|
func (m *ServerConfigMutation) AddedEdges() []string {
|
|
edges := make([]string, 0, 0)
|
|
return edges
|
|
}
|
|
|
|
// AddedIDs returns all IDs (to other nodes) that were added for the given edge
|
|
// name in this mutation.
|
|
func (m *ServerConfigMutation) AddedIDs(name string) []ent.Value {
|
|
return nil
|
|
}
|
|
|
|
// RemovedEdges returns all edge names that were removed in this mutation.
|
|
func (m *ServerConfigMutation) RemovedEdges() []string {
|
|
edges := make([]string, 0, 0)
|
|
return edges
|
|
}
|
|
|
|
// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
|
|
// the given name in this mutation.
|
|
func (m *ServerConfigMutation) RemovedIDs(name string) []ent.Value {
|
|
return nil
|
|
}
|
|
|
|
// ClearedEdges returns all edge names that were cleared in this mutation.
|
|
func (m *ServerConfigMutation) ClearedEdges() []string {
|
|
edges := make([]string, 0, 0)
|
|
return edges
|
|
}
|
|
|
|
// EdgeCleared returns a boolean which indicates if the edge with the given name
|
|
// was cleared in this mutation.
|
|
func (m *ServerConfigMutation) EdgeCleared(name string) bool {
|
|
return false
|
|
}
|
|
|
|
// ClearEdge clears the value of the edge with the given name. It returns an error
|
|
// if that edge is not defined in the schema.
|
|
func (m *ServerConfigMutation) ClearEdge(name string) error {
|
|
return fmt.Errorf("unknown ServerConfig unique edge %s", name)
|
|
}
|
|
|
|
// ResetEdge resets all changes to the edge with the given name in this mutation.
|
|
// It returns an error if the edge is not defined in the schema.
|
|
func (m *ServerConfigMutation) ResetEdge(name string) error {
|
|
return fmt.Errorf("unknown ServerConfig edge %s", name)
|
|
}
|
|
|
|
// UserMutation represents an operation that mutates the User nodes in the graph.
|
|
type UserMutation struct {
|
|
config
|
|
op Op
|
|
typ string
|
|
id *int
|
|
username *string
|
|
password *string
|
|
name *string
|
|
role *string
|
|
created_at *time.Time
|
|
updated_at *time.Time
|
|
clearedFields map[string]struct{}
|
|
done bool
|
|
oldValue func(context.Context) (*User, error)
|
|
predicates []predicate.User
|
|
}
|
|
|
|
var _ ent.Mutation = (*UserMutation)(nil)
|
|
|
|
// userOption allows management of the mutation configuration using functional options.
|
|
type userOption func(*UserMutation)
|
|
|
|
// newUserMutation creates new mutation for the User entity.
|
|
func newUserMutation(c config, op Op, opts ...userOption) *UserMutation {
|
|
m := &UserMutation{
|
|
config: c,
|
|
op: op,
|
|
typ: TypeUser,
|
|
clearedFields: make(map[string]struct{}),
|
|
}
|
|
for _, opt := range opts {
|
|
opt(m)
|
|
}
|
|
return m
|
|
}
|
|
|
|
// withUserID sets the ID field of the mutation.
|
|
func withUserID(id int) userOption {
|
|
return func(m *UserMutation) {
|
|
var (
|
|
err error
|
|
once sync.Once
|
|
value *User
|
|
)
|
|
m.oldValue = func(ctx context.Context) (*User, error) {
|
|
once.Do(func() {
|
|
if m.done {
|
|
err = errors.New("querying old values post mutation is not allowed")
|
|
} else {
|
|
value, err = m.Client().User.Get(ctx, id)
|
|
}
|
|
})
|
|
return value, err
|
|
}
|
|
m.id = &id
|
|
}
|
|
}
|
|
|
|
// withUser sets the old User of the mutation.
|
|
func withUser(node *User) userOption {
|
|
return func(m *UserMutation) {
|
|
m.oldValue = func(context.Context) (*User, error) {
|
|
return node, nil
|
|
}
|
|
m.id = &node.ID
|
|
}
|
|
}
|
|
|
|
// Client returns a new `ent.Client` from the mutation. If the mutation was
|
|
// executed in a transaction (ent.Tx), a transactional client is returned.
|
|
func (m UserMutation) Client() *Client {
|
|
client := &Client{config: m.config}
|
|
client.init()
|
|
return client
|
|
}
|
|
|
|
// Tx returns an `ent.Tx` for mutations that were executed in transactions;
|
|
// it returns an error otherwise.
|
|
func (m UserMutation) Tx() (*Tx, error) {
|
|
if _, ok := m.driver.(*txDriver); !ok {
|
|
return nil, errors.New("ent: mutation is not running in a transaction")
|
|
}
|
|
tx := &Tx{config: m.config}
|
|
tx.init()
|
|
return tx, nil
|
|
}
|
|
|
|
// ID returns the ID value in the mutation. Note that the ID is only available
|
|
// if it was provided to the builder or after it was returned from the database.
|
|
func (m *UserMutation) ID() (id int, exists bool) {
|
|
if m.id == nil {
|
|
return
|
|
}
|
|
return *m.id, true
|
|
}
|
|
|
|
// IDs queries the database and returns the entity ids that match the mutation's predicate.
|
|
// That means, if the mutation is applied within a transaction with an isolation level such
|
|
// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated
|
|
// or updated by the mutation.
|
|
func (m *UserMutation) IDs(ctx context.Context) ([]int, error) {
|
|
switch {
|
|
case m.op.Is(OpUpdateOne | OpDeleteOne):
|
|
id, exists := m.ID()
|
|
if exists {
|
|
return []int{id}, nil
|
|
}
|
|
fallthrough
|
|
case m.op.Is(OpUpdate | OpDelete):
|
|
return m.Client().User.Query().Where(m.predicates...).IDs(ctx)
|
|
default:
|
|
return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
|
|
}
|
|
}
|
|
|
|
// SetUsername sets the "username" field.
|
|
func (m *UserMutation) SetUsername(s string) {
|
|
m.username = &s
|
|
}
|
|
|
|
// Username returns the value of the "username" field in the mutation.
|
|
func (m *UserMutation) Username() (r string, exists bool) {
|
|
v := m.username
|
|
if v == nil {
|
|
return
|
|
}
|
|
return *v, true
|
|
}
|
|
|
|
// OldUsername returns the old "username" field's value of the User entity.
|
|
// If the User object wasn't provided to the builder, the object is fetched from the database.
|
|
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
|
func (m *UserMutation) OldUsername(ctx context.Context) (v string, err error) {
|
|
if !m.op.Is(OpUpdateOne) {
|
|
return v, errors.New("OldUsername is only allowed on UpdateOne operations")
|
|
}
|
|
if m.id == nil || m.oldValue == nil {
|
|
return v, errors.New("OldUsername requires an ID field in the mutation")
|
|
}
|
|
oldValue, err := m.oldValue(ctx)
|
|
if err != nil {
|
|
return v, fmt.Errorf("querying old value for OldUsername: %w", err)
|
|
}
|
|
return oldValue.Username, nil
|
|
}
|
|
|
|
// ResetUsername resets all changes to the "username" field.
|
|
func (m *UserMutation) ResetUsername() {
|
|
m.username = nil
|
|
}
|
|
|
|
// SetPassword sets the "password" field.
|
|
func (m *UserMutation) SetPassword(s string) {
|
|
m.password = &s
|
|
}
|
|
|
|
// Password returns the value of the "password" field in the mutation.
|
|
func (m *UserMutation) Password() (r string, exists bool) {
|
|
v := m.password
|
|
if v == nil {
|
|
return
|
|
}
|
|
return *v, true
|
|
}
|
|
|
|
// OldPassword returns the old "password" field's value of the User entity.
|
|
// If the User object wasn't provided to the builder, the object is fetched from the database.
|
|
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
|
func (m *UserMutation) OldPassword(ctx context.Context) (v string, err error) {
|
|
if !m.op.Is(OpUpdateOne) {
|
|
return v, errors.New("OldPassword is only allowed on UpdateOne operations")
|
|
}
|
|
if m.id == nil || m.oldValue == nil {
|
|
return v, errors.New("OldPassword requires an ID field in the mutation")
|
|
}
|
|
oldValue, err := m.oldValue(ctx)
|
|
if err != nil {
|
|
return v, fmt.Errorf("querying old value for OldPassword: %w", err)
|
|
}
|
|
return oldValue.Password, nil
|
|
}
|
|
|
|
// ResetPassword resets all changes to the "password" field.
|
|
func (m *UserMutation) ResetPassword() {
|
|
m.password = nil
|
|
}
|
|
|
|
// SetName sets the "name" field.
|
|
func (m *UserMutation) SetName(s string) {
|
|
m.name = &s
|
|
}
|
|
|
|
// Name returns the value of the "name" field in the mutation.
|
|
func (m *UserMutation) Name() (r string, exists bool) {
|
|
v := m.name
|
|
if v == nil {
|
|
return
|
|
}
|
|
return *v, true
|
|
}
|
|
|
|
// OldName returns the old "name" field's value of the User entity.
|
|
// If the User object wasn't provided to the builder, the object is fetched from the database.
|
|
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
|
func (m *UserMutation) OldName(ctx context.Context) (v string, err error) {
|
|
if !m.op.Is(OpUpdateOne) {
|
|
return v, errors.New("OldName is only allowed on UpdateOne operations")
|
|
}
|
|
if m.id == nil || m.oldValue == nil {
|
|
return v, errors.New("OldName requires an ID field in the mutation")
|
|
}
|
|
oldValue, err := m.oldValue(ctx)
|
|
if err != nil {
|
|
return v, fmt.Errorf("querying old value for OldName: %w", err)
|
|
}
|
|
return oldValue.Name, nil
|
|
}
|
|
|
|
// ResetName resets all changes to the "name" field.
|
|
func (m *UserMutation) ResetName() {
|
|
m.name = nil
|
|
}
|
|
|
|
// SetRole sets the "role" field.
|
|
func (m *UserMutation) SetRole(s string) {
|
|
m.role = &s
|
|
}
|
|
|
|
// Role returns the value of the "role" field in the mutation.
|
|
func (m *UserMutation) Role() (r string, exists bool) {
|
|
v := m.role
|
|
if v == nil {
|
|
return
|
|
}
|
|
return *v, true
|
|
}
|
|
|
|
// OldRole returns the old "role" field's value of the User entity.
|
|
// If the User object wasn't provided to the builder, the object is fetched from the database.
|
|
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
|
func (m *UserMutation) OldRole(ctx context.Context) (v string, err error) {
|
|
if !m.op.Is(OpUpdateOne) {
|
|
return v, errors.New("OldRole is only allowed on UpdateOne operations")
|
|
}
|
|
if m.id == nil || m.oldValue == nil {
|
|
return v, errors.New("OldRole requires an ID field in the mutation")
|
|
}
|
|
oldValue, err := m.oldValue(ctx)
|
|
if err != nil {
|
|
return v, fmt.Errorf("querying old value for OldRole: %w", err)
|
|
}
|
|
return oldValue.Role, nil
|
|
}
|
|
|
|
// ResetRole resets all changes to the "role" field.
|
|
func (m *UserMutation) ResetRole() {
|
|
m.role = nil
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (m *UserMutation) SetCreatedAt(t time.Time) {
|
|
m.created_at = &t
|
|
}
|
|
|
|
// CreatedAt returns the value of the "created_at" field in the mutation.
|
|
func (m *UserMutation) CreatedAt() (r time.Time, exists bool) {
|
|
v := m.created_at
|
|
if v == nil {
|
|
return
|
|
}
|
|
return *v, true
|
|
}
|
|
|
|
// OldCreatedAt returns the old "created_at" field's value of the User entity.
|
|
// If the User object wasn't provided to the builder, the object is fetched from the database.
|
|
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
|
func (m *UserMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) {
|
|
if !m.op.Is(OpUpdateOne) {
|
|
return v, errors.New("OldCreatedAt is only allowed on UpdateOne operations")
|
|
}
|
|
if m.id == nil || m.oldValue == nil {
|
|
return v, errors.New("OldCreatedAt requires an ID field in the mutation")
|
|
}
|
|
oldValue, err := m.oldValue(ctx)
|
|
if err != nil {
|
|
return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err)
|
|
}
|
|
return oldValue.CreatedAt, nil
|
|
}
|
|
|
|
// ResetCreatedAt resets all changes to the "created_at" field.
|
|
func (m *UserMutation) ResetCreatedAt() {
|
|
m.created_at = nil
|
|
}
|
|
|
|
// SetUpdatedAt sets the "updated_at" field.
|
|
func (m *UserMutation) SetUpdatedAt(t time.Time) {
|
|
m.updated_at = &t
|
|
}
|
|
|
|
// UpdatedAt returns the value of the "updated_at" field in the mutation.
|
|
func (m *UserMutation) UpdatedAt() (r time.Time, exists bool) {
|
|
v := m.updated_at
|
|
if v == nil {
|
|
return
|
|
}
|
|
return *v, true
|
|
}
|
|
|
|
// OldUpdatedAt returns the old "updated_at" field's value of the User entity.
|
|
// If the User object wasn't provided to the builder, the object is fetched from the database.
|
|
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
|
func (m *UserMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) {
|
|
if !m.op.Is(OpUpdateOne) {
|
|
return v, errors.New("OldUpdatedAt is only allowed on UpdateOne operations")
|
|
}
|
|
if m.id == nil || m.oldValue == nil {
|
|
return v, errors.New("OldUpdatedAt requires an ID field in the mutation")
|
|
}
|
|
oldValue, err := m.oldValue(ctx)
|
|
if err != nil {
|
|
return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err)
|
|
}
|
|
return oldValue.UpdatedAt, nil
|
|
}
|
|
|
|
// ResetUpdatedAt resets all changes to the "updated_at" field.
|
|
func (m *UserMutation) ResetUpdatedAt() {
|
|
m.updated_at = nil
|
|
}
|
|
|
|
// Where appends a list predicates to the UserMutation builder.
|
|
func (m *UserMutation) Where(ps ...predicate.User) {
|
|
m.predicates = append(m.predicates, ps...)
|
|
}
|
|
|
|
// WhereP appends storage-level predicates to the UserMutation builder. Using this method,
|
|
// users can use type-assertion to append predicates that do not depend on any generated package.
|
|
func (m *UserMutation) WhereP(ps ...func(*sql.Selector)) {
|
|
p := make([]predicate.User, len(ps))
|
|
for i := range ps {
|
|
p[i] = ps[i]
|
|
}
|
|
m.Where(p...)
|
|
}
|
|
|
|
// Op returns the operation name.
|
|
func (m *UserMutation) Op() Op {
|
|
return m.op
|
|
}
|
|
|
|
// SetOp allows setting the mutation operation.
|
|
func (m *UserMutation) SetOp(op Op) {
|
|
m.op = op
|
|
}
|
|
|
|
// Type returns the node type of this mutation (User).
|
|
func (m *UserMutation) Type() string {
|
|
return m.typ
|
|
}
|
|
|
|
// Fields returns all fields that were changed during this mutation. Note that in
|
|
// order to get all numeric fields that were incremented/decremented, call
|
|
// AddedFields().
|
|
func (m *UserMutation) Fields() []string {
|
|
fields := make([]string, 0, 6)
|
|
if m.username != nil {
|
|
fields = append(fields, user.FieldUsername)
|
|
}
|
|
if m.password != nil {
|
|
fields = append(fields, user.FieldPassword)
|
|
}
|
|
if m.name != nil {
|
|
fields = append(fields, user.FieldName)
|
|
}
|
|
if m.role != nil {
|
|
fields = append(fields, user.FieldRole)
|
|
}
|
|
if m.created_at != nil {
|
|
fields = append(fields, user.FieldCreatedAt)
|
|
}
|
|
if m.updated_at != nil {
|
|
fields = append(fields, user.FieldUpdatedAt)
|
|
}
|
|
return fields
|
|
}
|
|
|
|
// Field returns the value of a field with the given name. The second boolean
|
|
// return value indicates that this field was not set, or was not defined in the
|
|
// schema.
|
|
func (m *UserMutation) Field(name string) (ent.Value, bool) {
|
|
switch name {
|
|
case user.FieldUsername:
|
|
return m.Username()
|
|
case user.FieldPassword:
|
|
return m.Password()
|
|
case user.FieldName:
|
|
return m.Name()
|
|
case user.FieldRole:
|
|
return m.Role()
|
|
case user.FieldCreatedAt:
|
|
return m.CreatedAt()
|
|
case user.FieldUpdatedAt:
|
|
return m.UpdatedAt()
|
|
}
|
|
return nil, false
|
|
}
|
|
|
|
// OldField returns the old value of the field from the database. An error is
|
|
// returned if the mutation operation is not UpdateOne, or the query to the
|
|
// database failed.
|
|
func (m *UserMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
|
|
switch name {
|
|
case user.FieldUsername:
|
|
return m.OldUsername(ctx)
|
|
case user.FieldPassword:
|
|
return m.OldPassword(ctx)
|
|
case user.FieldName:
|
|
return m.OldName(ctx)
|
|
case user.FieldRole:
|
|
return m.OldRole(ctx)
|
|
case user.FieldCreatedAt:
|
|
return m.OldCreatedAt(ctx)
|
|
case user.FieldUpdatedAt:
|
|
return m.OldUpdatedAt(ctx)
|
|
}
|
|
return nil, fmt.Errorf("unknown User field %s", name)
|
|
}
|
|
|
|
// SetField sets the value of a field with the given name. It returns an error if
|
|
// the field is not defined in the schema, or if the type mismatched the field
|
|
// type.
|
|
func (m *UserMutation) SetField(name string, value ent.Value) error {
|
|
switch name {
|
|
case user.FieldUsername:
|
|
v, ok := value.(string)
|
|
if !ok {
|
|
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
|
}
|
|
m.SetUsername(v)
|
|
return nil
|
|
case user.FieldPassword:
|
|
v, ok := value.(string)
|
|
if !ok {
|
|
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
|
}
|
|
m.SetPassword(v)
|
|
return nil
|
|
case user.FieldName:
|
|
v, ok := value.(string)
|
|
if !ok {
|
|
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
|
}
|
|
m.SetName(v)
|
|
return nil
|
|
case user.FieldRole:
|
|
v, ok := value.(string)
|
|
if !ok {
|
|
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
|
}
|
|
m.SetRole(v)
|
|
return nil
|
|
case user.FieldCreatedAt:
|
|
v, ok := value.(time.Time)
|
|
if !ok {
|
|
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
|
}
|
|
m.SetCreatedAt(v)
|
|
return nil
|
|
case user.FieldUpdatedAt:
|
|
v, ok := value.(time.Time)
|
|
if !ok {
|
|
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
|
}
|
|
m.SetUpdatedAt(v)
|
|
return nil
|
|
}
|
|
return fmt.Errorf("unknown User field %s", name)
|
|
}
|
|
|
|
// AddedFields returns all numeric fields that were incremented/decremented during
|
|
// this mutation.
|
|
func (m *UserMutation) AddedFields() []string {
|
|
return nil
|
|
}
|
|
|
|
// AddedField returns the numeric value that was incremented/decremented on a field
|
|
// with the given name. The second boolean return value indicates that this field
|
|
// was not set, or was not defined in the schema.
|
|
func (m *UserMutation) AddedField(name string) (ent.Value, bool) {
|
|
return nil, false
|
|
}
|
|
|
|
// AddField adds the value to the field with the given name. It returns an error if
|
|
// the field is not defined in the schema, or if the type mismatched the field
|
|
// type.
|
|
func (m *UserMutation) AddField(name string, value ent.Value) error {
|
|
switch name {
|
|
}
|
|
return fmt.Errorf("unknown User numeric field %s", name)
|
|
}
|
|
|
|
// ClearedFields returns all nullable fields that were cleared during this
|
|
// mutation.
|
|
func (m *UserMutation) ClearedFields() []string {
|
|
return nil
|
|
}
|
|
|
|
// FieldCleared returns a boolean indicating if a field with the given name was
|
|
// cleared in this mutation.
|
|
func (m *UserMutation) FieldCleared(name string) bool {
|
|
_, ok := m.clearedFields[name]
|
|
return ok
|
|
}
|
|
|
|
// ClearField clears the value of the field with the given name. It returns an
|
|
// error if the field is not defined in the schema.
|
|
func (m *UserMutation) ClearField(name string) error {
|
|
return fmt.Errorf("unknown User nullable field %s", name)
|
|
}
|
|
|
|
// ResetField resets all changes in the mutation for the field with the given name.
|
|
// It returns an error if the field is not defined in the schema.
|
|
func (m *UserMutation) ResetField(name string) error {
|
|
switch name {
|
|
case user.FieldUsername:
|
|
m.ResetUsername()
|
|
return nil
|
|
case user.FieldPassword:
|
|
m.ResetPassword()
|
|
return nil
|
|
case user.FieldName:
|
|
m.ResetName()
|
|
return nil
|
|
case user.FieldRole:
|
|
m.ResetRole()
|
|
return nil
|
|
case user.FieldCreatedAt:
|
|
m.ResetCreatedAt()
|
|
return nil
|
|
case user.FieldUpdatedAt:
|
|
m.ResetUpdatedAt()
|
|
return nil
|
|
}
|
|
return fmt.Errorf("unknown User field %s", name)
|
|
}
|
|
|
|
// AddedEdges returns all edge names that were set/added in this mutation.
|
|
func (m *UserMutation) AddedEdges() []string {
|
|
edges := make([]string, 0, 0)
|
|
return edges
|
|
}
|
|
|
|
// AddedIDs returns all IDs (to other nodes) that were added for the given edge
|
|
// name in this mutation.
|
|
func (m *UserMutation) AddedIDs(name string) []ent.Value {
|
|
return nil
|
|
}
|
|
|
|
// RemovedEdges returns all edge names that were removed in this mutation.
|
|
func (m *UserMutation) RemovedEdges() []string {
|
|
edges := make([]string, 0, 0)
|
|
return edges
|
|
}
|
|
|
|
// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
|
|
// the given name in this mutation.
|
|
func (m *UserMutation) RemovedIDs(name string) []ent.Value {
|
|
return nil
|
|
}
|
|
|
|
// ClearedEdges returns all edge names that were cleared in this mutation.
|
|
func (m *UserMutation) ClearedEdges() []string {
|
|
edges := make([]string, 0, 0)
|
|
return edges
|
|
}
|
|
|
|
// EdgeCleared returns a boolean which indicates if the edge with the given name
|
|
// was cleared in this mutation.
|
|
func (m *UserMutation) EdgeCleared(name string) bool {
|
|
return false
|
|
}
|
|
|
|
// ClearEdge clears the value of the edge with the given name. It returns an error
|
|
// if that edge is not defined in the schema.
|
|
func (m *UserMutation) ClearEdge(name string) error {
|
|
return fmt.Errorf("unknown User unique edge %s", name)
|
|
}
|
|
|
|
// ResetEdge resets all changes to the edge with the given name in this mutation.
|
|
// It returns an error if the edge is not defined in the schema.
|
|
func (m *UserMutation) ResetEdge(name string) error {
|
|
return fmt.Errorf("unknown User edge %s", name)
|
|
}
|