Skip to content

v3: consider replacing .Opts(Struct) with per-option builder methods in CRUD requests #512

@bigbes

Description

@bigbes

Currently, CRUD operations in the crud module accept optional parameters via a single .Opts(...) call that takes a large struct (e.g. ReplaceObjectManyOpts). This approach has a few drawbacks:

  • It forces users to construct a full struct even when only one option is needed (especially if user uses exhaustruct linter).
  • It is less discoverable.
  • It makes call sites more verbose and less fluent compared to method chaining.

Proposal is to replace the .Opts(...) pattern with individual builder methods for each optional field:

req := crud.MakeReplaceObjectManyRequest("my_space").
    Objects(myObjects).
    Timeout(5.0).
    Fields("id", "name").
    StopOnError(true)

This style aligns better with common Go API design patterns and improves usability, especially for newcomers and interactive development.

Checklist

  • Refactor all CRUD request types (InsertObjectMany, ReplaceObjectMany, etc.).
  • Introduce typed setter methods for each field in the corresponding *Opts structs.
  • Update tests and examples.
  • Modify CHANGELOG.md and MIGRATION.md accordingly

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions