FindMatchingPresetID finds a preset ID that matches the provided parameters. It returns the preset ID if a match is found, or uuid.Nil if no match is found. The function performs a bidirectional comparison to ensure all parameters match exactly.
( ctx context.Context, store database.Store, templateVersionID uuid.UUID, parameterNames []string, parameterValues []string, )
| 15 | // It returns the preset ID if a match is found, or uuid.Nil if no match is found. |
| 16 | // The function performs a bidirectional comparison to ensure all parameters match exactly. |
| 17 | func FindMatchingPresetID( |
| 18 | ctx context.Context, |
| 19 | store database.Store, |
| 20 | templateVersionID uuid.UUID, |
| 21 | parameterNames []string, |
| 22 | parameterValues []string, |
| 23 | ) (uuid.UUID, error) { |
| 24 | if len(parameterNames) != len(parameterValues) { |
| 25 | return uuid.Nil, xerrors.New("parameter names and values must have the same length") |
| 26 | } |
| 27 | |
| 28 | result, err := store.FindMatchingPresetID(ctx, database.FindMatchingPresetIDParams{ |
| 29 | TemplateVersionID: templateVersionID, |
| 30 | ParameterNames: parameterNames, |
| 31 | ParameterValues: parameterValues, |
| 32 | }) |
| 33 | if err != nil { |
| 34 | // Handle the case where no matching preset is found (no rows returned) |
| 35 | if errors.Is(err, sql.ErrNoRows) { |
| 36 | return uuid.Nil, nil |
| 37 | } |
| 38 | return uuid.Nil, xerrors.Errorf("find matching preset ID: %w", err) |
| 39 | } |
| 40 | |
| 41 | return result, nil |
| 42 | } |