diff --git a/internal/storage/token_metadata.go b/internal/storage/token_metadata.go index 82432e5..8a80cad 100644 --- a/internal/storage/token_metadata.go +++ b/internal/storage/token_metadata.go @@ -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 }