mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-12 06:07:33 +00:00
24 lines
594 B
Go
24 lines
594 B
Go
![]() |
package eventstore
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
|
||
|
"github.com/zitadel/zitadel/backend/v3/storage/database"
|
||
|
)
|
||
|
|
||
|
type Event struct {
|
||
|
AggregateType string `json:"aggregateType"`
|
||
|
AggregateID string `json:"aggregateId"`
|
||
|
Type string `json:"type"`
|
||
|
Payload any `json:"payload,omitempty"`
|
||
|
}
|
||
|
|
||
|
func Publish(ctx context.Context, events []*Event, db database.Executor) error {
|
||
|
for _, event := range events {
|
||
|
if err := db.Exec(ctx, `INSERT INTO events (aggregate_type, aggregate_id) VALUES ($1, $2)`, event.AggregateType, event.AggregateID); err != nil {
|
||
|
return err
|
||
|
}
|
||
|
}
|
||
|
return nil
|
||
|
}
|