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

Method assignValues

pkg/database/ent/machine.go:104–229  ·  view source on GitHub ↗

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

(columns []string, values []any)

Source from the content-addressed store, hash-verified

102// assignValues assigns the values that were returned from sql.Rows (after scanning)
103// to the Machine fields.
104func (_m *Machine) assignValues(columns []string, values []any) error {
105 if m, n := len(values), len(columns); m < n {
106 return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
107 }
108 for i := range columns {
109 switch columns[i] {
110 case machine.FieldID:
111 value, ok := values[i].(*sql.NullInt64)
112 if !ok {
113 return fmt.Errorf("unexpected type %T for field id", value)
114 }
115 _m.ID = int(value.Int64)
116 case machine.FieldCreatedAt:
117 if value, ok := values[i].(*sql.NullTime); !ok {
118 return fmt.Errorf("unexpected type %T for field created_at", values[i])
119 } else if value.Valid {
120 _m.CreatedAt = value.Time
121 }
122 case machine.FieldUpdatedAt:
123 if value, ok := values[i].(*sql.NullTime); !ok {
124 return fmt.Errorf("unexpected type %T for field updated_at", values[i])
125 } else if value.Valid {
126 _m.UpdatedAt = value.Time
127 }
128 case machine.FieldLastPush:
129 if value, ok := values[i].(*sql.NullTime); !ok {
130 return fmt.Errorf("unexpected type %T for field last_push", values[i])
131 } else if value.Valid {
132 _m.LastPush = new(time.Time)
133 *_m.LastPush = value.Time
134 }
135 case machine.FieldLastHeartbeat:
136 if value, ok := values[i].(*sql.NullTime); !ok {
137 return fmt.Errorf("unexpected type %T for field last_heartbeat", values[i])
138 } else if value.Valid {
139 _m.LastHeartbeat = new(time.Time)
140 *_m.LastHeartbeat = value.Time
141 }
142 case machine.FieldMachineId:
143 if value, ok := values[i].(*sql.NullString); !ok {
144 return fmt.Errorf("unexpected type %T for field machineId", values[i])
145 } else if value.Valid {
146 _m.MachineId = value.String
147 }
148 case machine.FieldPassword:
149 if value, ok := values[i].(*sql.NullString); !ok {
150 return fmt.Errorf("unexpected type %T for field password", values[i])
151 } else if value.Valid {
152 _m.Password = value.String
153 }
154 case machine.FieldIpAddress:
155 if value, ok := values[i].(*sql.NullString); !ok {
156 return fmt.Errorf("unexpected type %T for field ipAddress", values[i])
157 } else if value.Valid {
158 _m.IpAddress = value.String
159 }
160 case machine.FieldScenarios:
161 if value, ok := values[i].(*sql.NullString); !ok {

Callers 1

sqlAllMethod · 0.95

Calls 1

SetMethod · 0.45

Tested by

no test coverage detected