mouthpiece/pkg/ent/dbmessage_update.go

1086 lines
31 KiB
Go

/*
MIT License
Copyright (c) 2021 Justin Hammond
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
// Code generated by entc, 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"
"github.com/Fishwaldo/mouthpiece/pkg/ent/dbapp"
"github.com/Fishwaldo/mouthpiece/pkg/ent/dbmessage"
"github.com/Fishwaldo/mouthpiece/pkg/ent/dbmessagefields"
"github.com/Fishwaldo/mouthpiece/pkg/ent/predicate"
"github.com/Fishwaldo/mouthpiece/pkg/ent/tenant"
"github.com/Fishwaldo/mouthpiece/pkg/interfaces"
)
// DbMessageUpdate is the builder for updating DbMessage entities.
type DbMessageUpdate struct {
config
hooks []Hook
mutation *DbMessageMutation
}
// Where appends a list predicates to the DbMessageUpdate builder.
func (dmu *DbMessageUpdate) Where(ps ...predicate.DbMessage) *DbMessageUpdate {
dmu.mutation.Where(ps...)
return dmu
}
// SetTenantID sets the "tenant_id" field.
func (dmu *DbMessageUpdate) SetTenantID(i int) *DbMessageUpdate {
dmu.mutation.SetTenantID(i)
return dmu
}
// SetAppData sets the "AppData" field.
func (dmu *DbMessageUpdate) SetAppData(id interfaces.AppData) *DbMessageUpdate {
dmu.mutation.SetAppData(id)
return dmu
}
// SetNillableAppData sets the "AppData" field if the given value is not nil.
func (dmu *DbMessageUpdate) SetNillableAppData(id *interfaces.AppData) *DbMessageUpdate {
if id != nil {
dmu.SetAppData(*id)
}
return dmu
}
// ClearAppData clears the value of the "AppData" field.
func (dmu *DbMessageUpdate) ClearAppData() *DbMessageUpdate {
dmu.mutation.ClearAppData()
return dmu
}
// SetMessage sets the "Message" field.
func (dmu *DbMessageUpdate) SetMessage(s string) *DbMessageUpdate {
dmu.mutation.SetMessage(s)
return dmu
}
// SetShortMsg sets the "ShortMsg" field.
func (dmu *DbMessageUpdate) SetShortMsg(s string) *DbMessageUpdate {
dmu.mutation.SetShortMsg(s)
return dmu
}
// SetNillableShortMsg sets the "ShortMsg" field if the given value is not nil.
func (dmu *DbMessageUpdate) SetNillableShortMsg(s *string) *DbMessageUpdate {
if s != nil {
dmu.SetShortMsg(*s)
}
return dmu
}
// ClearShortMsg clears the value of the "ShortMsg" field.
func (dmu *DbMessageUpdate) ClearShortMsg() *DbMessageUpdate {
dmu.mutation.ClearShortMsg()
return dmu
}
// SetTopic sets the "Topic" field.
func (dmu *DbMessageUpdate) SetTopic(s string) *DbMessageUpdate {
dmu.mutation.SetTopic(s)
return dmu
}
// SetNillableTopic sets the "Topic" field if the given value is not nil.
func (dmu *DbMessageUpdate) SetNillableTopic(s *string) *DbMessageUpdate {
if s != nil {
dmu.SetTopic(*s)
}
return dmu
}
// ClearTopic clears the value of the "Topic" field.
func (dmu *DbMessageUpdate) ClearTopic() *DbMessageUpdate {
dmu.mutation.ClearTopic()
return dmu
}
// SetSeverity sets the "Severity" field.
func (dmu *DbMessageUpdate) SetSeverity(i int) *DbMessageUpdate {
dmu.mutation.ResetSeverity()
dmu.mutation.SetSeverity(i)
return dmu
}
// SetNillableSeverity sets the "Severity" field if the given value is not nil.
func (dmu *DbMessageUpdate) SetNillableSeverity(i *int) *DbMessageUpdate {
if i != nil {
dmu.SetSeverity(*i)
}
return dmu
}
// AddSeverity adds i to the "Severity" field.
func (dmu *DbMessageUpdate) AddSeverity(i int) *DbMessageUpdate {
dmu.mutation.AddSeverity(i)
return dmu
}
// ClearSeverity clears the value of the "Severity" field.
func (dmu *DbMessageUpdate) ClearSeverity() *DbMessageUpdate {
dmu.mutation.ClearSeverity()
return dmu
}
// SetTimestamp sets the "Timestamp" field.
func (dmu *DbMessageUpdate) SetTimestamp(t time.Time) *DbMessageUpdate {
dmu.mutation.SetTimestamp(t)
return dmu
}
// SetNillableTimestamp sets the "Timestamp" field if the given value is not nil.
func (dmu *DbMessageUpdate) SetNillableTimestamp(t *time.Time) *DbMessageUpdate {
if t != nil {
dmu.SetTimestamp(*t)
}
return dmu
}
// SetTenant sets the "tenant" edge to the Tenant entity.
func (dmu *DbMessageUpdate) SetTenant(t *Tenant) *DbMessageUpdate {
return dmu.SetTenantID(t.ID)
}
// AddFieldIDs adds the "fields" edge to the DbMessageFields entity by IDs.
func (dmu *DbMessageUpdate) AddFieldIDs(ids ...int) *DbMessageUpdate {
dmu.mutation.AddFieldIDs(ids...)
return dmu
}
// AddFields adds the "fields" edges to the DbMessageFields entity.
func (dmu *DbMessageUpdate) AddFields(d ...*DbMessageFields) *DbMessageUpdate {
ids := make([]int, len(d))
for i := range d {
ids[i] = d[i].ID
}
return dmu.AddFieldIDs(ids...)
}
// SetAppID sets the "app" edge to the DbApp entity by ID.
func (dmu *DbMessageUpdate) SetAppID(id int) *DbMessageUpdate {
dmu.mutation.SetAppID(id)
return dmu
}
// SetApp sets the "app" edge to the DbApp entity.
func (dmu *DbMessageUpdate) SetApp(d *DbApp) *DbMessageUpdate {
return dmu.SetAppID(d.ID)
}
// Mutation returns the DbMessageMutation object of the builder.
func (dmu *DbMessageUpdate) Mutation() *DbMessageMutation {
return dmu.mutation
}
// ClearTenant clears the "tenant" edge to the Tenant entity.
func (dmu *DbMessageUpdate) ClearTenant() *DbMessageUpdate {
dmu.mutation.ClearTenant()
return dmu
}
// ClearFields clears all "fields" edges to the DbMessageFields entity.
func (dmu *DbMessageUpdate) ClearFields() *DbMessageUpdate {
dmu.mutation.ClearFields()
return dmu
}
// RemoveFieldIDs removes the "fields" edge to DbMessageFields entities by IDs.
func (dmu *DbMessageUpdate) RemoveFieldIDs(ids ...int) *DbMessageUpdate {
dmu.mutation.RemoveFieldIDs(ids...)
return dmu
}
// RemoveFields removes "fields" edges to DbMessageFields entities.
func (dmu *DbMessageUpdate) RemoveFields(d ...*DbMessageFields) *DbMessageUpdate {
ids := make([]int, len(d))
for i := range d {
ids[i] = d[i].ID
}
return dmu.RemoveFieldIDs(ids...)
}
// ClearApp clears the "app" edge to the DbApp entity.
func (dmu *DbMessageUpdate) ClearApp() *DbMessageUpdate {
dmu.mutation.ClearApp()
return dmu
}
// Save executes the query and returns the number of nodes affected by the update operation.
func (dmu *DbMessageUpdate) Save(ctx context.Context) (int, error) {
var (
err error
affected int
)
if len(dmu.hooks) == 0 {
if err = dmu.check(); err != nil {
return 0, err
}
affected, err = dmu.sqlSave(ctx)
} else {
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
mutation, ok := m.(*DbMessageMutation)
if !ok {
return nil, fmt.Errorf("unexpected mutation type %T", m)
}
if err = dmu.check(); err != nil {
return 0, err
}
dmu.mutation = mutation
affected, err = dmu.sqlSave(ctx)
mutation.done = true
return affected, err
})
for i := len(dmu.hooks) - 1; i >= 0; i-- {
if dmu.hooks[i] == nil {
return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
}
mut = dmu.hooks[i](mut)
}
if _, err := mut.Mutate(ctx, dmu.mutation); err != nil {
return 0, err
}
}
return affected, err
}
// SaveX is like Save, but panics if an error occurs.
func (dmu *DbMessageUpdate) SaveX(ctx context.Context) int {
affected, err := dmu.Save(ctx)
if err != nil {
panic(err)
}
return affected
}
// Exec executes the query.
func (dmu *DbMessageUpdate) Exec(ctx context.Context) error {
_, err := dmu.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (dmu *DbMessageUpdate) ExecX(ctx context.Context) {
if err := dmu.Exec(ctx); err != nil {
panic(err)
}
}
// check runs all checks and user-defined validators on the builder.
func (dmu *DbMessageUpdate) check() error {
if v, ok := dmu.mutation.Message(); ok {
if err := dbmessage.MessageValidator(v); err != nil {
return &ValidationError{Name: "Message", err: fmt.Errorf(`ent: validator failed for field "DbMessage.Message": %w`, err)}
}
}
if v, ok := dmu.mutation.Topic(); ok {
if err := dbmessage.TopicValidator(v); err != nil {
return &ValidationError{Name: "Topic", err: fmt.Errorf(`ent: validator failed for field "DbMessage.Topic": %w`, err)}
}
}
if v, ok := dmu.mutation.Severity(); ok {
if err := dbmessage.SeverityValidator(v); err != nil {
return &ValidationError{Name: "Severity", err: fmt.Errorf(`ent: validator failed for field "DbMessage.Severity": %w`, err)}
}
}
if _, ok := dmu.mutation.TenantID(); dmu.mutation.TenantCleared() && !ok {
return errors.New(`ent: clearing a required unique edge "DbMessage.tenant"`)
}
if _, ok := dmu.mutation.AppID(); dmu.mutation.AppCleared() && !ok {
return errors.New(`ent: clearing a required unique edge "DbMessage.app"`)
}
return nil
}
func (dmu *DbMessageUpdate) sqlSave(ctx context.Context) (n int, err error) {
_spec := &sqlgraph.UpdateSpec{
Node: &sqlgraph.NodeSpec{
Table: dbmessage.Table,
Columns: dbmessage.Columns,
ID: &sqlgraph.FieldSpec{
Type: field.TypeUUID,
Column: dbmessage.FieldID,
},
},
}
if ps := dmu.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if value, ok := dmu.mutation.AppData(); ok {
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
Type: field.TypeJSON,
Value: value,
Column: dbmessage.FieldAppData,
})
}
if dmu.mutation.AppDataCleared() {
_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
Type: field.TypeJSON,
Column: dbmessage.FieldAppData,
})
}
if value, ok := dmu.mutation.Message(); ok {
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
Type: field.TypeString,
Value: value,
Column: dbmessage.FieldMessage,
})
}
if value, ok := dmu.mutation.ShortMsg(); ok {
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
Type: field.TypeString,
Value: value,
Column: dbmessage.FieldShortMsg,
})
}
if dmu.mutation.ShortMsgCleared() {
_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
Type: field.TypeString,
Column: dbmessage.FieldShortMsg,
})
}
if value, ok := dmu.mutation.Topic(); ok {
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
Type: field.TypeString,
Value: value,
Column: dbmessage.FieldTopic,
})
}
if dmu.mutation.TopicCleared() {
_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
Type: field.TypeString,
Column: dbmessage.FieldTopic,
})
}
if value, ok := dmu.mutation.Severity(); ok {
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
Type: field.TypeInt,
Value: value,
Column: dbmessage.FieldSeverity,
})
}
if value, ok := dmu.mutation.AddedSeverity(); ok {
_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
Type: field.TypeInt,
Value: value,
Column: dbmessage.FieldSeverity,
})
}
if dmu.mutation.SeverityCleared() {
_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
Type: field.TypeInt,
Column: dbmessage.FieldSeverity,
})
}
if value, ok := dmu.mutation.Timestamp(); ok {
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
Type: field.TypeTime,
Value: value,
Column: dbmessage.FieldTimestamp,
})
}
if dmu.mutation.TenantCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: false,
Table: dbmessage.TenantTable,
Columns: []string{dbmessage.TenantColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: &sqlgraph.FieldSpec{
Type: field.TypeInt,
Column: tenant.FieldID,
},
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := dmu.mutation.TenantIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: false,
Table: dbmessage.TenantTable,
Columns: []string{dbmessage.TenantColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: &sqlgraph.FieldSpec{
Type: field.TypeInt,
Column: tenant.FieldID,
},
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if dmu.mutation.FieldsCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: dbmessage.FieldsTable,
Columns: []string{dbmessage.FieldsColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: &sqlgraph.FieldSpec{
Type: field.TypeInt,
Column: dbmessagefields.FieldID,
},
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := dmu.mutation.RemovedFieldsIDs(); len(nodes) > 0 && !dmu.mutation.FieldsCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: dbmessage.FieldsTable,
Columns: []string{dbmessage.FieldsColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: &sqlgraph.FieldSpec{
Type: field.TypeInt,
Column: dbmessagefields.FieldID,
},
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := dmu.mutation.FieldsIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: dbmessage.FieldsTable,
Columns: []string{dbmessage.FieldsColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: &sqlgraph.FieldSpec{
Type: field.TypeInt,
Column: dbmessagefields.FieldID,
},
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if dmu.mutation.AppCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: dbmessage.AppTable,
Columns: []string{dbmessage.AppColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: &sqlgraph.FieldSpec{
Type: field.TypeInt,
Column: dbapp.FieldID,
},
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := dmu.mutation.AppIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: dbmessage.AppTable,
Columns: []string{dbmessage.AppColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: &sqlgraph.FieldSpec{
Type: field.TypeInt,
Column: dbapp.FieldID,
},
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if n, err = sqlgraph.UpdateNodes(ctx, dmu.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{dbmessage.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return 0, err
}
return n, nil
}
// DbMessageUpdateOne is the builder for updating a single DbMessage entity.
type DbMessageUpdateOne struct {
config
fields []string
hooks []Hook
mutation *DbMessageMutation
}
// SetTenantID sets the "tenant_id" field.
func (dmuo *DbMessageUpdateOne) SetTenantID(i int) *DbMessageUpdateOne {
dmuo.mutation.SetTenantID(i)
return dmuo
}
// SetAppData sets the "AppData" field.
func (dmuo *DbMessageUpdateOne) SetAppData(id interfaces.AppData) *DbMessageUpdateOne {
dmuo.mutation.SetAppData(id)
return dmuo
}
// SetNillableAppData sets the "AppData" field if the given value is not nil.
func (dmuo *DbMessageUpdateOne) SetNillableAppData(id *interfaces.AppData) *DbMessageUpdateOne {
if id != nil {
dmuo.SetAppData(*id)
}
return dmuo
}
// ClearAppData clears the value of the "AppData" field.
func (dmuo *DbMessageUpdateOne) ClearAppData() *DbMessageUpdateOne {
dmuo.mutation.ClearAppData()
return dmuo
}
// SetMessage sets the "Message" field.
func (dmuo *DbMessageUpdateOne) SetMessage(s string) *DbMessageUpdateOne {
dmuo.mutation.SetMessage(s)
return dmuo
}
// SetShortMsg sets the "ShortMsg" field.
func (dmuo *DbMessageUpdateOne) SetShortMsg(s string) *DbMessageUpdateOne {
dmuo.mutation.SetShortMsg(s)
return dmuo
}
// SetNillableShortMsg sets the "ShortMsg" field if the given value is not nil.
func (dmuo *DbMessageUpdateOne) SetNillableShortMsg(s *string) *DbMessageUpdateOne {
if s != nil {
dmuo.SetShortMsg(*s)
}
return dmuo
}
// ClearShortMsg clears the value of the "ShortMsg" field.
func (dmuo *DbMessageUpdateOne) ClearShortMsg() *DbMessageUpdateOne {
dmuo.mutation.ClearShortMsg()
return dmuo
}
// SetTopic sets the "Topic" field.
func (dmuo *DbMessageUpdateOne) SetTopic(s string) *DbMessageUpdateOne {
dmuo.mutation.SetTopic(s)
return dmuo
}
// SetNillableTopic sets the "Topic" field if the given value is not nil.
func (dmuo *DbMessageUpdateOne) SetNillableTopic(s *string) *DbMessageUpdateOne {
if s != nil {
dmuo.SetTopic(*s)
}
return dmuo
}
// ClearTopic clears the value of the "Topic" field.
func (dmuo *DbMessageUpdateOne) ClearTopic() *DbMessageUpdateOne {
dmuo.mutation.ClearTopic()
return dmuo
}
// SetSeverity sets the "Severity" field.
func (dmuo *DbMessageUpdateOne) SetSeverity(i int) *DbMessageUpdateOne {
dmuo.mutation.ResetSeverity()
dmuo.mutation.SetSeverity(i)
return dmuo
}
// SetNillableSeverity sets the "Severity" field if the given value is not nil.
func (dmuo *DbMessageUpdateOne) SetNillableSeverity(i *int) *DbMessageUpdateOne {
if i != nil {
dmuo.SetSeverity(*i)
}
return dmuo
}
// AddSeverity adds i to the "Severity" field.
func (dmuo *DbMessageUpdateOne) AddSeverity(i int) *DbMessageUpdateOne {
dmuo.mutation.AddSeverity(i)
return dmuo
}
// ClearSeverity clears the value of the "Severity" field.
func (dmuo *DbMessageUpdateOne) ClearSeverity() *DbMessageUpdateOne {
dmuo.mutation.ClearSeverity()
return dmuo
}
// SetTimestamp sets the "Timestamp" field.
func (dmuo *DbMessageUpdateOne) SetTimestamp(t time.Time) *DbMessageUpdateOne {
dmuo.mutation.SetTimestamp(t)
return dmuo
}
// SetNillableTimestamp sets the "Timestamp" field if the given value is not nil.
func (dmuo *DbMessageUpdateOne) SetNillableTimestamp(t *time.Time) *DbMessageUpdateOne {
if t != nil {
dmuo.SetTimestamp(*t)
}
return dmuo
}
// SetTenant sets the "tenant" edge to the Tenant entity.
func (dmuo *DbMessageUpdateOne) SetTenant(t *Tenant) *DbMessageUpdateOne {
return dmuo.SetTenantID(t.ID)
}
// AddFieldIDs adds the "fields" edge to the DbMessageFields entity by IDs.
func (dmuo *DbMessageUpdateOne) AddFieldIDs(ids ...int) *DbMessageUpdateOne {
dmuo.mutation.AddFieldIDs(ids...)
return dmuo
}
// AddFields adds the "fields" edges to the DbMessageFields entity.
func (dmuo *DbMessageUpdateOne) AddFields(d ...*DbMessageFields) *DbMessageUpdateOne {
ids := make([]int, len(d))
for i := range d {
ids[i] = d[i].ID
}
return dmuo.AddFieldIDs(ids...)
}
// SetAppID sets the "app" edge to the DbApp entity by ID.
func (dmuo *DbMessageUpdateOne) SetAppID(id int) *DbMessageUpdateOne {
dmuo.mutation.SetAppID(id)
return dmuo
}
// SetApp sets the "app" edge to the DbApp entity.
func (dmuo *DbMessageUpdateOne) SetApp(d *DbApp) *DbMessageUpdateOne {
return dmuo.SetAppID(d.ID)
}
// Mutation returns the DbMessageMutation object of the builder.
func (dmuo *DbMessageUpdateOne) Mutation() *DbMessageMutation {
return dmuo.mutation
}
// ClearTenant clears the "tenant" edge to the Tenant entity.
func (dmuo *DbMessageUpdateOne) ClearTenant() *DbMessageUpdateOne {
dmuo.mutation.ClearTenant()
return dmuo
}
// ClearFields clears all "fields" edges to the DbMessageFields entity.
func (dmuo *DbMessageUpdateOne) ClearFields() *DbMessageUpdateOne {
dmuo.mutation.ClearFields()
return dmuo
}
// RemoveFieldIDs removes the "fields" edge to DbMessageFields entities by IDs.
func (dmuo *DbMessageUpdateOne) RemoveFieldIDs(ids ...int) *DbMessageUpdateOne {
dmuo.mutation.RemoveFieldIDs(ids...)
return dmuo
}
// RemoveFields removes "fields" edges to DbMessageFields entities.
func (dmuo *DbMessageUpdateOne) RemoveFields(d ...*DbMessageFields) *DbMessageUpdateOne {
ids := make([]int, len(d))
for i := range d {
ids[i] = d[i].ID
}
return dmuo.RemoveFieldIDs(ids...)
}
// ClearApp clears the "app" edge to the DbApp entity.
func (dmuo *DbMessageUpdateOne) ClearApp() *DbMessageUpdateOne {
dmuo.mutation.ClearApp()
return dmuo
}
// Select allows selecting one or more fields (columns) of the returned entity.
// The default is selecting all fields defined in the entity schema.
func (dmuo *DbMessageUpdateOne) Select(field string, fields ...string) *DbMessageUpdateOne {
dmuo.fields = append([]string{field}, fields...)
return dmuo
}
// Save executes the query and returns the updated DbMessage entity.
func (dmuo *DbMessageUpdateOne) Save(ctx context.Context) (*DbMessage, error) {
var (
err error
node *DbMessage
)
if len(dmuo.hooks) == 0 {
if err = dmuo.check(); err != nil {
return nil, err
}
node, err = dmuo.sqlSave(ctx)
} else {
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
mutation, ok := m.(*DbMessageMutation)
if !ok {
return nil, fmt.Errorf("unexpected mutation type %T", m)
}
if err = dmuo.check(); err != nil {
return nil, err
}
dmuo.mutation = mutation
node, err = dmuo.sqlSave(ctx)
mutation.done = true
return node, err
})
for i := len(dmuo.hooks) - 1; i >= 0; i-- {
if dmuo.hooks[i] == nil {
return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
}
mut = dmuo.hooks[i](mut)
}
v, err := mut.Mutate(ctx, dmuo.mutation)
if err != nil {
return nil, err
}
nv, ok := v.(*DbMessage)
if !ok {
return nil, fmt.Errorf("unexpected node type %T returned from DbMessageMutation", v)
}
node = nv
}
return node, err
}
// SaveX is like Save, but panics if an error occurs.
func (dmuo *DbMessageUpdateOne) SaveX(ctx context.Context) *DbMessage {
node, err := dmuo.Save(ctx)
if err != nil {
panic(err)
}
return node
}
// Exec executes the query on the entity.
func (dmuo *DbMessageUpdateOne) Exec(ctx context.Context) error {
_, err := dmuo.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (dmuo *DbMessageUpdateOne) ExecX(ctx context.Context) {
if err := dmuo.Exec(ctx); err != nil {
panic(err)
}
}
// check runs all checks and user-defined validators on the builder.
func (dmuo *DbMessageUpdateOne) check() error {
if v, ok := dmuo.mutation.Message(); ok {
if err := dbmessage.MessageValidator(v); err != nil {
return &ValidationError{Name: "Message", err: fmt.Errorf(`ent: validator failed for field "DbMessage.Message": %w`, err)}
}
}
if v, ok := dmuo.mutation.Topic(); ok {
if err := dbmessage.TopicValidator(v); err != nil {
return &ValidationError{Name: "Topic", err: fmt.Errorf(`ent: validator failed for field "DbMessage.Topic": %w`, err)}
}
}
if v, ok := dmuo.mutation.Severity(); ok {
if err := dbmessage.SeverityValidator(v); err != nil {
return &ValidationError{Name: "Severity", err: fmt.Errorf(`ent: validator failed for field "DbMessage.Severity": %w`, err)}
}
}
if _, ok := dmuo.mutation.TenantID(); dmuo.mutation.TenantCleared() && !ok {
return errors.New(`ent: clearing a required unique edge "DbMessage.tenant"`)
}
if _, ok := dmuo.mutation.AppID(); dmuo.mutation.AppCleared() && !ok {
return errors.New(`ent: clearing a required unique edge "DbMessage.app"`)
}
return nil
}
func (dmuo *DbMessageUpdateOne) sqlSave(ctx context.Context) (_node *DbMessage, err error) {
_spec := &sqlgraph.UpdateSpec{
Node: &sqlgraph.NodeSpec{
Table: dbmessage.Table,
Columns: dbmessage.Columns,
ID: &sqlgraph.FieldSpec{
Type: field.TypeUUID,
Column: dbmessage.FieldID,
},
},
}
id, ok := dmuo.mutation.ID()
if !ok {
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "DbMessage.id" for update`)}
}
_spec.Node.ID.Value = id
if fields := dmuo.fields; len(fields) > 0 {
_spec.Node.Columns = make([]string, 0, len(fields))
_spec.Node.Columns = append(_spec.Node.Columns, dbmessage.FieldID)
for _, f := range fields {
if !dbmessage.ValidColumn(f) {
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
}
if f != dbmessage.FieldID {
_spec.Node.Columns = append(_spec.Node.Columns, f)
}
}
}
if ps := dmuo.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if value, ok := dmuo.mutation.AppData(); ok {
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
Type: field.TypeJSON,
Value: value,
Column: dbmessage.FieldAppData,
})
}
if dmuo.mutation.AppDataCleared() {
_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
Type: field.TypeJSON,
Column: dbmessage.FieldAppData,
})
}
if value, ok := dmuo.mutation.Message(); ok {
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
Type: field.TypeString,
Value: value,
Column: dbmessage.FieldMessage,
})
}
if value, ok := dmuo.mutation.ShortMsg(); ok {
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
Type: field.TypeString,
Value: value,
Column: dbmessage.FieldShortMsg,
})
}
if dmuo.mutation.ShortMsgCleared() {
_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
Type: field.TypeString,
Column: dbmessage.FieldShortMsg,
})
}
if value, ok := dmuo.mutation.Topic(); ok {
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
Type: field.TypeString,
Value: value,
Column: dbmessage.FieldTopic,
})
}
if dmuo.mutation.TopicCleared() {
_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
Type: field.TypeString,
Column: dbmessage.FieldTopic,
})
}
if value, ok := dmuo.mutation.Severity(); ok {
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
Type: field.TypeInt,
Value: value,
Column: dbmessage.FieldSeverity,
})
}
if value, ok := dmuo.mutation.AddedSeverity(); ok {
_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
Type: field.TypeInt,
Value: value,
Column: dbmessage.FieldSeverity,
})
}
if dmuo.mutation.SeverityCleared() {
_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
Type: field.TypeInt,
Column: dbmessage.FieldSeverity,
})
}
if value, ok := dmuo.mutation.Timestamp(); ok {
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
Type: field.TypeTime,
Value: value,
Column: dbmessage.FieldTimestamp,
})
}
if dmuo.mutation.TenantCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: false,
Table: dbmessage.TenantTable,
Columns: []string{dbmessage.TenantColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: &sqlgraph.FieldSpec{
Type: field.TypeInt,
Column: tenant.FieldID,
},
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := dmuo.mutation.TenantIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: false,
Table: dbmessage.TenantTable,
Columns: []string{dbmessage.TenantColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: &sqlgraph.FieldSpec{
Type: field.TypeInt,
Column: tenant.FieldID,
},
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if dmuo.mutation.FieldsCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: dbmessage.FieldsTable,
Columns: []string{dbmessage.FieldsColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: &sqlgraph.FieldSpec{
Type: field.TypeInt,
Column: dbmessagefields.FieldID,
},
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := dmuo.mutation.RemovedFieldsIDs(); len(nodes) > 0 && !dmuo.mutation.FieldsCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: dbmessage.FieldsTable,
Columns: []string{dbmessage.FieldsColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: &sqlgraph.FieldSpec{
Type: field.TypeInt,
Column: dbmessagefields.FieldID,
},
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := dmuo.mutation.FieldsIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: dbmessage.FieldsTable,
Columns: []string{dbmessage.FieldsColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: &sqlgraph.FieldSpec{
Type: field.TypeInt,
Column: dbmessagefields.FieldID,
},
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if dmuo.mutation.AppCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: dbmessage.AppTable,
Columns: []string{dbmessage.AppColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: &sqlgraph.FieldSpec{
Type: field.TypeInt,
Column: dbapp.FieldID,
},
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := dmuo.mutation.AppIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: dbmessage.AppTable,
Columns: []string{dbmessage.AppColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: &sqlgraph.FieldSpec{
Type: field.TypeInt,
Column: dbapp.FieldID,
},
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
_node = &DbMessage{config: dmuo.config}
_spec.Assign = _node.assignValues
_spec.ScanValues = _node.scanValues
if err = sqlgraph.UpdateNode(ctx, dmuo.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{dbmessage.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return nil, err
}
return _node, nil
}