mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-23 16:20:29 +00:00
not that bad anymore
This commit is contained in:
7
backend/storage/cache/gomap/map.go
vendored
7
backend/storage/cache/gomap/map.go
vendored
@@ -11,6 +11,13 @@ type Map[K comparable, V any] struct {
|
||||
items map[K]V
|
||||
}
|
||||
|
||||
func New[K comparable, V any]() *Map[K, V] {
|
||||
return &Map[K, V]{
|
||||
items: make(map[K]V),
|
||||
mu: sync.RWMutex{},
|
||||
}
|
||||
}
|
||||
|
||||
// Clear implements cache.Cache.
|
||||
func (m *Map[K, V]) Clear() {
|
||||
m.mu.Lock()
|
||||
|
67
backend/storage/database/mock/transaction.go
Normal file
67
backend/storage/database/mock/transaction.go
Normal file
@@ -0,0 +1,67 @@
|
||||
package mock
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"github.com/zitadel/zitadel/backend/storage/database"
|
||||
)
|
||||
|
||||
type Transaction struct {
|
||||
committed bool
|
||||
rolledBack bool
|
||||
}
|
||||
|
||||
func NewTransaction() *Transaction {
|
||||
return new(Transaction)
|
||||
}
|
||||
|
||||
// Commit implements [database.Transaction].
|
||||
func (t *Transaction) Commit(ctx context.Context) error {
|
||||
if t.hasEnded() {
|
||||
return errors.New("transaction already committed or rolled back")
|
||||
}
|
||||
t.committed = true
|
||||
return nil
|
||||
}
|
||||
|
||||
// End implements [database.Transaction].
|
||||
func (t *Transaction) End(ctx context.Context, err error) error {
|
||||
if t.hasEnded() {
|
||||
return errors.New("transaction already committed or rolled back")
|
||||
}
|
||||
if err != nil {
|
||||
return t.Rollback(ctx)
|
||||
}
|
||||
return t.Commit(ctx)
|
||||
}
|
||||
|
||||
// Exec implements [database.Transaction].
|
||||
func (t *Transaction) Exec(ctx context.Context, sql string, args ...any) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Query implements [database.Transaction].
|
||||
func (t *Transaction) Query(ctx context.Context, sql string, args ...any) (database.Rows, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// QueryRow implements [database.Transaction].
|
||||
func (t *Transaction) QueryRow(ctx context.Context, sql string, args ...any) database.Row {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Rollback implements [database.Transaction].
|
||||
func (t *Transaction) Rollback(ctx context.Context) error {
|
||||
if t.hasEnded() {
|
||||
return errors.New("transaction already committed or rolled back")
|
||||
}
|
||||
t.rolledBack = true
|
||||
return nil
|
||||
}
|
||||
|
||||
var _ database.Transaction = (*Transaction)(nil)
|
||||
|
||||
func (t *Transaction) hasEnded() bool {
|
||||
return t.committed || t.rolledBack
|
||||
}
|
Reference in New Issue
Block a user