MCPcopy Index your code
hub / github.com/apache/devlake / CreateWithMap

Method CreateWithMap

backend/impls/dalgorm/dalgorm.go:237–254  ·  view source on GitHub ↗

CreateWithMap insert record to database

(entity interface{}, record map[string]interface{})

Source from the content-addressed store, hash-verified

235
236// CreateWithMap insert record to database
237func (d *Dalgorm) CreateWithMap(entity interface{}, record map[string]interface{}) errors.Error {
238 d.unwrapDynamic(&entity, nil)
239 if record != nil {
240 if id, ok := record["id"]; ok && id != nil {
241 var columns []string
242 for column := range record {
243 columns = append(columns, column)
244 }
245 return d.convertGormError(buildTx(d.db, nil).Model(entity).Clauses(clause.OnConflict{
246 Columns: []clause.Column{{Name: "id"}},
247 DoUpdates: clause.AssignmentColumns(columns),
248 }).Create(record).Error)
249 } else {
250 return d.convertGormError(buildTx(d.db, nil).Model(entity).Clauses(clause.OnConflict{UpdateAll: true}).Create(record).Error)
251 }
252 }
253 return d.convertGormError(buildTx(d.db, nil).Model(entity).Clauses(clause.OnConflict{UpdateAll: true}).Create(record).Error)
254}
255
256// Update updates record
257func (d *Dalgorm) Update(entity interface{}, clauses ...dal.Clause) errors.Error {

Callers

nothing calls this directly

Calls 4

unwrapDynamicMethod · 0.95
convertGormErrorMethod · 0.95
buildTxFunction · 0.85
CreateMethod · 0.65

Tested by

no test coverage detected