-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: allow updating zero values and fix pointer resolution on isZero
- Loading branch information
Showing
9 changed files
with
180 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,7 @@ func Example() { | |
CognitoUserID: "373f90eb-00ac-410f-9fe0-1a7058d090ba", | ||
Email: "[email protected]", | ||
Name: "kataras", | ||
Username: "kataras", | ||
} | ||
|
||
// Insert the customer into the database and get its ID. | ||
|
@@ -43,8 +44,6 @@ func Example() { | |
// Update specific columns by id: | ||
updated, err := customers.UpdateOnlyColumns( | ||
context.Background(), | ||
// TODO: make a generator for: models.Customers.Columns.CognitoUserID.Name so | ||
// end-developers have static safety for columns. | ||
[]string{"cognito_user_id"}, | ||
Customer{ | ||
BaseEntity: BaseEntity{ | ||
|
@@ -68,6 +67,21 @@ func Example() { | |
return fmt.Errorf("update: no record was updated") | ||
} | ||
|
||
// Update a default column to its zero value. | ||
updated, err = customers.UpdateOnlyColumns( | ||
context.Background(), | ||
[]string{"username"}, | ||
Customer{ | ||
BaseEntity: BaseEntity{ | ||
ID: customerToInsert.ID, | ||
}, | ||
Username: "", | ||
}) | ||
if err != nil { | ||
return fmt.Errorf("update username: %w", err) | ||
} else if updated == 0 { | ||
return fmt.Errorf("update username: no record was updated") | ||
} | ||
// Select the customer from the database by its ID. | ||
customer, err := customers.SelectSingle(context.Background(), `SELECT * FROM customers WHERE id = $1;`, customerToInsert.ID) | ||
if err != nil { | ||
|
@@ -218,4 +232,7 @@ func Example() { | |
fmt.Printf("expected other_features to be equal but got %#+v and %#+v", otherFeatures, existingBlogPost.OtherFeatures) | ||
return | ||
} | ||
|
||
// Output: | ||
// | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters