Files
polaris/ent/downloadclients_create.go
2024-07-01 11:35:28 +08:00

404 lines
13 KiB
Go

// Code generated by ent, DO NOT EDIT.
package ent
import (
"context"
"errors"
"fmt"
"polaris/ent/downloadclients"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
)
// DownloadClientsCreate is the builder for creating a DownloadClients entity.
type DownloadClientsCreate struct {
config
mutation *DownloadClientsMutation
hooks []Hook
}
// SetEnable sets the "enable" field.
func (dcc *DownloadClientsCreate) SetEnable(b bool) *DownloadClientsCreate {
dcc.mutation.SetEnable(b)
return dcc
}
// SetName sets the "name" field.
func (dcc *DownloadClientsCreate) SetName(s string) *DownloadClientsCreate {
dcc.mutation.SetName(s)
return dcc
}
// SetImplementation sets the "implementation" field.
func (dcc *DownloadClientsCreate) SetImplementation(s string) *DownloadClientsCreate {
dcc.mutation.SetImplementation(s)
return dcc
}
// SetURL sets the "url" field.
func (dcc *DownloadClientsCreate) SetURL(s string) *DownloadClientsCreate {
dcc.mutation.SetURL(s)
return dcc
}
// SetUser sets the "user" field.
func (dcc *DownloadClientsCreate) SetUser(s string) *DownloadClientsCreate {
dcc.mutation.SetUser(s)
return dcc
}
// SetNillableUser sets the "user" field if the given value is not nil.
func (dcc *DownloadClientsCreate) SetNillableUser(s *string) *DownloadClientsCreate {
if s != nil {
dcc.SetUser(*s)
}
return dcc
}
// SetPassword sets the "password" field.
func (dcc *DownloadClientsCreate) SetPassword(s string) *DownloadClientsCreate {
dcc.mutation.SetPassword(s)
return dcc
}
// SetNillablePassword sets the "password" field if the given value is not nil.
func (dcc *DownloadClientsCreate) SetNillablePassword(s *string) *DownloadClientsCreate {
if s != nil {
dcc.SetPassword(*s)
}
return dcc
}
// SetSettings sets the "settings" field.
func (dcc *DownloadClientsCreate) SetSettings(s string) *DownloadClientsCreate {
dcc.mutation.SetSettings(s)
return dcc
}
// SetNillableSettings sets the "settings" field if the given value is not nil.
func (dcc *DownloadClientsCreate) SetNillableSettings(s *string) *DownloadClientsCreate {
if s != nil {
dcc.SetSettings(*s)
}
return dcc
}
// SetPriority sets the "priority" field.
func (dcc *DownloadClientsCreate) SetPriority(s string) *DownloadClientsCreate {
dcc.mutation.SetPriority(s)
return dcc
}
// SetNillablePriority sets the "priority" field if the given value is not nil.
func (dcc *DownloadClientsCreate) SetNillablePriority(s *string) *DownloadClientsCreate {
if s != nil {
dcc.SetPriority(*s)
}
return dcc
}
// SetRemoveCompletedDownloads sets the "remove_completed_downloads" field.
func (dcc *DownloadClientsCreate) SetRemoveCompletedDownloads(b bool) *DownloadClientsCreate {
dcc.mutation.SetRemoveCompletedDownloads(b)
return dcc
}
// SetNillableRemoveCompletedDownloads sets the "remove_completed_downloads" field if the given value is not nil.
func (dcc *DownloadClientsCreate) SetNillableRemoveCompletedDownloads(b *bool) *DownloadClientsCreate {
if b != nil {
dcc.SetRemoveCompletedDownloads(*b)
}
return dcc
}
// SetRemoveFailedDownloads sets the "remove_failed_downloads" field.
func (dcc *DownloadClientsCreate) SetRemoveFailedDownloads(b bool) *DownloadClientsCreate {
dcc.mutation.SetRemoveFailedDownloads(b)
return dcc
}
// SetNillableRemoveFailedDownloads sets the "remove_failed_downloads" field if the given value is not nil.
func (dcc *DownloadClientsCreate) SetNillableRemoveFailedDownloads(b *bool) *DownloadClientsCreate {
if b != nil {
dcc.SetRemoveFailedDownloads(*b)
}
return dcc
}
// SetTags sets the "tags" field.
func (dcc *DownloadClientsCreate) SetTags(s string) *DownloadClientsCreate {
dcc.mutation.SetTags(s)
return dcc
}
// SetNillableTags sets the "tags" field if the given value is not nil.
func (dcc *DownloadClientsCreate) SetNillableTags(s *string) *DownloadClientsCreate {
if s != nil {
dcc.SetTags(*s)
}
return dcc
}
// Mutation returns the DownloadClientsMutation object of the builder.
func (dcc *DownloadClientsCreate) Mutation() *DownloadClientsMutation {
return dcc.mutation
}
// Save creates the DownloadClients in the database.
func (dcc *DownloadClientsCreate) Save(ctx context.Context) (*DownloadClients, error) {
dcc.defaults()
return withHooks(ctx, dcc.sqlSave, dcc.mutation, dcc.hooks)
}
// SaveX calls Save and panics if Save returns an error.
func (dcc *DownloadClientsCreate) SaveX(ctx context.Context) *DownloadClients {
v, err := dcc.Save(ctx)
if err != nil {
panic(err)
}
return v
}
// Exec executes the query.
func (dcc *DownloadClientsCreate) Exec(ctx context.Context) error {
_, err := dcc.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (dcc *DownloadClientsCreate) ExecX(ctx context.Context) {
if err := dcc.Exec(ctx); err != nil {
panic(err)
}
}
// defaults sets the default values of the builder before save.
func (dcc *DownloadClientsCreate) defaults() {
if _, ok := dcc.mutation.User(); !ok {
v := downloadclients.DefaultUser
dcc.mutation.SetUser(v)
}
if _, ok := dcc.mutation.Password(); !ok {
v := downloadclients.DefaultPassword
dcc.mutation.SetPassword(v)
}
if _, ok := dcc.mutation.Settings(); !ok {
v := downloadclients.DefaultSettings
dcc.mutation.SetSettings(v)
}
if _, ok := dcc.mutation.Priority(); !ok {
v := downloadclients.DefaultPriority
dcc.mutation.SetPriority(v)
}
if _, ok := dcc.mutation.RemoveCompletedDownloads(); !ok {
v := downloadclients.DefaultRemoveCompletedDownloads
dcc.mutation.SetRemoveCompletedDownloads(v)
}
if _, ok := dcc.mutation.RemoveFailedDownloads(); !ok {
v := downloadclients.DefaultRemoveFailedDownloads
dcc.mutation.SetRemoveFailedDownloads(v)
}
if _, ok := dcc.mutation.Tags(); !ok {
v := downloadclients.DefaultTags
dcc.mutation.SetTags(v)
}
}
// check runs all checks and user-defined validators on the builder.
func (dcc *DownloadClientsCreate) check() error {
if _, ok := dcc.mutation.Enable(); !ok {
return &ValidationError{Name: "enable", err: errors.New(`ent: missing required field "DownloadClients.enable"`)}
}
if _, ok := dcc.mutation.Name(); !ok {
return &ValidationError{Name: "name", err: errors.New(`ent: missing required field "DownloadClients.name"`)}
}
if _, ok := dcc.mutation.Implementation(); !ok {
return &ValidationError{Name: "implementation", err: errors.New(`ent: missing required field "DownloadClients.implementation"`)}
}
if _, ok := dcc.mutation.URL(); !ok {
return &ValidationError{Name: "url", err: errors.New(`ent: missing required field "DownloadClients.url"`)}
}
if _, ok := dcc.mutation.User(); !ok {
return &ValidationError{Name: "user", err: errors.New(`ent: missing required field "DownloadClients.user"`)}
}
if _, ok := dcc.mutation.Password(); !ok {
return &ValidationError{Name: "password", err: errors.New(`ent: missing required field "DownloadClients.password"`)}
}
if _, ok := dcc.mutation.Settings(); !ok {
return &ValidationError{Name: "settings", err: errors.New(`ent: missing required field "DownloadClients.settings"`)}
}
if _, ok := dcc.mutation.Priority(); !ok {
return &ValidationError{Name: "priority", err: errors.New(`ent: missing required field "DownloadClients.priority"`)}
}
if _, ok := dcc.mutation.RemoveCompletedDownloads(); !ok {
return &ValidationError{Name: "remove_completed_downloads", err: errors.New(`ent: missing required field "DownloadClients.remove_completed_downloads"`)}
}
if _, ok := dcc.mutation.RemoveFailedDownloads(); !ok {
return &ValidationError{Name: "remove_failed_downloads", err: errors.New(`ent: missing required field "DownloadClients.remove_failed_downloads"`)}
}
if _, ok := dcc.mutation.Tags(); !ok {
return &ValidationError{Name: "tags", err: errors.New(`ent: missing required field "DownloadClients.tags"`)}
}
return nil
}
func (dcc *DownloadClientsCreate) sqlSave(ctx context.Context) (*DownloadClients, error) {
if err := dcc.check(); err != nil {
return nil, err
}
_node, _spec := dcc.createSpec()
if err := sqlgraph.CreateNode(ctx, dcc.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)
dcc.mutation.id = &_node.ID
dcc.mutation.done = true
return _node, nil
}
func (dcc *DownloadClientsCreate) createSpec() (*DownloadClients, *sqlgraph.CreateSpec) {
var (
_node = &DownloadClients{config: dcc.config}
_spec = sqlgraph.NewCreateSpec(downloadclients.Table, sqlgraph.NewFieldSpec(downloadclients.FieldID, field.TypeInt))
)
if value, ok := dcc.mutation.Enable(); ok {
_spec.SetField(downloadclients.FieldEnable, field.TypeBool, value)
_node.Enable = value
}
if value, ok := dcc.mutation.Name(); ok {
_spec.SetField(downloadclients.FieldName, field.TypeString, value)
_node.Name = value
}
if value, ok := dcc.mutation.Implementation(); ok {
_spec.SetField(downloadclients.FieldImplementation, field.TypeString, value)
_node.Implementation = value
}
if value, ok := dcc.mutation.URL(); ok {
_spec.SetField(downloadclients.FieldURL, field.TypeString, value)
_node.URL = value
}
if value, ok := dcc.mutation.User(); ok {
_spec.SetField(downloadclients.FieldUser, field.TypeString, value)
_node.User = value
}
if value, ok := dcc.mutation.Password(); ok {
_spec.SetField(downloadclients.FieldPassword, field.TypeString, value)
_node.Password = value
}
if value, ok := dcc.mutation.Settings(); ok {
_spec.SetField(downloadclients.FieldSettings, field.TypeString, value)
_node.Settings = value
}
if value, ok := dcc.mutation.Priority(); ok {
_spec.SetField(downloadclients.FieldPriority, field.TypeString, value)
_node.Priority = value
}
if value, ok := dcc.mutation.RemoveCompletedDownloads(); ok {
_spec.SetField(downloadclients.FieldRemoveCompletedDownloads, field.TypeBool, value)
_node.RemoveCompletedDownloads = value
}
if value, ok := dcc.mutation.RemoveFailedDownloads(); ok {
_spec.SetField(downloadclients.FieldRemoveFailedDownloads, field.TypeBool, value)
_node.RemoveFailedDownloads = value
}
if value, ok := dcc.mutation.Tags(); ok {
_spec.SetField(downloadclients.FieldTags, field.TypeString, value)
_node.Tags = value
}
return _node, _spec
}
// DownloadClientsCreateBulk is the builder for creating many DownloadClients entities in bulk.
type DownloadClientsCreateBulk struct {
config
err error
builders []*DownloadClientsCreate
}
// Save creates the DownloadClients entities in the database.
func (dccb *DownloadClientsCreateBulk) Save(ctx context.Context) ([]*DownloadClients, error) {
if dccb.err != nil {
return nil, dccb.err
}
specs := make([]*sqlgraph.CreateSpec, len(dccb.builders))
nodes := make([]*DownloadClients, len(dccb.builders))
mutators := make([]Mutator, len(dccb.builders))
for i := range dccb.builders {
func(i int, root context.Context) {
builder := dccb.builders[i]
builder.defaults()
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
mutation, ok := m.(*DownloadClientsMutation)
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, dccb.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, dccb.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, dccb.builders[0].mutation); err != nil {
return nil, err
}
}
return nodes, nil
}
// SaveX is like Save, but panics if an error occurs.
func (dccb *DownloadClientsCreateBulk) SaveX(ctx context.Context) []*DownloadClients {
v, err := dccb.Save(ctx)
if err != nil {
panic(err)
}
return v
}
// Exec executes the query.
func (dccb *DownloadClientsCreateBulk) Exec(ctx context.Context) error {
_, err := dccb.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (dccb *DownloadClientsCreateBulk) ExecX(ctx context.Context) {
if err := dccb.Exec(ctx); err != nil {
panic(err)
}
}