MCPcopy
hub / github.com/crowdsecurity/crowdsec / sqlSave

Method sqlSave

pkg/database/ent/decision_update.go:354–449  ·  view source on GitHub ↗
(ctx context.Context)

Source from the content-addressed store, hash-verified

352}
353
354func (_u *DecisionUpdateOne) sqlSave(ctx context.Context) (_node *Decision, err error) {
355 _spec := sqlgraph.NewUpdateSpec(decision.Table, decision.Columns, sqlgraph.NewFieldSpec(decision.FieldID, field.TypeInt))
356 id, ok := _u.mutation.ID()
357 if !ok {
358 return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Decision.id" for update`)}
359 }
360 _spec.Node.ID.Value = id
361 if fields := _u.fields; len(fields) > 0 {
362 _spec.Node.Columns = make([]string, 0, len(fields))
363 _spec.Node.Columns = append(_spec.Node.Columns, decision.FieldID)
364 for _, f := range fields {
365 if !decision.ValidColumn(f) {
366 return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
367 }
368 if f != decision.FieldID {
369 _spec.Node.Columns = append(_spec.Node.Columns, f)
370 }
371 }
372 }
373 if ps := _u.mutation.predicates; len(ps) > 0 {
374 _spec.Predicate = func(selector *sql.Selector) {
375 for i := range ps {
376 ps[i](selector)
377 }
378 }
379 }
380 if value, ok := _u.mutation.UpdatedAt(); ok {
381 _spec.SetField(decision.FieldUpdatedAt, field.TypeTime, value)
382 }
383 if value, ok := _u.mutation.Until(); ok {
384 _spec.SetField(decision.FieldUntil, field.TypeTime, value)
385 }
386 if _u.mutation.UntilCleared() {
387 _spec.ClearField(decision.FieldUntil, field.TypeTime)
388 }
389 if _u.mutation.StartIPCleared() {
390 _spec.ClearField(decision.FieldStartIP, field.TypeInt64)
391 }
392 if _u.mutation.EndIPCleared() {
393 _spec.ClearField(decision.FieldEndIP, field.TypeInt64)
394 }
395 if _u.mutation.StartSuffixCleared() {
396 _spec.ClearField(decision.FieldStartSuffix, field.TypeInt64)
397 }
398 if _u.mutation.EndSuffixCleared() {
399 _spec.ClearField(decision.FieldEndSuffix, field.TypeInt64)
400 }
401 if _u.mutation.IPSizeCleared() {
402 _spec.ClearField(decision.FieldIPSize, field.TypeInt64)
403 }
404 if _u.mutation.UUIDCleared() {
405 _spec.ClearField(decision.FieldUUID, field.TypeString)
406 }
407 if _u.mutation.OwnerCleared() {
408 edge := &sqlgraph.EdgeSpec{
409 Rel: sqlgraph.M2O,
410 Inverse: true,
411 Table: decision.OwnerTable,

Callers

nothing calls this directly

Calls 15

ValidColumnFunction · 0.92
UntilMethod · 0.80
UntilClearedMethod · 0.80
ErrorMethod · 0.65
IDMethod · 0.45
UpdatedAtMethod · 0.45
SetFieldMethod · 0.45
ClearFieldMethod · 0.45
StartIPClearedMethod · 0.45
EndIPClearedMethod · 0.45
StartSuffixClearedMethod · 0.45
EndSuffixClearedMethod · 0.45

Tested by

no test coverage detected