Skip to content

Commit

Permalink
Fix/bun handlers (#9)
Browse files Browse the repository at this point in the history
* BeforeInsert and BeforeUpdate hooks replaced with BeforeAppendModel hook

* Rollback imports

* Added BeforeAppendModelHook interface check
  • Loading branch information
k-karuna authored Sep 9, 2024
1 parent 2fbfcdc commit 03c1e76
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions internal/storage/token_metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,18 @@ func (TokenMetadata) TableName() string {
return "token_metadata"
}

// BeforeInsert -
func (tm *TokenMetadata) BeforeInsert(ctx context.Context) (context.Context, error) {
tm.UpdatedAt = time.Now().Unix()
tm.CreatedAt = tm.UpdatedAt
tm.UpdateID = TokenUpdateID.Increment()
return ctx, nil
}

// BeforeUpdate -
func (tm *TokenMetadata) BeforeUpdate(ctx context.Context) (context.Context, error) {
tm.UpdatedAt = time.Now().Unix()
tm.UpdateID = TokenUpdateID.Increment()
return ctx, nil
var _ bun.BeforeAppendModelHook = (*TokenMetadata)(nil)

// BeforeAppendModel -
func (tm *TokenMetadata) BeforeAppendModel(ctx context.Context, query bun.Query) error {
switch query.(type) {
case *bun.InsertQuery:
tm.UpdatedAt = time.Now().Unix()
tm.CreatedAt = tm.UpdatedAt
tm.UpdateID = TokenUpdateID.Increment()
case *bun.UpdateQuery:
tm.UpdatedAt = time.Now().Unix()
tm.UpdateID = TokenUpdateID.Increment()
}
return nil
}

0 comments on commit 03c1e76

Please sign in to comment.