MCPcopy Create free account
hub / github.com/cloudwan/gohan / updateQuery

Method updateQuery

db/sql/sql.go:657–677  ·  view source on GitHub ↗
(resource *schema.Resource)

Source from the content-addressed store, hash-verified

655}
656
657func (tx *Transaction) updateQuery(resource *schema.Resource) (sq.UpdateBuilder, error) {
658 s := resource.Schema()
659 db := tx.db
660 data := resource.Data()
661 q := sq.Update(quote(s.GetDbTableName()))
662 for _, attr := range s.Properties {
663 //TODO(nati) support optional value
664 if _, ok := data[attr.ID]; ok {
665 handler := db.handler(&attr)
666 encoded, err := handler.encode(&attr, data[attr.ID])
667 if err != nil {
668 return q, fmt.Errorf("SQL Update encoding error: %s", err)
669 }
670 q = q.Set(quote(attr.ID), encoded)
671 }
672 }
673 if s.Parent != "" {
674 q = q.Set(s.ParentSchemaPropertyID(), resource.ParentID())
675 }
676 return q, nil
677}
678
679func (tx *Transaction) Update(resource *schema.Resource) error {
680 return tx.UpdateContext(context.Background(), resource)

Callers 2

UpdateContextMethod · 0.95
StateUpdateContextMethod · 0.95

Calls 11

GetDbTableNameMethod · 0.80
handlerMethod · 0.80
quoteFunction · 0.70
SchemaMethod · 0.65
UpdateMethod · 0.65
encodeMethod · 0.65
ErrorfMethod · 0.65
SetMethod · 0.65
DataMethod · 0.45
ParentIDMethod · 0.45

Tested by

no test coverage detected