guregu / dynamo

expressive DynamoDB library for Go
Other
1.3k stars 179 forks source link

Should the builder types be immutable? #213

Open guregu opened 1 year ago

guregu commented 1 year ago

This is a question for v2.

Currently the builder types like *Query and *Update are mutable. This works similar to the standard library text/template package where they return themselves for convenience.

Some other packages (like goqu for example) use immutable types instead. The advantage of this method is that you can create base queries and easily extend them.

The disadvantage of switching is it would break any v1 code that relies on the mutability. Alternatively we could ditch the builder pattern. Functional parameters are the current best practice but we have a lot of disparate parameters so it would probably be annoying to work with 🤔