assignValues assigns the values that were returned from sql.Rows (after scanning) to the Event fields.
(columns []string, values []any)
| 75 | // assignValues assigns the values that were returned from sql.Rows (after scanning) |
| 76 | // to the Event fields. |
| 77 | func (_m *Event) assignValues(columns []string, values []any) error { |
| 78 | if m, n := len(values), len(columns); m < n { |
| 79 | return fmt.Errorf("mismatch number of scan values: %d != %d", m, n) |
| 80 | } |
| 81 | for i := range columns { |
| 82 | switch columns[i] { |
| 83 | case event.FieldID: |
| 84 | value, ok := values[i].(*sql.NullInt64) |
| 85 | if !ok { |
| 86 | return fmt.Errorf("unexpected type %T for field id", value) |
| 87 | } |
| 88 | _m.ID = int(value.Int64) |
| 89 | case event.FieldCreatedAt: |
| 90 | if value, ok := values[i].(*sql.NullTime); !ok { |
| 91 | return fmt.Errorf("unexpected type %T for field created_at", values[i]) |
| 92 | } else if value.Valid { |
| 93 | _m.CreatedAt = value.Time |
| 94 | } |
| 95 | case event.FieldUpdatedAt: |
| 96 | if value, ok := values[i].(*sql.NullTime); !ok { |
| 97 | return fmt.Errorf("unexpected type %T for field updated_at", values[i]) |
| 98 | } else if value.Valid { |
| 99 | _m.UpdatedAt = value.Time |
| 100 | } |
| 101 | case event.FieldTime: |
| 102 | if value, ok := values[i].(*sql.NullTime); !ok { |
| 103 | return fmt.Errorf("unexpected type %T for field time", values[i]) |
| 104 | } else if value.Valid { |
| 105 | _m.Time = value.Time |
| 106 | } |
| 107 | case event.FieldSerialized: |
| 108 | if value, ok := values[i].(*sql.NullString); !ok { |
| 109 | return fmt.Errorf("unexpected type %T for field serialized", values[i]) |
| 110 | } else if value.Valid { |
| 111 | _m.Serialized = value.String |
| 112 | } |
| 113 | case event.FieldAlertEvents: |
| 114 | if value, ok := values[i].(*sql.NullInt64); !ok { |
| 115 | return fmt.Errorf("unexpected type %T for field alert_events", values[i]) |
| 116 | } else if value.Valid { |
| 117 | _m.AlertEvents = int(value.Int64) |
| 118 | } |
| 119 | default: |
| 120 | _m.selectValues.Set(columns[i], values[i]) |
| 121 | } |
| 122 | } |
| 123 | return nil |
| 124 | } |
| 125 | |
| 126 | // Value returns the ent.Value that was dynamically selected and assigned to the Event. |
| 127 | // This includes values selected through modifiers, order, etc. |