not that bad anymore

This commit is contained in:
adlerhurst
2025-03-15 11:29:11 +01:00
parent bc6b1d3fcf
commit fa02beb883
22 changed files with 466 additions and 383 deletions

View File

@@ -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()

View 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
}