first draft version

This commit is contained in:
Simon Ding
2024-06-22 17:15:24 +08:00
parent be0dc4a466
commit ab8e653c5b
63 changed files with 15137 additions and 17 deletions

View File

@@ -0,0 +1,274 @@
// 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
}
// SetSettings sets the "settings" field.
func (dcc *DownloadClientsCreate) SetSettings(s string) *DownloadClientsCreate {
dcc.mutation.SetSettings(s)
return dcc
}
// SetPriority sets the "priority" field.
func (dcc *DownloadClientsCreate) SetPriority(s string) *DownloadClientsCreate {
dcc.mutation.SetPriority(s)
return dcc
}
// SetRemoveCompletedDownloads sets the "remove_completed_downloads" field.
func (dcc *DownloadClientsCreate) SetRemoveCompletedDownloads(b bool) *DownloadClientsCreate {
dcc.mutation.SetRemoveCompletedDownloads(b)
return dcc
}
// SetRemoveFailedDownloads sets the "remove_failed_downloads" field.
func (dcc *DownloadClientsCreate) SetRemoveFailedDownloads(b bool) *DownloadClientsCreate {
dcc.mutation.SetRemoveFailedDownloads(b)
return dcc
}
// SetTags sets the "tags" field.
func (dcc *DownloadClientsCreate) SetTags(s string) *DownloadClientsCreate {
dcc.mutation.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) {
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)
}
}
// 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.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.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]
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)
}
}