~emersion/soju#206: 
Use safer pattern for record updates

A common pattern in soju is:

record := user.User // copy
record.Something = 42
user.updateUser(&record)

This is suboptimal because it's pretty easy to forget the copy and mutate the data directly:

user.Something = 42
user.updateUser(&user.User)

This is a mistake because the in-memory state goes out-of-sync with the DB state if updateUser fails.

Something safer could be:

user.updateUser(func(record *database.User) {
    record.Something = 42
})
Status
REPORTED
Submitter
~emersion
Assigned to
No-one
Submitted
1 year, 10 months ago
Updated
1 year, 9 months ago
Labels
enhancement

~emersion 1 year, 9 months ago

Simon Ser referenced this ticket in commit aecff32.

Register here or Log in to comment, or comment via email.