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

Method sqlSave

pkg/database/ent/allowlist_update.go:399–501  ·  view source on GitHub ↗
(ctx context.Context)

Source from the content-addressed store, hash-verified

397}
398
399func (_u *AllowListUpdateOne) sqlSave(ctx context.Context) (_node *AllowList, err error) {
400 _spec := sqlgraph.NewUpdateSpec(allowlist.Table, allowlist.Columns, sqlgraph.NewFieldSpec(allowlist.FieldID, field.TypeInt))
401 id, ok := _u.mutation.ID()
402 if !ok {
403 return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "AllowList.id" for update`)}
404 }
405 _spec.Node.ID.Value = id
406 if fields := _u.fields; len(fields) > 0 {
407 _spec.Node.Columns = make([]string, 0, len(fields))
408 _spec.Node.Columns = append(_spec.Node.Columns, allowlist.FieldID)
409 for _, f := range fields {
410 if !allowlist.ValidColumn(f) {
411 return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
412 }
413 if f != allowlist.FieldID {
414 _spec.Node.Columns = append(_spec.Node.Columns, f)
415 }
416 }
417 }
418 if ps := _u.mutation.predicates; len(ps) > 0 {
419 _spec.Predicate = func(selector *sql.Selector) {
420 for i := range ps {
421 ps[i](selector)
422 }
423 }
424 }
425 if value, ok := _u.mutation.UpdatedAt(); ok {
426 _spec.SetField(allowlist.FieldUpdatedAt, field.TypeTime, value)
427 }
428 if value, ok := _u.mutation.Name(); ok {
429 _spec.SetField(allowlist.FieldName, field.TypeString, value)
430 }
431 if value, ok := _u.mutation.FromConsole(); ok {
432 _spec.SetField(allowlist.FieldFromConsole, field.TypeBool, value)
433 }
434 if value, ok := _u.mutation.Description(); ok {
435 _spec.SetField(allowlist.FieldDescription, field.TypeString, value)
436 }
437 if _u.mutation.DescriptionCleared() {
438 _spec.ClearField(allowlist.FieldDescription, field.TypeString)
439 }
440 if _u.mutation.AllowlistIDCleared() {
441 _spec.ClearField(allowlist.FieldAllowlistID, field.TypeString)
442 }
443 if _u.mutation.AllowlistItemsCleared() {
444 edge := &sqlgraph.EdgeSpec{
445 Rel: sqlgraph.M2M,
446 Inverse: false,
447 Table: allowlist.AllowlistItemsTable,
448 Columns: allowlist.AllowlistItemsPrimaryKey,
449 Bidi: false,
450 Target: &sqlgraph.EdgeTarget{
451 IDSpec: sqlgraph.NewFieldSpec(allowlistitem.FieldID, field.TypeInt),
452 },
453 }
454 _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
455 }
456 if nodes := _u.mutation.RemovedAllowlistItemsIDs(); len(nodes) > 0 && !_u.mutation.AllowlistItemsCleared() {

Callers

nothing calls this directly

Calls 14

ValidColumnFunction · 0.92
FromConsoleMethod · 0.80
DescriptionClearedMethod · 0.80
AllowlistIDClearedMethod · 0.80
AllowlistItemsClearedMethod · 0.80
AllowlistItemsIDsMethod · 0.80
DescriptionMethod · 0.65
ErrorMethod · 0.65
IDMethod · 0.45
UpdatedAtMethod · 0.45
SetFieldMethod · 0.45

Tested by

no test coverage detected