MCPcopy Create free account
hub / github.com/crowdsecurity/crowdsec / assignValues

Method assignValues

pkg/database/ent/allowlist.go:78–131  ·  view source on GitHub ↗

assignValues assigns the values that were returned from sql.Rows (after scanning) to the AllowList fields.

(columns []string, values []any)

Source from the content-addressed store, hash-verified

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

Callers 1

sqlAllMethod · 0.95

Calls 1

SetMethod · 0.45

Tested by

no test coverage detected