370 lines
11 KiB
Go
370 lines
11 KiB
Go
// Code generated by ent, DO NOT EDIT.
|
|
|
|
package ent
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
"time"
|
|
"unR2/internal/ent/cloudflareaccounts"
|
|
"unR2/internal/ent/cloudflarer2"
|
|
|
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
|
"entgo.io/ent/schema/field"
|
|
)
|
|
|
|
// CloudflareAccountsCreate is the builder for creating a CloudflareAccounts entity.
|
|
type CloudflareAccountsCreate struct {
|
|
config
|
|
mutation *CloudflareAccountsMutation
|
|
hooks []Hook
|
|
}
|
|
|
|
// SetName sets the "name" field.
|
|
func (cac *CloudflareAccountsCreate) SetName(s string) *CloudflareAccountsCreate {
|
|
cac.mutation.SetName(s)
|
|
return cac
|
|
}
|
|
|
|
// SetAccountID sets the "account_id" field.
|
|
func (cac *CloudflareAccountsCreate) SetAccountID(s string) *CloudflareAccountsCreate {
|
|
cac.mutation.SetAccountID(s)
|
|
return cac
|
|
}
|
|
|
|
// SetAPIToken sets the "api_token" field.
|
|
func (cac *CloudflareAccountsCreate) SetAPIToken(s string) *CloudflareAccountsCreate {
|
|
cac.mutation.SetAPIToken(s)
|
|
return cac
|
|
}
|
|
|
|
// SetEmail sets the "email" field.
|
|
func (cac *CloudflareAccountsCreate) SetEmail(s string) *CloudflareAccountsCreate {
|
|
cac.mutation.SetEmail(s)
|
|
return cac
|
|
}
|
|
|
|
// SetNillableEmail sets the "email" field if the given value is not nil.
|
|
func (cac *CloudflareAccountsCreate) SetNillableEmail(s *string) *CloudflareAccountsCreate {
|
|
if s != nil {
|
|
cac.SetEmail(*s)
|
|
}
|
|
return cac
|
|
}
|
|
|
|
// SetStatus sets the "status" field.
|
|
func (cac *CloudflareAccountsCreate) SetStatus(i int8) *CloudflareAccountsCreate {
|
|
cac.mutation.SetStatus(i)
|
|
return cac
|
|
}
|
|
|
|
// SetNillableStatus sets the "status" field if the given value is not nil.
|
|
func (cac *CloudflareAccountsCreate) SetNillableStatus(i *int8) *CloudflareAccountsCreate {
|
|
if i != nil {
|
|
cac.SetStatus(*i)
|
|
}
|
|
return cac
|
|
}
|
|
|
|
// SetRemark sets the "remark" field.
|
|
func (cac *CloudflareAccountsCreate) SetRemark(s string) *CloudflareAccountsCreate {
|
|
cac.mutation.SetRemark(s)
|
|
return cac
|
|
}
|
|
|
|
// SetNillableRemark sets the "remark" field if the given value is not nil.
|
|
func (cac *CloudflareAccountsCreate) SetNillableRemark(s *string) *CloudflareAccountsCreate {
|
|
if s != nil {
|
|
cac.SetRemark(*s)
|
|
}
|
|
return cac
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (cac *CloudflareAccountsCreate) SetCreatedAt(t time.Time) *CloudflareAccountsCreate {
|
|
cac.mutation.SetCreatedAt(t)
|
|
return cac
|
|
}
|
|
|
|
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
|
func (cac *CloudflareAccountsCreate) SetNillableCreatedAt(t *time.Time) *CloudflareAccountsCreate {
|
|
if t != nil {
|
|
cac.SetCreatedAt(*t)
|
|
}
|
|
return cac
|
|
}
|
|
|
|
// SetUpdatedAt sets the "updated_at" field.
|
|
func (cac *CloudflareAccountsCreate) SetUpdatedAt(t time.Time) *CloudflareAccountsCreate {
|
|
cac.mutation.SetUpdatedAt(t)
|
|
return cac
|
|
}
|
|
|
|
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
|
|
func (cac *CloudflareAccountsCreate) SetNillableUpdatedAt(t *time.Time) *CloudflareAccountsCreate {
|
|
if t != nil {
|
|
cac.SetUpdatedAt(*t)
|
|
}
|
|
return cac
|
|
}
|
|
|
|
// AddCloudflareBucketIDs adds the "cloudflare_buckets" edge to the CloudflareR2 entity by IDs.
|
|
func (cac *CloudflareAccountsCreate) AddCloudflareBucketIDs(ids ...int) *CloudflareAccountsCreate {
|
|
cac.mutation.AddCloudflareBucketIDs(ids...)
|
|
return cac
|
|
}
|
|
|
|
// AddCloudflareBuckets adds the "cloudflare_buckets" edges to the CloudflareR2 entity.
|
|
func (cac *CloudflareAccountsCreate) AddCloudflareBuckets(c ...*CloudflareR2) *CloudflareAccountsCreate {
|
|
ids := make([]int, len(c))
|
|
for i := range c {
|
|
ids[i] = c[i].ID
|
|
}
|
|
return cac.AddCloudflareBucketIDs(ids...)
|
|
}
|
|
|
|
// Mutation returns the CloudflareAccountsMutation object of the builder.
|
|
func (cac *CloudflareAccountsCreate) Mutation() *CloudflareAccountsMutation {
|
|
return cac.mutation
|
|
}
|
|
|
|
// Save creates the CloudflareAccounts in the database.
|
|
func (cac *CloudflareAccountsCreate) Save(ctx context.Context) (*CloudflareAccounts, error) {
|
|
cac.defaults()
|
|
return withHooks(ctx, cac.sqlSave, cac.mutation, cac.hooks)
|
|
}
|
|
|
|
// SaveX calls Save and panics if Save returns an error.
|
|
func (cac *CloudflareAccountsCreate) SaveX(ctx context.Context) *CloudflareAccounts {
|
|
v, err := cac.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return v
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (cac *CloudflareAccountsCreate) Exec(ctx context.Context) error {
|
|
_, err := cac.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (cac *CloudflareAccountsCreate) ExecX(ctx context.Context) {
|
|
if err := cac.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
// defaults sets the default values of the builder before save.
|
|
func (cac *CloudflareAccountsCreate) defaults() {
|
|
if _, ok := cac.mutation.Status(); !ok {
|
|
v := cloudflareaccounts.DefaultStatus
|
|
cac.mutation.SetStatus(v)
|
|
}
|
|
if _, ok := cac.mutation.CreatedAt(); !ok {
|
|
v := cloudflareaccounts.DefaultCreatedAt()
|
|
cac.mutation.SetCreatedAt(v)
|
|
}
|
|
if _, ok := cac.mutation.UpdatedAt(); !ok {
|
|
v := cloudflareaccounts.DefaultUpdatedAt()
|
|
cac.mutation.SetUpdatedAt(v)
|
|
}
|
|
}
|
|
|
|
// check runs all checks and user-defined validators on the builder.
|
|
func (cac *CloudflareAccountsCreate) check() error {
|
|
if _, ok := cac.mutation.Name(); !ok {
|
|
return &ValidationError{Name: "name", err: errors.New(`ent: missing required field "CloudflareAccounts.name"`)}
|
|
}
|
|
if v, ok := cac.mutation.Name(); ok {
|
|
if err := cloudflareaccounts.NameValidator(v); err != nil {
|
|
return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "CloudflareAccounts.name": %w`, err)}
|
|
}
|
|
}
|
|
if _, ok := cac.mutation.AccountID(); !ok {
|
|
return &ValidationError{Name: "account_id", err: errors.New(`ent: missing required field "CloudflareAccounts.account_id"`)}
|
|
}
|
|
if v, ok := cac.mutation.AccountID(); ok {
|
|
if err := cloudflareaccounts.AccountIDValidator(v); err != nil {
|
|
return &ValidationError{Name: "account_id", err: fmt.Errorf(`ent: validator failed for field "CloudflareAccounts.account_id": %w`, err)}
|
|
}
|
|
}
|
|
if _, ok := cac.mutation.APIToken(); !ok {
|
|
return &ValidationError{Name: "api_token", err: errors.New(`ent: missing required field "CloudflareAccounts.api_token"`)}
|
|
}
|
|
if _, ok := cac.mutation.Status(); !ok {
|
|
return &ValidationError{Name: "status", err: errors.New(`ent: missing required field "CloudflareAccounts.status"`)}
|
|
}
|
|
if _, ok := cac.mutation.CreatedAt(); !ok {
|
|
return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "CloudflareAccounts.created_at"`)}
|
|
}
|
|
if _, ok := cac.mutation.UpdatedAt(); !ok {
|
|
return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "CloudflareAccounts.updated_at"`)}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (cac *CloudflareAccountsCreate) sqlSave(ctx context.Context) (*CloudflareAccounts, error) {
|
|
if err := cac.check(); err != nil {
|
|
return nil, err
|
|
}
|
|
_node, _spec := cac.createSpec()
|
|
if err := sqlgraph.CreateNode(ctx, cac.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)
|
|
cac.mutation.id = &_node.ID
|
|
cac.mutation.done = true
|
|
return _node, nil
|
|
}
|
|
|
|
func (cac *CloudflareAccountsCreate) createSpec() (*CloudflareAccounts, *sqlgraph.CreateSpec) {
|
|
var (
|
|
_node = &CloudflareAccounts{config: cac.config}
|
|
_spec = sqlgraph.NewCreateSpec(cloudflareaccounts.Table, sqlgraph.NewFieldSpec(cloudflareaccounts.FieldID, field.TypeInt))
|
|
)
|
|
if value, ok := cac.mutation.Name(); ok {
|
|
_spec.SetField(cloudflareaccounts.FieldName, field.TypeString, value)
|
|
_node.Name = value
|
|
}
|
|
if value, ok := cac.mutation.AccountID(); ok {
|
|
_spec.SetField(cloudflareaccounts.FieldAccountID, field.TypeString, value)
|
|
_node.AccountID = value
|
|
}
|
|
if value, ok := cac.mutation.APIToken(); ok {
|
|
_spec.SetField(cloudflareaccounts.FieldAPIToken, field.TypeString, value)
|
|
_node.APIToken = value
|
|
}
|
|
if value, ok := cac.mutation.Email(); ok {
|
|
_spec.SetField(cloudflareaccounts.FieldEmail, field.TypeString, value)
|
|
_node.Email = value
|
|
}
|
|
if value, ok := cac.mutation.Status(); ok {
|
|
_spec.SetField(cloudflareaccounts.FieldStatus, field.TypeInt8, value)
|
|
_node.Status = value
|
|
}
|
|
if value, ok := cac.mutation.Remark(); ok {
|
|
_spec.SetField(cloudflareaccounts.FieldRemark, field.TypeString, value)
|
|
_node.Remark = value
|
|
}
|
|
if value, ok := cac.mutation.CreatedAt(); ok {
|
|
_spec.SetField(cloudflareaccounts.FieldCreatedAt, field.TypeTime, value)
|
|
_node.CreatedAt = value
|
|
}
|
|
if value, ok := cac.mutation.UpdatedAt(); ok {
|
|
_spec.SetField(cloudflareaccounts.FieldUpdatedAt, field.TypeTime, value)
|
|
_node.UpdatedAt = value
|
|
}
|
|
if nodes := cac.mutation.CloudflareBucketsIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: false,
|
|
Table: cloudflareaccounts.CloudflareBucketsTable,
|
|
Columns: []string{cloudflareaccounts.CloudflareBucketsColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(cloudflarer2.FieldID, field.TypeInt),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_spec.Edges = append(_spec.Edges, edge)
|
|
}
|
|
return _node, _spec
|
|
}
|
|
|
|
// CloudflareAccountsCreateBulk is the builder for creating many CloudflareAccounts entities in bulk.
|
|
type CloudflareAccountsCreateBulk struct {
|
|
config
|
|
err error
|
|
builders []*CloudflareAccountsCreate
|
|
}
|
|
|
|
// Save creates the CloudflareAccounts entities in the database.
|
|
func (cacb *CloudflareAccountsCreateBulk) Save(ctx context.Context) ([]*CloudflareAccounts, error) {
|
|
if cacb.err != nil {
|
|
return nil, cacb.err
|
|
}
|
|
specs := make([]*sqlgraph.CreateSpec, len(cacb.builders))
|
|
nodes := make([]*CloudflareAccounts, len(cacb.builders))
|
|
mutators := make([]Mutator, len(cacb.builders))
|
|
for i := range cacb.builders {
|
|
func(i int, root context.Context) {
|
|
builder := cacb.builders[i]
|
|
builder.defaults()
|
|
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
|
mutation, ok := m.(*CloudflareAccountsMutation)
|
|
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, cacb.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, cacb.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, cacb.builders[0].mutation); err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
return nodes, nil
|
|
}
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
func (cacb *CloudflareAccountsCreateBulk) SaveX(ctx context.Context) []*CloudflareAccounts {
|
|
v, err := cacb.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return v
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (cacb *CloudflareAccountsCreateBulk) Exec(ctx context.Context) error {
|
|
_, err := cacb.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (cacb *CloudflareAccountsCreateBulk) ExecX(ctx context.Context) {
|
|
if err := cacb.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|