MCPcopy Index your code
hub / github.com/crowdsecurity/crowdsec / sqlSave

Method sqlSave

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

Source from the content-addressed store, hash-verified

161}
162
163func (_u *AllowListUpdate) sqlSave(ctx context.Context) (_node int, err error) {
164 _spec := sqlgraph.NewUpdateSpec(allowlist.Table, allowlist.Columns, sqlgraph.NewFieldSpec(allowlist.FieldID, field.TypeInt))
165 if ps := _u.mutation.predicates; len(ps) > 0 {
166 _spec.Predicate = func(selector *sql.Selector) {
167 for i := range ps {
168 ps[i](selector)
169 }
170 }
171 }
172 if value, ok := _u.mutation.UpdatedAt(); ok {
173 _spec.SetField(allowlist.FieldUpdatedAt, field.TypeTime, value)
174 }
175 if value, ok := _u.mutation.Name(); ok {
176 _spec.SetField(allowlist.FieldName, field.TypeString, value)
177 }
178 if value, ok := _u.mutation.FromConsole(); ok {
179 _spec.SetField(allowlist.FieldFromConsole, field.TypeBool, value)
180 }
181 if value, ok := _u.mutation.Description(); ok {
182 _spec.SetField(allowlist.FieldDescription, field.TypeString, value)
183 }
184 if _u.mutation.DescriptionCleared() {
185 _spec.ClearField(allowlist.FieldDescription, field.TypeString)
186 }
187 if _u.mutation.AllowlistIDCleared() {
188 _spec.ClearField(allowlist.FieldAllowlistID, field.TypeString)
189 }
190 if _u.mutation.AllowlistItemsCleared() {
191 edge := &sqlgraph.EdgeSpec{
192 Rel: sqlgraph.M2M,
193 Inverse: false,
194 Table: allowlist.AllowlistItemsTable,
195 Columns: allowlist.AllowlistItemsPrimaryKey,
196 Bidi: false,
197 Target: &sqlgraph.EdgeTarget{
198 IDSpec: sqlgraph.NewFieldSpec(allowlistitem.FieldID, field.TypeInt),
199 },
200 }
201 _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
202 }
203 if nodes := _u.mutation.RemovedAllowlistItemsIDs(); len(nodes) > 0 && !_u.mutation.AllowlistItemsCleared() {
204 edge := &sqlgraph.EdgeSpec{
205 Rel: sqlgraph.M2M,
206 Inverse: false,
207 Table: allowlist.AllowlistItemsTable,
208 Columns: allowlist.AllowlistItemsPrimaryKey,
209 Bidi: false,
210 Target: &sqlgraph.EdgeTarget{
211 IDSpec: sqlgraph.NewFieldSpec(allowlistitem.FieldID, field.TypeInt),
212 },
213 }
214 for _, k := range nodes {
215 edge.Target.Nodes = append(edge.Target.Nodes, k)
216 }
217 _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
218 }
219 if nodes := _u.mutation.AllowlistItemsIDs(); len(nodes) > 0 {
220 edge := &sqlgraph.EdgeSpec{

Callers

nothing calls this directly

Calls 12

FromConsoleMethod · 0.80
DescriptionClearedMethod · 0.80
AllowlistIDClearedMethod · 0.80
AllowlistItemsClearedMethod · 0.80
AllowlistItemsIDsMethod · 0.80
DescriptionMethod · 0.65
ErrorMethod · 0.65
UpdatedAtMethod · 0.45
SetFieldMethod · 0.45
NameMethod · 0.45
ClearFieldMethod · 0.45

Tested by

no test coverage detected