429 lines
12 KiB
Go
429 lines
12 KiB
Go
// Code generated by ent, DO NOT EDIT.
|
|
|
|
package ent
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
"time"
|
|
|
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
|
"entgo.io/ent/schema/field"
|
|
"kanhole/pkg/db/ent/proxy"
|
|
)
|
|
|
|
// ProxyCreate is the builder for creating a Proxy entity.
|
|
type ProxyCreate struct {
|
|
config
|
|
mutation *ProxyMutation
|
|
hooks []Hook
|
|
}
|
|
|
|
// SetName sets the "name" field.
|
|
func (_c *ProxyCreate) SetName(v string) *ProxyCreate {
|
|
_c.mutation.SetName(v)
|
|
return _c
|
|
}
|
|
|
|
// SetProxyType sets the "proxy_type" field.
|
|
func (_c *ProxyCreate) SetProxyType(v string) *ProxyCreate {
|
|
_c.mutation.SetProxyType(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableProxyType sets the "proxy_type" field if the given value is not nil.
|
|
func (_c *ProxyCreate) SetNillableProxyType(v *string) *ProxyCreate {
|
|
if v != nil {
|
|
_c.SetProxyType(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetLocalIP sets the "local_ip" field.
|
|
func (_c *ProxyCreate) SetLocalIP(v string) *ProxyCreate {
|
|
_c.mutation.SetLocalIP(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableLocalIP sets the "local_ip" field if the given value is not nil.
|
|
func (_c *ProxyCreate) SetNillableLocalIP(v *string) *ProxyCreate {
|
|
if v != nil {
|
|
_c.SetLocalIP(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetLocalPort sets the "local_port" field.
|
|
func (_c *ProxyCreate) SetLocalPort(v int) *ProxyCreate {
|
|
_c.mutation.SetLocalPort(v)
|
|
return _c
|
|
}
|
|
|
|
// SetRemotePort sets the "remote_port" field.
|
|
func (_c *ProxyCreate) SetRemotePort(v int) *ProxyCreate {
|
|
_c.mutation.SetRemotePort(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableRemotePort sets the "remote_port" field if the given value is not nil.
|
|
func (_c *ProxyCreate) SetNillableRemotePort(v *int) *ProxyCreate {
|
|
if v != nil {
|
|
_c.SetRemotePort(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetStatus sets the "status" field.
|
|
func (_c *ProxyCreate) SetStatus(v string) *ProxyCreate {
|
|
_c.mutation.SetStatus(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableStatus sets the "status" field if the given value is not nil.
|
|
func (_c *ProxyCreate) SetNillableStatus(v *string) *ProxyCreate {
|
|
if v != nil {
|
|
_c.SetStatus(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetCustomDomains sets the "custom_domains" field.
|
|
func (_c *ProxyCreate) SetCustomDomains(v string) *ProxyCreate {
|
|
_c.mutation.SetCustomDomains(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableCustomDomains sets the "custom_domains" field if the given value is not nil.
|
|
func (_c *ProxyCreate) SetNillableCustomDomains(v *string) *ProxyCreate {
|
|
if v != nil {
|
|
_c.SetCustomDomains(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetMetadata sets the "metadata" field.
|
|
func (_c *ProxyCreate) SetMetadata(v string) *ProxyCreate {
|
|
_c.mutation.SetMetadata(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableMetadata sets the "metadata" field if the given value is not nil.
|
|
func (_c *ProxyCreate) SetNillableMetadata(v *string) *ProxyCreate {
|
|
if v != nil {
|
|
_c.SetMetadata(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetClientID sets the "client_id" field.
|
|
func (_c *ProxyCreate) SetClientID(v int) *ProxyCreate {
|
|
_c.mutation.SetClientID(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableClientID sets the "client_id" field if the given value is not nil.
|
|
func (_c *ProxyCreate) SetNillableClientID(v *int) *ProxyCreate {
|
|
if v != nil {
|
|
_c.SetClientID(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (_c *ProxyCreate) SetCreatedAt(v time.Time) *ProxyCreate {
|
|
_c.mutation.SetCreatedAt(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
|
func (_c *ProxyCreate) SetNillableCreatedAt(v *time.Time) *ProxyCreate {
|
|
if v != nil {
|
|
_c.SetCreatedAt(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetUpdatedAt sets the "updated_at" field.
|
|
func (_c *ProxyCreate) SetUpdatedAt(v time.Time) *ProxyCreate {
|
|
_c.mutation.SetUpdatedAt(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
|
|
func (_c *ProxyCreate) SetNillableUpdatedAt(v *time.Time) *ProxyCreate {
|
|
if v != nil {
|
|
_c.SetUpdatedAt(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// Mutation returns the ProxyMutation object of the builder.
|
|
func (_c *ProxyCreate) Mutation() *ProxyMutation {
|
|
return _c.mutation
|
|
}
|
|
|
|
// Save creates the Proxy in the database.
|
|
func (_c *ProxyCreate) Save(ctx context.Context) (*Proxy, error) {
|
|
_c.defaults()
|
|
return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
|
|
}
|
|
|
|
// SaveX calls Save and panics if Save returns an error.
|
|
func (_c *ProxyCreate) SaveX(ctx context.Context) *Proxy {
|
|
v, err := _c.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return v
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (_c *ProxyCreate) Exec(ctx context.Context) error {
|
|
_, err := _c.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_c *ProxyCreate) ExecX(ctx context.Context) {
|
|
if err := _c.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
// defaults sets the default values of the builder before save.
|
|
func (_c *ProxyCreate) defaults() {
|
|
if _, ok := _c.mutation.ProxyType(); !ok {
|
|
v := proxy.DefaultProxyType
|
|
_c.mutation.SetProxyType(v)
|
|
}
|
|
if _, ok := _c.mutation.LocalIP(); !ok {
|
|
v := proxy.DefaultLocalIP
|
|
_c.mutation.SetLocalIP(v)
|
|
}
|
|
if _, ok := _c.mutation.RemotePort(); !ok {
|
|
v := proxy.DefaultRemotePort
|
|
_c.mutation.SetRemotePort(v)
|
|
}
|
|
if _, ok := _c.mutation.Status(); !ok {
|
|
v := proxy.DefaultStatus
|
|
_c.mutation.SetStatus(v)
|
|
}
|
|
if _, ok := _c.mutation.CustomDomains(); !ok {
|
|
v := proxy.DefaultCustomDomains
|
|
_c.mutation.SetCustomDomains(v)
|
|
}
|
|
if _, ok := _c.mutation.Metadata(); !ok {
|
|
v := proxy.DefaultMetadata
|
|
_c.mutation.SetMetadata(v)
|
|
}
|
|
if _, ok := _c.mutation.ClientID(); !ok {
|
|
v := proxy.DefaultClientID
|
|
_c.mutation.SetClientID(v)
|
|
}
|
|
if _, ok := _c.mutation.CreatedAt(); !ok {
|
|
v := proxy.DefaultCreatedAt()
|
|
_c.mutation.SetCreatedAt(v)
|
|
}
|
|
if _, ok := _c.mutation.UpdatedAt(); !ok {
|
|
v := proxy.DefaultUpdatedAt()
|
|
_c.mutation.SetUpdatedAt(v)
|
|
}
|
|
}
|
|
|
|
// check runs all checks and user-defined validators on the builder.
|
|
func (_c *ProxyCreate) check() error {
|
|
if _, ok := _c.mutation.Name(); !ok {
|
|
return &ValidationError{Name: "name", err: errors.New(`ent: missing required field "Proxy.name"`)}
|
|
}
|
|
if _, ok := _c.mutation.ProxyType(); !ok {
|
|
return &ValidationError{Name: "proxy_type", err: errors.New(`ent: missing required field "Proxy.proxy_type"`)}
|
|
}
|
|
if _, ok := _c.mutation.LocalIP(); !ok {
|
|
return &ValidationError{Name: "local_ip", err: errors.New(`ent: missing required field "Proxy.local_ip"`)}
|
|
}
|
|
if _, ok := _c.mutation.LocalPort(); !ok {
|
|
return &ValidationError{Name: "local_port", err: errors.New(`ent: missing required field "Proxy.local_port"`)}
|
|
}
|
|
if _, ok := _c.mutation.RemotePort(); !ok {
|
|
return &ValidationError{Name: "remote_port", err: errors.New(`ent: missing required field "Proxy.remote_port"`)}
|
|
}
|
|
if _, ok := _c.mutation.Status(); !ok {
|
|
return &ValidationError{Name: "status", err: errors.New(`ent: missing required field "Proxy.status"`)}
|
|
}
|
|
if _, ok := _c.mutation.CustomDomains(); !ok {
|
|
return &ValidationError{Name: "custom_domains", err: errors.New(`ent: missing required field "Proxy.custom_domains"`)}
|
|
}
|
|
if _, ok := _c.mutation.Metadata(); !ok {
|
|
return &ValidationError{Name: "metadata", err: errors.New(`ent: missing required field "Proxy.metadata"`)}
|
|
}
|
|
if _, ok := _c.mutation.ClientID(); !ok {
|
|
return &ValidationError{Name: "client_id", err: errors.New(`ent: missing required field "Proxy.client_id"`)}
|
|
}
|
|
if _, ok := _c.mutation.CreatedAt(); !ok {
|
|
return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "Proxy.created_at"`)}
|
|
}
|
|
if _, ok := _c.mutation.UpdatedAt(); !ok {
|
|
return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "Proxy.updated_at"`)}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (_c *ProxyCreate) sqlSave(ctx context.Context) (*Proxy, error) {
|
|
if err := _c.check(); err != nil {
|
|
return nil, err
|
|
}
|
|
_node, _spec := _c.createSpec()
|
|
if err := sqlgraph.CreateNode(ctx, _c.driver, _spec); err != nil {
|
|
if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
return nil, err
|
|
}
|
|
id := _spec.ID.Value.(int64)
|
|
_node.ID = int(id)
|
|
_c.mutation.id = &_node.ID
|
|
_c.mutation.done = true
|
|
return _node, nil
|
|
}
|
|
|
|
func (_c *ProxyCreate) createSpec() (*Proxy, *sqlgraph.CreateSpec) {
|
|
var (
|
|
_node = &Proxy{config: _c.config}
|
|
_spec = sqlgraph.NewCreateSpec(proxy.Table, sqlgraph.NewFieldSpec(proxy.FieldID, field.TypeInt))
|
|
)
|
|
if value, ok := _c.mutation.Name(); ok {
|
|
_spec.SetField(proxy.FieldName, field.TypeString, value)
|
|
_node.Name = value
|
|
}
|
|
if value, ok := _c.mutation.ProxyType(); ok {
|
|
_spec.SetField(proxy.FieldProxyType, field.TypeString, value)
|
|
_node.ProxyType = value
|
|
}
|
|
if value, ok := _c.mutation.LocalIP(); ok {
|
|
_spec.SetField(proxy.FieldLocalIP, field.TypeString, value)
|
|
_node.LocalIP = value
|
|
}
|
|
if value, ok := _c.mutation.LocalPort(); ok {
|
|
_spec.SetField(proxy.FieldLocalPort, field.TypeInt, value)
|
|
_node.LocalPort = value
|
|
}
|
|
if value, ok := _c.mutation.RemotePort(); ok {
|
|
_spec.SetField(proxy.FieldRemotePort, field.TypeInt, value)
|
|
_node.RemotePort = value
|
|
}
|
|
if value, ok := _c.mutation.Status(); ok {
|
|
_spec.SetField(proxy.FieldStatus, field.TypeString, value)
|
|
_node.Status = value
|
|
}
|
|
if value, ok := _c.mutation.CustomDomains(); ok {
|
|
_spec.SetField(proxy.FieldCustomDomains, field.TypeString, value)
|
|
_node.CustomDomains = value
|
|
}
|
|
if value, ok := _c.mutation.Metadata(); ok {
|
|
_spec.SetField(proxy.FieldMetadata, field.TypeString, value)
|
|
_node.Metadata = value
|
|
}
|
|
if value, ok := _c.mutation.ClientID(); ok {
|
|
_spec.SetField(proxy.FieldClientID, field.TypeInt, value)
|
|
_node.ClientID = value
|
|
}
|
|
if value, ok := _c.mutation.CreatedAt(); ok {
|
|
_spec.SetField(proxy.FieldCreatedAt, field.TypeTime, value)
|
|
_node.CreatedAt = value
|
|
}
|
|
if value, ok := _c.mutation.UpdatedAt(); ok {
|
|
_spec.SetField(proxy.FieldUpdatedAt, field.TypeTime, value)
|
|
_node.UpdatedAt = value
|
|
}
|
|
return _node, _spec
|
|
}
|
|
|
|
// ProxyCreateBulk is the builder for creating many Proxy entities in bulk.
|
|
type ProxyCreateBulk struct {
|
|
config
|
|
err error
|
|
builders []*ProxyCreate
|
|
}
|
|
|
|
// Save creates the Proxy entities in the database.
|
|
func (_c *ProxyCreateBulk) Save(ctx context.Context) ([]*Proxy, error) {
|
|
if _c.err != nil {
|
|
return nil, _c.err
|
|
}
|
|
specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
|
|
nodes := make([]*Proxy, len(_c.builders))
|
|
mutators := make([]Mutator, len(_c.builders))
|
|
for i := range _c.builders {
|
|
func(i int, root context.Context) {
|
|
builder := _c.builders[i]
|
|
builder.defaults()
|
|
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
|
mutation, ok := m.(*ProxyMutation)
|
|
if !ok {
|
|
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
|
}
|
|
if err := builder.check(); err != nil {
|
|
return nil, err
|
|
}
|
|
builder.mutation = mutation
|
|
var err error
|
|
nodes[i], specs[i] = builder.createSpec()
|
|
if i < len(mutators)-1 {
|
|
_, err = mutators[i+1].Mutate(root, _c.builders[i+1].mutation)
|
|
} else {
|
|
spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
|
|
// Invoke the actual operation on the latest mutation in the chain.
|
|
if err = sqlgraph.BatchCreate(ctx, _c.driver, spec); err != nil {
|
|
if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
}
|
|
}
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
mutation.id = &nodes[i].ID
|
|
if specs[i].ID.Value != nil {
|
|
id := specs[i].ID.Value.(int64)
|
|
nodes[i].ID = int(id)
|
|
}
|
|
mutation.done = true
|
|
return nodes[i], nil
|
|
})
|
|
for i := len(builder.hooks) - 1; i >= 0; i-- {
|
|
mut = builder.hooks[i](mut)
|
|
}
|
|
mutators[i] = mut
|
|
}(i, ctx)
|
|
}
|
|
if len(mutators) > 0 {
|
|
if _, err := mutators[0].Mutate(ctx, _c.builders[0].mutation); err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
return nodes, nil
|
|
}
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
func (_c *ProxyCreateBulk) SaveX(ctx context.Context) []*Proxy {
|
|
v, err := _c.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return v
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (_c *ProxyCreateBulk) Exec(ctx context.Context) error {
|
|
_, err := _c.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_c *ProxyCreateBulk) ExecX(ctx context.Context) {
|
|
if err := _c.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|