mirror of
https://github.com/chaitin/MonkeyCode.git
synced 2026-11-22 19:39:31 +08:00
1078 lines
32 KiB
Go
1078 lines
32 KiB
Go
// Code generated by ent, DO NOT EDIT.
|
|
|
|
package db
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
"time"
|
|
|
|
"entgo.io/ent/dialect"
|
|
"entgo.io/ent/dialect/sql"
|
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
|
"entgo.io/ent/schema/field"
|
|
"github.com/chaitin/MonkeyCode/backend/consts"
|
|
"github.com/chaitin/MonkeyCode/backend/db/user"
|
|
"github.com/chaitin/MonkeyCode/backend/db/useridentity"
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
// UserIdentityCreate is the builder for creating a UserIdentity entity.
|
|
type UserIdentityCreate struct {
|
|
config
|
|
mutation *UserIdentityMutation
|
|
hooks []Hook
|
|
conflict []sql.ConflictOption
|
|
}
|
|
|
|
// SetDeletedAt sets the "deleted_at" field.
|
|
func (_c *UserIdentityCreate) SetDeletedAt(v time.Time) *UserIdentityCreate {
|
|
_c.mutation.SetDeletedAt(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
|
|
func (_c *UserIdentityCreate) SetNillableDeletedAt(v *time.Time) *UserIdentityCreate {
|
|
if v != nil {
|
|
_c.SetDeletedAt(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetUserID sets the "user_id" field.
|
|
func (_c *UserIdentityCreate) SetUserID(v uuid.UUID) *UserIdentityCreate {
|
|
_c.mutation.SetUserID(v)
|
|
return _c
|
|
}
|
|
|
|
// SetPlatform sets the "platform" field.
|
|
func (_c *UserIdentityCreate) SetPlatform(v consts.UserPlatform) *UserIdentityCreate {
|
|
_c.mutation.SetPlatform(v)
|
|
return _c
|
|
}
|
|
|
|
// SetIdentityID sets the "identity_id" field.
|
|
func (_c *UserIdentityCreate) SetIdentityID(v string) *UserIdentityCreate {
|
|
_c.mutation.SetIdentityID(v)
|
|
return _c
|
|
}
|
|
|
|
// SetUsername sets the "username" field.
|
|
func (_c *UserIdentityCreate) SetUsername(v string) *UserIdentityCreate {
|
|
_c.mutation.SetUsername(v)
|
|
return _c
|
|
}
|
|
|
|
// SetEmail sets the "email" field.
|
|
func (_c *UserIdentityCreate) SetEmail(v string) *UserIdentityCreate {
|
|
_c.mutation.SetEmail(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableEmail sets the "email" field if the given value is not nil.
|
|
func (_c *UserIdentityCreate) SetNillableEmail(v *string) *UserIdentityCreate {
|
|
if v != nil {
|
|
_c.SetEmail(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetAvatarURL sets the "avatar_url" field.
|
|
func (_c *UserIdentityCreate) SetAvatarURL(v string) *UserIdentityCreate {
|
|
_c.mutation.SetAvatarURL(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableAvatarURL sets the "avatar_url" field if the given value is not nil.
|
|
func (_c *UserIdentityCreate) SetNillableAvatarURL(v *string) *UserIdentityCreate {
|
|
if v != nil {
|
|
_c.SetAvatarURL(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (_c *UserIdentityCreate) SetCreatedAt(v time.Time) *UserIdentityCreate {
|
|
_c.mutation.SetCreatedAt(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
|
func (_c *UserIdentityCreate) SetNillableCreatedAt(v *time.Time) *UserIdentityCreate {
|
|
if v != nil {
|
|
_c.SetCreatedAt(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetUpdatedAt sets the "updated_at" field.
|
|
func (_c *UserIdentityCreate) SetUpdatedAt(v time.Time) *UserIdentityCreate {
|
|
_c.mutation.SetUpdatedAt(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
|
|
func (_c *UserIdentityCreate) SetNillableUpdatedAt(v *time.Time) *UserIdentityCreate {
|
|
if v != nil {
|
|
_c.SetUpdatedAt(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetID sets the "id" field.
|
|
func (_c *UserIdentityCreate) SetID(v uuid.UUID) *UserIdentityCreate {
|
|
_c.mutation.SetID(v)
|
|
return _c
|
|
}
|
|
|
|
// SetUser sets the "user" edge to the User entity.
|
|
func (_c *UserIdentityCreate) SetUser(v *User) *UserIdentityCreate {
|
|
return _c.SetUserID(v.ID)
|
|
}
|
|
|
|
// Mutation returns the UserIdentityMutation object of the builder.
|
|
func (_c *UserIdentityCreate) Mutation() *UserIdentityMutation {
|
|
return _c.mutation
|
|
}
|
|
|
|
// Save creates the UserIdentity in the database.
|
|
func (_c *UserIdentityCreate) Save(ctx context.Context) (*UserIdentity, error) {
|
|
if err := _c.defaults(); err != nil {
|
|
return nil, err
|
|
}
|
|
return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
|
|
}
|
|
|
|
// SaveX calls Save and panics if Save returns an error.
|
|
func (_c *UserIdentityCreate) SaveX(ctx context.Context) *UserIdentity {
|
|
v, err := _c.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return v
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (_c *UserIdentityCreate) Exec(ctx context.Context) error {
|
|
_, err := _c.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_c *UserIdentityCreate) 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 *UserIdentityCreate) defaults() error {
|
|
if _, ok := _c.mutation.CreatedAt(); !ok {
|
|
if useridentity.DefaultCreatedAt == nil {
|
|
return fmt.Errorf("db: uninitialized useridentity.DefaultCreatedAt (forgotten import db/runtime?)")
|
|
}
|
|
v := useridentity.DefaultCreatedAt()
|
|
_c.mutation.SetCreatedAt(v)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// check runs all checks and user-defined validators on the builder.
|
|
func (_c *UserIdentityCreate) check() error {
|
|
if _, ok := _c.mutation.UserID(); !ok {
|
|
return &ValidationError{Name: "user_id", err: errors.New(`db: missing required field "UserIdentity.user_id"`)}
|
|
}
|
|
if _, ok := _c.mutation.Platform(); !ok {
|
|
return &ValidationError{Name: "platform", err: errors.New(`db: missing required field "UserIdentity.platform"`)}
|
|
}
|
|
if v, ok := _c.mutation.Platform(); ok {
|
|
if err := useridentity.PlatformValidator(string(v)); err != nil {
|
|
return &ValidationError{Name: "platform", err: fmt.Errorf(`db: validator failed for field "UserIdentity.platform": %w`, err)}
|
|
}
|
|
}
|
|
if _, ok := _c.mutation.IdentityID(); !ok {
|
|
return &ValidationError{Name: "identity_id", err: errors.New(`db: missing required field "UserIdentity.identity_id"`)}
|
|
}
|
|
if v, ok := _c.mutation.IdentityID(); ok {
|
|
if err := useridentity.IdentityIDValidator(v); err != nil {
|
|
return &ValidationError{Name: "identity_id", err: fmt.Errorf(`db: validator failed for field "UserIdentity.identity_id": %w`, err)}
|
|
}
|
|
}
|
|
if _, ok := _c.mutation.Username(); !ok {
|
|
return &ValidationError{Name: "username", err: errors.New(`db: missing required field "UserIdentity.username"`)}
|
|
}
|
|
if v, ok := _c.mutation.Username(); ok {
|
|
if err := useridentity.UsernameValidator(v); err != nil {
|
|
return &ValidationError{Name: "username", err: fmt.Errorf(`db: validator failed for field "UserIdentity.username": %w`, err)}
|
|
}
|
|
}
|
|
if _, ok := _c.mutation.CreatedAt(); !ok {
|
|
return &ValidationError{Name: "created_at", err: errors.New(`db: missing required field "UserIdentity.created_at"`)}
|
|
}
|
|
if len(_c.mutation.UserIDs()) == 0 {
|
|
return &ValidationError{Name: "user", err: errors.New(`db: missing required edge "UserIdentity.user"`)}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (_c *UserIdentityCreate) sqlSave(ctx context.Context) (*UserIdentity, 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 != nil {
|
|
if id, ok := _spec.ID.Value.(*uuid.UUID); ok {
|
|
_node.ID = *id
|
|
} else if err := _node.ID.Scan(_spec.ID.Value); err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
_c.mutation.id = &_node.ID
|
|
_c.mutation.done = true
|
|
return _node, nil
|
|
}
|
|
|
|
func (_c *UserIdentityCreate) createSpec() (*UserIdentity, *sqlgraph.CreateSpec) {
|
|
var (
|
|
_node = &UserIdentity{config: _c.config}
|
|
_spec = sqlgraph.NewCreateSpec(useridentity.Table, sqlgraph.NewFieldSpec(useridentity.FieldID, field.TypeUUID))
|
|
)
|
|
_spec.OnConflict = _c.conflict
|
|
if id, ok := _c.mutation.ID(); ok {
|
|
_node.ID = id
|
|
_spec.ID.Value = &id
|
|
}
|
|
if value, ok := _c.mutation.DeletedAt(); ok {
|
|
_spec.SetField(useridentity.FieldDeletedAt, field.TypeTime, value)
|
|
_node.DeletedAt = value
|
|
}
|
|
if value, ok := _c.mutation.Platform(); ok {
|
|
_spec.SetField(useridentity.FieldPlatform, field.TypeString, value)
|
|
_node.Platform = value
|
|
}
|
|
if value, ok := _c.mutation.IdentityID(); ok {
|
|
_spec.SetField(useridentity.FieldIdentityID, field.TypeString, value)
|
|
_node.IdentityID = value
|
|
}
|
|
if value, ok := _c.mutation.Username(); ok {
|
|
_spec.SetField(useridentity.FieldUsername, field.TypeString, value)
|
|
_node.Username = value
|
|
}
|
|
if value, ok := _c.mutation.Email(); ok {
|
|
_spec.SetField(useridentity.FieldEmail, field.TypeString, value)
|
|
_node.Email = value
|
|
}
|
|
if value, ok := _c.mutation.AvatarURL(); ok {
|
|
_spec.SetField(useridentity.FieldAvatarURL, field.TypeString, value)
|
|
_node.AvatarURL = value
|
|
}
|
|
if value, ok := _c.mutation.CreatedAt(); ok {
|
|
_spec.SetField(useridentity.FieldCreatedAt, field.TypeTime, value)
|
|
_node.CreatedAt = value
|
|
}
|
|
if value, ok := _c.mutation.UpdatedAt(); ok {
|
|
_spec.SetField(useridentity.FieldUpdatedAt, field.TypeTime, value)
|
|
_node.UpdatedAt = value
|
|
}
|
|
if nodes := _c.mutation.UserIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: true,
|
|
Table: useridentity.UserTable,
|
|
Columns: []string{useridentity.UserColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID),
|
|
},
|
|
}
|
|
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.UserIdentity.Create().
|
|
// SetDeletedAt(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.UserIdentityUpsert) {
|
|
// SetDeletedAt(v+v).
|
|
// }).
|
|
// Exec(ctx)
|
|
func (_c *UserIdentityCreate) OnConflict(opts ...sql.ConflictOption) *UserIdentityUpsertOne {
|
|
_c.conflict = opts
|
|
return &UserIdentityUpsertOne{
|
|
create: _c,
|
|
}
|
|
}
|
|
|
|
// OnConflictColumns calls `OnConflict` and configures the columns
|
|
// as conflict target. Using this option is equivalent to using:
|
|
//
|
|
// client.UserIdentity.Create().
|
|
// OnConflict(sql.ConflictColumns(columns...)).
|
|
// Exec(ctx)
|
|
func (_c *UserIdentityCreate) OnConflictColumns(columns ...string) *UserIdentityUpsertOne {
|
|
_c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
|
|
return &UserIdentityUpsertOne{
|
|
create: _c,
|
|
}
|
|
}
|
|
|
|
type (
|
|
// UserIdentityUpsertOne is the builder for "upsert"-ing
|
|
// one UserIdentity node.
|
|
UserIdentityUpsertOne struct {
|
|
create *UserIdentityCreate
|
|
}
|
|
|
|
// UserIdentityUpsert is the "OnConflict" setter.
|
|
UserIdentityUpsert struct {
|
|
*sql.UpdateSet
|
|
}
|
|
)
|
|
|
|
// SetDeletedAt sets the "deleted_at" field.
|
|
func (u *UserIdentityUpsert) SetDeletedAt(v time.Time) *UserIdentityUpsert {
|
|
u.Set(useridentity.FieldDeletedAt, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
|
|
func (u *UserIdentityUpsert) UpdateDeletedAt() *UserIdentityUpsert {
|
|
u.SetExcluded(useridentity.FieldDeletedAt)
|
|
return u
|
|
}
|
|
|
|
// ClearDeletedAt clears the value of the "deleted_at" field.
|
|
func (u *UserIdentityUpsert) ClearDeletedAt() *UserIdentityUpsert {
|
|
u.SetNull(useridentity.FieldDeletedAt)
|
|
return u
|
|
}
|
|
|
|
// SetUserID sets the "user_id" field.
|
|
func (u *UserIdentityUpsert) SetUserID(v uuid.UUID) *UserIdentityUpsert {
|
|
u.Set(useridentity.FieldUserID, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateUserID sets the "user_id" field to the value that was provided on create.
|
|
func (u *UserIdentityUpsert) UpdateUserID() *UserIdentityUpsert {
|
|
u.SetExcluded(useridentity.FieldUserID)
|
|
return u
|
|
}
|
|
|
|
// SetPlatform sets the "platform" field.
|
|
func (u *UserIdentityUpsert) SetPlatform(v consts.UserPlatform) *UserIdentityUpsert {
|
|
u.Set(useridentity.FieldPlatform, v)
|
|
return u
|
|
}
|
|
|
|
// UpdatePlatform sets the "platform" field to the value that was provided on create.
|
|
func (u *UserIdentityUpsert) UpdatePlatform() *UserIdentityUpsert {
|
|
u.SetExcluded(useridentity.FieldPlatform)
|
|
return u
|
|
}
|
|
|
|
// SetIdentityID sets the "identity_id" field.
|
|
func (u *UserIdentityUpsert) SetIdentityID(v string) *UserIdentityUpsert {
|
|
u.Set(useridentity.FieldIdentityID, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateIdentityID sets the "identity_id" field to the value that was provided on create.
|
|
func (u *UserIdentityUpsert) UpdateIdentityID() *UserIdentityUpsert {
|
|
u.SetExcluded(useridentity.FieldIdentityID)
|
|
return u
|
|
}
|
|
|
|
// SetUsername sets the "username" field.
|
|
func (u *UserIdentityUpsert) SetUsername(v string) *UserIdentityUpsert {
|
|
u.Set(useridentity.FieldUsername, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateUsername sets the "username" field to the value that was provided on create.
|
|
func (u *UserIdentityUpsert) UpdateUsername() *UserIdentityUpsert {
|
|
u.SetExcluded(useridentity.FieldUsername)
|
|
return u
|
|
}
|
|
|
|
// SetEmail sets the "email" field.
|
|
func (u *UserIdentityUpsert) SetEmail(v string) *UserIdentityUpsert {
|
|
u.Set(useridentity.FieldEmail, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateEmail sets the "email" field to the value that was provided on create.
|
|
func (u *UserIdentityUpsert) UpdateEmail() *UserIdentityUpsert {
|
|
u.SetExcluded(useridentity.FieldEmail)
|
|
return u
|
|
}
|
|
|
|
// ClearEmail clears the value of the "email" field.
|
|
func (u *UserIdentityUpsert) ClearEmail() *UserIdentityUpsert {
|
|
u.SetNull(useridentity.FieldEmail)
|
|
return u
|
|
}
|
|
|
|
// SetAvatarURL sets the "avatar_url" field.
|
|
func (u *UserIdentityUpsert) SetAvatarURL(v string) *UserIdentityUpsert {
|
|
u.Set(useridentity.FieldAvatarURL, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateAvatarURL sets the "avatar_url" field to the value that was provided on create.
|
|
func (u *UserIdentityUpsert) UpdateAvatarURL() *UserIdentityUpsert {
|
|
u.SetExcluded(useridentity.FieldAvatarURL)
|
|
return u
|
|
}
|
|
|
|
// ClearAvatarURL clears the value of the "avatar_url" field.
|
|
func (u *UserIdentityUpsert) ClearAvatarURL() *UserIdentityUpsert {
|
|
u.SetNull(useridentity.FieldAvatarURL)
|
|
return u
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (u *UserIdentityUpsert) SetCreatedAt(v time.Time) *UserIdentityUpsert {
|
|
u.Set(useridentity.FieldCreatedAt, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateCreatedAt sets the "created_at" field to the value that was provided on create.
|
|
func (u *UserIdentityUpsert) UpdateCreatedAt() *UserIdentityUpsert {
|
|
u.SetExcluded(useridentity.FieldCreatedAt)
|
|
return u
|
|
}
|
|
|
|
// SetUpdatedAt sets the "updated_at" field.
|
|
func (u *UserIdentityUpsert) SetUpdatedAt(v time.Time) *UserIdentityUpsert {
|
|
u.Set(useridentity.FieldUpdatedAt, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
|
|
func (u *UserIdentityUpsert) UpdateUpdatedAt() *UserIdentityUpsert {
|
|
u.SetExcluded(useridentity.FieldUpdatedAt)
|
|
return u
|
|
}
|
|
|
|
// ClearUpdatedAt clears the value of the "updated_at" field.
|
|
func (u *UserIdentityUpsert) ClearUpdatedAt() *UserIdentityUpsert {
|
|
u.SetNull(useridentity.FieldUpdatedAt)
|
|
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.UserIdentity.Create().
|
|
// OnConflict(
|
|
// sql.ResolveWithNewValues(),
|
|
// sql.ResolveWith(func(u *sql.UpdateSet) {
|
|
// u.SetIgnore(useridentity.FieldID)
|
|
// }),
|
|
// ).
|
|
// Exec(ctx)
|
|
func (u *UserIdentityUpsertOne) UpdateNewValues() *UserIdentityUpsertOne {
|
|
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(useridentity.FieldID)
|
|
}
|
|
}))
|
|
return u
|
|
}
|
|
|
|
// Ignore sets each column to itself in case of conflict.
|
|
// Using this option is equivalent to using:
|
|
//
|
|
// client.UserIdentity.Create().
|
|
// OnConflict(sql.ResolveWithIgnore()).
|
|
// Exec(ctx)
|
|
func (u *UserIdentityUpsertOne) Ignore() *UserIdentityUpsertOne {
|
|
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 *UserIdentityUpsertOne) DoNothing() *UserIdentityUpsertOne {
|
|
u.create.conflict = append(u.create.conflict, sql.DoNothing())
|
|
return u
|
|
}
|
|
|
|
// Update allows overriding fields `UPDATE` values. See the UserIdentityCreate.OnConflict
|
|
// documentation for more info.
|
|
func (u *UserIdentityUpsertOne) Update(set func(*UserIdentityUpsert)) *UserIdentityUpsertOne {
|
|
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
|
|
set(&UserIdentityUpsert{UpdateSet: update})
|
|
}))
|
|
return u
|
|
}
|
|
|
|
// SetDeletedAt sets the "deleted_at" field.
|
|
func (u *UserIdentityUpsertOne) SetDeletedAt(v time.Time) *UserIdentityUpsertOne {
|
|
return u.Update(func(s *UserIdentityUpsert) {
|
|
s.SetDeletedAt(v)
|
|
})
|
|
}
|
|
|
|
// UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
|
|
func (u *UserIdentityUpsertOne) UpdateDeletedAt() *UserIdentityUpsertOne {
|
|
return u.Update(func(s *UserIdentityUpsert) {
|
|
s.UpdateDeletedAt()
|
|
})
|
|
}
|
|
|
|
// ClearDeletedAt clears the value of the "deleted_at" field.
|
|
func (u *UserIdentityUpsertOne) ClearDeletedAt() *UserIdentityUpsertOne {
|
|
return u.Update(func(s *UserIdentityUpsert) {
|
|
s.ClearDeletedAt()
|
|
})
|
|
}
|
|
|
|
// SetUserID sets the "user_id" field.
|
|
func (u *UserIdentityUpsertOne) SetUserID(v uuid.UUID) *UserIdentityUpsertOne {
|
|
return u.Update(func(s *UserIdentityUpsert) {
|
|
s.SetUserID(v)
|
|
})
|
|
}
|
|
|
|
// UpdateUserID sets the "user_id" field to the value that was provided on create.
|
|
func (u *UserIdentityUpsertOne) UpdateUserID() *UserIdentityUpsertOne {
|
|
return u.Update(func(s *UserIdentityUpsert) {
|
|
s.UpdateUserID()
|
|
})
|
|
}
|
|
|
|
// SetPlatform sets the "platform" field.
|
|
func (u *UserIdentityUpsertOne) SetPlatform(v consts.UserPlatform) *UserIdentityUpsertOne {
|
|
return u.Update(func(s *UserIdentityUpsert) {
|
|
s.SetPlatform(v)
|
|
})
|
|
}
|
|
|
|
// UpdatePlatform sets the "platform" field to the value that was provided on create.
|
|
func (u *UserIdentityUpsertOne) UpdatePlatform() *UserIdentityUpsertOne {
|
|
return u.Update(func(s *UserIdentityUpsert) {
|
|
s.UpdatePlatform()
|
|
})
|
|
}
|
|
|
|
// SetIdentityID sets the "identity_id" field.
|
|
func (u *UserIdentityUpsertOne) SetIdentityID(v string) *UserIdentityUpsertOne {
|
|
return u.Update(func(s *UserIdentityUpsert) {
|
|
s.SetIdentityID(v)
|
|
})
|
|
}
|
|
|
|
// UpdateIdentityID sets the "identity_id" field to the value that was provided on create.
|
|
func (u *UserIdentityUpsertOne) UpdateIdentityID() *UserIdentityUpsertOne {
|
|
return u.Update(func(s *UserIdentityUpsert) {
|
|
s.UpdateIdentityID()
|
|
})
|
|
}
|
|
|
|
// SetUsername sets the "username" field.
|
|
func (u *UserIdentityUpsertOne) SetUsername(v string) *UserIdentityUpsertOne {
|
|
return u.Update(func(s *UserIdentityUpsert) {
|
|
s.SetUsername(v)
|
|
})
|
|
}
|
|
|
|
// UpdateUsername sets the "username" field to the value that was provided on create.
|
|
func (u *UserIdentityUpsertOne) UpdateUsername() *UserIdentityUpsertOne {
|
|
return u.Update(func(s *UserIdentityUpsert) {
|
|
s.UpdateUsername()
|
|
})
|
|
}
|
|
|
|
// SetEmail sets the "email" field.
|
|
func (u *UserIdentityUpsertOne) SetEmail(v string) *UserIdentityUpsertOne {
|
|
return u.Update(func(s *UserIdentityUpsert) {
|
|
s.SetEmail(v)
|
|
})
|
|
}
|
|
|
|
// UpdateEmail sets the "email" field to the value that was provided on create.
|
|
func (u *UserIdentityUpsertOne) UpdateEmail() *UserIdentityUpsertOne {
|
|
return u.Update(func(s *UserIdentityUpsert) {
|
|
s.UpdateEmail()
|
|
})
|
|
}
|
|
|
|
// ClearEmail clears the value of the "email" field.
|
|
func (u *UserIdentityUpsertOne) ClearEmail() *UserIdentityUpsertOne {
|
|
return u.Update(func(s *UserIdentityUpsert) {
|
|
s.ClearEmail()
|
|
})
|
|
}
|
|
|
|
// SetAvatarURL sets the "avatar_url" field.
|
|
func (u *UserIdentityUpsertOne) SetAvatarURL(v string) *UserIdentityUpsertOne {
|
|
return u.Update(func(s *UserIdentityUpsert) {
|
|
s.SetAvatarURL(v)
|
|
})
|
|
}
|
|
|
|
// UpdateAvatarURL sets the "avatar_url" field to the value that was provided on create.
|
|
func (u *UserIdentityUpsertOne) UpdateAvatarURL() *UserIdentityUpsertOne {
|
|
return u.Update(func(s *UserIdentityUpsert) {
|
|
s.UpdateAvatarURL()
|
|
})
|
|
}
|
|
|
|
// ClearAvatarURL clears the value of the "avatar_url" field.
|
|
func (u *UserIdentityUpsertOne) ClearAvatarURL() *UserIdentityUpsertOne {
|
|
return u.Update(func(s *UserIdentityUpsert) {
|
|
s.ClearAvatarURL()
|
|
})
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (u *UserIdentityUpsertOne) SetCreatedAt(v time.Time) *UserIdentityUpsertOne {
|
|
return u.Update(func(s *UserIdentityUpsert) {
|
|
s.SetCreatedAt(v)
|
|
})
|
|
}
|
|
|
|
// UpdateCreatedAt sets the "created_at" field to the value that was provided on create.
|
|
func (u *UserIdentityUpsertOne) UpdateCreatedAt() *UserIdentityUpsertOne {
|
|
return u.Update(func(s *UserIdentityUpsert) {
|
|
s.UpdateCreatedAt()
|
|
})
|
|
}
|
|
|
|
// SetUpdatedAt sets the "updated_at" field.
|
|
func (u *UserIdentityUpsertOne) SetUpdatedAt(v time.Time) *UserIdentityUpsertOne {
|
|
return u.Update(func(s *UserIdentityUpsert) {
|
|
s.SetUpdatedAt(v)
|
|
})
|
|
}
|
|
|
|
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
|
|
func (u *UserIdentityUpsertOne) UpdateUpdatedAt() *UserIdentityUpsertOne {
|
|
return u.Update(func(s *UserIdentityUpsert) {
|
|
s.UpdateUpdatedAt()
|
|
})
|
|
}
|
|
|
|
// ClearUpdatedAt clears the value of the "updated_at" field.
|
|
func (u *UserIdentityUpsertOne) ClearUpdatedAt() *UserIdentityUpsertOne {
|
|
return u.Update(func(s *UserIdentityUpsert) {
|
|
s.ClearUpdatedAt()
|
|
})
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (u *UserIdentityUpsertOne) Exec(ctx context.Context) error {
|
|
if len(u.create.conflict) == 0 {
|
|
return errors.New("db: missing options for UserIdentityCreate.OnConflict")
|
|
}
|
|
return u.create.Exec(ctx)
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (u *UserIdentityUpsertOne) 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 *UserIdentityUpsertOne) ID(ctx context.Context) (id uuid.UUID, err error) {
|
|
if u.create.driver.Dialect() == dialect.MySQL {
|
|
// In case of "ON CONFLICT", there is no way to get back non-numeric ID
|
|
// fields from the database since MySQL does not support the RETURNING clause.
|
|
return id, errors.New("db: UserIdentityUpsertOne.ID is not supported by MySQL driver. Use UserIdentityUpsertOne.Exec instead")
|
|
}
|
|
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 *UserIdentityUpsertOne) IDX(ctx context.Context) uuid.UUID {
|
|
id, err := u.ID(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return id
|
|
}
|
|
|
|
// UserIdentityCreateBulk is the builder for creating many UserIdentity entities in bulk.
|
|
type UserIdentityCreateBulk struct {
|
|
config
|
|
err error
|
|
builders []*UserIdentityCreate
|
|
conflict []sql.ConflictOption
|
|
}
|
|
|
|
// Save creates the UserIdentity entities in the database.
|
|
func (_c *UserIdentityCreateBulk) Save(ctx context.Context) ([]*UserIdentity, error) {
|
|
if _c.err != nil {
|
|
return nil, _c.err
|
|
}
|
|
specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
|
|
nodes := make([]*UserIdentity, 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.(*UserIdentityMutation)
|
|
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
|
|
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 *UserIdentityCreateBulk) SaveX(ctx context.Context) []*UserIdentity {
|
|
v, err := _c.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return v
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (_c *UserIdentityCreateBulk) Exec(ctx context.Context) error {
|
|
_, err := _c.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_c *UserIdentityCreateBulk) 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.UserIdentity.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.UserIdentityUpsert) {
|
|
// SetDeletedAt(v+v).
|
|
// }).
|
|
// Exec(ctx)
|
|
func (_c *UserIdentityCreateBulk) OnConflict(opts ...sql.ConflictOption) *UserIdentityUpsertBulk {
|
|
_c.conflict = opts
|
|
return &UserIdentityUpsertBulk{
|
|
create: _c,
|
|
}
|
|
}
|
|
|
|
// OnConflictColumns calls `OnConflict` and configures the columns
|
|
// as conflict target. Using this option is equivalent to using:
|
|
//
|
|
// client.UserIdentity.Create().
|
|
// OnConflict(sql.ConflictColumns(columns...)).
|
|
// Exec(ctx)
|
|
func (_c *UserIdentityCreateBulk) OnConflictColumns(columns ...string) *UserIdentityUpsertBulk {
|
|
_c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
|
|
return &UserIdentityUpsertBulk{
|
|
create: _c,
|
|
}
|
|
}
|
|
|
|
// UserIdentityUpsertBulk is the builder for "upsert"-ing
|
|
// a bulk of UserIdentity nodes.
|
|
type UserIdentityUpsertBulk struct {
|
|
create *UserIdentityCreateBulk
|
|
}
|
|
|
|
// UpdateNewValues updates the mutable fields using the new values that
|
|
// were set on create. Using this option is equivalent to using:
|
|
//
|
|
// client.UserIdentity.Create().
|
|
// OnConflict(
|
|
// sql.ResolveWithNewValues(),
|
|
// sql.ResolveWith(func(u *sql.UpdateSet) {
|
|
// u.SetIgnore(useridentity.FieldID)
|
|
// }),
|
|
// ).
|
|
// Exec(ctx)
|
|
func (u *UserIdentityUpsertBulk) UpdateNewValues() *UserIdentityUpsertBulk {
|
|
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(useridentity.FieldID)
|
|
}
|
|
}
|
|
}))
|
|
return u
|
|
}
|
|
|
|
// Ignore sets each column to itself in case of conflict.
|
|
// Using this option is equivalent to using:
|
|
//
|
|
// client.UserIdentity.Create().
|
|
// OnConflict(sql.ResolveWithIgnore()).
|
|
// Exec(ctx)
|
|
func (u *UserIdentityUpsertBulk) Ignore() *UserIdentityUpsertBulk {
|
|
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 *UserIdentityUpsertBulk) DoNothing() *UserIdentityUpsertBulk {
|
|
u.create.conflict = append(u.create.conflict, sql.DoNothing())
|
|
return u
|
|
}
|
|
|
|
// Update allows overriding fields `UPDATE` values. See the UserIdentityCreateBulk.OnConflict
|
|
// documentation for more info.
|
|
func (u *UserIdentityUpsertBulk) Update(set func(*UserIdentityUpsert)) *UserIdentityUpsertBulk {
|
|
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
|
|
set(&UserIdentityUpsert{UpdateSet: update})
|
|
}))
|
|
return u
|
|
}
|
|
|
|
// SetDeletedAt sets the "deleted_at" field.
|
|
func (u *UserIdentityUpsertBulk) SetDeletedAt(v time.Time) *UserIdentityUpsertBulk {
|
|
return u.Update(func(s *UserIdentityUpsert) {
|
|
s.SetDeletedAt(v)
|
|
})
|
|
}
|
|
|
|
// UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
|
|
func (u *UserIdentityUpsertBulk) UpdateDeletedAt() *UserIdentityUpsertBulk {
|
|
return u.Update(func(s *UserIdentityUpsert) {
|
|
s.UpdateDeletedAt()
|
|
})
|
|
}
|
|
|
|
// ClearDeletedAt clears the value of the "deleted_at" field.
|
|
func (u *UserIdentityUpsertBulk) ClearDeletedAt() *UserIdentityUpsertBulk {
|
|
return u.Update(func(s *UserIdentityUpsert) {
|
|
s.ClearDeletedAt()
|
|
})
|
|
}
|
|
|
|
// SetUserID sets the "user_id" field.
|
|
func (u *UserIdentityUpsertBulk) SetUserID(v uuid.UUID) *UserIdentityUpsertBulk {
|
|
return u.Update(func(s *UserIdentityUpsert) {
|
|
s.SetUserID(v)
|
|
})
|
|
}
|
|
|
|
// UpdateUserID sets the "user_id" field to the value that was provided on create.
|
|
func (u *UserIdentityUpsertBulk) UpdateUserID() *UserIdentityUpsertBulk {
|
|
return u.Update(func(s *UserIdentityUpsert) {
|
|
s.UpdateUserID()
|
|
})
|
|
}
|
|
|
|
// SetPlatform sets the "platform" field.
|
|
func (u *UserIdentityUpsertBulk) SetPlatform(v consts.UserPlatform) *UserIdentityUpsertBulk {
|
|
return u.Update(func(s *UserIdentityUpsert) {
|
|
s.SetPlatform(v)
|
|
})
|
|
}
|
|
|
|
// UpdatePlatform sets the "platform" field to the value that was provided on create.
|
|
func (u *UserIdentityUpsertBulk) UpdatePlatform() *UserIdentityUpsertBulk {
|
|
return u.Update(func(s *UserIdentityUpsert) {
|
|
s.UpdatePlatform()
|
|
})
|
|
}
|
|
|
|
// SetIdentityID sets the "identity_id" field.
|
|
func (u *UserIdentityUpsertBulk) SetIdentityID(v string) *UserIdentityUpsertBulk {
|
|
return u.Update(func(s *UserIdentityUpsert) {
|
|
s.SetIdentityID(v)
|
|
})
|
|
}
|
|
|
|
// UpdateIdentityID sets the "identity_id" field to the value that was provided on create.
|
|
func (u *UserIdentityUpsertBulk) UpdateIdentityID() *UserIdentityUpsertBulk {
|
|
return u.Update(func(s *UserIdentityUpsert) {
|
|
s.UpdateIdentityID()
|
|
})
|
|
}
|
|
|
|
// SetUsername sets the "username" field.
|
|
func (u *UserIdentityUpsertBulk) SetUsername(v string) *UserIdentityUpsertBulk {
|
|
return u.Update(func(s *UserIdentityUpsert) {
|
|
s.SetUsername(v)
|
|
})
|
|
}
|
|
|
|
// UpdateUsername sets the "username" field to the value that was provided on create.
|
|
func (u *UserIdentityUpsertBulk) UpdateUsername() *UserIdentityUpsertBulk {
|
|
return u.Update(func(s *UserIdentityUpsert) {
|
|
s.UpdateUsername()
|
|
})
|
|
}
|
|
|
|
// SetEmail sets the "email" field.
|
|
func (u *UserIdentityUpsertBulk) SetEmail(v string) *UserIdentityUpsertBulk {
|
|
return u.Update(func(s *UserIdentityUpsert) {
|
|
s.SetEmail(v)
|
|
})
|
|
}
|
|
|
|
// UpdateEmail sets the "email" field to the value that was provided on create.
|
|
func (u *UserIdentityUpsertBulk) UpdateEmail() *UserIdentityUpsertBulk {
|
|
return u.Update(func(s *UserIdentityUpsert) {
|
|
s.UpdateEmail()
|
|
})
|
|
}
|
|
|
|
// ClearEmail clears the value of the "email" field.
|
|
func (u *UserIdentityUpsertBulk) ClearEmail() *UserIdentityUpsertBulk {
|
|
return u.Update(func(s *UserIdentityUpsert) {
|
|
s.ClearEmail()
|
|
})
|
|
}
|
|
|
|
// SetAvatarURL sets the "avatar_url" field.
|
|
func (u *UserIdentityUpsertBulk) SetAvatarURL(v string) *UserIdentityUpsertBulk {
|
|
return u.Update(func(s *UserIdentityUpsert) {
|
|
s.SetAvatarURL(v)
|
|
})
|
|
}
|
|
|
|
// UpdateAvatarURL sets the "avatar_url" field to the value that was provided on create.
|
|
func (u *UserIdentityUpsertBulk) UpdateAvatarURL() *UserIdentityUpsertBulk {
|
|
return u.Update(func(s *UserIdentityUpsert) {
|
|
s.UpdateAvatarURL()
|
|
})
|
|
}
|
|
|
|
// ClearAvatarURL clears the value of the "avatar_url" field.
|
|
func (u *UserIdentityUpsertBulk) ClearAvatarURL() *UserIdentityUpsertBulk {
|
|
return u.Update(func(s *UserIdentityUpsert) {
|
|
s.ClearAvatarURL()
|
|
})
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (u *UserIdentityUpsertBulk) SetCreatedAt(v time.Time) *UserIdentityUpsertBulk {
|
|
return u.Update(func(s *UserIdentityUpsert) {
|
|
s.SetCreatedAt(v)
|
|
})
|
|
}
|
|
|
|
// UpdateCreatedAt sets the "created_at" field to the value that was provided on create.
|
|
func (u *UserIdentityUpsertBulk) UpdateCreatedAt() *UserIdentityUpsertBulk {
|
|
return u.Update(func(s *UserIdentityUpsert) {
|
|
s.UpdateCreatedAt()
|
|
})
|
|
}
|
|
|
|
// SetUpdatedAt sets the "updated_at" field.
|
|
func (u *UserIdentityUpsertBulk) SetUpdatedAt(v time.Time) *UserIdentityUpsertBulk {
|
|
return u.Update(func(s *UserIdentityUpsert) {
|
|
s.SetUpdatedAt(v)
|
|
})
|
|
}
|
|
|
|
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
|
|
func (u *UserIdentityUpsertBulk) UpdateUpdatedAt() *UserIdentityUpsertBulk {
|
|
return u.Update(func(s *UserIdentityUpsert) {
|
|
s.UpdateUpdatedAt()
|
|
})
|
|
}
|
|
|
|
// ClearUpdatedAt clears the value of the "updated_at" field.
|
|
func (u *UserIdentityUpsertBulk) ClearUpdatedAt() *UserIdentityUpsertBulk {
|
|
return u.Update(func(s *UserIdentityUpsert) {
|
|
s.ClearUpdatedAt()
|
|
})
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (u *UserIdentityUpsertBulk) 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("db: OnConflict was set for builder %d. Set it on the UserIdentityCreateBulk instead", i)
|
|
}
|
|
}
|
|
if len(u.create.conflict) == 0 {
|
|
return errors.New("db: missing options for UserIdentityCreateBulk.OnConflict")
|
|
}
|
|
return u.create.Exec(ctx)
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (u *UserIdentityUpsertBulk) ExecX(ctx context.Context) {
|
|
if err := u.create.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|