mirror of
https://github.com/chaitin/MonkeyCode.git
synced 2026-11-22 11:28:46 +08:00
1073 lines
30 KiB
Go
1073 lines
30 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/db/image"
|
|
"github.com/chaitin/MonkeyCode/backend/db/project"
|
|
"github.com/chaitin/MonkeyCode/backend/db/projecttask"
|
|
"github.com/chaitin/MonkeyCode/backend/db/team"
|
|
"github.com/chaitin/MonkeyCode/backend/db/teamgroup"
|
|
"github.com/chaitin/MonkeyCode/backend/db/teamgroupimage"
|
|
"github.com/chaitin/MonkeyCode/backend/db/teamimage"
|
|
"github.com/chaitin/MonkeyCode/backend/db/user"
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
// ImageCreate is the builder for creating a Image entity.
|
|
type ImageCreate struct {
|
|
config
|
|
mutation *ImageMutation
|
|
hooks []Hook
|
|
conflict []sql.ConflictOption
|
|
}
|
|
|
|
// SetDeletedAt sets the "deleted_at" field.
|
|
func (_c *ImageCreate) SetDeletedAt(v time.Time) *ImageCreate {
|
|
_c.mutation.SetDeletedAt(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
|
|
func (_c *ImageCreate) SetNillableDeletedAt(v *time.Time) *ImageCreate {
|
|
if v != nil {
|
|
_c.SetDeletedAt(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetUserID sets the "user_id" field.
|
|
func (_c *ImageCreate) SetUserID(v uuid.UUID) *ImageCreate {
|
|
_c.mutation.SetUserID(v)
|
|
return _c
|
|
}
|
|
|
|
// SetName sets the "name" field.
|
|
func (_c *ImageCreate) SetName(v string) *ImageCreate {
|
|
_c.mutation.SetName(v)
|
|
return _c
|
|
}
|
|
|
|
// SetRemark sets the "remark" field.
|
|
func (_c *ImageCreate) SetRemark(v string) *ImageCreate {
|
|
_c.mutation.SetRemark(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableRemark sets the "remark" field if the given value is not nil.
|
|
func (_c *ImageCreate) SetNillableRemark(v *string) *ImageCreate {
|
|
if v != nil {
|
|
_c.SetRemark(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (_c *ImageCreate) SetCreatedAt(v time.Time) *ImageCreate {
|
|
_c.mutation.SetCreatedAt(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
|
func (_c *ImageCreate) SetNillableCreatedAt(v *time.Time) *ImageCreate {
|
|
if v != nil {
|
|
_c.SetCreatedAt(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetUpdatedAt sets the "updated_at" field.
|
|
func (_c *ImageCreate) SetUpdatedAt(v time.Time) *ImageCreate {
|
|
_c.mutation.SetUpdatedAt(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
|
|
func (_c *ImageCreate) SetNillableUpdatedAt(v *time.Time) *ImageCreate {
|
|
if v != nil {
|
|
_c.SetUpdatedAt(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetID sets the "id" field.
|
|
func (_c *ImageCreate) SetID(v uuid.UUID) *ImageCreate {
|
|
_c.mutation.SetID(v)
|
|
return _c
|
|
}
|
|
|
|
// SetUser sets the "user" edge to the User entity.
|
|
func (_c *ImageCreate) SetUser(v *User) *ImageCreate {
|
|
return _c.SetUserID(v.ID)
|
|
}
|
|
|
|
// AddTeamIDs adds the "teams" edge to the Team entity by IDs.
|
|
func (_c *ImageCreate) AddTeamIDs(ids ...uuid.UUID) *ImageCreate {
|
|
_c.mutation.AddTeamIDs(ids...)
|
|
return _c
|
|
}
|
|
|
|
// AddTeams adds the "teams" edges to the Team entity.
|
|
func (_c *ImageCreate) AddTeams(v ...*Team) *ImageCreate {
|
|
ids := make([]uuid.UUID, len(v))
|
|
for i := range v {
|
|
ids[i] = v[i].ID
|
|
}
|
|
return _c.AddTeamIDs(ids...)
|
|
}
|
|
|
|
// AddGroupIDs adds the "groups" edge to the TeamGroup entity by IDs.
|
|
func (_c *ImageCreate) AddGroupIDs(ids ...uuid.UUID) *ImageCreate {
|
|
_c.mutation.AddGroupIDs(ids...)
|
|
return _c
|
|
}
|
|
|
|
// AddGroups adds the "groups" edges to the TeamGroup entity.
|
|
func (_c *ImageCreate) AddGroups(v ...*TeamGroup) *ImageCreate {
|
|
ids := make([]uuid.UUID, len(v))
|
|
for i := range v {
|
|
ids[i] = v[i].ID
|
|
}
|
|
return _c.AddGroupIDs(ids...)
|
|
}
|
|
|
|
// AddProjectTaskIDs adds the "project_tasks" edge to the ProjectTask entity by IDs.
|
|
func (_c *ImageCreate) AddProjectTaskIDs(ids ...uuid.UUID) *ImageCreate {
|
|
_c.mutation.AddProjectTaskIDs(ids...)
|
|
return _c
|
|
}
|
|
|
|
// AddProjectTasks adds the "project_tasks" edges to the ProjectTask entity.
|
|
func (_c *ImageCreate) AddProjectTasks(v ...*ProjectTask) *ImageCreate {
|
|
ids := make([]uuid.UUID, len(v))
|
|
for i := range v {
|
|
ids[i] = v[i].ID
|
|
}
|
|
return _c.AddProjectTaskIDs(ids...)
|
|
}
|
|
|
|
// AddProjectIDs adds the "projects" edge to the Project entity by IDs.
|
|
func (_c *ImageCreate) AddProjectIDs(ids ...uuid.UUID) *ImageCreate {
|
|
_c.mutation.AddProjectIDs(ids...)
|
|
return _c
|
|
}
|
|
|
|
// AddProjects adds the "projects" edges to the Project entity.
|
|
func (_c *ImageCreate) AddProjects(v ...*Project) *ImageCreate {
|
|
ids := make([]uuid.UUID, len(v))
|
|
for i := range v {
|
|
ids[i] = v[i].ID
|
|
}
|
|
return _c.AddProjectIDs(ids...)
|
|
}
|
|
|
|
// AddTeamImageIDs adds the "team_images" edge to the TeamImage entity by IDs.
|
|
func (_c *ImageCreate) AddTeamImageIDs(ids ...uuid.UUID) *ImageCreate {
|
|
_c.mutation.AddTeamImageIDs(ids...)
|
|
return _c
|
|
}
|
|
|
|
// AddTeamImages adds the "team_images" edges to the TeamImage entity.
|
|
func (_c *ImageCreate) AddTeamImages(v ...*TeamImage) *ImageCreate {
|
|
ids := make([]uuid.UUID, len(v))
|
|
for i := range v {
|
|
ids[i] = v[i].ID
|
|
}
|
|
return _c.AddTeamImageIDs(ids...)
|
|
}
|
|
|
|
// AddTeamGroupImageIDs adds the "team_group_images" edge to the TeamGroupImage entity by IDs.
|
|
func (_c *ImageCreate) AddTeamGroupImageIDs(ids ...uuid.UUID) *ImageCreate {
|
|
_c.mutation.AddTeamGroupImageIDs(ids...)
|
|
return _c
|
|
}
|
|
|
|
// AddTeamGroupImages adds the "team_group_images" edges to the TeamGroupImage entity.
|
|
func (_c *ImageCreate) AddTeamGroupImages(v ...*TeamGroupImage) *ImageCreate {
|
|
ids := make([]uuid.UUID, len(v))
|
|
for i := range v {
|
|
ids[i] = v[i].ID
|
|
}
|
|
return _c.AddTeamGroupImageIDs(ids...)
|
|
}
|
|
|
|
// Mutation returns the ImageMutation object of the builder.
|
|
func (_c *ImageCreate) Mutation() *ImageMutation {
|
|
return _c.mutation
|
|
}
|
|
|
|
// Save creates the Image in the database.
|
|
func (_c *ImageCreate) Save(ctx context.Context) (*Image, 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 *ImageCreate) SaveX(ctx context.Context) *Image {
|
|
v, err := _c.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return v
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (_c *ImageCreate) Exec(ctx context.Context) error {
|
|
_, err := _c.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_c *ImageCreate) 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 *ImageCreate) defaults() error {
|
|
if _, ok := _c.mutation.CreatedAt(); !ok {
|
|
if image.DefaultCreatedAt == nil {
|
|
return fmt.Errorf("db: uninitialized image.DefaultCreatedAt (forgotten import db/runtime?)")
|
|
}
|
|
v := image.DefaultCreatedAt()
|
|
_c.mutation.SetCreatedAt(v)
|
|
}
|
|
if _, ok := _c.mutation.UpdatedAt(); !ok {
|
|
if image.DefaultUpdatedAt == nil {
|
|
return fmt.Errorf("db: uninitialized image.DefaultUpdatedAt (forgotten import db/runtime?)")
|
|
}
|
|
v := image.DefaultUpdatedAt()
|
|
_c.mutation.SetUpdatedAt(v)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// check runs all checks and user-defined validators on the builder.
|
|
func (_c *ImageCreate) check() error {
|
|
if _, ok := _c.mutation.UserID(); !ok {
|
|
return &ValidationError{Name: "user_id", err: errors.New(`db: missing required field "Image.user_id"`)}
|
|
}
|
|
if _, ok := _c.mutation.Name(); !ok {
|
|
return &ValidationError{Name: "name", err: errors.New(`db: missing required field "Image.name"`)}
|
|
}
|
|
if v, ok := _c.mutation.Name(); ok {
|
|
if err := image.NameValidator(v); err != nil {
|
|
return &ValidationError{Name: "name", err: fmt.Errorf(`db: validator failed for field "Image.name": %w`, err)}
|
|
}
|
|
}
|
|
if _, ok := _c.mutation.CreatedAt(); !ok {
|
|
return &ValidationError{Name: "created_at", err: errors.New(`db: missing required field "Image.created_at"`)}
|
|
}
|
|
if _, ok := _c.mutation.UpdatedAt(); !ok {
|
|
return &ValidationError{Name: "updated_at", err: errors.New(`db: missing required field "Image.updated_at"`)}
|
|
}
|
|
if len(_c.mutation.UserIDs()) == 0 {
|
|
return &ValidationError{Name: "user", err: errors.New(`db: missing required edge "Image.user"`)}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (_c *ImageCreate) sqlSave(ctx context.Context) (*Image, 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 *ImageCreate) createSpec() (*Image, *sqlgraph.CreateSpec) {
|
|
var (
|
|
_node = &Image{config: _c.config}
|
|
_spec = sqlgraph.NewCreateSpec(image.Table, sqlgraph.NewFieldSpec(image.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(image.FieldDeletedAt, field.TypeTime, value)
|
|
_node.DeletedAt = value
|
|
}
|
|
if value, ok := _c.mutation.Name(); ok {
|
|
_spec.SetField(image.FieldName, field.TypeString, value)
|
|
_node.Name = value
|
|
}
|
|
if value, ok := _c.mutation.Remark(); ok {
|
|
_spec.SetField(image.FieldRemark, field.TypeString, value)
|
|
_node.Remark = value
|
|
}
|
|
if value, ok := _c.mutation.CreatedAt(); ok {
|
|
_spec.SetField(image.FieldCreatedAt, field.TypeTime, value)
|
|
_node.CreatedAt = value
|
|
}
|
|
if value, ok := _c.mutation.UpdatedAt(); ok {
|
|
_spec.SetField(image.FieldUpdatedAt, field.TypeTime, value)
|
|
_node.UpdatedAt = value
|
|
}
|
|
if nodes := _c.mutation.UserIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: true,
|
|
Table: image.UserTable,
|
|
Columns: []string{image.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)
|
|
}
|
|
if nodes := _c.mutation.TeamsIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2M,
|
|
Inverse: true,
|
|
Table: image.TeamsTable,
|
|
Columns: image.TeamsPrimaryKey,
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(team.FieldID, field.TypeUUID),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
createE := &TeamImageCreate{config: _c.config, mutation: newTeamImageMutation(_c.config, OpCreate)}
|
|
createE.defaults()
|
|
_, specE := createE.createSpec()
|
|
edge.Target.Fields = specE.Fields
|
|
_spec.Edges = append(_spec.Edges, edge)
|
|
}
|
|
if nodes := _c.mutation.GroupsIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2M,
|
|
Inverse: true,
|
|
Table: image.GroupsTable,
|
|
Columns: image.GroupsPrimaryKey,
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(teamgroup.FieldID, field.TypeUUID),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
createE := &TeamGroupImageCreate{config: _c.config, mutation: newTeamGroupImageMutation(_c.config, OpCreate)}
|
|
createE.defaults()
|
|
_, specE := createE.createSpec()
|
|
edge.Target.Fields = specE.Fields
|
|
_spec.Edges = append(_spec.Edges, edge)
|
|
}
|
|
if nodes := _c.mutation.ProjectTasksIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: false,
|
|
Table: image.ProjectTasksTable,
|
|
Columns: []string{image.ProjectTasksColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(projecttask.FieldID, field.TypeUUID),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_spec.Edges = append(_spec.Edges, edge)
|
|
}
|
|
if nodes := _c.mutation.ProjectsIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: false,
|
|
Table: image.ProjectsTable,
|
|
Columns: []string{image.ProjectsColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(project.FieldID, field.TypeUUID),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_spec.Edges = append(_spec.Edges, edge)
|
|
}
|
|
if nodes := _c.mutation.TeamImagesIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: true,
|
|
Table: image.TeamImagesTable,
|
|
Columns: []string{image.TeamImagesColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(teamimage.FieldID, field.TypeUUID),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_spec.Edges = append(_spec.Edges, edge)
|
|
}
|
|
if nodes := _c.mutation.TeamGroupImagesIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: true,
|
|
Table: image.TeamGroupImagesTable,
|
|
Columns: []string{image.TeamGroupImagesColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(teamgroupimage.FieldID, field.TypeUUID),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_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.Image.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.ImageUpsert) {
|
|
// SetDeletedAt(v+v).
|
|
// }).
|
|
// Exec(ctx)
|
|
func (_c *ImageCreate) OnConflict(opts ...sql.ConflictOption) *ImageUpsertOne {
|
|
_c.conflict = opts
|
|
return &ImageUpsertOne{
|
|
create: _c,
|
|
}
|
|
}
|
|
|
|
// OnConflictColumns calls `OnConflict` and configures the columns
|
|
// as conflict target. Using this option is equivalent to using:
|
|
//
|
|
// client.Image.Create().
|
|
// OnConflict(sql.ConflictColumns(columns...)).
|
|
// Exec(ctx)
|
|
func (_c *ImageCreate) OnConflictColumns(columns ...string) *ImageUpsertOne {
|
|
_c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
|
|
return &ImageUpsertOne{
|
|
create: _c,
|
|
}
|
|
}
|
|
|
|
type (
|
|
// ImageUpsertOne is the builder for "upsert"-ing
|
|
// one Image node.
|
|
ImageUpsertOne struct {
|
|
create *ImageCreate
|
|
}
|
|
|
|
// ImageUpsert is the "OnConflict" setter.
|
|
ImageUpsert struct {
|
|
*sql.UpdateSet
|
|
}
|
|
)
|
|
|
|
// SetDeletedAt sets the "deleted_at" field.
|
|
func (u *ImageUpsert) SetDeletedAt(v time.Time) *ImageUpsert {
|
|
u.Set(image.FieldDeletedAt, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
|
|
func (u *ImageUpsert) UpdateDeletedAt() *ImageUpsert {
|
|
u.SetExcluded(image.FieldDeletedAt)
|
|
return u
|
|
}
|
|
|
|
// ClearDeletedAt clears the value of the "deleted_at" field.
|
|
func (u *ImageUpsert) ClearDeletedAt() *ImageUpsert {
|
|
u.SetNull(image.FieldDeletedAt)
|
|
return u
|
|
}
|
|
|
|
// SetUserID sets the "user_id" field.
|
|
func (u *ImageUpsert) SetUserID(v uuid.UUID) *ImageUpsert {
|
|
u.Set(image.FieldUserID, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateUserID sets the "user_id" field to the value that was provided on create.
|
|
func (u *ImageUpsert) UpdateUserID() *ImageUpsert {
|
|
u.SetExcluded(image.FieldUserID)
|
|
return u
|
|
}
|
|
|
|
// SetName sets the "name" field.
|
|
func (u *ImageUpsert) SetName(v string) *ImageUpsert {
|
|
u.Set(image.FieldName, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateName sets the "name" field to the value that was provided on create.
|
|
func (u *ImageUpsert) UpdateName() *ImageUpsert {
|
|
u.SetExcluded(image.FieldName)
|
|
return u
|
|
}
|
|
|
|
// SetRemark sets the "remark" field.
|
|
func (u *ImageUpsert) SetRemark(v string) *ImageUpsert {
|
|
u.Set(image.FieldRemark, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateRemark sets the "remark" field to the value that was provided on create.
|
|
func (u *ImageUpsert) UpdateRemark() *ImageUpsert {
|
|
u.SetExcluded(image.FieldRemark)
|
|
return u
|
|
}
|
|
|
|
// ClearRemark clears the value of the "remark" field.
|
|
func (u *ImageUpsert) ClearRemark() *ImageUpsert {
|
|
u.SetNull(image.FieldRemark)
|
|
return u
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (u *ImageUpsert) SetCreatedAt(v time.Time) *ImageUpsert {
|
|
u.Set(image.FieldCreatedAt, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateCreatedAt sets the "created_at" field to the value that was provided on create.
|
|
func (u *ImageUpsert) UpdateCreatedAt() *ImageUpsert {
|
|
u.SetExcluded(image.FieldCreatedAt)
|
|
return u
|
|
}
|
|
|
|
// SetUpdatedAt sets the "updated_at" field.
|
|
func (u *ImageUpsert) SetUpdatedAt(v time.Time) *ImageUpsert {
|
|
u.Set(image.FieldUpdatedAt, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
|
|
func (u *ImageUpsert) UpdateUpdatedAt() *ImageUpsert {
|
|
u.SetExcluded(image.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.Image.Create().
|
|
// OnConflict(
|
|
// sql.ResolveWithNewValues(),
|
|
// sql.ResolveWith(func(u *sql.UpdateSet) {
|
|
// u.SetIgnore(image.FieldID)
|
|
// }),
|
|
// ).
|
|
// Exec(ctx)
|
|
func (u *ImageUpsertOne) UpdateNewValues() *ImageUpsertOne {
|
|
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(image.FieldID)
|
|
}
|
|
}))
|
|
return u
|
|
}
|
|
|
|
// Ignore sets each column to itself in case of conflict.
|
|
// Using this option is equivalent to using:
|
|
//
|
|
// client.Image.Create().
|
|
// OnConflict(sql.ResolveWithIgnore()).
|
|
// Exec(ctx)
|
|
func (u *ImageUpsertOne) Ignore() *ImageUpsertOne {
|
|
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 *ImageUpsertOne) DoNothing() *ImageUpsertOne {
|
|
u.create.conflict = append(u.create.conflict, sql.DoNothing())
|
|
return u
|
|
}
|
|
|
|
// Update allows overriding fields `UPDATE` values. See the ImageCreate.OnConflict
|
|
// documentation for more info.
|
|
func (u *ImageUpsertOne) Update(set func(*ImageUpsert)) *ImageUpsertOne {
|
|
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
|
|
set(&ImageUpsert{UpdateSet: update})
|
|
}))
|
|
return u
|
|
}
|
|
|
|
// SetDeletedAt sets the "deleted_at" field.
|
|
func (u *ImageUpsertOne) SetDeletedAt(v time.Time) *ImageUpsertOne {
|
|
return u.Update(func(s *ImageUpsert) {
|
|
s.SetDeletedAt(v)
|
|
})
|
|
}
|
|
|
|
// UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
|
|
func (u *ImageUpsertOne) UpdateDeletedAt() *ImageUpsertOne {
|
|
return u.Update(func(s *ImageUpsert) {
|
|
s.UpdateDeletedAt()
|
|
})
|
|
}
|
|
|
|
// ClearDeletedAt clears the value of the "deleted_at" field.
|
|
func (u *ImageUpsertOne) ClearDeletedAt() *ImageUpsertOne {
|
|
return u.Update(func(s *ImageUpsert) {
|
|
s.ClearDeletedAt()
|
|
})
|
|
}
|
|
|
|
// SetUserID sets the "user_id" field.
|
|
func (u *ImageUpsertOne) SetUserID(v uuid.UUID) *ImageUpsertOne {
|
|
return u.Update(func(s *ImageUpsert) {
|
|
s.SetUserID(v)
|
|
})
|
|
}
|
|
|
|
// UpdateUserID sets the "user_id" field to the value that was provided on create.
|
|
func (u *ImageUpsertOne) UpdateUserID() *ImageUpsertOne {
|
|
return u.Update(func(s *ImageUpsert) {
|
|
s.UpdateUserID()
|
|
})
|
|
}
|
|
|
|
// SetName sets the "name" field.
|
|
func (u *ImageUpsertOne) SetName(v string) *ImageUpsertOne {
|
|
return u.Update(func(s *ImageUpsert) {
|
|
s.SetName(v)
|
|
})
|
|
}
|
|
|
|
// UpdateName sets the "name" field to the value that was provided on create.
|
|
func (u *ImageUpsertOne) UpdateName() *ImageUpsertOne {
|
|
return u.Update(func(s *ImageUpsert) {
|
|
s.UpdateName()
|
|
})
|
|
}
|
|
|
|
// SetRemark sets the "remark" field.
|
|
func (u *ImageUpsertOne) SetRemark(v string) *ImageUpsertOne {
|
|
return u.Update(func(s *ImageUpsert) {
|
|
s.SetRemark(v)
|
|
})
|
|
}
|
|
|
|
// UpdateRemark sets the "remark" field to the value that was provided on create.
|
|
func (u *ImageUpsertOne) UpdateRemark() *ImageUpsertOne {
|
|
return u.Update(func(s *ImageUpsert) {
|
|
s.UpdateRemark()
|
|
})
|
|
}
|
|
|
|
// ClearRemark clears the value of the "remark" field.
|
|
func (u *ImageUpsertOne) ClearRemark() *ImageUpsertOne {
|
|
return u.Update(func(s *ImageUpsert) {
|
|
s.ClearRemark()
|
|
})
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (u *ImageUpsertOne) SetCreatedAt(v time.Time) *ImageUpsertOne {
|
|
return u.Update(func(s *ImageUpsert) {
|
|
s.SetCreatedAt(v)
|
|
})
|
|
}
|
|
|
|
// UpdateCreatedAt sets the "created_at" field to the value that was provided on create.
|
|
func (u *ImageUpsertOne) UpdateCreatedAt() *ImageUpsertOne {
|
|
return u.Update(func(s *ImageUpsert) {
|
|
s.UpdateCreatedAt()
|
|
})
|
|
}
|
|
|
|
// SetUpdatedAt sets the "updated_at" field.
|
|
func (u *ImageUpsertOne) SetUpdatedAt(v time.Time) *ImageUpsertOne {
|
|
return u.Update(func(s *ImageUpsert) {
|
|
s.SetUpdatedAt(v)
|
|
})
|
|
}
|
|
|
|
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
|
|
func (u *ImageUpsertOne) UpdateUpdatedAt() *ImageUpsertOne {
|
|
return u.Update(func(s *ImageUpsert) {
|
|
s.UpdateUpdatedAt()
|
|
})
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (u *ImageUpsertOne) Exec(ctx context.Context) error {
|
|
if len(u.create.conflict) == 0 {
|
|
return errors.New("db: missing options for ImageCreate.OnConflict")
|
|
}
|
|
return u.create.Exec(ctx)
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (u *ImageUpsertOne) 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 *ImageUpsertOne) 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: ImageUpsertOne.ID is not supported by MySQL driver. Use ImageUpsertOne.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 *ImageUpsertOne) IDX(ctx context.Context) uuid.UUID {
|
|
id, err := u.ID(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return id
|
|
}
|
|
|
|
// ImageCreateBulk is the builder for creating many Image entities in bulk.
|
|
type ImageCreateBulk struct {
|
|
config
|
|
err error
|
|
builders []*ImageCreate
|
|
conflict []sql.ConflictOption
|
|
}
|
|
|
|
// Save creates the Image entities in the database.
|
|
func (_c *ImageCreateBulk) Save(ctx context.Context) ([]*Image, error) {
|
|
if _c.err != nil {
|
|
return nil, _c.err
|
|
}
|
|
specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
|
|
nodes := make([]*Image, 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.(*ImageMutation)
|
|
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 *ImageCreateBulk) SaveX(ctx context.Context) []*Image {
|
|
v, err := _c.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return v
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (_c *ImageCreateBulk) Exec(ctx context.Context) error {
|
|
_, err := _c.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_c *ImageCreateBulk) 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.Image.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.ImageUpsert) {
|
|
// SetDeletedAt(v+v).
|
|
// }).
|
|
// Exec(ctx)
|
|
func (_c *ImageCreateBulk) OnConflict(opts ...sql.ConflictOption) *ImageUpsertBulk {
|
|
_c.conflict = opts
|
|
return &ImageUpsertBulk{
|
|
create: _c,
|
|
}
|
|
}
|
|
|
|
// OnConflictColumns calls `OnConflict` and configures the columns
|
|
// as conflict target. Using this option is equivalent to using:
|
|
//
|
|
// client.Image.Create().
|
|
// OnConflict(sql.ConflictColumns(columns...)).
|
|
// Exec(ctx)
|
|
func (_c *ImageCreateBulk) OnConflictColumns(columns ...string) *ImageUpsertBulk {
|
|
_c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
|
|
return &ImageUpsertBulk{
|
|
create: _c,
|
|
}
|
|
}
|
|
|
|
// ImageUpsertBulk is the builder for "upsert"-ing
|
|
// a bulk of Image nodes.
|
|
type ImageUpsertBulk struct {
|
|
create *ImageCreateBulk
|
|
}
|
|
|
|
// UpdateNewValues updates the mutable fields using the new values that
|
|
// were set on create. Using this option is equivalent to using:
|
|
//
|
|
// client.Image.Create().
|
|
// OnConflict(
|
|
// sql.ResolveWithNewValues(),
|
|
// sql.ResolveWith(func(u *sql.UpdateSet) {
|
|
// u.SetIgnore(image.FieldID)
|
|
// }),
|
|
// ).
|
|
// Exec(ctx)
|
|
func (u *ImageUpsertBulk) UpdateNewValues() *ImageUpsertBulk {
|
|
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(image.FieldID)
|
|
}
|
|
}
|
|
}))
|
|
return u
|
|
}
|
|
|
|
// Ignore sets each column to itself in case of conflict.
|
|
// Using this option is equivalent to using:
|
|
//
|
|
// client.Image.Create().
|
|
// OnConflict(sql.ResolveWithIgnore()).
|
|
// Exec(ctx)
|
|
func (u *ImageUpsertBulk) Ignore() *ImageUpsertBulk {
|
|
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 *ImageUpsertBulk) DoNothing() *ImageUpsertBulk {
|
|
u.create.conflict = append(u.create.conflict, sql.DoNothing())
|
|
return u
|
|
}
|
|
|
|
// Update allows overriding fields `UPDATE` values. See the ImageCreateBulk.OnConflict
|
|
// documentation for more info.
|
|
func (u *ImageUpsertBulk) Update(set func(*ImageUpsert)) *ImageUpsertBulk {
|
|
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
|
|
set(&ImageUpsert{UpdateSet: update})
|
|
}))
|
|
return u
|
|
}
|
|
|
|
// SetDeletedAt sets the "deleted_at" field.
|
|
func (u *ImageUpsertBulk) SetDeletedAt(v time.Time) *ImageUpsertBulk {
|
|
return u.Update(func(s *ImageUpsert) {
|
|
s.SetDeletedAt(v)
|
|
})
|
|
}
|
|
|
|
// UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
|
|
func (u *ImageUpsertBulk) UpdateDeletedAt() *ImageUpsertBulk {
|
|
return u.Update(func(s *ImageUpsert) {
|
|
s.UpdateDeletedAt()
|
|
})
|
|
}
|
|
|
|
// ClearDeletedAt clears the value of the "deleted_at" field.
|
|
func (u *ImageUpsertBulk) ClearDeletedAt() *ImageUpsertBulk {
|
|
return u.Update(func(s *ImageUpsert) {
|
|
s.ClearDeletedAt()
|
|
})
|
|
}
|
|
|
|
// SetUserID sets the "user_id" field.
|
|
func (u *ImageUpsertBulk) SetUserID(v uuid.UUID) *ImageUpsertBulk {
|
|
return u.Update(func(s *ImageUpsert) {
|
|
s.SetUserID(v)
|
|
})
|
|
}
|
|
|
|
// UpdateUserID sets the "user_id" field to the value that was provided on create.
|
|
func (u *ImageUpsertBulk) UpdateUserID() *ImageUpsertBulk {
|
|
return u.Update(func(s *ImageUpsert) {
|
|
s.UpdateUserID()
|
|
})
|
|
}
|
|
|
|
// SetName sets the "name" field.
|
|
func (u *ImageUpsertBulk) SetName(v string) *ImageUpsertBulk {
|
|
return u.Update(func(s *ImageUpsert) {
|
|
s.SetName(v)
|
|
})
|
|
}
|
|
|
|
// UpdateName sets the "name" field to the value that was provided on create.
|
|
func (u *ImageUpsertBulk) UpdateName() *ImageUpsertBulk {
|
|
return u.Update(func(s *ImageUpsert) {
|
|
s.UpdateName()
|
|
})
|
|
}
|
|
|
|
// SetRemark sets the "remark" field.
|
|
func (u *ImageUpsertBulk) SetRemark(v string) *ImageUpsertBulk {
|
|
return u.Update(func(s *ImageUpsert) {
|
|
s.SetRemark(v)
|
|
})
|
|
}
|
|
|
|
// UpdateRemark sets the "remark" field to the value that was provided on create.
|
|
func (u *ImageUpsertBulk) UpdateRemark() *ImageUpsertBulk {
|
|
return u.Update(func(s *ImageUpsert) {
|
|
s.UpdateRemark()
|
|
})
|
|
}
|
|
|
|
// ClearRemark clears the value of the "remark" field.
|
|
func (u *ImageUpsertBulk) ClearRemark() *ImageUpsertBulk {
|
|
return u.Update(func(s *ImageUpsert) {
|
|
s.ClearRemark()
|
|
})
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (u *ImageUpsertBulk) SetCreatedAt(v time.Time) *ImageUpsertBulk {
|
|
return u.Update(func(s *ImageUpsert) {
|
|
s.SetCreatedAt(v)
|
|
})
|
|
}
|
|
|
|
// UpdateCreatedAt sets the "created_at" field to the value that was provided on create.
|
|
func (u *ImageUpsertBulk) UpdateCreatedAt() *ImageUpsertBulk {
|
|
return u.Update(func(s *ImageUpsert) {
|
|
s.UpdateCreatedAt()
|
|
})
|
|
}
|
|
|
|
// SetUpdatedAt sets the "updated_at" field.
|
|
func (u *ImageUpsertBulk) SetUpdatedAt(v time.Time) *ImageUpsertBulk {
|
|
return u.Update(func(s *ImageUpsert) {
|
|
s.SetUpdatedAt(v)
|
|
})
|
|
}
|
|
|
|
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
|
|
func (u *ImageUpsertBulk) UpdateUpdatedAt() *ImageUpsertBulk {
|
|
return u.Update(func(s *ImageUpsert) {
|
|
s.UpdateUpdatedAt()
|
|
})
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (u *ImageUpsertBulk) 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 ImageCreateBulk instead", i)
|
|
}
|
|
}
|
|
if len(u.create.conflict) == 0 {
|
|
return errors.New("db: missing options for ImageCreateBulk.OnConflict")
|
|
}
|
|
return u.create.Exec(ctx)
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (u *ImageUpsertBulk) ExecX(ctx context.Context) {
|
|
if err := u.create.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|