342 lines
		
	
	
		
			9.5 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			342 lines
		
	
	
		
			9.5 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"
 | 
						|
	"github.com/FrankenBotDev/FrankenAPI/ent/supportresponse"
 | 
						|
)
 | 
						|
 | 
						|
// SupportResponseCreate is the builder for creating a SupportResponse entity.
 | 
						|
type SupportResponseCreate struct {
 | 
						|
	config
 | 
						|
	mutation *SupportResponseMutation
 | 
						|
	hooks    []Hook
 | 
						|
}
 | 
						|
 | 
						|
// SetRefid sets the "refid" field.
 | 
						|
func (src *SupportResponseCreate) SetRefid(s string) *SupportResponseCreate {
 | 
						|
	src.mutation.SetRefid(s)
 | 
						|
	return src
 | 
						|
}
 | 
						|
 | 
						|
// SetWriter sets the "writer" field.
 | 
						|
func (src *SupportResponseCreate) SetWriter(s string) *SupportResponseCreate {
 | 
						|
	src.mutation.SetWriter(s)
 | 
						|
	return src
 | 
						|
}
 | 
						|
 | 
						|
// SetMessage sets the "message" field.
 | 
						|
func (src *SupportResponseCreate) SetMessage(s string) *SupportResponseCreate {
 | 
						|
	src.mutation.SetMessage(s)
 | 
						|
	return src
 | 
						|
}
 | 
						|
 | 
						|
// SetType sets the "type" field.
 | 
						|
func (src *SupportResponseCreate) SetType(s string) *SupportResponseCreate {
 | 
						|
	src.mutation.SetType(s)
 | 
						|
	return src
 | 
						|
}
 | 
						|
 | 
						|
// SetRtcchannel sets the "rtcchannel" field.
 | 
						|
func (src *SupportResponseCreate) SetRtcchannel(s string) *SupportResponseCreate {
 | 
						|
	src.mutation.SetRtcchannel(s)
 | 
						|
	return src
 | 
						|
}
 | 
						|
 | 
						|
// SetIsread sets the "isread" field.
 | 
						|
func (src *SupportResponseCreate) SetIsread(b bool) *SupportResponseCreate {
 | 
						|
	src.mutation.SetIsread(b)
 | 
						|
	return src
 | 
						|
}
 | 
						|
 | 
						|
// SetCreated sets the "created" field.
 | 
						|
func (src *SupportResponseCreate) SetCreated(t time.Time) *SupportResponseCreate {
 | 
						|
	src.mutation.SetCreated(t)
 | 
						|
	return src
 | 
						|
}
 | 
						|
 | 
						|
// SetID sets the "id" field.
 | 
						|
func (src *SupportResponseCreate) SetID(i int) *SupportResponseCreate {
 | 
						|
	src.mutation.SetID(i)
 | 
						|
	return src
 | 
						|
}
 | 
						|
 | 
						|
// Mutation returns the SupportResponseMutation object of the builder.
 | 
						|
func (src *SupportResponseCreate) Mutation() *SupportResponseMutation {
 | 
						|
	return src.mutation
 | 
						|
}
 | 
						|
 | 
						|
// Save creates the SupportResponse in the database.
 | 
						|
func (src *SupportResponseCreate) Save(ctx context.Context) (*SupportResponse, error) {
 | 
						|
	var (
 | 
						|
		err  error
 | 
						|
		node *SupportResponse
 | 
						|
	)
 | 
						|
	if len(src.hooks) == 0 {
 | 
						|
		if err = src.check(); err != nil {
 | 
						|
			return nil, err
 | 
						|
		}
 | 
						|
		node, err = src.sqlSave(ctx)
 | 
						|
	} else {
 | 
						|
		var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
 | 
						|
			mutation, ok := m.(*SupportResponseMutation)
 | 
						|
			if !ok {
 | 
						|
				return nil, fmt.Errorf("unexpected mutation type %T", m)
 | 
						|
			}
 | 
						|
			if err = src.check(); err != nil {
 | 
						|
				return nil, err
 | 
						|
			}
 | 
						|
			src.mutation = mutation
 | 
						|
			if node, err = src.sqlSave(ctx); err != nil {
 | 
						|
				return nil, err
 | 
						|
			}
 | 
						|
			mutation.id = &node.ID
 | 
						|
			mutation.done = true
 | 
						|
			return node, err
 | 
						|
		})
 | 
						|
		for i := len(src.hooks) - 1; i >= 0; i-- {
 | 
						|
			if src.hooks[i] == nil {
 | 
						|
				return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
 | 
						|
			}
 | 
						|
			mut = src.hooks[i](mut)
 | 
						|
		}
 | 
						|
		v, err := mut.Mutate(ctx, src.mutation)
 | 
						|
		if err != nil {
 | 
						|
			return nil, err
 | 
						|
		}
 | 
						|
		nv, ok := v.(*SupportResponse)
 | 
						|
		if !ok {
 | 
						|
			return nil, fmt.Errorf("unexpected node type %T returned from SupportResponseMutation", v)
 | 
						|
		}
 | 
						|
		node = nv
 | 
						|
	}
 | 
						|
	return node, err
 | 
						|
}
 | 
						|
 | 
						|
// SaveX calls Save and panics if Save returns an error.
 | 
						|
func (src *SupportResponseCreate) SaveX(ctx context.Context) *SupportResponse {
 | 
						|
	v, err := src.Save(ctx)
 | 
						|
	if err != nil {
 | 
						|
		panic(err)
 | 
						|
	}
 | 
						|
	return v
 | 
						|
}
 | 
						|
 | 
						|
// Exec executes the query.
 | 
						|
func (src *SupportResponseCreate) Exec(ctx context.Context) error {
 | 
						|
	_, err := src.Save(ctx)
 | 
						|
	return err
 | 
						|
}
 | 
						|
 | 
						|
// ExecX is like Exec, but panics if an error occurs.
 | 
						|
func (src *SupportResponseCreate) ExecX(ctx context.Context) {
 | 
						|
	if err := src.Exec(ctx); err != nil {
 | 
						|
		panic(err)
 | 
						|
	}
 | 
						|
}
 | 
						|
 | 
						|
// check runs all checks and user-defined validators on the builder.
 | 
						|
func (src *SupportResponseCreate) check() error {
 | 
						|
	if _, ok := src.mutation.Refid(); !ok {
 | 
						|
		return &ValidationError{Name: "refid", err: errors.New(`ent: missing required field "SupportResponse.refid"`)}
 | 
						|
	}
 | 
						|
	if _, ok := src.mutation.Writer(); !ok {
 | 
						|
		return &ValidationError{Name: "writer", err: errors.New(`ent: missing required field "SupportResponse.writer"`)}
 | 
						|
	}
 | 
						|
	if _, ok := src.mutation.Message(); !ok {
 | 
						|
		return &ValidationError{Name: "message", err: errors.New(`ent: missing required field "SupportResponse.message"`)}
 | 
						|
	}
 | 
						|
	if _, ok := src.mutation.GetType(); !ok {
 | 
						|
		return &ValidationError{Name: "type", err: errors.New(`ent: missing required field "SupportResponse.type"`)}
 | 
						|
	}
 | 
						|
	if _, ok := src.mutation.Rtcchannel(); !ok {
 | 
						|
		return &ValidationError{Name: "rtcchannel", err: errors.New(`ent: missing required field "SupportResponse.rtcchannel"`)}
 | 
						|
	}
 | 
						|
	if _, ok := src.mutation.Isread(); !ok {
 | 
						|
		return &ValidationError{Name: "isread", err: errors.New(`ent: missing required field "SupportResponse.isread"`)}
 | 
						|
	}
 | 
						|
	if _, ok := src.mutation.Created(); !ok {
 | 
						|
		return &ValidationError{Name: "created", err: errors.New(`ent: missing required field "SupportResponse.created"`)}
 | 
						|
	}
 | 
						|
	return nil
 | 
						|
}
 | 
						|
 | 
						|
func (src *SupportResponseCreate) sqlSave(ctx context.Context) (*SupportResponse, error) {
 | 
						|
	_node, _spec := src.createSpec()
 | 
						|
	if err := sqlgraph.CreateNode(ctx, src.driver, _spec); err != nil {
 | 
						|
		if sqlgraph.IsConstraintError(err) {
 | 
						|
			err = &ConstraintError{msg: err.Error(), wrap: err}
 | 
						|
		}
 | 
						|
		return nil, err
 | 
						|
	}
 | 
						|
	if _spec.ID.Value != _node.ID {
 | 
						|
		id := _spec.ID.Value.(int64)
 | 
						|
		_node.ID = int(id)
 | 
						|
	}
 | 
						|
	return _node, nil
 | 
						|
}
 | 
						|
 | 
						|
func (src *SupportResponseCreate) createSpec() (*SupportResponse, *sqlgraph.CreateSpec) {
 | 
						|
	var (
 | 
						|
		_node = &SupportResponse{config: src.config}
 | 
						|
		_spec = &sqlgraph.CreateSpec{
 | 
						|
			Table: supportresponse.Table,
 | 
						|
			ID: &sqlgraph.FieldSpec{
 | 
						|
				Type:   field.TypeInt,
 | 
						|
				Column: supportresponse.FieldID,
 | 
						|
			},
 | 
						|
		}
 | 
						|
	)
 | 
						|
	if id, ok := src.mutation.ID(); ok {
 | 
						|
		_node.ID = id
 | 
						|
		_spec.ID.Value = id
 | 
						|
	}
 | 
						|
	if value, ok := src.mutation.Refid(); ok {
 | 
						|
		_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
 | 
						|
			Type:   field.TypeString,
 | 
						|
			Value:  value,
 | 
						|
			Column: supportresponse.FieldRefid,
 | 
						|
		})
 | 
						|
		_node.Refid = value
 | 
						|
	}
 | 
						|
	if value, ok := src.mutation.Writer(); ok {
 | 
						|
		_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
 | 
						|
			Type:   field.TypeString,
 | 
						|
			Value:  value,
 | 
						|
			Column: supportresponse.FieldWriter,
 | 
						|
		})
 | 
						|
		_node.Writer = value
 | 
						|
	}
 | 
						|
	if value, ok := src.mutation.Message(); ok {
 | 
						|
		_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
 | 
						|
			Type:   field.TypeString,
 | 
						|
			Value:  value,
 | 
						|
			Column: supportresponse.FieldMessage,
 | 
						|
		})
 | 
						|
		_node.Message = value
 | 
						|
	}
 | 
						|
	if value, ok := src.mutation.GetType(); ok {
 | 
						|
		_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
 | 
						|
			Type:   field.TypeString,
 | 
						|
			Value:  value,
 | 
						|
			Column: supportresponse.FieldType,
 | 
						|
		})
 | 
						|
		_node.Type = value
 | 
						|
	}
 | 
						|
	if value, ok := src.mutation.Rtcchannel(); ok {
 | 
						|
		_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
 | 
						|
			Type:   field.TypeString,
 | 
						|
			Value:  value,
 | 
						|
			Column: supportresponse.FieldRtcchannel,
 | 
						|
		})
 | 
						|
		_node.Rtcchannel = value
 | 
						|
	}
 | 
						|
	if value, ok := src.mutation.Isread(); ok {
 | 
						|
		_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
 | 
						|
			Type:   field.TypeBool,
 | 
						|
			Value:  value,
 | 
						|
			Column: supportresponse.FieldIsread,
 | 
						|
		})
 | 
						|
		_node.Isread = value
 | 
						|
	}
 | 
						|
	if value, ok := src.mutation.Created(); ok {
 | 
						|
		_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
 | 
						|
			Type:   field.TypeTime,
 | 
						|
			Value:  value,
 | 
						|
			Column: supportresponse.FieldCreated,
 | 
						|
		})
 | 
						|
		_node.Created = value
 | 
						|
	}
 | 
						|
	return _node, _spec
 | 
						|
}
 | 
						|
 | 
						|
// SupportResponseCreateBulk is the builder for creating many SupportResponse entities in bulk.
 | 
						|
type SupportResponseCreateBulk struct {
 | 
						|
	config
 | 
						|
	builders []*SupportResponseCreate
 | 
						|
}
 | 
						|
 | 
						|
// Save creates the SupportResponse entities in the database.
 | 
						|
func (srcb *SupportResponseCreateBulk) Save(ctx context.Context) ([]*SupportResponse, error) {
 | 
						|
	specs := make([]*sqlgraph.CreateSpec, len(srcb.builders))
 | 
						|
	nodes := make([]*SupportResponse, len(srcb.builders))
 | 
						|
	mutators := make([]Mutator, len(srcb.builders))
 | 
						|
	for i := range srcb.builders {
 | 
						|
		func(i int, root context.Context) {
 | 
						|
			builder := srcb.builders[i]
 | 
						|
			var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
 | 
						|
				mutation, ok := m.(*SupportResponseMutation)
 | 
						|
				if !ok {
 | 
						|
					return nil, fmt.Errorf("unexpected mutation type %T", m)
 | 
						|
				}
 | 
						|
				if err := builder.check(); err != nil {
 | 
						|
					return nil, err
 | 
						|
				}
 | 
						|
				builder.mutation = mutation
 | 
						|
				nodes[i], specs[i] = builder.createSpec()
 | 
						|
				var err error
 | 
						|
				if i < len(mutators)-1 {
 | 
						|
					_, err = mutators[i+1].Mutate(root, srcb.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, srcb.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 && nodes[i].ID == 0 {
 | 
						|
					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, srcb.builders[0].mutation); err != nil {
 | 
						|
			return nil, err
 | 
						|
		}
 | 
						|
	}
 | 
						|
	return nodes, nil
 | 
						|
}
 | 
						|
 | 
						|
// SaveX is like Save, but panics if an error occurs.
 | 
						|
func (srcb *SupportResponseCreateBulk) SaveX(ctx context.Context) []*SupportResponse {
 | 
						|
	v, err := srcb.Save(ctx)
 | 
						|
	if err != nil {
 | 
						|
		panic(err)
 | 
						|
	}
 | 
						|
	return v
 | 
						|
}
 | 
						|
 | 
						|
// Exec executes the query.
 | 
						|
func (srcb *SupportResponseCreateBulk) Exec(ctx context.Context) error {
 | 
						|
	_, err := srcb.Save(ctx)
 | 
						|
	return err
 | 
						|
}
 | 
						|
 | 
						|
// ExecX is like Exec, but panics if an error occurs.
 | 
						|
func (srcb *SupportResponseCreateBulk) ExecX(ctx context.Context) {
 | 
						|
	if err := srcb.Exec(ctx); err != nil {
 | 
						|
		panic(err)
 | 
						|
	}
 | 
						|
}
 |