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

Method createSpec

pkg/database/ent/meta_create.go:184–224  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

182}
183
184func (_c *MetaCreate) createSpec() (*Meta, *sqlgraph.CreateSpec) {
185 var (
186 _node = &Meta{config: _c.config}
187 _spec = sqlgraph.NewCreateSpec(meta.Table, sqlgraph.NewFieldSpec(meta.FieldID, field.TypeInt))
188 )
189 _spec.OnConflict = _c.conflict
190 if value, ok := _c.mutation.CreatedAt(); ok {
191 _spec.SetField(meta.FieldCreatedAt, field.TypeTime, value)
192 _node.CreatedAt = value
193 }
194 if value, ok := _c.mutation.UpdatedAt(); ok {
195 _spec.SetField(meta.FieldUpdatedAt, field.TypeTime, value)
196 _node.UpdatedAt = value
197 }
198 if value, ok := _c.mutation.Key(); ok {
199 _spec.SetField(meta.FieldKey, field.TypeString, value)
200 _node.Key = value
201 }
202 if value, ok := _c.mutation.Value(); ok {
203 _spec.SetField(meta.FieldValue, field.TypeString, value)
204 _node.Value = value
205 }
206 if nodes := _c.mutation.OwnerIDs(); len(nodes) > 0 {
207 edge := &sqlgraph.EdgeSpec{
208 Rel: sqlgraph.M2O,
209 Inverse: true,
210 Table: meta.OwnerTable,
211 Columns: []string{meta.OwnerColumn},
212 Bidi: false,
213 Target: &sqlgraph.EdgeTarget{
214 IDSpec: sqlgraph.NewFieldSpec(alert.FieldID, field.TypeInt),
215 },
216 }
217 for _, k := range nodes {
218 edge.Target.Nodes = append(edge.Target.Nodes, k)
219 }
220 _node.AlertMetas = nodes[0]
221 _spec.Edges = append(_spec.Edges, edge)
222 }
223 return _node, _spec
224}
225
226// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
227// of the `INSERT` statement. For example:

Callers 2

sqlSaveMethod · 0.95
SaveMethod · 0.45

Calls 6

KeyMethod · 0.80
CreatedAtMethod · 0.45
SetFieldMethod · 0.45
UpdatedAtMethod · 0.45
ValueMethod · 0.45
OwnerIDsMethod · 0.45

Tested by

no test coverage detected