| 655 | } |
| 656 | |
| 657 | func (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 | |
| 679 | func (tx *Transaction) Update(resource *schema.Resource) error { |
| 680 | return tx.UpdateContext(context.Background(), resource) |