follow sql schema
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
package auth
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
|
||||
"mediarr/database"
|
||||
"mediarr/identity"
|
||||
)
|
||||
|
||||
type Service struct {
|
||||
db database.DatabaseClient
|
||||
identity *identity.Service
|
||||
}
|
||||
|
||||
func NewService(db database.DatabaseClient) *Service {
|
||||
return &Service{
|
||||
db: db,
|
||||
identity: identity.NewService(db),
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Service) withTx(ctx context.Context, fn func(*database.Queries) error) error {
|
||||
tx, err := s.db.WriteDB.BeginTx(ctx, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer func() {
|
||||
_ = tx.Rollback()
|
||||
}()
|
||||
|
||||
if err := fn(s.db.WriteQueries.WithTx(tx)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return tx.Commit()
|
||||
}
|
||||
|
||||
func isUniqueViolation(err error) bool {
|
||||
return err != nil && strings.Contains(strings.ToLower(err.Error()), "unique constraint failed")
|
||||
}
|
||||
Reference in New Issue
Block a user