You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
868 lines
24 KiB
Go
868 lines
24 KiB
Go
// 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"
|
|
"git.noahlan.cn/n-admin/n-admin-server/rpc/core/ent/user"
|
|
"git.noahlan.cn/n-admin/n-admin-server/rpc/core/ent/usermeta"
|
|
)
|
|
|
|
// UserMetaCreate is the builder for creating a UserMeta entity.
|
|
type UserMetaCreate struct {
|
|
config
|
|
mutation *UserMetaMutation
|
|
hooks []Hook
|
|
conflict []sql.ConflictOption
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (umc *UserMetaCreate) SetCreatedAt(t time.Time) *UserMetaCreate {
|
|
umc.mutation.SetCreatedAt(t)
|
|
return umc
|
|
}
|
|
|
|
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
|
func (umc *UserMetaCreate) SetNillableCreatedAt(t *time.Time) *UserMetaCreate {
|
|
if t != nil {
|
|
umc.SetCreatedAt(*t)
|
|
}
|
|
return umc
|
|
}
|
|
|
|
// SetUpdatedAt sets the "updated_at" field.
|
|
func (umc *UserMetaCreate) SetUpdatedAt(t time.Time) *UserMetaCreate {
|
|
umc.mutation.SetUpdatedAt(t)
|
|
return umc
|
|
}
|
|
|
|
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
|
|
func (umc *UserMetaCreate) SetNillableUpdatedAt(t *time.Time) *UserMetaCreate {
|
|
if t != nil {
|
|
umc.SetUpdatedAt(*t)
|
|
}
|
|
return umc
|
|
}
|
|
|
|
// SetVersion sets the "version" field.
|
|
func (umc *UserMetaCreate) SetVersion(i int64) *UserMetaCreate {
|
|
umc.mutation.SetVersion(i)
|
|
return umc
|
|
}
|
|
|
|
// SetNillableVersion sets the "version" field if the given value is not nil.
|
|
func (umc *UserMetaCreate) SetNillableVersion(i *int64) *UserMetaCreate {
|
|
if i != nil {
|
|
umc.SetVersion(*i)
|
|
}
|
|
return umc
|
|
}
|
|
|
|
// SetUserID sets the "user_id" field.
|
|
func (umc *UserMetaCreate) SetUserID(i int64) *UserMetaCreate {
|
|
umc.mutation.SetUserID(i)
|
|
return umc
|
|
}
|
|
|
|
// SetKey sets the "key" field.
|
|
func (umc *UserMetaCreate) SetKey(s string) *UserMetaCreate {
|
|
umc.mutation.SetKey(s)
|
|
return umc
|
|
}
|
|
|
|
// SetNillableKey sets the "key" field if the given value is not nil.
|
|
func (umc *UserMetaCreate) SetNillableKey(s *string) *UserMetaCreate {
|
|
if s != nil {
|
|
umc.SetKey(*s)
|
|
}
|
|
return umc
|
|
}
|
|
|
|
// SetValue sets the "value" field.
|
|
func (umc *UserMetaCreate) SetValue(s string) *UserMetaCreate {
|
|
umc.mutation.SetValue(s)
|
|
return umc
|
|
}
|
|
|
|
// SetNillableValue sets the "value" field if the given value is not nil.
|
|
func (umc *UserMetaCreate) SetNillableValue(s *string) *UserMetaCreate {
|
|
if s != nil {
|
|
umc.SetValue(*s)
|
|
}
|
|
return umc
|
|
}
|
|
|
|
// SetID sets the "id" field.
|
|
func (umc *UserMetaCreate) SetID(i int64) *UserMetaCreate {
|
|
umc.mutation.SetID(i)
|
|
return umc
|
|
}
|
|
|
|
// SetNillableID sets the "id" field if the given value is not nil.
|
|
func (umc *UserMetaCreate) SetNillableID(i *int64) *UserMetaCreate {
|
|
if i != nil {
|
|
umc.SetID(*i)
|
|
}
|
|
return umc
|
|
}
|
|
|
|
// SetUser sets the "user" edge to the User entity.
|
|
func (umc *UserMetaCreate) SetUser(u *User) *UserMetaCreate {
|
|
return umc.SetUserID(u.ID)
|
|
}
|
|
|
|
// Mutation returns the UserMetaMutation object of the builder.
|
|
func (umc *UserMetaCreate) Mutation() *UserMetaMutation {
|
|
return umc.mutation
|
|
}
|
|
|
|
// Save creates the UserMeta in the database.
|
|
func (umc *UserMetaCreate) Save(ctx context.Context) (*UserMeta, error) {
|
|
if err := umc.defaults(); err != nil {
|
|
return nil, err
|
|
}
|
|
return withHooks(ctx, umc.sqlSave, umc.mutation, umc.hooks)
|
|
}
|
|
|
|
// SaveX calls Save and panics if Save returns an error.
|
|
func (umc *UserMetaCreate) SaveX(ctx context.Context) *UserMeta {
|
|
v, err := umc.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return v
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (umc *UserMetaCreate) Exec(ctx context.Context) error {
|
|
_, err := umc.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (umc *UserMetaCreate) ExecX(ctx context.Context) {
|
|
if err := umc.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
// defaults sets the default values of the builder before save.
|
|
func (umc *UserMetaCreate) defaults() error {
|
|
if _, ok := umc.mutation.CreatedAt(); !ok {
|
|
if usermeta.DefaultCreatedAt == nil {
|
|
return fmt.Errorf("ent: uninitialized usermeta.DefaultCreatedAt (forgotten import ent/runtime?)")
|
|
}
|
|
v := usermeta.DefaultCreatedAt()
|
|
umc.mutation.SetCreatedAt(v)
|
|
}
|
|
if _, ok := umc.mutation.UpdatedAt(); !ok {
|
|
if usermeta.DefaultUpdatedAt == nil {
|
|
return fmt.Errorf("ent: uninitialized usermeta.DefaultUpdatedAt (forgotten import ent/runtime?)")
|
|
}
|
|
v := usermeta.DefaultUpdatedAt()
|
|
umc.mutation.SetUpdatedAt(v)
|
|
}
|
|
if _, ok := umc.mutation.Version(); !ok {
|
|
v := usermeta.DefaultVersion
|
|
umc.mutation.SetVersion(v)
|
|
}
|
|
if _, ok := umc.mutation.ID(); !ok {
|
|
if usermeta.DefaultID == nil {
|
|
return fmt.Errorf("ent: uninitialized usermeta.DefaultID (forgotten import ent/runtime?)")
|
|
}
|
|
v := usermeta.DefaultID()
|
|
umc.mutation.SetID(v)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// check runs all checks and user-defined validators on the builder.
|
|
func (umc *UserMetaCreate) check() error {
|
|
if _, ok := umc.mutation.CreatedAt(); !ok {
|
|
return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "UserMeta.created_at"`)}
|
|
}
|
|
if _, ok := umc.mutation.UpdatedAt(); !ok {
|
|
return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "UserMeta.updated_at"`)}
|
|
}
|
|
if _, ok := umc.mutation.Version(); !ok {
|
|
return &ValidationError{Name: "version", err: errors.New(`ent: missing required field "UserMeta.version"`)}
|
|
}
|
|
if _, ok := umc.mutation.UserID(); !ok {
|
|
return &ValidationError{Name: "user_id", err: errors.New(`ent: missing required field "UserMeta.user_id"`)}
|
|
}
|
|
if _, ok := umc.mutation.UserID(); !ok {
|
|
return &ValidationError{Name: "user", err: errors.New(`ent: missing required edge "UserMeta.user"`)}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (umc *UserMetaCreate) sqlSave(ctx context.Context) (*UserMeta, error) {
|
|
if err := umc.check(); err != nil {
|
|
return nil, err
|
|
}
|
|
_node, _spec := umc.createSpec()
|
|
if err := sqlgraph.CreateNode(ctx, umc.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)
|
|
}
|
|
umc.mutation.id = &_node.ID
|
|
umc.mutation.done = true
|
|
return _node, nil
|
|
}
|
|
|
|
func (umc *UserMetaCreate) createSpec() (*UserMeta, *sqlgraph.CreateSpec) {
|
|
var (
|
|
_node = &UserMeta{config: umc.config}
|
|
_spec = sqlgraph.NewCreateSpec(usermeta.Table, sqlgraph.NewFieldSpec(usermeta.FieldID, field.TypeInt64))
|
|
)
|
|
_spec.OnConflict = umc.conflict
|
|
if id, ok := umc.mutation.ID(); ok {
|
|
_node.ID = id
|
|
_spec.ID.Value = id
|
|
}
|
|
if value, ok := umc.mutation.CreatedAt(); ok {
|
|
_spec.SetField(usermeta.FieldCreatedAt, field.TypeTime, value)
|
|
_node.CreatedAt = value
|
|
}
|
|
if value, ok := umc.mutation.UpdatedAt(); ok {
|
|
_spec.SetField(usermeta.FieldUpdatedAt, field.TypeTime, value)
|
|
_node.UpdatedAt = value
|
|
}
|
|
if value, ok := umc.mutation.Version(); ok {
|
|
_spec.SetField(usermeta.FieldVersion, field.TypeInt64, value)
|
|
_node.Version = value
|
|
}
|
|
if value, ok := umc.mutation.Key(); ok {
|
|
_spec.SetField(usermeta.FieldKey, field.TypeString, value)
|
|
_node.Key = value
|
|
}
|
|
if value, ok := umc.mutation.Value(); ok {
|
|
_spec.SetField(usermeta.FieldValue, field.TypeString, value)
|
|
_node.Value = value
|
|
}
|
|
if nodes := umc.mutation.UserIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: true,
|
|
Table: usermeta.UserTable,
|
|
Columns: []string{usermeta.UserColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt64),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_node.UserID = nodes[0]
|
|
_spec.Edges = append(_spec.Edges, edge)
|
|
}
|
|
return _node, _spec
|
|
}
|
|
|
|
// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
|
|
// of the `INSERT` statement. For example:
|
|
//
|
|
// client.UserMeta.Create().
|
|
// SetCreatedAt(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.UserMetaUpsert) {
|
|
// SetCreatedAt(v+v).
|
|
// }).
|
|
// Exec(ctx)
|
|
func (umc *UserMetaCreate) OnConflict(opts ...sql.ConflictOption) *UserMetaUpsertOne {
|
|
umc.conflict = opts
|
|
return &UserMetaUpsertOne{
|
|
create: umc,
|
|
}
|
|
}
|
|
|
|
// OnConflictColumns calls `OnConflict` and configures the columns
|
|
// as conflict target. Using this option is equivalent to using:
|
|
//
|
|
// client.UserMeta.Create().
|
|
// OnConflict(sql.ConflictColumns(columns...)).
|
|
// Exec(ctx)
|
|
func (umc *UserMetaCreate) OnConflictColumns(columns ...string) *UserMetaUpsertOne {
|
|
umc.conflict = append(umc.conflict, sql.ConflictColumns(columns...))
|
|
return &UserMetaUpsertOne{
|
|
create: umc,
|
|
}
|
|
}
|
|
|
|
type (
|
|
// UserMetaUpsertOne is the builder for "upsert"-ing
|
|
// one UserMeta node.
|
|
UserMetaUpsertOne struct {
|
|
create *UserMetaCreate
|
|
}
|
|
|
|
// UserMetaUpsert is the "OnConflict" setter.
|
|
UserMetaUpsert struct {
|
|
*sql.UpdateSet
|
|
}
|
|
)
|
|
|
|
// SetUpdatedAt sets the "updated_at" field.
|
|
func (u *UserMetaUpsert) SetUpdatedAt(v time.Time) *UserMetaUpsert {
|
|
u.Set(usermeta.FieldUpdatedAt, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
|
|
func (u *UserMetaUpsert) UpdateUpdatedAt() *UserMetaUpsert {
|
|
u.SetExcluded(usermeta.FieldUpdatedAt)
|
|
return u
|
|
}
|
|
|
|
// SetVersion sets the "version" field.
|
|
func (u *UserMetaUpsert) SetVersion(v int64) *UserMetaUpsert {
|
|
u.Set(usermeta.FieldVersion, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateVersion sets the "version" field to the value that was provided on create.
|
|
func (u *UserMetaUpsert) UpdateVersion() *UserMetaUpsert {
|
|
u.SetExcluded(usermeta.FieldVersion)
|
|
return u
|
|
}
|
|
|
|
// AddVersion adds v to the "version" field.
|
|
func (u *UserMetaUpsert) AddVersion(v int64) *UserMetaUpsert {
|
|
u.Add(usermeta.FieldVersion, v)
|
|
return u
|
|
}
|
|
|
|
// SetUserID sets the "user_id" field.
|
|
func (u *UserMetaUpsert) SetUserID(v int64) *UserMetaUpsert {
|
|
u.Set(usermeta.FieldUserID, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateUserID sets the "user_id" field to the value that was provided on create.
|
|
func (u *UserMetaUpsert) UpdateUserID() *UserMetaUpsert {
|
|
u.SetExcluded(usermeta.FieldUserID)
|
|
return u
|
|
}
|
|
|
|
// SetKey sets the "key" field.
|
|
func (u *UserMetaUpsert) SetKey(v string) *UserMetaUpsert {
|
|
u.Set(usermeta.FieldKey, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateKey sets the "key" field to the value that was provided on create.
|
|
func (u *UserMetaUpsert) UpdateKey() *UserMetaUpsert {
|
|
u.SetExcluded(usermeta.FieldKey)
|
|
return u
|
|
}
|
|
|
|
// ClearKey clears the value of the "key" field.
|
|
func (u *UserMetaUpsert) ClearKey() *UserMetaUpsert {
|
|
u.SetNull(usermeta.FieldKey)
|
|
return u
|
|
}
|
|
|
|
// SetValue sets the "value" field.
|
|
func (u *UserMetaUpsert) SetValue(v string) *UserMetaUpsert {
|
|
u.Set(usermeta.FieldValue, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateValue sets the "value" field to the value that was provided on create.
|
|
func (u *UserMetaUpsert) UpdateValue() *UserMetaUpsert {
|
|
u.SetExcluded(usermeta.FieldValue)
|
|
return u
|
|
}
|
|
|
|
// ClearValue clears the value of the "value" field.
|
|
func (u *UserMetaUpsert) ClearValue() *UserMetaUpsert {
|
|
u.SetNull(usermeta.FieldValue)
|
|
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.UserMeta.Create().
|
|
// OnConflict(
|
|
// sql.ResolveWithNewValues(),
|
|
// sql.ResolveWith(func(u *sql.UpdateSet) {
|
|
// u.SetIgnore(usermeta.FieldID)
|
|
// }),
|
|
// ).
|
|
// Exec(ctx)
|
|
func (u *UserMetaUpsertOne) UpdateNewValues() *UserMetaUpsertOne {
|
|
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(usermeta.FieldID)
|
|
}
|
|
if _, exists := u.create.mutation.CreatedAt(); exists {
|
|
s.SetIgnore(usermeta.FieldCreatedAt)
|
|
}
|
|
}))
|
|
return u
|
|
}
|
|
|
|
// Ignore sets each column to itself in case of conflict.
|
|
// Using this option is equivalent to using:
|
|
//
|
|
// client.UserMeta.Create().
|
|
// OnConflict(sql.ResolveWithIgnore()).
|
|
// Exec(ctx)
|
|
func (u *UserMetaUpsertOne) Ignore() *UserMetaUpsertOne {
|
|
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 *UserMetaUpsertOne) DoNothing() *UserMetaUpsertOne {
|
|
u.create.conflict = append(u.create.conflict, sql.DoNothing())
|
|
return u
|
|
}
|
|
|
|
// Update allows overriding fields `UPDATE` values. See the UserMetaCreate.OnConflict
|
|
// documentation for more info.
|
|
func (u *UserMetaUpsertOne) Update(set func(*UserMetaUpsert)) *UserMetaUpsertOne {
|
|
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
|
|
set(&UserMetaUpsert{UpdateSet: update})
|
|
}))
|
|
return u
|
|
}
|
|
|
|
// SetUpdatedAt sets the "updated_at" field.
|
|
func (u *UserMetaUpsertOne) SetUpdatedAt(v time.Time) *UserMetaUpsertOne {
|
|
return u.Update(func(s *UserMetaUpsert) {
|
|
s.SetUpdatedAt(v)
|
|
})
|
|
}
|
|
|
|
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
|
|
func (u *UserMetaUpsertOne) UpdateUpdatedAt() *UserMetaUpsertOne {
|
|
return u.Update(func(s *UserMetaUpsert) {
|
|
s.UpdateUpdatedAt()
|
|
})
|
|
}
|
|
|
|
// SetVersion sets the "version" field.
|
|
func (u *UserMetaUpsertOne) SetVersion(v int64) *UserMetaUpsertOne {
|
|
return u.Update(func(s *UserMetaUpsert) {
|
|
s.SetVersion(v)
|
|
})
|
|
}
|
|
|
|
// AddVersion adds v to the "version" field.
|
|
func (u *UserMetaUpsertOne) AddVersion(v int64) *UserMetaUpsertOne {
|
|
return u.Update(func(s *UserMetaUpsert) {
|
|
s.AddVersion(v)
|
|
})
|
|
}
|
|
|
|
// UpdateVersion sets the "version" field to the value that was provided on create.
|
|
func (u *UserMetaUpsertOne) UpdateVersion() *UserMetaUpsertOne {
|
|
return u.Update(func(s *UserMetaUpsert) {
|
|
s.UpdateVersion()
|
|
})
|
|
}
|
|
|
|
// SetUserID sets the "user_id" field.
|
|
func (u *UserMetaUpsertOne) SetUserID(v int64) *UserMetaUpsertOne {
|
|
return u.Update(func(s *UserMetaUpsert) {
|
|
s.SetUserID(v)
|
|
})
|
|
}
|
|
|
|
// UpdateUserID sets the "user_id" field to the value that was provided on create.
|
|
func (u *UserMetaUpsertOne) UpdateUserID() *UserMetaUpsertOne {
|
|
return u.Update(func(s *UserMetaUpsert) {
|
|
s.UpdateUserID()
|
|
})
|
|
}
|
|
|
|
// SetKey sets the "key" field.
|
|
func (u *UserMetaUpsertOne) SetKey(v string) *UserMetaUpsertOne {
|
|
return u.Update(func(s *UserMetaUpsert) {
|
|
s.SetKey(v)
|
|
})
|
|
}
|
|
|
|
// UpdateKey sets the "key" field to the value that was provided on create.
|
|
func (u *UserMetaUpsertOne) UpdateKey() *UserMetaUpsertOne {
|
|
return u.Update(func(s *UserMetaUpsert) {
|
|
s.UpdateKey()
|
|
})
|
|
}
|
|
|
|
// ClearKey clears the value of the "key" field.
|
|
func (u *UserMetaUpsertOne) ClearKey() *UserMetaUpsertOne {
|
|
return u.Update(func(s *UserMetaUpsert) {
|
|
s.ClearKey()
|
|
})
|
|
}
|
|
|
|
// SetValue sets the "value" field.
|
|
func (u *UserMetaUpsertOne) SetValue(v string) *UserMetaUpsertOne {
|
|
return u.Update(func(s *UserMetaUpsert) {
|
|
s.SetValue(v)
|
|
})
|
|
}
|
|
|
|
// UpdateValue sets the "value" field to the value that was provided on create.
|
|
func (u *UserMetaUpsertOne) UpdateValue() *UserMetaUpsertOne {
|
|
return u.Update(func(s *UserMetaUpsert) {
|
|
s.UpdateValue()
|
|
})
|
|
}
|
|
|
|
// ClearValue clears the value of the "value" field.
|
|
func (u *UserMetaUpsertOne) ClearValue() *UserMetaUpsertOne {
|
|
return u.Update(func(s *UserMetaUpsert) {
|
|
s.ClearValue()
|
|
})
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (u *UserMetaUpsertOne) Exec(ctx context.Context) error {
|
|
if len(u.create.conflict) == 0 {
|
|
return errors.New("ent: missing options for UserMetaCreate.OnConflict")
|
|
}
|
|
return u.create.Exec(ctx)
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (u *UserMetaUpsertOne) 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 *UserMetaUpsertOne) 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 *UserMetaUpsertOne) IDX(ctx context.Context) int64 {
|
|
id, err := u.ID(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return id
|
|
}
|
|
|
|
// UserMetaCreateBulk is the builder for creating many UserMeta entities in bulk.
|
|
type UserMetaCreateBulk struct {
|
|
config
|
|
builders []*UserMetaCreate
|
|
conflict []sql.ConflictOption
|
|
}
|
|
|
|
// Save creates the UserMeta entities in the database.
|
|
func (umcb *UserMetaCreateBulk) Save(ctx context.Context) ([]*UserMeta, error) {
|
|
specs := make([]*sqlgraph.CreateSpec, len(umcb.builders))
|
|
nodes := make([]*UserMeta, len(umcb.builders))
|
|
mutators := make([]Mutator, len(umcb.builders))
|
|
for i := range umcb.builders {
|
|
func(i int, root context.Context) {
|
|
builder := umcb.builders[i]
|
|
builder.defaults()
|
|
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
|
mutation, ok := m.(*UserMetaMutation)
|
|
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, umcb.builders[i+1].mutation)
|
|
} else {
|
|
spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
|
|
spec.OnConflict = umcb.conflict
|
|
// Invoke the actual operation on the latest mutation in the chain.
|
|
if err = sqlgraph.BatchCreate(ctx, umcb.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, umcb.builders[0].mutation); err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
return nodes, nil
|
|
}
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
func (umcb *UserMetaCreateBulk) SaveX(ctx context.Context) []*UserMeta {
|
|
v, err := umcb.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return v
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (umcb *UserMetaCreateBulk) Exec(ctx context.Context) error {
|
|
_, err := umcb.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (umcb *UserMetaCreateBulk) ExecX(ctx context.Context) {
|
|
if err := umcb.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
|
|
// of the `INSERT` statement. For example:
|
|
//
|
|
// client.UserMeta.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.UserMetaUpsert) {
|
|
// SetCreatedAt(v+v).
|
|
// }).
|
|
// Exec(ctx)
|
|
func (umcb *UserMetaCreateBulk) OnConflict(opts ...sql.ConflictOption) *UserMetaUpsertBulk {
|
|
umcb.conflict = opts
|
|
return &UserMetaUpsertBulk{
|
|
create: umcb,
|
|
}
|
|
}
|
|
|
|
// OnConflictColumns calls `OnConflict` and configures the columns
|
|
// as conflict target. Using this option is equivalent to using:
|
|
//
|
|
// client.UserMeta.Create().
|
|
// OnConflict(sql.ConflictColumns(columns...)).
|
|
// Exec(ctx)
|
|
func (umcb *UserMetaCreateBulk) OnConflictColumns(columns ...string) *UserMetaUpsertBulk {
|
|
umcb.conflict = append(umcb.conflict, sql.ConflictColumns(columns...))
|
|
return &UserMetaUpsertBulk{
|
|
create: umcb,
|
|
}
|
|
}
|
|
|
|
// UserMetaUpsertBulk is the builder for "upsert"-ing
|
|
// a bulk of UserMeta nodes.
|
|
type UserMetaUpsertBulk struct {
|
|
create *UserMetaCreateBulk
|
|
}
|
|
|
|
// UpdateNewValues updates the mutable fields using the new values that
|
|
// were set on create. Using this option is equivalent to using:
|
|
//
|
|
// client.UserMeta.Create().
|
|
// OnConflict(
|
|
// sql.ResolveWithNewValues(),
|
|
// sql.ResolveWith(func(u *sql.UpdateSet) {
|
|
// u.SetIgnore(usermeta.FieldID)
|
|
// }),
|
|
// ).
|
|
// Exec(ctx)
|
|
func (u *UserMetaUpsertBulk) UpdateNewValues() *UserMetaUpsertBulk {
|
|
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(usermeta.FieldID)
|
|
}
|
|
if _, exists := b.mutation.CreatedAt(); exists {
|
|
s.SetIgnore(usermeta.FieldCreatedAt)
|
|
}
|
|
}
|
|
}))
|
|
return u
|
|
}
|
|
|
|
// Ignore sets each column to itself in case of conflict.
|
|
// Using this option is equivalent to using:
|
|
//
|
|
// client.UserMeta.Create().
|
|
// OnConflict(sql.ResolveWithIgnore()).
|
|
// Exec(ctx)
|
|
func (u *UserMetaUpsertBulk) Ignore() *UserMetaUpsertBulk {
|
|
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 *UserMetaUpsertBulk) DoNothing() *UserMetaUpsertBulk {
|
|
u.create.conflict = append(u.create.conflict, sql.DoNothing())
|
|
return u
|
|
}
|
|
|
|
// Update allows overriding fields `UPDATE` values. See the UserMetaCreateBulk.OnConflict
|
|
// documentation for more info.
|
|
func (u *UserMetaUpsertBulk) Update(set func(*UserMetaUpsert)) *UserMetaUpsertBulk {
|
|
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
|
|
set(&UserMetaUpsert{UpdateSet: update})
|
|
}))
|
|
return u
|
|
}
|
|
|
|
// SetUpdatedAt sets the "updated_at" field.
|
|
func (u *UserMetaUpsertBulk) SetUpdatedAt(v time.Time) *UserMetaUpsertBulk {
|
|
return u.Update(func(s *UserMetaUpsert) {
|
|
s.SetUpdatedAt(v)
|
|
})
|
|
}
|
|
|
|
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
|
|
func (u *UserMetaUpsertBulk) UpdateUpdatedAt() *UserMetaUpsertBulk {
|
|
return u.Update(func(s *UserMetaUpsert) {
|
|
s.UpdateUpdatedAt()
|
|
})
|
|
}
|
|
|
|
// SetVersion sets the "version" field.
|
|
func (u *UserMetaUpsertBulk) SetVersion(v int64) *UserMetaUpsertBulk {
|
|
return u.Update(func(s *UserMetaUpsert) {
|
|
s.SetVersion(v)
|
|
})
|
|
}
|
|
|
|
// AddVersion adds v to the "version" field.
|
|
func (u *UserMetaUpsertBulk) AddVersion(v int64) *UserMetaUpsertBulk {
|
|
return u.Update(func(s *UserMetaUpsert) {
|
|
s.AddVersion(v)
|
|
})
|
|
}
|
|
|
|
// UpdateVersion sets the "version" field to the value that was provided on create.
|
|
func (u *UserMetaUpsertBulk) UpdateVersion() *UserMetaUpsertBulk {
|
|
return u.Update(func(s *UserMetaUpsert) {
|
|
s.UpdateVersion()
|
|
})
|
|
}
|
|
|
|
// SetUserID sets the "user_id" field.
|
|
func (u *UserMetaUpsertBulk) SetUserID(v int64) *UserMetaUpsertBulk {
|
|
return u.Update(func(s *UserMetaUpsert) {
|
|
s.SetUserID(v)
|
|
})
|
|
}
|
|
|
|
// UpdateUserID sets the "user_id" field to the value that was provided on create.
|
|
func (u *UserMetaUpsertBulk) UpdateUserID() *UserMetaUpsertBulk {
|
|
return u.Update(func(s *UserMetaUpsert) {
|
|
s.UpdateUserID()
|
|
})
|
|
}
|
|
|
|
// SetKey sets the "key" field.
|
|
func (u *UserMetaUpsertBulk) SetKey(v string) *UserMetaUpsertBulk {
|
|
return u.Update(func(s *UserMetaUpsert) {
|
|
s.SetKey(v)
|
|
})
|
|
}
|
|
|
|
// UpdateKey sets the "key" field to the value that was provided on create.
|
|
func (u *UserMetaUpsertBulk) UpdateKey() *UserMetaUpsertBulk {
|
|
return u.Update(func(s *UserMetaUpsert) {
|
|
s.UpdateKey()
|
|
})
|
|
}
|
|
|
|
// ClearKey clears the value of the "key" field.
|
|
func (u *UserMetaUpsertBulk) ClearKey() *UserMetaUpsertBulk {
|
|
return u.Update(func(s *UserMetaUpsert) {
|
|
s.ClearKey()
|
|
})
|
|
}
|
|
|
|
// SetValue sets the "value" field.
|
|
func (u *UserMetaUpsertBulk) SetValue(v string) *UserMetaUpsertBulk {
|
|
return u.Update(func(s *UserMetaUpsert) {
|
|
s.SetValue(v)
|
|
})
|
|
}
|
|
|
|
// UpdateValue sets the "value" field to the value that was provided on create.
|
|
func (u *UserMetaUpsertBulk) UpdateValue() *UserMetaUpsertBulk {
|
|
return u.Update(func(s *UserMetaUpsert) {
|
|
s.UpdateValue()
|
|
})
|
|
}
|
|
|
|
// ClearValue clears the value of the "value" field.
|
|
func (u *UserMetaUpsertBulk) ClearValue() *UserMetaUpsertBulk {
|
|
return u.Update(func(s *UserMetaUpsert) {
|
|
s.ClearValue()
|
|
})
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (u *UserMetaUpsertBulk) Exec(ctx context.Context) error {
|
|
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 UserMetaCreateBulk instead", i)
|
|
}
|
|
}
|
|
if len(u.create.conflict) == 0 {
|
|
return errors.New("ent: missing options for UserMetaCreateBulk.OnConflict")
|
|
}
|
|
return u.create.Exec(ctx)
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (u *UserMetaUpsertBulk) ExecX(ctx context.Context) {
|
|
if err := u.create.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|