Skip to content

Commit

Permalink
Remove lastResultID() helper function
Browse files Browse the repository at this point in the history
  • Loading branch information
benbjohnson committed Jan 30, 2021
1 parent 440ee60 commit 030fcb0
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 10 deletions.
4 changes: 3 additions & 1 deletion sqlite/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,9 +292,11 @@ func createAuth(ctx context.Context, tx *Tx, auth *wtf.Auth) error {
}

// Update caller object to set ID.
if auth.ID, err = lastInsertID(result); err != nil {
id, err := result.LastInsertId()
if err != nil {
return err
}
auth.ID = int(id)

return nil
}
Expand Down
4 changes: 3 additions & 1 deletion sqlite/dial.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,9 +397,11 @@ func createDial(ctx context.Context, tx *Tx, dial *wtf.Dial) error {
}

// Read back new dial ID into caller argument.
if dial.ID, err = lastInsertID(result); err != nil {
id, err := result.LastInsertId()
if err != nil {
return err
}
dial.ID = int(id)

// Record initial value to history table.
if err := insertDialValue(ctx, tx, dial.ID, dial.Value, dial.CreatedAt); err != nil {
Expand Down
4 changes: 3 additions & 1 deletion sqlite/dial_membership.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,9 +268,11 @@ func createDialMembership(ctx context.Context, tx *Tx, membership *wtf.DialMembe
}

// Assign new database ID to the caller's arg.
if membership.ID, err = lastInsertID(result); err != nil {
id, err := result.LastInsertId()
if err != nil {
return err
}
membership.ID = int(id)

// Ensure computed parent dial value is up to date.
if err := refreshDialValue(ctx, tx, membership.DialID); err != nil {
Expand Down
6 changes: 0 additions & 6 deletions sqlite/sqlite.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,12 +256,6 @@ type Tx struct {
now time.Time
}

// lastInsertID is a helper function for reading the last inserted ID as an int.
func lastInsertID(result sql.Result) (int, error) {
id, err := result.LastInsertId()
return int(id), err
}

// NullTime represents a helper wrapper for time.Time. It automatically converts
// time fields to/from RFC 3339 format. Also supports NULL for zero time.
type NullTime time.Time
Expand Down
4 changes: 3 additions & 1 deletion sqlite/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,9 +247,11 @@ func createUser(ctx context.Context, tx *Tx, user *wtf.User) error {
return FormatError(err)
}

if user.ID, err = lastInsertID(result); err != nil {
id, err := result.LastInsertId()
if err != nil {
return err
}
user.ID = int(id)

return nil
}
Expand Down

0 comments on commit 030fcb0

Please sign in to comment.