refactor(v2): init events (#7823)

creates events structures for initial projections and read models
This commit is contained in:
Silvan
2024-05-23 06:36:08 +02:00
committed by GitHub
parent f37113194d
commit 12be21a3ff
56 changed files with 1952 additions and 316 deletions

View File

@@ -3,6 +3,7 @@ package postgres
import (
"context"
"database/sql"
"encoding/json"
"slices"
"github.com/zitadel/logging"
@@ -38,7 +39,7 @@ func executeQuery(ctx context.Context, tx database.Querier, stmt *database.State
}
err = database.MapRowsToObject(rows, func(scan func(dest ...any) error) error {
e := new(eventstore.Event[eventstore.StoragePayload])
e := new(eventstore.StorageEvent)
var payload sql.Null[[]byte]
@@ -59,7 +60,12 @@ func executeQuery(ctx context.Context, tx database.Querier, stmt *database.State
if err != nil {
return err
}
e.Payload = unmarshalPayload(payload.V)
e.Payload = func(ptr any) error {
if len(payload.V) == 0 {
return nil
}
return json.Unmarshal(payload.V, ptr)
}
eventCount++
return reducer.Reduce(e)