code: func (t *SwitchesTable) add(c context.Context) error {
  	// Avoid using the database connection to prepare unnecessary statements.
  	if len(t.additions) == 0 {
  		return nil
  	}
  
  	db := database.Get(c)
  	stmt, err := db.PrepareContext(c, `
  		INSERT INTO switches (name, description, ports, state, rack_id)
  		VALUES (?, ?, ?, ?, ?)
  	`)
  	if err != nil {
  		return errors.Annotate(err, "failed to prepare statement").Err()
  	}
  	defer stmt.Close()
  
  	// Add each switch to the database, and update the slice of switches with each addition.
  	for len(t.additions) > 0 {
  		s := t.additions[0]
  		result, err := stmt.ExecContext(c, s.Name, s.Description, s.Ports, s.State, s.RackId)
  		if err != nil {
  			return errors.Annotate(err, "failed to add switch %q", s.Name).Err()
  		}
  		t.current = append(t.current, s)
  		t.additions = t.additions[1:]
  		logging.Infof(c, "Added switch %q", s.Name)
  		s.Id, err = result.LastInsertId()
  		if err != nil {
  			return errors.Annotate(err, "failed to get switch ID %q", s.Name).Err()
  		}
  	}
  	return nil
  }
docs: // add adds all switches pending addition to the database, clearing pending additions.
  // No-op unless computeChanges was called first. Idempotent until computeChanges is called again.