feat: initial commit - kratos admin service
This commit is contained in:
Generated
+859
@@ -0,0 +1,859 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
"kra/internal/data/ent/admin"
|
||||
)
|
||||
|
||||
// AdminCreate is the builder for creating a Admin entity.
|
||||
type AdminCreate struct {
|
||||
config
|
||||
mutation *AdminMutation
|
||||
hooks []Hook
|
||||
conflict []sql.ConflictOption
|
||||
}
|
||||
|
||||
// SetName sets the "name" field.
|
||||
func (_c *AdminCreate) SetName(v string) *AdminCreate {
|
||||
_c.mutation.SetName(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableName sets the "name" field if the given value is not nil.
|
||||
func (_c *AdminCreate) SetNillableName(v *string) *AdminCreate {
|
||||
if v != nil {
|
||||
_c.SetName(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetEmail sets the "email" field.
|
||||
func (_c *AdminCreate) SetEmail(v string) *AdminCreate {
|
||||
_c.mutation.SetEmail(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableEmail sets the "email" field if the given value is not nil.
|
||||
func (_c *AdminCreate) SetNillableEmail(v *string) *AdminCreate {
|
||||
if v != nil {
|
||||
_c.SetEmail(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetAvatar sets the "avatar" field.
|
||||
func (_c *AdminCreate) SetAvatar(v string) *AdminCreate {
|
||||
_c.mutation.SetAvatar(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableAvatar sets the "avatar" field if the given value is not nil.
|
||||
func (_c *AdminCreate) SetNillableAvatar(v *string) *AdminCreate {
|
||||
if v != nil {
|
||||
_c.SetAvatar(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetAccess sets the "access" field.
|
||||
func (_c *AdminCreate) SetAccess(v string) *AdminCreate {
|
||||
_c.mutation.SetAccess(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableAccess sets the "access" field if the given value is not nil.
|
||||
func (_c *AdminCreate) SetNillableAccess(v *string) *AdminCreate {
|
||||
if v != nil {
|
||||
_c.SetAccess(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetPassword sets the "password" field.
|
||||
func (_c *AdminCreate) SetPassword(v string) *AdminCreate {
|
||||
_c.mutation.SetPassword(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillablePassword sets the "password" field if the given value is not nil.
|
||||
func (_c *AdminCreate) SetNillablePassword(v *string) *AdminCreate {
|
||||
if v != nil {
|
||||
_c.SetPassword(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetCreateTime sets the "create_time" field.
|
||||
func (_c *AdminCreate) SetCreateTime(v time.Time) *AdminCreate {
|
||||
_c.mutation.SetCreateTime(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableCreateTime sets the "create_time" field if the given value is not nil.
|
||||
func (_c *AdminCreate) SetNillableCreateTime(v *time.Time) *AdminCreate {
|
||||
if v != nil {
|
||||
_c.SetCreateTime(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetUpdateTime sets the "update_time" field.
|
||||
func (_c *AdminCreate) SetUpdateTime(v time.Time) *AdminCreate {
|
||||
_c.mutation.SetUpdateTime(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableUpdateTime sets the "update_time" field if the given value is not nil.
|
||||
func (_c *AdminCreate) SetNillableUpdateTime(v *time.Time) *AdminCreate {
|
||||
if v != nil {
|
||||
_c.SetUpdateTime(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetID sets the "id" field.
|
||||
func (_c *AdminCreate) SetID(v int64) *AdminCreate {
|
||||
_c.mutation.SetID(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// Mutation returns the AdminMutation object of the builder.
|
||||
func (_c *AdminCreate) Mutation() *AdminMutation {
|
||||
return _c.mutation
|
||||
}
|
||||
|
||||
// Save creates the Admin in the database.
|
||||
func (_c *AdminCreate) Save(ctx context.Context) (*Admin, error) {
|
||||
_c.defaults()
|
||||
return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
|
||||
}
|
||||
|
||||
// SaveX calls Save and panics if Save returns an error.
|
||||
func (_c *AdminCreate) SaveX(ctx context.Context) *Admin {
|
||||
v, err := _c.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (_c *AdminCreate) Exec(ctx context.Context) error {
|
||||
_, err := _c.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_c *AdminCreate) ExecX(ctx context.Context) {
|
||||
if err := _c.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// defaults sets the default values of the builder before save.
|
||||
func (_c *AdminCreate) defaults() {
|
||||
if _, ok := _c.mutation.Name(); !ok {
|
||||
v := admin.DefaultName
|
||||
_c.mutation.SetName(v)
|
||||
}
|
||||
if _, ok := _c.mutation.Email(); !ok {
|
||||
v := admin.DefaultEmail
|
||||
_c.mutation.SetEmail(v)
|
||||
}
|
||||
if _, ok := _c.mutation.Avatar(); !ok {
|
||||
v := admin.DefaultAvatar
|
||||
_c.mutation.SetAvatar(v)
|
||||
}
|
||||
if _, ok := _c.mutation.Access(); !ok {
|
||||
v := admin.DefaultAccess
|
||||
_c.mutation.SetAccess(v)
|
||||
}
|
||||
if _, ok := _c.mutation.Password(); !ok {
|
||||
v := admin.DefaultPassword
|
||||
_c.mutation.SetPassword(v)
|
||||
}
|
||||
if _, ok := _c.mutation.CreateTime(); !ok {
|
||||
v := admin.DefaultCreateTime()
|
||||
_c.mutation.SetCreateTime(v)
|
||||
}
|
||||
if _, ok := _c.mutation.UpdateTime(); !ok {
|
||||
v := admin.DefaultUpdateTime()
|
||||
_c.mutation.SetUpdateTime(v)
|
||||
}
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (_c *AdminCreate) check() error {
|
||||
if _, ok := _c.mutation.Name(); !ok {
|
||||
return &ValidationError{Name: "name", err: errors.New(`ent: missing required field "Admin.name"`)}
|
||||
}
|
||||
if _, ok := _c.mutation.Email(); !ok {
|
||||
return &ValidationError{Name: "email", err: errors.New(`ent: missing required field "Admin.email"`)}
|
||||
}
|
||||
if _, ok := _c.mutation.Avatar(); !ok {
|
||||
return &ValidationError{Name: "avatar", err: errors.New(`ent: missing required field "Admin.avatar"`)}
|
||||
}
|
||||
if _, ok := _c.mutation.Access(); !ok {
|
||||
return &ValidationError{Name: "access", err: errors.New(`ent: missing required field "Admin.access"`)}
|
||||
}
|
||||
if _, ok := _c.mutation.Password(); !ok {
|
||||
return &ValidationError{Name: "password", err: errors.New(`ent: missing required field "Admin.password"`)}
|
||||
}
|
||||
if _, ok := _c.mutation.CreateTime(); !ok {
|
||||
return &ValidationError{Name: "create_time", err: errors.New(`ent: missing required field "Admin.create_time"`)}
|
||||
}
|
||||
if _, ok := _c.mutation.UpdateTime(); !ok {
|
||||
return &ValidationError{Name: "update_time", err: errors.New(`ent: missing required field "Admin.update_time"`)}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (_c *AdminCreate) sqlSave(ctx context.Context) (*Admin, error) {
|
||||
if err := _c.check(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
_node, _spec := _c.createSpec()
|
||||
if err := sqlgraph.CreateNode(ctx, _c.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 = int64(id)
|
||||
}
|
||||
_c.mutation.id = &_node.ID
|
||||
_c.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
|
||||
func (_c *AdminCreate) createSpec() (*Admin, *sqlgraph.CreateSpec) {
|
||||
var (
|
||||
_node = &Admin{config: _c.config}
|
||||
_spec = sqlgraph.NewCreateSpec(admin.Table, sqlgraph.NewFieldSpec(admin.FieldID, field.TypeInt64))
|
||||
)
|
||||
_spec.OnConflict = _c.conflict
|
||||
if id, ok := _c.mutation.ID(); ok {
|
||||
_node.ID = id
|
||||
_spec.ID.Value = id
|
||||
}
|
||||
if value, ok := _c.mutation.Name(); ok {
|
||||
_spec.SetField(admin.FieldName, field.TypeString, value)
|
||||
_node.Name = value
|
||||
}
|
||||
if value, ok := _c.mutation.Email(); ok {
|
||||
_spec.SetField(admin.FieldEmail, field.TypeString, value)
|
||||
_node.Email = value
|
||||
}
|
||||
if value, ok := _c.mutation.Avatar(); ok {
|
||||
_spec.SetField(admin.FieldAvatar, field.TypeString, value)
|
||||
_node.Avatar = value
|
||||
}
|
||||
if value, ok := _c.mutation.Access(); ok {
|
||||
_spec.SetField(admin.FieldAccess, field.TypeString, value)
|
||||
_node.Access = value
|
||||
}
|
||||
if value, ok := _c.mutation.Password(); ok {
|
||||
_spec.SetField(admin.FieldPassword, field.TypeString, value)
|
||||
_node.Password = value
|
||||
}
|
||||
if value, ok := _c.mutation.CreateTime(); ok {
|
||||
_spec.SetField(admin.FieldCreateTime, field.TypeTime, value)
|
||||
_node.CreateTime = value
|
||||
}
|
||||
if value, ok := _c.mutation.UpdateTime(); ok {
|
||||
_spec.SetField(admin.FieldUpdateTime, field.TypeTime, value)
|
||||
_node.UpdateTime = value
|
||||
}
|
||||
return _node, _spec
|
||||
}
|
||||
|
||||
// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
|
||||
// of the `INSERT` statement. For example:
|
||||
//
|
||||
// client.Admin.Create().
|
||||
// SetName(v).
|
||||
// OnConflict(
|
||||
// // Update the row with the new values
|
||||
// // the was proposed for insertion.
|
||||
// sql.ResolveWithNewValues(),
|
||||
// ).
|
||||
// // Override some of the fields with custom
|
||||
// // update values.
|
||||
// Update(func(u *ent.AdminUpsert) {
|
||||
// SetName(v+v).
|
||||
// }).
|
||||
// Exec(ctx)
|
||||
func (_c *AdminCreate) OnConflict(opts ...sql.ConflictOption) *AdminUpsertOne {
|
||||
_c.conflict = opts
|
||||
return &AdminUpsertOne{
|
||||
create: _c,
|
||||
}
|
||||
}
|
||||
|
||||
// OnConflictColumns calls `OnConflict` and configures the columns
|
||||
// as conflict target. Using this option is equivalent to using:
|
||||
//
|
||||
// client.Admin.Create().
|
||||
// OnConflict(sql.ConflictColumns(columns...)).
|
||||
// Exec(ctx)
|
||||
func (_c *AdminCreate) OnConflictColumns(columns ...string) *AdminUpsertOne {
|
||||
_c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
|
||||
return &AdminUpsertOne{
|
||||
create: _c,
|
||||
}
|
||||
}
|
||||
|
||||
type (
|
||||
// AdminUpsertOne is the builder for "upsert"-ing
|
||||
// one Admin node.
|
||||
AdminUpsertOne struct {
|
||||
create *AdminCreate
|
||||
}
|
||||
|
||||
// AdminUpsert is the "OnConflict" setter.
|
||||
AdminUpsert struct {
|
||||
*sql.UpdateSet
|
||||
}
|
||||
)
|
||||
|
||||
// SetName sets the "name" field.
|
||||
func (u *AdminUpsert) SetName(v string) *AdminUpsert {
|
||||
u.Set(admin.FieldName, v)
|
||||
return u
|
||||
}
|
||||
|
||||
// UpdateName sets the "name" field to the value that was provided on create.
|
||||
func (u *AdminUpsert) UpdateName() *AdminUpsert {
|
||||
u.SetExcluded(admin.FieldName)
|
||||
return u
|
||||
}
|
||||
|
||||
// SetEmail sets the "email" field.
|
||||
func (u *AdminUpsert) SetEmail(v string) *AdminUpsert {
|
||||
u.Set(admin.FieldEmail, v)
|
||||
return u
|
||||
}
|
||||
|
||||
// UpdateEmail sets the "email" field to the value that was provided on create.
|
||||
func (u *AdminUpsert) UpdateEmail() *AdminUpsert {
|
||||
u.SetExcluded(admin.FieldEmail)
|
||||
return u
|
||||
}
|
||||
|
||||
// SetAvatar sets the "avatar" field.
|
||||
func (u *AdminUpsert) SetAvatar(v string) *AdminUpsert {
|
||||
u.Set(admin.FieldAvatar, v)
|
||||
return u
|
||||
}
|
||||
|
||||
// UpdateAvatar sets the "avatar" field to the value that was provided on create.
|
||||
func (u *AdminUpsert) UpdateAvatar() *AdminUpsert {
|
||||
u.SetExcluded(admin.FieldAvatar)
|
||||
return u
|
||||
}
|
||||
|
||||
// SetAccess sets the "access" field.
|
||||
func (u *AdminUpsert) SetAccess(v string) *AdminUpsert {
|
||||
u.Set(admin.FieldAccess, v)
|
||||
return u
|
||||
}
|
||||
|
||||
// UpdateAccess sets the "access" field to the value that was provided on create.
|
||||
func (u *AdminUpsert) UpdateAccess() *AdminUpsert {
|
||||
u.SetExcluded(admin.FieldAccess)
|
||||
return u
|
||||
}
|
||||
|
||||
// SetPassword sets the "password" field.
|
||||
func (u *AdminUpsert) SetPassword(v string) *AdminUpsert {
|
||||
u.Set(admin.FieldPassword, v)
|
||||
return u
|
||||
}
|
||||
|
||||
// UpdatePassword sets the "password" field to the value that was provided on create.
|
||||
func (u *AdminUpsert) UpdatePassword() *AdminUpsert {
|
||||
u.SetExcluded(admin.FieldPassword)
|
||||
return u
|
||||
}
|
||||
|
||||
// SetUpdateTime sets the "update_time" field.
|
||||
func (u *AdminUpsert) SetUpdateTime(v time.Time) *AdminUpsert {
|
||||
u.Set(admin.FieldUpdateTime, v)
|
||||
return u
|
||||
}
|
||||
|
||||
// UpdateUpdateTime sets the "update_time" field to the value that was provided on create.
|
||||
func (u *AdminUpsert) UpdateUpdateTime() *AdminUpsert {
|
||||
u.SetExcluded(admin.FieldUpdateTime)
|
||||
return u
|
||||
}
|
||||
|
||||
// UpdateNewValues updates the mutable fields using the new values that were set on create except the ID field.
|
||||
// Using this option is equivalent to using:
|
||||
//
|
||||
// client.Admin.Create().
|
||||
// OnConflict(
|
||||
// sql.ResolveWithNewValues(),
|
||||
// sql.ResolveWith(func(u *sql.UpdateSet) {
|
||||
// u.SetIgnore(admin.FieldID)
|
||||
// }),
|
||||
// ).
|
||||
// Exec(ctx)
|
||||
func (u *AdminUpsertOne) UpdateNewValues() *AdminUpsertOne {
|
||||
u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
|
||||
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) {
|
||||
if _, exists := u.create.mutation.ID(); exists {
|
||||
s.SetIgnore(admin.FieldID)
|
||||
}
|
||||
if _, exists := u.create.mutation.CreateTime(); exists {
|
||||
s.SetIgnore(admin.FieldCreateTime)
|
||||
}
|
||||
}))
|
||||
return u
|
||||
}
|
||||
|
||||
// Ignore sets each column to itself in case of conflict.
|
||||
// Using this option is equivalent to using:
|
||||
//
|
||||
// client.Admin.Create().
|
||||
// OnConflict(sql.ResolveWithIgnore()).
|
||||
// Exec(ctx)
|
||||
func (u *AdminUpsertOne) Ignore() *AdminUpsertOne {
|
||||
u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
|
||||
return u
|
||||
}
|
||||
|
||||
// DoNothing configures the conflict_action to `DO NOTHING`.
|
||||
// Supported only by SQLite and PostgreSQL.
|
||||
func (u *AdminUpsertOne) DoNothing() *AdminUpsertOne {
|
||||
u.create.conflict = append(u.create.conflict, sql.DoNothing())
|
||||
return u
|
||||
}
|
||||
|
||||
// Update allows overriding fields `UPDATE` values. See the AdminCreate.OnConflict
|
||||
// documentation for more info.
|
||||
func (u *AdminUpsertOne) Update(set func(*AdminUpsert)) *AdminUpsertOne {
|
||||
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
|
||||
set(&AdminUpsert{UpdateSet: update})
|
||||
}))
|
||||
return u
|
||||
}
|
||||
|
||||
// SetName sets the "name" field.
|
||||
func (u *AdminUpsertOne) SetName(v string) *AdminUpsertOne {
|
||||
return u.Update(func(s *AdminUpsert) {
|
||||
s.SetName(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateName sets the "name" field to the value that was provided on create.
|
||||
func (u *AdminUpsertOne) UpdateName() *AdminUpsertOne {
|
||||
return u.Update(func(s *AdminUpsert) {
|
||||
s.UpdateName()
|
||||
})
|
||||
}
|
||||
|
||||
// SetEmail sets the "email" field.
|
||||
func (u *AdminUpsertOne) SetEmail(v string) *AdminUpsertOne {
|
||||
return u.Update(func(s *AdminUpsert) {
|
||||
s.SetEmail(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateEmail sets the "email" field to the value that was provided on create.
|
||||
func (u *AdminUpsertOne) UpdateEmail() *AdminUpsertOne {
|
||||
return u.Update(func(s *AdminUpsert) {
|
||||
s.UpdateEmail()
|
||||
})
|
||||
}
|
||||
|
||||
// SetAvatar sets the "avatar" field.
|
||||
func (u *AdminUpsertOne) SetAvatar(v string) *AdminUpsertOne {
|
||||
return u.Update(func(s *AdminUpsert) {
|
||||
s.SetAvatar(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateAvatar sets the "avatar" field to the value that was provided on create.
|
||||
func (u *AdminUpsertOne) UpdateAvatar() *AdminUpsertOne {
|
||||
return u.Update(func(s *AdminUpsert) {
|
||||
s.UpdateAvatar()
|
||||
})
|
||||
}
|
||||
|
||||
// SetAccess sets the "access" field.
|
||||
func (u *AdminUpsertOne) SetAccess(v string) *AdminUpsertOne {
|
||||
return u.Update(func(s *AdminUpsert) {
|
||||
s.SetAccess(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateAccess sets the "access" field to the value that was provided on create.
|
||||
func (u *AdminUpsertOne) UpdateAccess() *AdminUpsertOne {
|
||||
return u.Update(func(s *AdminUpsert) {
|
||||
s.UpdateAccess()
|
||||
})
|
||||
}
|
||||
|
||||
// SetPassword sets the "password" field.
|
||||
func (u *AdminUpsertOne) SetPassword(v string) *AdminUpsertOne {
|
||||
return u.Update(func(s *AdminUpsert) {
|
||||
s.SetPassword(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdatePassword sets the "password" field to the value that was provided on create.
|
||||
func (u *AdminUpsertOne) UpdatePassword() *AdminUpsertOne {
|
||||
return u.Update(func(s *AdminUpsert) {
|
||||
s.UpdatePassword()
|
||||
})
|
||||
}
|
||||
|
||||
// SetUpdateTime sets the "update_time" field.
|
||||
func (u *AdminUpsertOne) SetUpdateTime(v time.Time) *AdminUpsertOne {
|
||||
return u.Update(func(s *AdminUpsert) {
|
||||
s.SetUpdateTime(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateUpdateTime sets the "update_time" field to the value that was provided on create.
|
||||
func (u *AdminUpsertOne) UpdateUpdateTime() *AdminUpsertOne {
|
||||
return u.Update(func(s *AdminUpsert) {
|
||||
s.UpdateUpdateTime()
|
||||
})
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (u *AdminUpsertOne) Exec(ctx context.Context) error {
|
||||
if len(u.create.conflict) == 0 {
|
||||
return errors.New("ent: missing options for AdminCreate.OnConflict")
|
||||
}
|
||||
return u.create.Exec(ctx)
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (u *AdminUpsertOne) ExecX(ctx context.Context) {
|
||||
if err := u.create.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// Exec executes the UPSERT query and returns the inserted/updated ID.
|
||||
func (u *AdminUpsertOne) ID(ctx context.Context) (id int64, err error) {
|
||||
node, err := u.create.Save(ctx)
|
||||
if err != nil {
|
||||
return id, err
|
||||
}
|
||||
return node.ID, nil
|
||||
}
|
||||
|
||||
// IDX is like ID, but panics if an error occurs.
|
||||
func (u *AdminUpsertOne) IDX(ctx context.Context) int64 {
|
||||
id, err := u.ID(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
// AdminCreateBulk is the builder for creating many Admin entities in bulk.
|
||||
type AdminCreateBulk struct {
|
||||
config
|
||||
err error
|
||||
builders []*AdminCreate
|
||||
conflict []sql.ConflictOption
|
||||
}
|
||||
|
||||
// Save creates the Admin entities in the database.
|
||||
func (_c *AdminCreateBulk) Save(ctx context.Context) ([]*Admin, error) {
|
||||
if _c.err != nil {
|
||||
return nil, _c.err
|
||||
}
|
||||
specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
|
||||
nodes := make([]*Admin, len(_c.builders))
|
||||
mutators := make([]Mutator, len(_c.builders))
|
||||
for i := range _c.builders {
|
||||
func(i int, root context.Context) {
|
||||
builder := _c.builders[i]
|
||||
builder.defaults()
|
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||
mutation, ok := m.(*AdminMutation)
|
||||
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, _c.builders[i+1].mutation)
|
||||
} else {
|
||||
spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
|
||||
spec.OnConflict = _c.conflict
|
||||
// Invoke the actual operation on the latest mutation in the chain.
|
||||
if err = sqlgraph.BatchCreate(ctx, _c.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 = int64(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, _c.builders[0].mutation); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (_c *AdminCreateBulk) SaveX(ctx context.Context) []*Admin {
|
||||
v, err := _c.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (_c *AdminCreateBulk) Exec(ctx context.Context) error {
|
||||
_, err := _c.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_c *AdminCreateBulk) ExecX(ctx context.Context) {
|
||||
if err := _c.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
|
||||
// of the `INSERT` statement. For example:
|
||||
//
|
||||
// client.Admin.CreateBulk(builders...).
|
||||
// OnConflict(
|
||||
// // Update the row with the new values
|
||||
// // the was proposed for insertion.
|
||||
// sql.ResolveWithNewValues(),
|
||||
// ).
|
||||
// // Override some of the fields with custom
|
||||
// // update values.
|
||||
// Update(func(u *ent.AdminUpsert) {
|
||||
// SetName(v+v).
|
||||
// }).
|
||||
// Exec(ctx)
|
||||
func (_c *AdminCreateBulk) OnConflict(opts ...sql.ConflictOption) *AdminUpsertBulk {
|
||||
_c.conflict = opts
|
||||
return &AdminUpsertBulk{
|
||||
create: _c,
|
||||
}
|
||||
}
|
||||
|
||||
// OnConflictColumns calls `OnConflict` and configures the columns
|
||||
// as conflict target. Using this option is equivalent to using:
|
||||
//
|
||||
// client.Admin.Create().
|
||||
// OnConflict(sql.ConflictColumns(columns...)).
|
||||
// Exec(ctx)
|
||||
func (_c *AdminCreateBulk) OnConflictColumns(columns ...string) *AdminUpsertBulk {
|
||||
_c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
|
||||
return &AdminUpsertBulk{
|
||||
create: _c,
|
||||
}
|
||||
}
|
||||
|
||||
// AdminUpsertBulk is the builder for "upsert"-ing
|
||||
// a bulk of Admin nodes.
|
||||
type AdminUpsertBulk struct {
|
||||
create *AdminCreateBulk
|
||||
}
|
||||
|
||||
// UpdateNewValues updates the mutable fields using the new values that
|
||||
// were set on create. Using this option is equivalent to using:
|
||||
//
|
||||
// client.Admin.Create().
|
||||
// OnConflict(
|
||||
// sql.ResolveWithNewValues(),
|
||||
// sql.ResolveWith(func(u *sql.UpdateSet) {
|
||||
// u.SetIgnore(admin.FieldID)
|
||||
// }),
|
||||
// ).
|
||||
// Exec(ctx)
|
||||
func (u *AdminUpsertBulk) UpdateNewValues() *AdminUpsertBulk {
|
||||
u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
|
||||
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) {
|
||||
for _, b := range u.create.builders {
|
||||
if _, exists := b.mutation.ID(); exists {
|
||||
s.SetIgnore(admin.FieldID)
|
||||
}
|
||||
if _, exists := b.mutation.CreateTime(); exists {
|
||||
s.SetIgnore(admin.FieldCreateTime)
|
||||
}
|
||||
}
|
||||
}))
|
||||
return u
|
||||
}
|
||||
|
||||
// Ignore sets each column to itself in case of conflict.
|
||||
// Using this option is equivalent to using:
|
||||
//
|
||||
// client.Admin.Create().
|
||||
// OnConflict(sql.ResolveWithIgnore()).
|
||||
// Exec(ctx)
|
||||
func (u *AdminUpsertBulk) Ignore() *AdminUpsertBulk {
|
||||
u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
|
||||
return u
|
||||
}
|
||||
|
||||
// DoNothing configures the conflict_action to `DO NOTHING`.
|
||||
// Supported only by SQLite and PostgreSQL.
|
||||
func (u *AdminUpsertBulk) DoNothing() *AdminUpsertBulk {
|
||||
u.create.conflict = append(u.create.conflict, sql.DoNothing())
|
||||
return u
|
||||
}
|
||||
|
||||
// Update allows overriding fields `UPDATE` values. See the AdminCreateBulk.OnConflict
|
||||
// documentation for more info.
|
||||
func (u *AdminUpsertBulk) Update(set func(*AdminUpsert)) *AdminUpsertBulk {
|
||||
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
|
||||
set(&AdminUpsert{UpdateSet: update})
|
||||
}))
|
||||
return u
|
||||
}
|
||||
|
||||
// SetName sets the "name" field.
|
||||
func (u *AdminUpsertBulk) SetName(v string) *AdminUpsertBulk {
|
||||
return u.Update(func(s *AdminUpsert) {
|
||||
s.SetName(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateName sets the "name" field to the value that was provided on create.
|
||||
func (u *AdminUpsertBulk) UpdateName() *AdminUpsertBulk {
|
||||
return u.Update(func(s *AdminUpsert) {
|
||||
s.UpdateName()
|
||||
})
|
||||
}
|
||||
|
||||
// SetEmail sets the "email" field.
|
||||
func (u *AdminUpsertBulk) SetEmail(v string) *AdminUpsertBulk {
|
||||
return u.Update(func(s *AdminUpsert) {
|
||||
s.SetEmail(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateEmail sets the "email" field to the value that was provided on create.
|
||||
func (u *AdminUpsertBulk) UpdateEmail() *AdminUpsertBulk {
|
||||
return u.Update(func(s *AdminUpsert) {
|
||||
s.UpdateEmail()
|
||||
})
|
||||
}
|
||||
|
||||
// SetAvatar sets the "avatar" field.
|
||||
func (u *AdminUpsertBulk) SetAvatar(v string) *AdminUpsertBulk {
|
||||
return u.Update(func(s *AdminUpsert) {
|
||||
s.SetAvatar(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateAvatar sets the "avatar" field to the value that was provided on create.
|
||||
func (u *AdminUpsertBulk) UpdateAvatar() *AdminUpsertBulk {
|
||||
return u.Update(func(s *AdminUpsert) {
|
||||
s.UpdateAvatar()
|
||||
})
|
||||
}
|
||||
|
||||
// SetAccess sets the "access" field.
|
||||
func (u *AdminUpsertBulk) SetAccess(v string) *AdminUpsertBulk {
|
||||
return u.Update(func(s *AdminUpsert) {
|
||||
s.SetAccess(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateAccess sets the "access" field to the value that was provided on create.
|
||||
func (u *AdminUpsertBulk) UpdateAccess() *AdminUpsertBulk {
|
||||
return u.Update(func(s *AdminUpsert) {
|
||||
s.UpdateAccess()
|
||||
})
|
||||
}
|
||||
|
||||
// SetPassword sets the "password" field.
|
||||
func (u *AdminUpsertBulk) SetPassword(v string) *AdminUpsertBulk {
|
||||
return u.Update(func(s *AdminUpsert) {
|
||||
s.SetPassword(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdatePassword sets the "password" field to the value that was provided on create.
|
||||
func (u *AdminUpsertBulk) UpdatePassword() *AdminUpsertBulk {
|
||||
return u.Update(func(s *AdminUpsert) {
|
||||
s.UpdatePassword()
|
||||
})
|
||||
}
|
||||
|
||||
// SetUpdateTime sets the "update_time" field.
|
||||
func (u *AdminUpsertBulk) SetUpdateTime(v time.Time) *AdminUpsertBulk {
|
||||
return u.Update(func(s *AdminUpsert) {
|
||||
s.SetUpdateTime(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateUpdateTime sets the "update_time" field to the value that was provided on create.
|
||||
func (u *AdminUpsertBulk) UpdateUpdateTime() *AdminUpsertBulk {
|
||||
return u.Update(func(s *AdminUpsert) {
|
||||
s.UpdateUpdateTime()
|
||||
})
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (u *AdminUpsertBulk) Exec(ctx context.Context) error {
|
||||
if u.create.err != nil {
|
||||
return u.create.err
|
||||
}
|
||||
for i, b := range u.create.builders {
|
||||
if len(b.conflict) != 0 {
|
||||
return fmt.Errorf("ent: OnConflict was set for builder %d. Set it on the AdminCreateBulk instead", i)
|
||||
}
|
||||
}
|
||||
if len(u.create.conflict) == 0 {
|
||||
return errors.New("ent: missing options for AdminCreateBulk.OnConflict")
|
||||
}
|
||||
return u.create.Exec(ctx)
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (u *AdminUpsertBulk) ExecX(ctx context.Context) {
|
||||
if err := u.create.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user