(_ context.Context, tx *gorm.DB, instanceNameOrID string, preload ...string)
| 128 | } |
| 129 | |
| 130 | func (s *sqlDatabase) getInstance(_ context.Context, tx *gorm.DB, instanceNameOrID string, preload ...string) (Instance, error) { |
| 131 | var instance Instance |
| 132 | |
| 133 | var whereArg any = instanceNameOrID |
| 134 | whereClause := "name = ?" |
| 135 | id, err := uuid.Parse(instanceNameOrID) |
| 136 | if err == nil { |
| 137 | whereArg = id |
| 138 | whereClause = "id = ?" |
| 139 | } |
| 140 | q := tx |
| 141 | |
| 142 | if len(preload) > 0 { |
| 143 | for _, item := range preload { |
| 144 | q = q.Preload(item) |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | q = q.Model(&Instance{}). |
| 149 | Preload(clause.Associations). |
| 150 | Where(whereClause, whereArg). |
| 151 | First(&instance) |
| 152 | if q.Error != nil { |
| 153 | if errors.Is(q.Error, gorm.ErrRecordNotFound) { |
| 154 | return Instance{}, fmt.Errorf("error fetching instance by name: %w", runnerErrors.ErrNotFound) |
| 155 | } |
| 156 | return Instance{}, fmt.Errorf("error fetching instance by name: %w", q.Error) |
| 157 | } |
| 158 | return instance, nil |
| 159 | } |
| 160 | |
| 161 | func (s *sqlDatabase) GetInstance(ctx context.Context, instanceName string) (params.Instance, error) { |
| 162 | instance, err := s.getInstance(ctx, s.conn, instanceName, "StatusMessages", "Pool", "ScaleSet") |
no outgoing calls
no test coverage detected