// Code generated by ent, DO NOT EDIT.
package ent
import (
"context"
"errors"
"fmt"
"time"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
"github.com/safedep/vet/ent/predicate"
"github.com/safedep/vet/ent/reportmalware"
"github.com/safedep/vet/ent/reportpackage"
)
// ReportMalwareUpdate is the builder for updating ReportMalware entities.
type ReportMalwareUpdate struct {
config
hooks []Hook
mutation *ReportMalwareMutation
}
// Where appends a list predicates to the ReportMalwareUpdate builder.
func (rmu *ReportMalwareUpdate) Where(ps ...predicate.ReportMalware) *ReportMalwareUpdate {
rmu.mutation.Where(ps...)
return rmu
}
// SetAnalysisID sets the "analysis_id" field.
func (rmu *ReportMalwareUpdate) SetAnalysisID(s string) *ReportMalwareUpdate {
rmu.mutation.SetAnalysisID(s)
return rmu
}
// SetNillableAnalysisID sets the "analysis_id" field if the given value is not nil.
func (rmu *ReportMalwareUpdate) SetNillableAnalysisID(s *string) *ReportMalwareUpdate {
if s != nil {
rmu.SetAnalysisID(*s)
}
return rmu
}
// SetIsMalware sets the "is_malware" field.
func (rmu *ReportMalwareUpdate) SetIsMalware(b bool) *ReportMalwareUpdate {
rmu.mutation.SetIsMalware(b)
return rmu
}
// SetNillableIsMalware sets the "is_malware" field if the given value is not nil.
func (rmu *ReportMalwareUpdate) SetNillableIsMalware(b *bool) *ReportMalwareUpdate {
if b != nil {
rmu.SetIsMalware(*b)
}
return rmu
}
// SetIsSuspicious sets the "is_suspicious" field.
func (rmu *ReportMalwareUpdate) SetIsSuspicious(b bool) *ReportMalwareUpdate {
rmu.mutation.SetIsSuspicious(b)
return rmu
}
// SetNillableIsSuspicious sets the "is_suspicious" field if the given value is not nil.
func (rmu *ReportMalwareUpdate) SetNillableIsSuspicious(b *bool) *ReportMalwareUpdate {
if b != nil {
rmu.SetIsSuspicious(*b)
}
return rmu
}
// SetConfidence sets the "confidence" field.
func (rmu *ReportMalwareUpdate) SetConfidence(s string) *ReportMalwareUpdate {
rmu.mutation.SetConfidence(s)
return rmu
}
// SetNillableConfidence sets the "confidence" field if the given value is not nil.
func (rmu *ReportMalwareUpdate) SetNillableConfidence(s *string) *ReportMalwareUpdate {
if s != nil {
rmu.SetConfidence(*s)
}
return rmu
}
// ClearConfidence clears the value of the "confidence" field.
func (rmu *ReportMalwareUpdate) ClearConfidence() *ReportMalwareUpdate {
rmu.mutation.ClearConfidence()
return rmu
}
// SetReport sets the "report" field.
func (rmu *ReportMalwareUpdate) SetReport(m map[string]interface{}) *ReportMalwareUpdate {
rmu.mutation.SetReport(m)
return rmu
}
// ClearReport clears the value of the "report" field.
func (rmu *ReportMalwareUpdate) ClearReport() *ReportMalwareUpdate {
rmu.mutation.ClearReport()
return rmu
}
// SetVerificationRecord sets the "verification_record" field.
func (rmu *ReportMalwareUpdate) SetVerificationRecord(m map[string]interface{}) *ReportMalwareUpdate {
rmu.mutation.SetVerificationRecord(m)
return rmu
}
// ClearVerificationRecord clears the value of the "verification_record" field.
func (rmu *ReportMalwareUpdate) ClearVerificationRecord() *ReportMalwareUpdate {
rmu.mutation.ClearVerificationRecord()
return rmu
}
// SetCreatedAt sets the "created_at" field.
func (rmu *ReportMalwareUpdate) SetCreatedAt(t time.Time) *ReportMalwareUpdate {
rmu.mutation.SetCreatedAt(t)
return rmu
}
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
func (rmu *ReportMalwareUpdate) SetNillableCreatedAt(t *time.Time) *ReportMalwareUpdate {
if t != nil {
rmu.SetCreatedAt(*t)
}
return rmu
}
// ClearCreatedAt clears the value of the "created_at" field.
func (rmu *ReportMalwareUpdate) ClearCreatedAt() *ReportMalwareUpdate {
rmu.mutation.ClearCreatedAt()
return rmu
}
// SetUpdatedAt sets the "updated_at" field.
func (rmu *ReportMalwareUpdate) SetUpdatedAt(t time.Time) *ReportMalwareUpdate {
rmu.mutation.SetUpdatedAt(t)
return rmu
}
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
func (rmu *ReportMalwareUpdate) SetNillableUpdatedAt(t *time.Time) *ReportMalwareUpdate {
if t != nil {
rmu.SetUpdatedAt(*t)
}
return rmu
}
// ClearUpdatedAt clears the value of the "updated_at" field.
func (rmu *ReportMalwareUpdate) ClearUpdatedAt() *ReportMalwareUpdate {
rmu.mutation.ClearUpdatedAt()
return rmu
}
// SetPackageID sets the "package" edge to the ReportPackage entity by ID.
func (rmu *ReportMalwareUpdate) SetPackageID(id int) *ReportMalwareUpdate {
rmu.mutation.SetPackageID(id)
return rmu
}
// SetNillablePackageID sets the "package" edge to the ReportPackage entity by ID if the given value is not nil.
func (rmu *ReportMalwareUpdate) SetNillablePackageID(id *int) *ReportMalwareUpdate {
if id != nil {
rmu = rmu.SetPackageID(*id)
}
return rmu
}
// SetPackage sets the "package" edge to the ReportPackage entity.
func (rmu *ReportMalwareUpdate) SetPackage(r *ReportPackage) *ReportMalwareUpdate {
return rmu.SetPackageID(r.ID)
}
// Mutation returns the ReportMalwareMutation object of the builder.
func (rmu *ReportMalwareUpdate) Mutation() *ReportMalwareMutation {
return rmu.mutation
}
// ClearPackage clears the "package" edge to the ReportPackage entity.
func (rmu *ReportMalwareUpdate) ClearPackage() *ReportMalwareUpdate {
rmu.mutation.ClearPackage()
return rmu
}
// Save executes the query and returns the number of nodes affected by the update operation.
func (rmu *ReportMalwareUpdate) Save(ctx context.Context) (int, error) {
return withHooks(ctx, rmu.sqlSave, rmu.mutation, rmu.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (rmu *ReportMalwareUpdate) SaveX(ctx context.Context) int {
affected, err := rmu.Save(ctx)
if err != nil {
panic(err)
}
return affected
}
// Exec executes the query.
func (rmu *ReportMalwareUpdate) Exec(ctx context.Context) error {
_, err := rmu.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (rmu *ReportMalwareUpdate) ExecX(ctx context.Context) {
if err := rmu.Exec(ctx); err != nil {
panic(err)
}
}
// check runs all checks and user-defined validators on the builder.
func (rmu *ReportMalwareUpdate) check() error {
if v, ok := rmu.mutation.AnalysisID(); ok {
if err := reportmalware.AnalysisIDValidator(v); err != nil {
return &ValidationError{Name: "analysis_id", err: fmt.Errorf(`ent: validator failed for field "ReportMalware.analysis_id": %w`, err)}
}
}
return nil
}
func (rmu *ReportMalwareUpdate) sqlSave(ctx context.Context) (n int, err error) {
if err := rmu.check(); err != nil {
return n, err
}
_spec := sqlgraph.NewUpdateSpec(reportmalware.Table, reportmalware.Columns, sqlgraph.NewFieldSpec(reportmalware.FieldID, field.TypeInt))
if ps := rmu.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if value, ok := rmu.mutation.AnalysisID(); ok {
_spec.SetField(reportmalware.FieldAnalysisID, field.TypeString, value)
}
if value, ok := rmu.mutation.IsMalware(); ok {
_spec.SetField(reportmalware.FieldIsMalware, field.TypeBool, value)
}
if value, ok := rmu.mutation.IsSuspicious(); ok {
_spec.SetField(reportmalware.FieldIsSuspicious, field.TypeBool, value)
}
if value, ok := rmu.mutation.Confidence(); ok {
_spec.SetField(reportmalware.FieldConfidence, field.TypeString, value)
}
if rmu.mutation.ConfidenceCleared() {
_spec.ClearField(reportmalware.FieldConfidence, field.TypeString)
}
if value, ok := rmu.mutation.Report(); ok {
_spec.SetField(reportmalware.FieldReport, field.TypeJSON, value)
}
if rmu.mutation.ReportCleared() {
_spec.ClearField(reportmalware.FieldReport, field.TypeJSON)
}
if value, ok := rmu.mutation.VerificationRecord(); ok {
_spec.SetField(reportmalware.FieldVerificationRecord, field.TypeJSON, value)
}
if rmu.mutation.VerificationRecordCleared() {
_spec.ClearField(reportmalware.FieldVerificationRecord, field.TypeJSON)
}
if value, ok := rmu.mutation.CreatedAt(); ok {
_spec.SetField(reportmalware.FieldCreatedAt, field.TypeTime, value)
}
if rmu.mutation.CreatedAtCleared() {
_spec.ClearField(reportmalware.FieldCreatedAt, field.TypeTime)
}
if value, ok := rmu.mutation.UpdatedAt(); ok {
_spec.SetField(reportmalware.FieldUpdatedAt, field.TypeTime, value)
}
if rmu.mutation.UpdatedAtCleared() {
_spec.ClearField(reportmalware.FieldUpdatedAt, field.TypeTime)
}
if rmu.mutation.PackageCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2O,
Inverse: true,
Table: reportmalware.PackageTable,
Columns: []string{reportmalware.PackageColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(reportpackage.FieldID, field.TypeInt),
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := rmu.mutation.PackageIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2O,
Inverse: true,
Table: reportmalware.PackageTable,
Columns: []string{reportmalware.PackageColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(reportpackage.FieldID, field.TypeInt),
},
}
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, rmu.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{reportmalware.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return 0, err
}
rmu.mutation.done = true
return n, nil
}
// ReportMalwareUpdateOne is the builder for updating a single ReportMalware entity.
type ReportMalwareUpdateOne struct {
config
fields []string
hooks []Hook
mutation *ReportMalwareMutation
}
// SetAnalysisID sets the "analysis_id" field.
func (rmuo *ReportMalwareUpdateOne) SetAnalysisID(s string) *ReportMalwareUpdateOne {
rmuo.mutation.SetAnalysisID(s)
return rmuo
}
// SetNillableAnalysisID sets the "analysis_id" field if the given value is not nil.
func (rmuo *ReportMalwareUpdateOne) SetNillableAnalysisID(s *string) *ReportMalwareUpdateOne {
if s != nil {
rmuo.SetAnalysisID(*s)
}
return rmuo
}
// SetIsMalware sets the "is_malware" field.
func (rmuo *ReportMalwareUpdateOne) SetIsMalware(b bool) *ReportMalwareUpdateOne {
rmuo.mutation.SetIsMalware(b)
return rmuo
}
// SetNillableIsMalware sets the "is_malware" field if the given value is not nil.
func (rmuo *ReportMalwareUpdateOne) SetNillableIsMalware(b *bool) *ReportMalwareUpdateOne {
if b != nil {
rmuo.SetIsMalware(*b)
}
return rmuo
}
// SetIsSuspicious sets the "is_suspicious" field.
func (rmuo *ReportMalwareUpdateOne) SetIsSuspicious(b bool) *ReportMalwareUpdateOne {
rmuo.mutation.SetIsSuspicious(b)
return rmuo
}
// SetNillableIsSuspicious sets the "is_suspicious" field if the given value is not nil.
func (rmuo *ReportMalwareUpdateOne) SetNillableIsSuspicious(b *bool) *ReportMalwareUpdateOne {
if b != nil {
rmuo.SetIsSuspicious(*b)
}
return rmuo
}
// SetConfidence sets the "confidence" field.
func (rmuo *ReportMalwareUpdateOne) SetConfidence(s string) *ReportMalwareUpdateOne {
rmuo.mutation.SetConfidence(s)
return rmuo
}
// SetNillableConfidence sets the "confidence" field if the given value is not nil.
func (rmuo *ReportMalwareUpdateOne) SetNillableConfidence(s *string) *ReportMalwareUpdateOne {
if s != nil {
rmuo.SetConfidence(*s)
}
return rmuo
}
// ClearConfidence clears the value of the "confidence" field.
func (rmuo *ReportMalwareUpdateOne) ClearConfidence() *ReportMalwareUpdateOne {
rmuo.mutation.ClearConfidence()
return rmuo
}
// SetReport sets the "report" field.
func (rmuo *ReportMalwareUpdateOne) SetReport(m map[string]interface{}) *ReportMalwareUpdateOne {
rmuo.mutation.SetReport(m)
return rmuo
}
// ClearReport clears the value of the "report" field.
func (rmuo *ReportMalwareUpdateOne) ClearReport() *ReportMalwareUpdateOne {
rmuo.mutation.ClearReport()
return rmuo
}
// SetVerificationRecord sets the "verification_record" field.
func (rmuo *ReportMalwareUpdateOne) SetVerificationRecord(m map[string]interface{}) *ReportMalwareUpdateOne {
rmuo.mutation.SetVerificationRecord(m)
return rmuo
}
// ClearVerificationRecord clears the value of the "verification_record" field.
func (rmuo *ReportMalwareUpdateOne) ClearVerificationRecord() *ReportMalwareUpdateOne {
rmuo.mutation.ClearVerificationRecord()
return rmuo
}
// SetCreatedAt sets the "created_at" field.
func (rmuo *ReportMalwareUpdateOne) SetCreatedAt(t time.Time) *ReportMalwareUpdateOne {
rmuo.mutation.SetCreatedAt(t)
return rmuo
}
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
func (rmuo *ReportMalwareUpdateOne) SetNillableCreatedAt(t *time.Time) *ReportMalwareUpdateOne {
if t != nil {
rmuo.SetCreatedAt(*t)
}
return rmuo
}
// ClearCreatedAt clears the value of the "created_at" field.
func (rmuo *ReportMalwareUpdateOne) ClearCreatedAt() *ReportMalwareUpdateOne {
rmuo.mutation.ClearCreatedAt()
return rmuo
}
// SetUpdatedAt sets the "updated_at" field.
func (rmuo *ReportMalwareUpdateOne) SetUpdatedAt(t time.Time) *ReportMalwareUpdateOne {
rmuo.mutation.SetUpdatedAt(t)
return rmuo
}
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
func (rmuo *ReportMalwareUpdateOne) SetNillableUpdatedAt(t *time.Time) *ReportMalwareUpdateOne {
if t != nil {
rmuo.SetUpdatedAt(*t)
}
return rmuo
}
// ClearUpdatedAt clears the value of the "updated_at" field.
func (rmuo *ReportMalwareUpdateOne) ClearUpdatedAt() *ReportMalwareUpdateOne {
rmuo.mutation.ClearUpdatedAt()
return rmuo
}
// SetPackageID sets the "package" edge to the ReportPackage entity by ID.
func (rmuo *ReportMalwareUpdateOne) SetPackageID(id int) *ReportMalwareUpdateOne {
rmuo.mutation.SetPackageID(id)
return rmuo
}
// SetNillablePackageID sets the "package" edge to the ReportPackage entity by ID if the given value is not nil.
func (rmuo *ReportMalwareUpdateOne) SetNillablePackageID(id *int) *ReportMalwareUpdateOne {
if id != nil {
rmuo = rmuo.SetPackageID(*id)
}
return rmuo
}
// SetPackage sets the "package" edge to the ReportPackage entity.
func (rmuo *ReportMalwareUpdateOne) SetPackage(r *ReportPackage) *ReportMalwareUpdateOne {
return rmuo.SetPackageID(r.ID)
}
// Mutation returns the ReportMalwareMutation object of the builder.
func (rmuo *ReportMalwareUpdateOne) Mutation() *ReportMalwareMutation {
return rmuo.mutation
}
// ClearPackage clears the "package" edge to the ReportPackage entity.
func (rmuo *ReportMalwareUpdateOne) ClearPackage() *ReportMalwareUpdateOne {
rmuo.mutation.ClearPackage()
return rmuo
}
// Where appends a list predicates to the ReportMalwareUpdate builder.
func (rmuo *ReportMalwareUpdateOne) Where(ps ...predicate.ReportMalware) *ReportMalwareUpdateOne {
rmuo.mutation.Where(ps...)
return rmuo
}
// Select allows selecting one or more fields (columns) of the returned entity.
// The default is selecting all fields defined in the entity schema.
func (rmuo *ReportMalwareUpdateOne) Select(field string, fields ...string) *ReportMalwareUpdateOne {
rmuo.fields = append([]string{field}, fields...)
return rmuo
}
// Save executes the query and returns the updated ReportMalware entity.
func (rmuo *ReportMalwareUpdateOne) Save(ctx context.Context) (*ReportMalware, error) {
return withHooks(ctx, rmuo.sqlSave, rmuo.mutation, rmuo.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (rmuo *ReportMalwareUpdateOne) SaveX(ctx context.Context) *ReportMalware {
node, err := rmuo.Save(ctx)
if err != nil {
panic(err)
}
return node
}
// Exec executes the query on the entity.
func (rmuo *ReportMalwareUpdateOne) Exec(ctx context.Context) error {
_, err := rmuo.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (rmuo *ReportMalwareUpdateOne) ExecX(ctx context.Context) {
if err := rmuo.Exec(ctx); err != nil {
panic(err)
}
}
// check runs all checks and user-defined validators on the builder.
func (rmuo *ReportMalwareUpdateOne) check() error {
if v, ok := rmuo.mutation.AnalysisID(); ok {
if err := reportmalware.AnalysisIDValidator(v); err != nil {
return &ValidationError{Name: "analysis_id", err: fmt.Errorf(`ent: validator failed for field "ReportMalware.analysis_id": %w`, err)}
}
}
return nil
}
func (rmuo *ReportMalwareUpdateOne) sqlSave(ctx context.Context) (_node *ReportMalware, err error) {
if err := rmuo.check(); err != nil {
return _node, err
}
_spec := sqlgraph.NewUpdateSpec(reportmalware.Table, reportmalware.Columns, sqlgraph.NewFieldSpec(reportmalware.FieldID, field.TypeInt))
id, ok := rmuo.mutation.ID()
if !ok {
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "ReportMalware.id" for update`)}
}
_spec.Node.ID.Value = id
if fields := rmuo.fields; len(fields) > 0 {
_spec.Node.Columns = make([]string, 0, len(fields))
_spec.Node.Columns = append(_spec.Node.Columns, reportmalware.FieldID)
for _, f := range fields {
if !reportmalware.ValidColumn(f) {
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
}
if f != reportmalware.FieldID {
_spec.Node.Columns = append(_spec.Node.Columns, f)
}
}
}
if ps := rmuo.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if value, ok := rmuo.mutation.AnalysisID(); ok {
_spec.SetField(reportmalware.FieldAnalysisID, field.TypeString, value)
}
if value, ok := rmuo.mutation.IsMalware(); ok {
_spec.SetField(reportmalware.FieldIsMalware, field.TypeBool, value)
}
if value, ok := rmuo.mutation.IsSuspicious(); ok {
_spec.SetField(reportmalware.FieldIsSuspicious, field.TypeBool, value)
}
if value, ok := rmuo.mutation.Confidence(); ok {
_spec.SetField(reportmalware.FieldConfidence, field.TypeString, value)
}
if rmuo.mutation.ConfidenceCleared() {
_spec.ClearField(reportmalware.FieldConfidence, field.TypeString)
}
if value, ok := rmuo.mutation.Report(); ok {
_spec.SetField(reportmalware.FieldReport, field.TypeJSON, value)
}
if rmuo.mutation.ReportCleared() {
_spec.ClearField(reportmalware.FieldReport, field.TypeJSON)
}
if value, ok := rmuo.mutation.VerificationRecord(); ok {
_spec.SetField(reportmalware.FieldVerificationRecord, field.TypeJSON, value)
}
if rmuo.mutation.VerificationRecordCleared() {
_spec.ClearField(reportmalware.FieldVerificationRecord, field.TypeJSON)
}
if value, ok := rmuo.mutation.CreatedAt(); ok {
_spec.SetField(reportmalware.FieldCreatedAt, field.TypeTime, value)
}
if rmuo.mutation.CreatedAtCleared() {
_spec.ClearField(reportmalware.FieldCreatedAt, field.TypeTime)
}
if value, ok := rmuo.mutation.UpdatedAt(); ok {
_spec.SetField(reportmalware.FieldUpdatedAt, field.TypeTime, value)
}
if rmuo.mutation.UpdatedAtCleared() {
_spec.ClearField(reportmalware.FieldUpdatedAt, field.TypeTime)
}
if rmuo.mutation.PackageCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2O,
Inverse: true,
Table: reportmalware.PackageTable,
Columns: []string{reportmalware.PackageColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(reportpackage.FieldID, field.TypeInt),
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := rmuo.mutation.PackageIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2O,
Inverse: true,
Table: reportmalware.PackageTable,
Columns: []string{reportmalware.PackageColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(reportpackage.FieldID, field.TypeInt),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
_node = &ReportMalware{config: rmuo.config}
_spec.Assign = _node.assignValues
_spec.ScanValues = _node.scanValues
if err = sqlgraph.UpdateNode(ctx, rmuo.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{reportmalware.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return nil, err
}
rmuo.mutation.done = true
return _node, nil
}