445 lines
14 KiB
Go
445 lines
14 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"
|
|
)
|
|
|
|
// CloudflareR2Create is the builder for creating a CloudflareR2 entity.
|
|
type CloudflareR2Create struct {
|
|
config
|
|
mutation *CloudflareR2Mutation
|
|
hooks []Hook
|
|
}
|
|
|
|
// SetOwnerID sets the "owner_id" field.
|
|
func (cr *CloudflareR2Create) SetOwnerID(s string) *CloudflareR2Create {
|
|
cr.mutation.SetOwnerID(s)
|
|
return cr
|
|
}
|
|
|
|
// SetName sets the "name" field.
|
|
func (cr *CloudflareR2Create) SetName(s string) *CloudflareR2Create {
|
|
cr.mutation.SetName(s)
|
|
return cr
|
|
}
|
|
|
|
// SetLocation sets the "location" field.
|
|
func (cr *CloudflareR2Create) SetLocation(s string) *CloudflareR2Create {
|
|
cr.mutation.SetLocation(s)
|
|
return cr
|
|
}
|
|
|
|
// SetStorageClass sets the "storage_class" field.
|
|
func (cr *CloudflareR2Create) SetStorageClass(s string) *CloudflareR2Create {
|
|
cr.mutation.SetStorageClass(s)
|
|
return cr
|
|
}
|
|
|
|
// SetStatus sets the "status" field.
|
|
func (cr *CloudflareR2Create) SetStatus(i int8) *CloudflareR2Create {
|
|
cr.mutation.SetStatus(i)
|
|
return cr
|
|
}
|
|
|
|
// SetNillableStatus sets the "status" field if the given value is not nil.
|
|
func (cr *CloudflareR2Create) SetNillableStatus(i *int8) *CloudflareR2Create {
|
|
if i != nil {
|
|
cr.SetStatus(*i)
|
|
}
|
|
return cr
|
|
}
|
|
|
|
// SetPayloadSize sets the "payload_size" field.
|
|
func (cr *CloudflareR2Create) SetPayloadSize(i int64) *CloudflareR2Create {
|
|
cr.mutation.SetPayloadSize(i)
|
|
return cr
|
|
}
|
|
|
|
// SetNillablePayloadSize sets the "payload_size" field if the given value is not nil.
|
|
func (cr *CloudflareR2Create) SetNillablePayloadSize(i *int64) *CloudflareR2Create {
|
|
if i != nil {
|
|
cr.SetPayloadSize(*i)
|
|
}
|
|
return cr
|
|
}
|
|
|
|
// SetMetadataSize sets the "metadata_size" field.
|
|
func (cr *CloudflareR2Create) SetMetadataSize(i int64) *CloudflareR2Create {
|
|
cr.mutation.SetMetadataSize(i)
|
|
return cr
|
|
}
|
|
|
|
// SetNillableMetadataSize sets the "metadata_size" field if the given value is not nil.
|
|
func (cr *CloudflareR2Create) SetNillableMetadataSize(i *int64) *CloudflareR2Create {
|
|
if i != nil {
|
|
cr.SetMetadataSize(*i)
|
|
}
|
|
return cr
|
|
}
|
|
|
|
// SetObjectCount sets the "object_count" field.
|
|
func (cr *CloudflareR2Create) SetObjectCount(i int) *CloudflareR2Create {
|
|
cr.mutation.SetObjectCount(i)
|
|
return cr
|
|
}
|
|
|
|
// SetNillableObjectCount sets the "object_count" field if the given value is not nil.
|
|
func (cr *CloudflareR2Create) SetNillableObjectCount(i *int) *CloudflareR2Create {
|
|
if i != nil {
|
|
cr.SetObjectCount(*i)
|
|
}
|
|
return cr
|
|
}
|
|
|
|
// SetRemark sets the "remark" field.
|
|
func (cr *CloudflareR2Create) SetRemark(s string) *CloudflareR2Create {
|
|
cr.mutation.SetRemark(s)
|
|
return cr
|
|
}
|
|
|
|
// SetNillableRemark sets the "remark" field if the given value is not nil.
|
|
func (cr *CloudflareR2Create) SetNillableRemark(s *string) *CloudflareR2Create {
|
|
if s != nil {
|
|
cr.SetRemark(*s)
|
|
}
|
|
return cr
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (cr *CloudflareR2Create) SetCreatedAt(t time.Time) *CloudflareR2Create {
|
|
cr.mutation.SetCreatedAt(t)
|
|
return cr
|
|
}
|
|
|
|
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
|
func (cr *CloudflareR2Create) SetNillableCreatedAt(t *time.Time) *CloudflareR2Create {
|
|
if t != nil {
|
|
cr.SetCreatedAt(*t)
|
|
}
|
|
return cr
|
|
}
|
|
|
|
// SetUpdatedAt sets the "updated_at" field.
|
|
func (cr *CloudflareR2Create) SetUpdatedAt(t time.Time) *CloudflareR2Create {
|
|
cr.mutation.SetUpdatedAt(t)
|
|
return cr
|
|
}
|
|
|
|
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
|
|
func (cr *CloudflareR2Create) SetNillableUpdatedAt(t *time.Time) *CloudflareR2Create {
|
|
if t != nil {
|
|
cr.SetUpdatedAt(*t)
|
|
}
|
|
return cr
|
|
}
|
|
|
|
// SetCloudflareAccountID sets the "cloudflare_account" edge to the CloudflareAccounts entity by ID.
|
|
func (cr *CloudflareR2Create) SetCloudflareAccountID(id int) *CloudflareR2Create {
|
|
cr.mutation.SetCloudflareAccountID(id)
|
|
return cr
|
|
}
|
|
|
|
// SetCloudflareAccount sets the "cloudflare_account" edge to the CloudflareAccounts entity.
|
|
func (cr *CloudflareR2Create) SetCloudflareAccount(c *CloudflareAccounts) *CloudflareR2Create {
|
|
return cr.SetCloudflareAccountID(c.ID)
|
|
}
|
|
|
|
// Mutation returns the CloudflareR2Mutation object of the builder.
|
|
func (cr *CloudflareR2Create) Mutation() *CloudflareR2Mutation {
|
|
return cr.mutation
|
|
}
|
|
|
|
// Save creates the CloudflareR2 in the database.
|
|
func (cr *CloudflareR2Create) Save(ctx context.Context) (*CloudflareR2, error) {
|
|
cr.defaults()
|
|
return withHooks(ctx, cr.sqlSave, cr.mutation, cr.hooks)
|
|
}
|
|
|
|
// SaveX calls Save and panics if Save returns an error.
|
|
func (cr *CloudflareR2Create) SaveX(ctx context.Context) *CloudflareR2 {
|
|
v, err := cr.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return v
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (cr *CloudflareR2Create) Exec(ctx context.Context) error {
|
|
_, err := cr.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (cr *CloudflareR2Create) ExecX(ctx context.Context) {
|
|
if err := cr.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
// defaults sets the default values of the builder before save.
|
|
func (cr *CloudflareR2Create) defaults() {
|
|
if _, ok := cr.mutation.Status(); !ok {
|
|
v := cloudflarer2.DefaultStatus
|
|
cr.mutation.SetStatus(v)
|
|
}
|
|
if _, ok := cr.mutation.PayloadSize(); !ok {
|
|
v := cloudflarer2.DefaultPayloadSize
|
|
cr.mutation.SetPayloadSize(v)
|
|
}
|
|
if _, ok := cr.mutation.MetadataSize(); !ok {
|
|
v := cloudflarer2.DefaultMetadataSize
|
|
cr.mutation.SetMetadataSize(v)
|
|
}
|
|
if _, ok := cr.mutation.ObjectCount(); !ok {
|
|
v := cloudflarer2.DefaultObjectCount
|
|
cr.mutation.SetObjectCount(v)
|
|
}
|
|
if _, ok := cr.mutation.CreatedAt(); !ok {
|
|
v := cloudflarer2.DefaultCreatedAt()
|
|
cr.mutation.SetCreatedAt(v)
|
|
}
|
|
if _, ok := cr.mutation.UpdatedAt(); !ok {
|
|
v := cloudflarer2.DefaultUpdatedAt()
|
|
cr.mutation.SetUpdatedAt(v)
|
|
}
|
|
}
|
|
|
|
// check runs all checks and user-defined validators on the builder.
|
|
func (cr *CloudflareR2Create) check() error {
|
|
if _, ok := cr.mutation.OwnerID(); !ok {
|
|
return &ValidationError{Name: "owner_id", err: errors.New(`ent: missing required field "CloudflareR2.owner_id"`)}
|
|
}
|
|
if _, ok := cr.mutation.Name(); !ok {
|
|
return &ValidationError{Name: "name", err: errors.New(`ent: missing required field "CloudflareR2.name"`)}
|
|
}
|
|
if v, ok := cr.mutation.Name(); ok {
|
|
if err := cloudflarer2.NameValidator(v); err != nil {
|
|
return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "CloudflareR2.name": %w`, err)}
|
|
}
|
|
}
|
|
if _, ok := cr.mutation.Location(); !ok {
|
|
return &ValidationError{Name: "location", err: errors.New(`ent: missing required field "CloudflareR2.location"`)}
|
|
}
|
|
if v, ok := cr.mutation.Location(); ok {
|
|
if err := cloudflarer2.LocationValidator(v); err != nil {
|
|
return &ValidationError{Name: "location", err: fmt.Errorf(`ent: validator failed for field "CloudflareR2.location": %w`, err)}
|
|
}
|
|
}
|
|
if _, ok := cr.mutation.StorageClass(); !ok {
|
|
return &ValidationError{Name: "storage_class", err: errors.New(`ent: missing required field "CloudflareR2.storage_class"`)}
|
|
}
|
|
if v, ok := cr.mutation.StorageClass(); ok {
|
|
if err := cloudflarer2.StorageClassValidator(v); err != nil {
|
|
return &ValidationError{Name: "storage_class", err: fmt.Errorf(`ent: validator failed for field "CloudflareR2.storage_class": %w`, err)}
|
|
}
|
|
}
|
|
if _, ok := cr.mutation.Status(); !ok {
|
|
return &ValidationError{Name: "status", err: errors.New(`ent: missing required field "CloudflareR2.status"`)}
|
|
}
|
|
if _, ok := cr.mutation.PayloadSize(); !ok {
|
|
return &ValidationError{Name: "payload_size", err: errors.New(`ent: missing required field "CloudflareR2.payload_size"`)}
|
|
}
|
|
if _, ok := cr.mutation.MetadataSize(); !ok {
|
|
return &ValidationError{Name: "metadata_size", err: errors.New(`ent: missing required field "CloudflareR2.metadata_size"`)}
|
|
}
|
|
if _, ok := cr.mutation.ObjectCount(); !ok {
|
|
return &ValidationError{Name: "object_count", err: errors.New(`ent: missing required field "CloudflareR2.object_count"`)}
|
|
}
|
|
if _, ok := cr.mutation.CreatedAt(); !ok {
|
|
return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "CloudflareR2.created_at"`)}
|
|
}
|
|
if _, ok := cr.mutation.UpdatedAt(); !ok {
|
|
return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "CloudflareR2.updated_at"`)}
|
|
}
|
|
if len(cr.mutation.CloudflareAccountIDs()) == 0 {
|
|
return &ValidationError{Name: "cloudflare_account", err: errors.New(`ent: missing required edge "CloudflareR2.cloudflare_account"`)}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (cr *CloudflareR2Create) sqlSave(ctx context.Context) (*CloudflareR2, error) {
|
|
if err := cr.check(); err != nil {
|
|
return nil, err
|
|
}
|
|
_node, _spec := cr.createSpec()
|
|
if err := sqlgraph.CreateNode(ctx, cr.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)
|
|
cr.mutation.id = &_node.ID
|
|
cr.mutation.done = true
|
|
return _node, nil
|
|
}
|
|
|
|
func (cr *CloudflareR2Create) createSpec() (*CloudflareR2, *sqlgraph.CreateSpec) {
|
|
var (
|
|
_node = &CloudflareR2{config: cr.config}
|
|
_spec = sqlgraph.NewCreateSpec(cloudflarer2.Table, sqlgraph.NewFieldSpec(cloudflarer2.FieldID, field.TypeInt))
|
|
)
|
|
if value, ok := cr.mutation.OwnerID(); ok {
|
|
_spec.SetField(cloudflarer2.FieldOwnerID, field.TypeString, value)
|
|
_node.OwnerID = value
|
|
}
|
|
if value, ok := cr.mutation.Name(); ok {
|
|
_spec.SetField(cloudflarer2.FieldName, field.TypeString, value)
|
|
_node.Name = value
|
|
}
|
|
if value, ok := cr.mutation.Location(); ok {
|
|
_spec.SetField(cloudflarer2.FieldLocation, field.TypeString, value)
|
|
_node.Location = value
|
|
}
|
|
if value, ok := cr.mutation.StorageClass(); ok {
|
|
_spec.SetField(cloudflarer2.FieldStorageClass, field.TypeString, value)
|
|
_node.StorageClass = value
|
|
}
|
|
if value, ok := cr.mutation.Status(); ok {
|
|
_spec.SetField(cloudflarer2.FieldStatus, field.TypeInt8, value)
|
|
_node.Status = value
|
|
}
|
|
if value, ok := cr.mutation.PayloadSize(); ok {
|
|
_spec.SetField(cloudflarer2.FieldPayloadSize, field.TypeInt64, value)
|
|
_node.PayloadSize = value
|
|
}
|
|
if value, ok := cr.mutation.MetadataSize(); ok {
|
|
_spec.SetField(cloudflarer2.FieldMetadataSize, field.TypeInt64, value)
|
|
_node.MetadataSize = value
|
|
}
|
|
if value, ok := cr.mutation.ObjectCount(); ok {
|
|
_spec.SetField(cloudflarer2.FieldObjectCount, field.TypeInt, value)
|
|
_node.ObjectCount = value
|
|
}
|
|
if value, ok := cr.mutation.Remark(); ok {
|
|
_spec.SetField(cloudflarer2.FieldRemark, field.TypeString, value)
|
|
_node.Remark = value
|
|
}
|
|
if value, ok := cr.mutation.CreatedAt(); ok {
|
|
_spec.SetField(cloudflarer2.FieldCreatedAt, field.TypeTime, value)
|
|
_node.CreatedAt = value
|
|
}
|
|
if value, ok := cr.mutation.UpdatedAt(); ok {
|
|
_spec.SetField(cloudflarer2.FieldUpdatedAt, field.TypeTime, value)
|
|
_node.UpdatedAt = value
|
|
}
|
|
if nodes := cr.mutation.CloudflareAccountIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: true,
|
|
Table: cloudflarer2.CloudflareAccountTable,
|
|
Columns: []string{cloudflarer2.CloudflareAccountColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(cloudflareaccounts.FieldID, field.TypeInt),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_node.cloudflare_accounts_cloudflare_buckets = &nodes[0]
|
|
_spec.Edges = append(_spec.Edges, edge)
|
|
}
|
|
return _node, _spec
|
|
}
|
|
|
|
// CloudflareR2CreateBulk is the builder for creating many CloudflareR2 entities in bulk.
|
|
type CloudflareR2CreateBulk struct {
|
|
config
|
|
err error
|
|
builders []*CloudflareR2Create
|
|
}
|
|
|
|
// Save creates the CloudflareR2 entities in the database.
|
|
func (crb *CloudflareR2CreateBulk) Save(ctx context.Context) ([]*CloudflareR2, error) {
|
|
if crb.err != nil {
|
|
return nil, crb.err
|
|
}
|
|
specs := make([]*sqlgraph.CreateSpec, len(crb.builders))
|
|
nodes := make([]*CloudflareR2, len(crb.builders))
|
|
mutators := make([]Mutator, len(crb.builders))
|
|
for i := range crb.builders {
|
|
func(i int, root context.Context) {
|
|
builder := crb.builders[i]
|
|
builder.defaults()
|
|
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
|
mutation, ok := m.(*CloudflareR2Mutation)
|
|
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, crb.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, crb.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, crb.builders[0].mutation); err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
return nodes, nil
|
|
}
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
func (crb *CloudflareR2CreateBulk) SaveX(ctx context.Context) []*CloudflareR2 {
|
|
v, err := crb.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return v
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (crb *CloudflareR2CreateBulk) Exec(ctx context.Context) error {
|
|
_, err := crb.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (crb *CloudflareR2CreateBulk) ExecX(ctx context.Context) {
|
|
if err := crb.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|