feat: initial commit
This commit is contained in:
@ -2,6 +2,7 @@ package store
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"sync"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
@ -31,6 +32,21 @@ func (s *Store) Do(ctx context.Context, fn func(db *gorm.DB) error) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Store) Tx(ctx context.Context, fn func(db *gorm.DB) error, opts ...*sql.TxOptions) error {
|
||||
return errors.WithStack(s.Do(ctx, func(db *gorm.DB) error {
|
||||
err := db.Transaction(func(tx *gorm.DB) error {
|
||||
if err := fn(tx); err != nil {
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
return nil
|
||||
}, opts...)
|
||||
if err != nil {
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
return nil
|
||||
}))
|
||||
}
|
||||
|
||||
func createGetDatabase(db *gorm.DB) func(ctx context.Context) (*gorm.DB, error) {
|
||||
var (
|
||||
migrateOnce sync.Once
|
||||
|
Reference in New Issue
Block a user