851 lines
23 KiB
Go
851 lines
23 KiB
Go
// Code generated by ent, DO NOT EDIT.
|
|||
|
|
|
||
|
|
package ent
|
||
|
|
|
||
|
|
import (
|
||
|
|
"bj_power_wms/ent/role"
|
||
|
|
"context"
|
||
|
|
"errors"
|
||
|
|
"fmt"
|
||
|
|
|
||
|
|
"entgo.io/ent/dialect/sql"
|
||
|
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||
|
|
"entgo.io/ent/schema/field"
|
||
|
|
)
|
||
|
|
|
||
|
|
// RoleCreate is the builder for creating a Role entity.
|
||
|
|
type RoleCreate struct {
|
||
|
|
config
|
||
|
|
mutation *RoleMutation
|
||
|
|
hooks []Hook
|
||
|
|
conflict []sql.ConflictOption
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetName sets the "name" field.
|
||
|
|
func (_c *RoleCreate) SetName(v string) *RoleCreate {
|
||
|
|
_c.mutation.SetName(v)
|
||
|
|
return _c
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetCode sets the "code" field.
|
||
|
|
func (_c *RoleCreate) SetCode(v string) *RoleCreate {
|
||
|
|
_c.mutation.SetCode(v)
|
||
|
|
return _c
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetRemark sets the "remark" field.
|
||
|
|
func (_c *RoleCreate) SetRemark(v string) *RoleCreate {
|
||
|
|
_c.mutation.SetRemark(v)
|
||
|
|
return _c
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetNillableRemark sets the "remark" field if the given value is not nil.
|
||
|
|
func (_c *RoleCreate) SetNillableRemark(v *string) *RoleCreate {
|
||
|
|
if v != nil {
|
||
|
|
_c.SetRemark(*v)
|
||
|
|
}
|
||
|
|
return _c
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetPermissionCodes sets the "permission_codes" field.
|
||
|
|
func (_c *RoleCreate) SetPermissionCodes(v []string) *RoleCreate {
|
||
|
|
_c.mutation.SetPermissionCodes(v)
|
||
|
|
return _c
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetCreatedAt sets the "created_at" field.
|
||
|
|
func (_c *RoleCreate) SetCreatedAt(v int64) *RoleCreate {
|
||
|
|
_c.mutation.SetCreatedAt(v)
|
||
|
|
return _c
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
||
|
|
func (_c *RoleCreate) SetNillableCreatedAt(v *int64) *RoleCreate {
|
||
|
|
if v != nil {
|
||
|
|
_c.SetCreatedAt(*v)
|
||
|
|
}
|
||
|
|
return _c
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetUpdatedAt sets the "updated_at" field.
|
||
|
|
func (_c *RoleCreate) SetUpdatedAt(v int64) *RoleCreate {
|
||
|
|
_c.mutation.SetUpdatedAt(v)
|
||
|
|
return _c
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
|
||
|
|
func (_c *RoleCreate) SetNillableUpdatedAt(v *int64) *RoleCreate {
|
||
|
|
if v != nil {
|
||
|
|
_c.SetUpdatedAt(*v)
|
||
|
|
}
|
||
|
|
return _c
|
||
|
|
}
|
||
|
|
|
||
|
|
// Mutation returns the RoleMutation object of the builder.
|
||
|
|
func (_c *RoleCreate) Mutation() *RoleMutation {
|
||
|
|
return _c.mutation
|
||
|
|
}
|
||
|
|
|
||
|
|
// Save creates the Role in the database.
|
||
|
|
func (_c *RoleCreate) Save(ctx context.Context) (*Role, error) {
|
||
|
|
_c.defaults()
|
||
|
|
return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
|
||
|
|
}
|
||
|
|
|
||
|
|
// SaveX calls Save and panics if Save returns an error.
|
||
|
|
func (_c *RoleCreate) SaveX(ctx context.Context) *Role {
|
||
|
|
v, err := _c.Save(ctx)
|
||
|
|
if err != nil {
|
||
|
|
panic(err)
|
||
|
|
}
|
||
|
|
return v
|
||
|
|
}
|
||
|
|
|
||
|
|
// Exec executes the query.
|
||
|
|
func (_c *RoleCreate) Exec(ctx context.Context) error {
|
||
|
|
_, err := _c.Save(ctx)
|
||
|
|
return err
|
||
|
|
}
|
||
|
|
|
||
|
|
// ExecX is like Exec, but panics if an error occurs.
|
||
|
|
func (_c *RoleCreate) 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 *RoleCreate) defaults() {
|
||
|
|
if _, ok := _c.mutation.Remark(); !ok {
|
||
|
|
v := role.DefaultRemark
|
||
|
|
_c.mutation.SetRemark(v)
|
||
|
|
}
|
||
|
|
if _, ok := _c.mutation.CreatedAt(); !ok {
|
||
|
|
v := role.DefaultCreatedAt()
|
||
|
|
_c.mutation.SetCreatedAt(v)
|
||
|
|
}
|
||
|
|
if _, ok := _c.mutation.UpdatedAt(); !ok {
|
||
|
|
v := role.DefaultUpdatedAt()
|
||
|
|
_c.mutation.SetUpdatedAt(v)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// check runs all checks and user-defined validators on the builder.
|
||
|
|
func (_c *RoleCreate) check() error {
|
||
|
|
if _, ok := _c.mutation.Name(); !ok {
|
||
|
|
return &ValidationError{Name: "name", err: errors.New(`ent: missing required field "Role.name"`)}
|
||
|
|
}
|
||
|
|
if v, ok := _c.mutation.Name(); ok {
|
||
|
|
if err := role.NameValidator(v); err != nil {
|
||
|
|
return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "Role.name": %w`, err)}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if _, ok := _c.mutation.Code(); !ok {
|
||
|
|
return &ValidationError{Name: "code", err: errors.New(`ent: missing required field "Role.code"`)}
|
||
|
|
}
|
||
|
|
if v, ok := _c.mutation.Code(); ok {
|
||
|
|
if err := role.CodeValidator(v); err != nil {
|
||
|
|
return &ValidationError{Name: "code", err: fmt.Errorf(`ent: validator failed for field "Role.code": %w`, err)}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if v, ok := _c.mutation.Remark(); ok {
|
||
|
|
if err := role.RemarkValidator(v); err != nil {
|
||
|
|
return &ValidationError{Name: "remark", err: fmt.Errorf(`ent: validator failed for field "Role.remark": %w`, err)}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if _, ok := _c.mutation.CreatedAt(); !ok {
|
||
|
|
return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "Role.created_at"`)}
|
||
|
|
}
|
||
|
|
if _, ok := _c.mutation.UpdatedAt(); !ok {
|
||
|
|
return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "Role.updated_at"`)}
|
||
|
|
}
|
||
|
|
return nil
|
||
|
|
}
|
||
|
|
|
||
|
|
func (_c *RoleCreate) sqlSave(ctx context.Context) (*Role, 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
|
||
|
|
}
|
||
|
|
id := _spec.ID.Value.(int64)
|
||
|
|
_node.ID = int(id)
|
||
|
|
_c.mutation.id = &_node.ID
|
||
|
|
_c.mutation.done = true
|
||
|
|
return _node, nil
|
||
|
|
}
|
||
|
|
|
||
|
|
func (_c *RoleCreate) createSpec() (*Role, *sqlgraph.CreateSpec) {
|
||
|
|
var (
|
||
|
|
_node = &Role{config: _c.config}
|
||
|
|
_spec = sqlgraph.NewCreateSpec(role.Table, sqlgraph.NewFieldSpec(role.FieldID, field.TypeInt))
|
||
|
|
)
|
||
|
|
_spec.OnConflict = _c.conflict
|
||
|
|
if value, ok := _c.mutation.Name(); ok {
|
||
|
|
_spec.SetField(role.FieldName, field.TypeString, value)
|
||
|
|
_node.Name = value
|
||
|
|
}
|
||
|
|
if value, ok := _c.mutation.Code(); ok {
|
||
|
|
_spec.SetField(role.FieldCode, field.TypeString, value)
|
||
|
|
_node.Code = value
|
||
|
|
}
|
||
|
|
if value, ok := _c.mutation.Remark(); ok {
|
||
|
|
_spec.SetField(role.FieldRemark, field.TypeString, value)
|
||
|
|
_node.Remark = value
|
||
|
|
}
|
||
|
|
if value, ok := _c.mutation.PermissionCodes(); ok {
|
||
|
|
_spec.SetField(role.FieldPermissionCodes, field.TypeJSON, value)
|
||
|
|
_node.PermissionCodes = value
|
||
|
|
}
|
||
|
|
if value, ok := _c.mutation.CreatedAt(); ok {
|
||
|
|
_spec.SetField(role.FieldCreatedAt, field.TypeInt64, value)
|
||
|
|
_node.CreatedAt = value
|
||
|
|
}
|
||
|
|
if value, ok := _c.mutation.UpdatedAt(); ok {
|
||
|
|
_spec.SetField(role.FieldUpdatedAt, field.TypeInt64, value)
|
||
|
|
_node.UpdatedAt = value
|
||
|
|
}
|
||
|
|
return _node, _spec
|
||
|
|
}
|
||
|
|
|
||
|
|
// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
|
||
|
|
// of the `INSERT` statement. For example:
|
||
|
|
//
|
||
|
|
// client.Role.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.RoleUpsert) {
|
||
|
|
// SetName(v+v).
|
||
|
|
// }).
|
||
|
|
// Exec(ctx)
|
||
|
|
func (_c *RoleCreate) OnConflict(opts ...sql.ConflictOption) *RoleUpsertOne {
|
||
|
|
_c.conflict = opts
|
||
|
|
return &RoleUpsertOne{
|
||
|
|
create: _c,
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// OnConflictColumns calls `OnConflict` and configures the columns
|
||
|
|
// as conflict target. Using this option is equivalent to using:
|
||
|
|
//
|
||
|
|
// client.Role.Create().
|
||
|
|
// OnConflict(sql.ConflictColumns(columns...)).
|
||
|
|
// Exec(ctx)
|
||
|
|
func (_c *RoleCreate) OnConflictColumns(columns ...string) *RoleUpsertOne {
|
||
|
|
_c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
|
||
|
|
return &RoleUpsertOne{
|
||
|
|
create: _c,
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
type (
|
||
|
|
// RoleUpsertOne is the builder for "upsert"-ing
|
||
|
|
// one Role node.
|
||
|
|
RoleUpsertOne struct {
|
||
|
|
create *RoleCreate
|
||
|
|
}
|
||
|
|
|
||
|
|
// RoleUpsert is the "OnConflict" setter.
|
||
|
|
RoleUpsert struct {
|
||
|
|
*sql.UpdateSet
|
||
|
|
}
|
||
|
|
)
|
||
|
|
|
||
|
|
// SetName sets the "name" field.
|
||
|
|
func (u *RoleUpsert) SetName(v string) *RoleUpsert {
|
||
|
|
u.Set(role.FieldName, v)
|
||
|
|
return u
|
||
|
|
}
|
||
|
|
|
||
|
|
// UpdateName sets the "name" field to the value that was provided on create.
|
||
|
|
func (u *RoleUpsert) UpdateName() *RoleUpsert {
|
||
|
|
u.SetExcluded(role.FieldName)
|
||
|
|
return u
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetCode sets the "code" field.
|
||
|
|
func (u *RoleUpsert) SetCode(v string) *RoleUpsert {
|
||
|
|
u.Set(role.FieldCode, v)
|
||
|
|
return u
|
||
|
|
}
|
||
|
|
|
||
|
|
// UpdateCode sets the "code" field to the value that was provided on create.
|
||
|
|
func (u *RoleUpsert) UpdateCode() *RoleUpsert {
|
||
|
|
u.SetExcluded(role.FieldCode)
|
||
|
|
return u
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetRemark sets the "remark" field.
|
||
|
|
func (u *RoleUpsert) SetRemark(v string) *RoleUpsert {
|
||
|
|
u.Set(role.FieldRemark, v)
|
||
|
|
return u
|
||
|
|
}
|
||
|
|
|
||
|
|
// UpdateRemark sets the "remark" field to the value that was provided on create.
|
||
|
|
func (u *RoleUpsert) UpdateRemark() *RoleUpsert {
|
||
|
|
u.SetExcluded(role.FieldRemark)
|
||
|
|
return u
|
||
|
|
}
|
||
|
|
|
||
|
|
// ClearRemark clears the value of the "remark" field.
|
||
|
|
func (u *RoleUpsert) ClearRemark() *RoleUpsert {
|
||
|
|
u.SetNull(role.FieldRemark)
|
||
|
|
return u
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetPermissionCodes sets the "permission_codes" field.
|
||
|
|
func (u *RoleUpsert) SetPermissionCodes(v []string) *RoleUpsert {
|
||
|
|
u.Set(role.FieldPermissionCodes, v)
|
||
|
|
return u
|
||
|
|
}
|
||
|
|
|
||
|
|
// UpdatePermissionCodes sets the "permission_codes" field to the value that was provided on create.
|
||
|
|
func (u *RoleUpsert) UpdatePermissionCodes() *RoleUpsert {
|
||
|
|
u.SetExcluded(role.FieldPermissionCodes)
|
||
|
|
return u
|
||
|
|
}
|
||
|
|
|
||
|
|
// ClearPermissionCodes clears the value of the "permission_codes" field.
|
||
|
|
func (u *RoleUpsert) ClearPermissionCodes() *RoleUpsert {
|
||
|
|
u.SetNull(role.FieldPermissionCodes)
|
||
|
|
return u
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetCreatedAt sets the "created_at" field.
|
||
|
|
func (u *RoleUpsert) SetCreatedAt(v int64) *RoleUpsert {
|
||
|
|
u.Set(role.FieldCreatedAt, v)
|
||
|
|
return u
|
||
|
|
}
|
||
|
|
|
||
|
|
// UpdateCreatedAt sets the "created_at" field to the value that was provided on create.
|
||
|
|
func (u *RoleUpsert) UpdateCreatedAt() *RoleUpsert {
|
||
|
|
u.SetExcluded(role.FieldCreatedAt)
|
||
|
|
return u
|
||
|
|
}
|
||
|
|
|
||
|
|
// AddCreatedAt adds v to the "created_at" field.
|
||
|
|
func (u *RoleUpsert) AddCreatedAt(v int64) *RoleUpsert {
|
||
|
|
u.Add(role.FieldCreatedAt, v)
|
||
|
|
return u
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetUpdatedAt sets the "updated_at" field.
|
||
|
|
func (u *RoleUpsert) SetUpdatedAt(v int64) *RoleUpsert {
|
||
|
|
u.Set(role.FieldUpdatedAt, v)
|
||
|
|
return u
|
||
|
|
}
|
||
|
|
|
||
|
|
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
|
||
|
|
func (u *RoleUpsert) UpdateUpdatedAt() *RoleUpsert {
|
||
|
|
u.SetExcluded(role.FieldUpdatedAt)
|
||
|
|
return u
|
||
|
|
}
|
||
|
|
|
||
|
|
// AddUpdatedAt adds v to the "updated_at" field.
|
||
|
|
func (u *RoleUpsert) AddUpdatedAt(v int64) *RoleUpsert {
|
||
|
|
u.Add(role.FieldUpdatedAt, v)
|
||
|
|
return u
|
||
|
|
}
|
||
|
|
|
||
|
|
// UpdateNewValues updates the mutable fields using the new values that were set on create.
|
||
|
|
// Using this option is equivalent to using:
|
||
|
|
//
|
||
|
|
// client.Role.Create().
|
||
|
|
// OnConflict(
|
||
|
|
// sql.ResolveWithNewValues(),
|
||
|
|
// ).
|
||
|
|
// Exec(ctx)
|
||
|
|
func (u *RoleUpsertOne) UpdateNewValues() *RoleUpsertOne {
|
||
|
|
u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
|
||
|
|
return u
|
||
|
|
}
|
||
|
|
|
||
|
|
// Ignore sets each column to itself in case of conflict.
|
||
|
|
// Using this option is equivalent to using:
|
||
|
|
//
|
||
|
|
// client.Role.Create().
|
||
|
|
// OnConflict(sql.ResolveWithIgnore()).
|
||
|
|
// Exec(ctx)
|
||
|
|
func (u *RoleUpsertOne) Ignore() *RoleUpsertOne {
|
||
|
|
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 *RoleUpsertOne) DoNothing() *RoleUpsertOne {
|
||
|
|
u.create.conflict = append(u.create.conflict, sql.DoNothing())
|
||
|
|
return u
|
||
|
|
}
|
||
|
|
|
||
|
|
// Update allows overriding fields `UPDATE` values. See the RoleCreate.OnConflict
|
||
|
|
// documentation for more info.
|
||
|
|
func (u *RoleUpsertOne) Update(set func(*RoleUpsert)) *RoleUpsertOne {
|
||
|
|
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
|
||
|
|
set(&RoleUpsert{UpdateSet: update})
|
||
|
|
}))
|
||
|
|
return u
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetName sets the "name" field.
|
||
|
|
func (u *RoleUpsertOne) SetName(v string) *RoleUpsertOne {
|
||
|
|
return u.Update(func(s *RoleUpsert) {
|
||
|
|
s.SetName(v)
|
||
|
|
})
|
||
|
|
}
|
||
|
|
|
||
|
|
// UpdateName sets the "name" field to the value that was provided on create.
|
||
|
|
func (u *RoleUpsertOne) UpdateName() *RoleUpsertOne {
|
||
|
|
return u.Update(func(s *RoleUpsert) {
|
||
|
|
s.UpdateName()
|
||
|
|
})
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetCode sets the "code" field.
|
||
|
|
func (u *RoleUpsertOne) SetCode(v string) *RoleUpsertOne {
|
||
|
|
return u.Update(func(s *RoleUpsert) {
|
||
|
|
s.SetCode(v)
|
||
|
|
})
|
||
|
|
}
|
||
|
|
|
||
|
|
// UpdateCode sets the "code" field to the value that was provided on create.
|
||
|
|
func (u *RoleUpsertOne) UpdateCode() *RoleUpsertOne {
|
||
|
|
return u.Update(func(s *RoleUpsert) {
|
||
|
|
s.UpdateCode()
|
||
|
|
})
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetRemark sets the "remark" field.
|
||
|
|
func (u *RoleUpsertOne) SetRemark(v string) *RoleUpsertOne {
|
||
|
|
return u.Update(func(s *RoleUpsert) {
|
||
|
|
s.SetRemark(v)
|
||
|
|
})
|
||
|
|
}
|
||
|
|
|
||
|
|
// UpdateRemark sets the "remark" field to the value that was provided on create.
|
||
|
|
func (u *RoleUpsertOne) UpdateRemark() *RoleUpsertOne {
|
||
|
|
return u.Update(func(s *RoleUpsert) {
|
||
|
|
s.UpdateRemark()
|
||
|
|
})
|
||
|
|
}
|
||
|
|
|
||
|
|
// ClearRemark clears the value of the "remark" field.
|
||
|
|
func (u *RoleUpsertOne) ClearRemark() *RoleUpsertOne {
|
||
|
|
return u.Update(func(s *RoleUpsert) {
|
||
|
|
s.ClearRemark()
|
||
|
|
})
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetPermissionCodes sets the "permission_codes" field.
|
||
|
|
func (u *RoleUpsertOne) SetPermissionCodes(v []string) *RoleUpsertOne {
|
||
|
|
return u.Update(func(s *RoleUpsert) {
|
||
|
|
s.SetPermissionCodes(v)
|
||
|
|
})
|
||
|
|
}
|
||
|
|
|
||
|
|
// UpdatePermissionCodes sets the "permission_codes" field to the value that was provided on create.
|
||
|
|
func (u *RoleUpsertOne) UpdatePermissionCodes() *RoleUpsertOne {
|
||
|
|
return u.Update(func(s *RoleUpsert) {
|
||
|
|
s.UpdatePermissionCodes()
|
||
|
|
})
|
||
|
|
}
|
||
|
|
|
||
|
|
// ClearPermissionCodes clears the value of the "permission_codes" field.
|
||
|
|
func (u *RoleUpsertOne) ClearPermissionCodes() *RoleUpsertOne {
|
||
|
|
return u.Update(func(s *RoleUpsert) {
|
||
|
|
s.ClearPermissionCodes()
|
||
|
|
})
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetCreatedAt sets the "created_at" field.
|
||
|
|
func (u *RoleUpsertOne) SetCreatedAt(v int64) *RoleUpsertOne {
|
||
|
|
return u.Update(func(s *RoleUpsert) {
|
||
|
|
s.SetCreatedAt(v)
|
||
|
|
})
|
||
|
|
}
|
||
|
|
|
||
|
|
// AddCreatedAt adds v to the "created_at" field.
|
||
|
|
func (u *RoleUpsertOne) AddCreatedAt(v int64) *RoleUpsertOne {
|
||
|
|
return u.Update(func(s *RoleUpsert) {
|
||
|
|
s.AddCreatedAt(v)
|
||
|
|
})
|
||
|
|
}
|
||
|
|
|
||
|
|
// UpdateCreatedAt sets the "created_at" field to the value that was provided on create.
|
||
|
|
func (u *RoleUpsertOne) UpdateCreatedAt() *RoleUpsertOne {
|
||
|
|
return u.Update(func(s *RoleUpsert) {
|
||
|
|
s.UpdateCreatedAt()
|
||
|
|
})
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetUpdatedAt sets the "updated_at" field.
|
||
|
|
func (u *RoleUpsertOne) SetUpdatedAt(v int64) *RoleUpsertOne {
|
||
|
|
return u.Update(func(s *RoleUpsert) {
|
||
|
|
s.SetUpdatedAt(v)
|
||
|
|
})
|
||
|
|
}
|
||
|
|
|
||
|
|
// AddUpdatedAt adds v to the "updated_at" field.
|
||
|
|
func (u *RoleUpsertOne) AddUpdatedAt(v int64) *RoleUpsertOne {
|
||
|
|
return u.Update(func(s *RoleUpsert) {
|
||
|
|
s.AddUpdatedAt(v)
|
||
|
|
})
|
||
|
|
}
|
||
|
|
|
||
|
|
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
|
||
|
|
func (u *RoleUpsertOne) UpdateUpdatedAt() *RoleUpsertOne {
|
||
|
|
return u.Update(func(s *RoleUpsert) {
|
||
|
|
s.UpdateUpdatedAt()
|
||
|
|
})
|
||
|
|
}
|
||
|
|
|
||
|
|
// Exec executes the query.
|
||
|
|
func (u *RoleUpsertOne) Exec(ctx context.Context) error {
|
||
|
|
if len(u.create.conflict) == 0 {
|
||
|
|
return errors.New("ent: missing options for RoleCreate.OnConflict")
|
||
|
|
}
|
||
|
|
return u.create.Exec(ctx)
|
||
|
|
}
|
||
|
|
|
||
|
|
// ExecX is like Exec, but panics if an error occurs.
|
||
|
|
func (u *RoleUpsertOne) 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 *RoleUpsertOne) ID(ctx context.Context) (id int, 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 *RoleUpsertOne) IDX(ctx context.Context) int {
|
||
|
|
id, err := u.ID(ctx)
|
||
|
|
if err != nil {
|
||
|
|
panic(err)
|
||
|
|
}
|
||
|
|
return id
|
||
|
|
}
|
||
|
|
|
||
|
|
// RoleCreateBulk is the builder for creating many Role entities in bulk.
|
||
|
|
type RoleCreateBulk struct {
|
||
|
|
config
|
||
|
|
err error
|
||
|
|
builders []*RoleCreate
|
||
|
|
conflict []sql.ConflictOption
|
||
|
|
}
|
||
|
|
|
||
|
|
// Save creates the Role entities in the database.
|
||
|
|
func (_c *RoleCreateBulk) Save(ctx context.Context) ([]*Role, error) {
|
||
|
|
if _c.err != nil {
|
||
|
|
return nil, _c.err
|
||
|
|
}
|
||
|
|
specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
|
||
|
|
nodes := make([]*Role, 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.(*RoleMutation)
|
||
|
|
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 {
|
||
|
|
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, _c.builders[0].mutation); err != nil {
|
||
|
|
return nil, err
|
||
|
|
}
|
||
|
|
}
|
||
|
|
return nodes, nil
|
||
|
|
}
|
||
|
|
|
||
|
|
// SaveX is like Save, but panics if an error occurs.
|
||
|
|
func (_c *RoleCreateBulk) SaveX(ctx context.Context) []*Role {
|
||
|
|
v, err := _c.Save(ctx)
|
||
|
|
if err != nil {
|
||
|
|
panic(err)
|
||
|
|
}
|
||
|
|
return v
|
||
|
|
}
|
||
|
|
|
||
|
|
// Exec executes the query.
|
||
|
|
func (_c *RoleCreateBulk) Exec(ctx context.Context) error {
|
||
|
|
_, err := _c.Save(ctx)
|
||
|
|
return err
|
||
|
|
}
|
||
|
|
|
||
|
|
// ExecX is like Exec, but panics if an error occurs.
|
||
|
|
func (_c *RoleCreateBulk) 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.Role.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.RoleUpsert) {
|
||
|
|
// SetName(v+v).
|
||
|
|
// }).
|
||
|
|
// Exec(ctx)
|
||
|
|
func (_c *RoleCreateBulk) OnConflict(opts ...sql.ConflictOption) *RoleUpsertBulk {
|
||
|
|
_c.conflict = opts
|
||
|
|
return &RoleUpsertBulk{
|
||
|
|
create: _c,
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// OnConflictColumns calls `OnConflict` and configures the columns
|
||
|
|
// as conflict target. Using this option is equivalent to using:
|
||
|
|
//
|
||
|
|
// client.Role.Create().
|
||
|
|
// OnConflict(sql.ConflictColumns(columns...)).
|
||
|
|
// Exec(ctx)
|
||
|
|
func (_c *RoleCreateBulk) OnConflictColumns(columns ...string) *RoleUpsertBulk {
|
||
|
|
_c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
|
||
|
|
return &RoleUpsertBulk{
|
||
|
|
create: _c,
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// RoleUpsertBulk is the builder for "upsert"-ing
|
||
|
|
// a bulk of Role nodes.
|
||
|
|
type RoleUpsertBulk struct {
|
||
|
|
create *RoleCreateBulk
|
||
|
|
}
|
||
|
|
|
||
|
|
// UpdateNewValues updates the mutable fields using the new values that
|
||
|
|
// were set on create. Using this option is equivalent to using:
|
||
|
|
//
|
||
|
|
// client.Role.Create().
|
||
|
|
// OnConflict(
|
||
|
|
// sql.ResolveWithNewValues(),
|
||
|
|
// ).
|
||
|
|
// Exec(ctx)
|
||
|
|
func (u *RoleUpsertBulk) UpdateNewValues() *RoleUpsertBulk {
|
||
|
|
u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
|
||
|
|
return u
|
||
|
|
}
|
||
|
|
|
||
|
|
// Ignore sets each column to itself in case of conflict.
|
||
|
|
// Using this option is equivalent to using:
|
||
|
|
//
|
||
|
|
// client.Role.Create().
|
||
|
|
// OnConflict(sql.ResolveWithIgnore()).
|
||
|
|
// Exec(ctx)
|
||
|
|
func (u *RoleUpsertBulk) Ignore() *RoleUpsertBulk {
|
||
|
|
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 *RoleUpsertBulk) DoNothing() *RoleUpsertBulk {
|
||
|
|
u.create.conflict = append(u.create.conflict, sql.DoNothing())
|
||
|
|
return u
|
||
|
|
}
|
||
|
|
|
||
|
|
// Update allows overriding fields `UPDATE` values. See the RoleCreateBulk.OnConflict
|
||
|
|
// documentation for more info.
|
||
|
|
func (u *RoleUpsertBulk) Update(set func(*RoleUpsert)) *RoleUpsertBulk {
|
||
|
|
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
|
||
|
|
set(&RoleUpsert{UpdateSet: update})
|
||
|
|
}))
|
||
|
|
return u
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetName sets the "name" field.
|
||
|
|
func (u *RoleUpsertBulk) SetName(v string) *RoleUpsertBulk {
|
||
|
|
return u.Update(func(s *RoleUpsert) {
|
||
|
|
s.SetName(v)
|
||
|
|
})
|
||
|
|
}
|
||
|
|
|
||
|
|
// UpdateName sets the "name" field to the value that was provided on create.
|
||
|
|
func (u *RoleUpsertBulk) UpdateName() *RoleUpsertBulk {
|
||
|
|
return u.Update(func(s *RoleUpsert) {
|
||
|
|
s.UpdateName()
|
||
|
|
})
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetCode sets the "code" field.
|
||
|
|
func (u *RoleUpsertBulk) SetCode(v string) *RoleUpsertBulk {
|
||
|
|
return u.Update(func(s *RoleUpsert) {
|
||
|
|
s.SetCode(v)
|
||
|
|
})
|
||
|
|
}
|
||
|
|
|
||
|
|
// UpdateCode sets the "code" field to the value that was provided on create.
|
||
|
|
func (u *RoleUpsertBulk) UpdateCode() *RoleUpsertBulk {
|
||
|
|
return u.Update(func(s *RoleUpsert) {
|
||
|
|
s.UpdateCode()
|
||
|
|
})
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetRemark sets the "remark" field.
|
||
|
|
func (u *RoleUpsertBulk) SetRemark(v string) *RoleUpsertBulk {
|
||
|
|
return u.Update(func(s *RoleUpsert) {
|
||
|
|
s.SetRemark(v)
|
||
|
|
})
|
||
|
|
}
|
||
|
|
|
||
|
|
// UpdateRemark sets the "remark" field to the value that was provided on create.
|
||
|
|
func (u *RoleUpsertBulk) UpdateRemark() *RoleUpsertBulk {
|
||
|
|
return u.Update(func(s *RoleUpsert) {
|
||
|
|
s.UpdateRemark()
|
||
|
|
})
|
||
|
|
}
|
||
|
|
|
||
|
|
// ClearRemark clears the value of the "remark" field.
|
||
|
|
func (u *RoleUpsertBulk) ClearRemark() *RoleUpsertBulk {
|
||
|
|
return u.Update(func(s *RoleUpsert) {
|
||
|
|
s.ClearRemark()
|
||
|
|
})
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetPermissionCodes sets the "permission_codes" field.
|
||
|
|
func (u *RoleUpsertBulk) SetPermissionCodes(v []string) *RoleUpsertBulk {
|
||
|
|
return u.Update(func(s *RoleUpsert) {
|
||
|
|
s.SetPermissionCodes(v)
|
||
|
|
})
|
||
|
|
}
|
||
|
|
|
||
|
|
// UpdatePermissionCodes sets the "permission_codes" field to the value that was provided on create.
|
||
|
|
func (u *RoleUpsertBulk) UpdatePermissionCodes() *RoleUpsertBulk {
|
||
|
|
return u.Update(func(s *RoleUpsert) {
|
||
|
|
s.UpdatePermissionCodes()
|
||
|
|
})
|
||
|
|
}
|
||
|
|
|
||
|
|
// ClearPermissionCodes clears the value of the "permission_codes" field.
|
||
|
|
func (u *RoleUpsertBulk) ClearPermissionCodes() *RoleUpsertBulk {
|
||
|
|
return u.Update(func(s *RoleUpsert) {
|
||
|
|
s.ClearPermissionCodes()
|
||
|
|
})
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetCreatedAt sets the "created_at" field.
|
||
|
|
func (u *RoleUpsertBulk) SetCreatedAt(v int64) *RoleUpsertBulk {
|
||
|
|
return u.Update(func(s *RoleUpsert) {
|
||
|
|
s.SetCreatedAt(v)
|
||
|
|
})
|
||
|
|
}
|
||
|
|
|
||
|
|
// AddCreatedAt adds v to the "created_at" field.
|
||
|
|
func (u *RoleUpsertBulk) AddCreatedAt(v int64) *RoleUpsertBulk {
|
||
|
|
return u.Update(func(s *RoleUpsert) {
|
||
|
|
s.AddCreatedAt(v)
|
||
|
|
})
|
||
|
|
}
|
||
|
|
|
||
|
|
// UpdateCreatedAt sets the "created_at" field to the value that was provided on create.
|
||
|
|
func (u *RoleUpsertBulk) UpdateCreatedAt() *RoleUpsertBulk {
|
||
|
|
return u.Update(func(s *RoleUpsert) {
|
||
|
|
s.UpdateCreatedAt()
|
||
|
|
})
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetUpdatedAt sets the "updated_at" field.
|
||
|
|
func (u *RoleUpsertBulk) SetUpdatedAt(v int64) *RoleUpsertBulk {
|
||
|
|
return u.Update(func(s *RoleUpsert) {
|
||
|
|
s.SetUpdatedAt(v)
|
||
|
|
})
|
||
|
|
}
|
||
|
|
|
||
|
|
// AddUpdatedAt adds v to the "updated_at" field.
|
||
|
|
func (u *RoleUpsertBulk) AddUpdatedAt(v int64) *RoleUpsertBulk {
|
||
|
|
return u.Update(func(s *RoleUpsert) {
|
||
|
|
s.AddUpdatedAt(v)
|
||
|
|
})
|
||
|
|
}
|
||
|
|
|
||
|
|
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
|
||
|
|
func (u *RoleUpsertBulk) UpdateUpdatedAt() *RoleUpsertBulk {
|
||
|
|
return u.Update(func(s *RoleUpsert) {
|
||
|
|
s.UpdateUpdatedAt()
|
||
|
|
})
|
||
|
|
}
|
||
|
|
|
||
|
|
// Exec executes the query.
|
||
|
|
func (u *RoleUpsertBulk) 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 RoleCreateBulk instead", i)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if len(u.create.conflict) == 0 {
|
||
|
|
return errors.New("ent: missing options for RoleCreateBulk.OnConflict")
|
||
|
|
}
|
||
|
|
return u.create.Exec(ctx)
|
||
|
|
}
|
||
|
|
|
||
|
|
// ExecX is like Exec, but panics if an error occurs.
|
||
|
|
func (u *RoleUpsertBulk) ExecX(ctx context.Context) {
|
||
|
|
if err := u.create.Exec(ctx); err != nil {
|
||
|
|
panic(err)
|
||
|
|
}
|
||
|
|
}
|