{"modulePath":"github.com/kernelplex/evercore","version":"v0.0.43","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package evercore\n\n## Constants\n\n```go\nconst (\n\tStartBeginning = \"beginning\"\n\tStartEnd       = \"end\"\n\tStartEventID   = \"event_id\"\n\tStartTimestamp = \"timestamp\"\n)\n```\nStartFromKind identifies how a subscription initializes its cursor.\n\n```go\nconst (\n\tErrorNotFound                = \"not_found\"\n\tErrorTypeConstraintViolation = \"constraint_violation\"\n)\n```\nCommon storage engine error types\n\n## Variables\n\n```go\nvar ErrEventStateIsNotAStateEvent = ErrorMessage(\"Event state is not a StateEvent.\")\n```\n\n```go\nvar ErrSubscriptionAlreadyOwned = errors.New(\"subscription already owned\")\n```\nErrSubscriptionAlreadyOwned indicates the subscription could not be claimed because another owner currently holds the lease.\n\n```go\nvar ErrorKeyExceedsMaximumLength error = fmt.Errorf(\"The specified key exceeds the maximum key length\")\n```\n\n## Functions\n\n```go\nfunc CopyFields(e, t any) error\n```\nCopyFields uses reflection to copy matching fields from e to t. If a pointer field in e is nil, the field is skipped.\n\n```go\nfunc DecodeEventStateTo[U any](e SerializedEvent, state *U) error\n```\nDecodes the event state into the specified type.\n\n```go\nfunc DeserializeFromJson[T any](serialized string, target *T) error\n```\n\n```go\nfunc InContext[T any](ctx context.Context, store *EventStore, exec contextFuncReturns[T]) (T, error)\n```\nExecutes a function callback that returns a value after the context complets.  This is the similar to the EventStore.Incontext method except it allows a return value after completion.\n\n```go\nfunc InReadonlyContext[T any](ctx context.Context, store *EventStore, exec readonlyContextFuncReturns[T]) (T, error)\n```\nExecutes a function within a readonly context returning a value.\n\n```go\nfunc RegisterEventDecoder(decoders ...EventDecoder)\n```\nRegisterEventDecoder sets the EventDecoder for StateAggregate - the function should be able to decode all events for any aggregate using StateAggregate.\n\n```go\nfunc SerializeToJson(ev any) string\n```\n\n```go\nfunc TypeNameFromType[T any](ev T) string\n```\n\n## Types\n\n```go\ntype Aggregate interface {\n\tGetId() int64\n\tSetId(int64)\n\tGetSequence() int64\n\tSetSequence(int64)\n\tGetAggregateType() string\n\tGetSnapshotFrequency() int64\n\tGetSnapshotState() (*string, error)\n\tApplyEventState(eventState EventState, eventTime time.Time, reference string) error\n\tApplySnapshot(snapshot *Snapshot) error\n}\n```\nOptinionated version of aggregate\n\n```go\ntype AggregateState struct {\n\tAggregateId int64\n\tNaturalKey  *string\n\tSnapshot    *Snapshot\n\tEvents      EventSlice\n}\n```\nRepresents the state of the aggregate including the latest snapshot (if it exists) and the events required to reconstitute its current state.\n\n```go\ntype ApplyFunc func(eventState EventState, eventTime time.Time, reference string) error\n```\n\n```go\ntype ContextOwner interface {\n\t// contains filtered or unexported methods\n}\n```\nMethods for the EventStoreContext uses.\n\n```go\ntype ErrorMessage string\n```\n\n```go\nfunc (e ErrorMessage) Error() string\n```\n\n```go\ntype EventDecoder func(ev SerializedEvent) (EventState, error)\n```\nEventDecoder is a function that decodes an event into an EventState.\n\n```go\ntype EventSlice []SerializedEvent\n```\nSlice of serialized events.\n\n```go\ntype EventState interface {\n\tGetEventType() string\n\tSerialize() string\n}\n```\nEventState represents the state of an event.\n\n```go\nfunc DecodeEvent(ev SerializedEvent) (bool, EventState, error)\n```\nDecodeEventStateTo decodes an event into an EventState.\n\n```go\ntype EventStore struct {\n\t// contains filtered or unexported fields\n}\n```\nEventStore is the main entry point for interacting with the event store.\n\n```go\nfunc NewEventStore(storageEngine StorageEngine) *EventStore\n```\n\n```go\nfunc (store *EventStore) Close() error\n```\nCloses the storage engine.\n\n```go\nfunc (store *EventStore) RunEphemeralSubscription(\n\tctx context.Context,\n\tfilter SubscriptionFilter,\n\tstart StartFrom,\n\topts Options,\n\thandler func(context.Context, []SerializedEvent) error,\n) error\n```\nRunEphemeralSubscription streams events without creating any persisted subscription metadata or cursor. The position is tracked in-process only and is lost when the caller exits. Useful for local caches, projections that can rebuild, etc.\n\nSupports:\n\n  - AggregateType (optional)\n  - AggregateKey (optional)\n  - EventTypes: if multiple are provided, filtering is applied in-memory. For a single event type, filtering happens in the storage engine query.\n\n```go\nfunc (store *EventStore) RunSubscription(\n\tctx context.Context,\n\tname string,\n\tfilter SubscriptionFilter,\n\tstart StartFrom,\n\topts Options,\n\thandler func(context.Context, []SerializedEvent) error,\n) error\n```\nRunSubscription ensures a durable subscription exists, claims a lease, and processes events using handler with at-least-once semantics.\n\n```go\nfunc (store *EventStore) SaveState(ctx context.Context, tx StorageEngineTxInfo, events EventSlice, snapshots SnapshotSlice) error\n```\nThis is used at the end of a context to save all the events and snapshots that happened during the context.\n\n```go\nfunc (store *EventStore) Warmup(ctx context.Context, knownAggregateTypes []string, knownEventTypes []string) error\n```\nWarmup pre-loads aggregate and event types into memory to avoid database calls during contexts. This is intended to be called during application startup.\n\nParameters:\n\n  - knownAggregateTypes: List of aggregate type names to pre-load\n  - knownEventTypes: List of event type names to pre-load\n\nThis memoizes the type IDs in an internal map, saving database calls during normal operation. Should be called as early as possible in application startup.\n\n```go\nfunc (store *EventStore) WithContext(ctx context.Context, exec contextFunc) error\n```\nExecutes a function inside a context This is used to ensure the all events and snapshots are written after the context completes or that they are not written when an error happens.\n\n```go\nfunc (store *EventStore) WithReadonlyContext(ctx context.Context, exec readonlyContextFunc) error\n```\nExecutes a callback function within a readonly context\n\n```go\ntype EventStoreContext interface {\n\tEventStoreReadonlyContext\n\tNewAggregateId(aggregateType string) (int64, error)\n\tNewAggregateIdWithKey(aggregateType string, naturalKey string) (int64, error)\n\n\tLoadOrCreateAggregate(agg Aggregate, naturalKey string) (bool, error)\n\tCreateAggregateInto(agg Aggregate) error\n\tCreateAggregateWithKeyInto(agg Aggregate, naturalKey string) error\n\tChangeAggregateNaturalKey(id int64, naturalKey string) error\n\tApplyEventTo(agg Aggregate, event EventState, time time.Time, reference string) error\n\n\tPublish(*SerializedEvent)\n\tSaveSnapshot(snapshot Snapshot)\n}\n```\nRepresents a read/write context access to the event store.\n\n```go\ntype EventStoreContextType struct {\n\tTransaction StorageEngineTxInfo\n\t// contains filtered or unexported fields\n}\n```\nTracks information related to the current event store context.\n\n```go\nfunc (etx *EventStoreContextType) ApplyEventTo(\n\tagg Aggregate,\n\teventState EventState,\n\ttime time.Time,\n\treference string) error\n```\nApplies an event to the aggregate.\n\n```go\nfunc (etx *EventStoreContextType) ChangeAggregateNaturalKey(\n\tid int64,\n\tnaturalKey string) error\n```\nChanges the natural key of an aggregate.\n\n```go\nfunc (etx *EventStoreContextType) CreateAggregateInto(agg Aggregate) error\n```\nCreates a new aggregate of the specified type.\n\n```go\nfunc (etx *EventStoreContextType) CreateAggregateWithKeyInto(\n\tagg Aggregate,\n\tnaturalKey string) error\n```\nCreates a new aggregate of the specified type with the specified natural key.\n\n```go\nfunc (ctx *EventStoreContextType) LoadAggregateState(\n\taggregateType string,\n\taggregateId int64) (*AggregateState, error)\n```\nLoads the most recent snapshot and events from the event store\n\n```go\nfunc (ctx *EventStoreContextType) LoadAggregateStateByKey(\n\taggregateType string,\n\tnaturalKey string) (*AggregateState, error)\n```\nLoads the aggregate state using the natural key.\n\n```go\nfunc (etx *EventStoreContextType) LoadOrCreateAggregate(\n\tagg Aggregate,\n\tnaturalKey string) (bool, error)\n```\nLoadOrCreateAggregate loads an existing aggregate by natural key if it exists, otherwise creates a new one. Returns true if the aggregate was created, false if loaded.\n\n```go\nfunc (etx *EventStoreContextType) LoadStateByKeyInto(\n\tagg Aggregate,\n\tnaturalKey string) error\n```\nLoads the state of an aggregate into the aggregate using the natural key.\n\n```go\nfunc (etx *EventStoreContextType) LoadStateInto(\n\tagg Aggregate,\n\taggregateId int64) error\n```\nLoads the state of an aggregate into the aggregate.\n\n```go\nfunc (ctx EventStoreContextType) NewAggregateId(aggregateType string) (int64, error)\n```\nAdds a new aggregate stream and returns the resulting id.\n\n```go\nfunc (ctx EventStoreContextType) NewAggregateIdWithKey(\n\taggregateType string,\n\tnaturalKey string) (int64, error)\n```\nAdds a new aggregate stream with the specified natural key and returns the resulting id.\n\n```go\nfunc (ctx *EventStoreContextType) Publish(event *SerializedEvent)\n```\nPublishes an event for storage once the context completes.\n\n```go\nfunc (etx *EventStoreContextType) SaveSnapshot(snapshot Snapshot)\n```\nStages a snapshot to save once the context completes.\n\n```go\ntype EventStoreReadonlyContext interface {\n\tLoadStateInto(aggregate Aggregate, id int64) error\n\tLoadStateByKeyInto(aggregate Aggregate, naturalKey string) error\n\n\tLoadAggregateState(aggregateType string, aggregateId int64) (*AggregateState, error)\n\tLoadAggregateStateByKey(aggregateType string, naturalKey string) (*AggregateState, error)\n}\n```\nRepresents a readonly context access to the event store.\n\n```go\ntype IdNameMap map[int64]string\n```\nRepresents a map of id to name.\n\n```go\nfunc MapIdToName(idNamePair []IdNamePair) IdNameMap\n```\nMaps a slice of IdNamePair to a map of id to name.\n\n```go\ntype IdNamePair struct {\n\tId   int64\n\tName string\n}\n```\nRepresents a pair of id and name.\n\n```go\ntype MemoryStorageEngine struct {\n\tCapturedEvents    []StorageEngineEvent\n\tCapturedSnapshots []Snapshot\n\n\tAggregateTypes     map[string]int64\n\tAggregateTypesInv  map[int64]string\n\tEventTypes         map[string]int64\n\tEventTypesInv      map[int64]string\n\tCountAggregateType int64\n\tCountEventTypes    int64\n\tCountAggregates    int64\n\tAggregateToTypeId  map[int64]int64\n\tAggregates         map[string]int64\n\tAggregateInv       map[int64]*string\n\n\t// Subscriptions (in-memory only)\n\tSubscriptions          map[string]*Subscription\n\tSubscriptionByID       map[int64]*Subscription\n\tSubscriptionEventTypes map[int64]map[int64]bool // subscriptionID -\u003e set(eventTypeID)\n\tNextSubscriptionID     int64\n}\n```\nEphemeral memory storage engine useful for testing without a database.\n\n```go\nfunc NewMemoryStorageEngine() *MemoryStorageEngine\n```\nNewMemoryStorageEngine creates a new in-memory storage engine.\n\n```go\nfunc (store *MemoryStorageEngine) AddSubscriptionEventType(tx StorageEngineTxInfo, ctx context.Context, subscriptionId int64, eventTypeId int64) error\n```\n\n```go\nfunc (store *MemoryStorageEngine) AdvanceSubscriptionCursor(tx StorageEngineTxInfo, ctx context.Context, id int64, lastEventId int64) error\n```\n\n```go\nfunc (store *MemoryStorageEngine) ChangeAggregateNaturalKey(tx StorageEngineTxInfo, ctx context.Context, aggregateId int64, naturalKey string) error\n```\n\n```go\nfunc (store *MemoryStorageEngine) ClaimSubscription(tx StorageEngineTxInfo, ctx context.Context, name string, owner string, lease time.Duration) (bool, error)\n```\n\n```go\nfunc (store *MemoryStorageEngine) Close() error\n```\n\n```go\nfunc (store *MemoryStorageEngine) GetAggregateById(tx StorageEngineTxInfo, ctx context.Context, aggregateTypeId int64, aggregateId int64) (int64, *string, error)\n```\n\n```go\nfunc (store *MemoryStorageEngine) GetAggregateByKey(tx StorageEngineTxInfo, ctx context.Context, aggregateTypeId int64, naturalKey string) (int64, error)\n```\n\n```go\nfunc (store *MemoryStorageEngine) GetAggregateTypeId(tx StorageEngineTxInfo, ctx context.Context, name string) (int64, error)\n```\n\n```go\nfunc (store *MemoryStorageEngine) GetAggregateTypes(tx StorageEngineTxInfo, ctx context.Context) ([]IdNamePair, error)\n```\n\n```go\nfunc (store *MemoryStorageEngine) GetEventTypeId(tx StorageEngineTxInfo, ctx context.Context, name string) (int64, error)\n```\n\n```go\nfunc (store *MemoryStorageEngine) GetEventTypes(tx StorageEngineTxInfo, ctx context.Context) ([]IdNamePair, error)\n```\n\n```go\nfunc (store *MemoryStorageEngine) GetEventsForAggregate(tx StorageEngineTxInfo, ctx context.Context, aggregateId int64, afterSequence int64) ([]SerializedEvent, error)\n```\n\n```go\nfunc (store *MemoryStorageEngine) GetEventsForSubscription(tx StorageEngineTxInfo, ctx context.Context, sub *Subscription, limit int) ([]SerializedEvent, error)\n```\n\n```go\nfunc (store *MemoryStorageEngine) GetFirstEventIdFromTimestamp(tx StorageEngineTxInfo, ctx context.Context, ts time.Time) (int64, error)\n```\n\n```go\nfunc (store *MemoryStorageEngine) GetMaxEventId(tx StorageEngineTxInfo, ctx context.Context) (int64, error)\n```\n\n```go\nfunc (stor *MemoryStorageEngine) GetMaxKeyLength() int\n```\n\n```go\nfunc (store *MemoryStorageEngine) GetOrCreateAggregateByKey(tx StorageEngineTxInfo, ctx context.Context, aggregateTypeId int64, naturalKey string) (bool, int64, error)\n```\n\n```go\nfunc (store *MemoryStorageEngine) GetSnapshotForAggregate(tx StorageEngineTxInfo, ctx context.Context, aggregateId int64) (*Snapshot, error)\n```\n\n```go\nfunc (store *MemoryStorageEngine) GetSubscriptionByName(tx StorageEngineTxInfo, ctx context.Context, name string) (*Subscription, error)\n```\n\n```go\nfunc (stor *MemoryStorageEngine) GetTransactionInfo() (StorageEngineTxInfo, error)\n```\n\n```go\nfunc (store *MemoryStorageEngine) NewAggregate(tx StorageEngineTxInfo, ctx context.Context, aggregateTypeId int64) (int64, error)\n```\n\n```go\nfunc (store *MemoryStorageEngine) NewAggregateWithKey(tx StorageEngineTxInfo, ctx context.Context, aggregateTypeId int64, naturalKey string) (int64, error)\n```\n\n```go\nfunc (store *MemoryStorageEngine) ReleaseSubscription(tx StorageEngineTxInfo, ctx context.Context, name string, owner string) error\n```\n\n```go\nfunc (store *MemoryStorageEngine) RenewSubscription(tx StorageEngineTxInfo, ctx context.Context, name string, owner string, lease time.Duration) (bool, error)\n```\n\n```go\nfunc (store *MemoryStorageEngine) SetSubscriptionActive(tx StorageEngineTxInfo, ctx context.Context, id int64, active bool) error\n```\n\n```go\nfunc (store *MemoryStorageEngine) UpsertSubscription(tx StorageEngineTxInfo, ctx context.Context, name string, aggregateTypeId *int64, eventTypeId *int64, aggregateKey *string, startFrom string, startEventId int64, startTimestamp *time.Time) (int64, error)\n```\n\n```go\nfunc (store *MemoryStorageEngine) WriteState(tx StorageEngineTxInfo, ctx context.Context, events []StorageEngineEvent, snapshot SnapshotSlice) error\n```\n\n```go\ntype MemoryStorageEngineTransaction struct {\n}\n```\nMemoryStorageEngineTransaction is a transaction for the in-memory storage engine.\n\n```go\nfunc (tx MemoryStorageEngineTransaction) Commit() error\n```\n\n```go\nfunc (tx MemoryStorageEngineTransaction) Rollback() error\n```\n\n```go\ntype NameIdMap map[string]int64\n```\nRepresents a map of name to id.\n\n```go\nfunc MapNameToId(idNamePair []IdNamePair) NameIdMap\n```\nMaps a slice of IdNamePair to a map of name to id.\n\n```go\ntype Options struct {\n\tBatchSize    int\n\tPollInterval time.Duration\n\tLease        time.Duration\n\tOwner        string // optional; autogenerated if empty\n}\n```\nOptions controls runtime behavior of a subscription runner.\n\n```go\ntype SerializedEvent struct {\n\t// EventID is the global, monotonically increasing id from the events table.\n\t// It may be zero when events are loaded by-aggregate (not via event_log).\n\tEventID     int64\n\tAggregateId int64\n\tEventType   string\n\tState       string\n\tSequence    int64\n\tReference   string\n\tEventTime   time.Time\n}\n```\nRepresents an event to be published with the state serialized.\n\n```go\ntype Snapshot struct {\n\tAggregateId int64\n\tState       string\n\tSequence    int64\n}\n```\nRepresents a snapshot of an aggregate.\n\n```go\ntype SnapshotSlice []Snapshot\n```\nSlice of snapshots.\n\n```go\ntype StartFrom struct {\n\tKind      string\n\tEventID   int64\n\tTimestamp time.Time\n}\n```\nStartFrom specifies where to start a subscription from.\n\n```go\ntype StateAggregate[T any] struct {\n\tId       int64\n\tState    T\n\tSequence int64\n\t// contains filtered or unexported fields\n}\n```\nStateAggregate can be used for aggregates that contain simple state. It provides common aggregate functionality and handles state management.\n\nHandleOtherEvents is an optional function that can be set to handle events that don't implement iStateEvent. When an event is applied that isn't a StateEvent, this function will be called if set. If not set, such events will return ErrEventStateIsNotAStateEvent.\n\nExample usage:\n\n\taggregate.HandleOtherEvents = func(eventState EventState, eventTime time.Time, reference string) error {\n\t    switch event := eventState.(type) {\n\t    case SetActiveEvent:\n\t        aggregate.State.Active = event.Active\n\t        return nil\n\t    default:\n\t        return fmt.Errorf(\"unknown event type %s\", event.GetEventType())\n\t    }\n\t}\n\n```go\nfunc (t *StateAggregate[T]) ApplyEventState(eventState EventState, eventTime time.Time, reference string) error\n```\nApplyEventState applies an event state to the aggregate\n\n```go\nfunc (t *StateAggregate[T]) ApplySnapshot(snapshot *Snapshot) error\n```\nApplySnapshot applies a snapshot to the aggregate\n\n```go\nfunc (t *StateAggregate[T]) DecodeEvent(ev SerializedEvent) (EventState, error)\n```\n\n```go\nfunc (t *StateAggregate[T]) GetAggregateType() string\n```\nGetAggregateType gets the aggregate type\n\n```go\nfunc (t *StateAggregate[T]) GetId() int64\n```\nGetId gets the aggregate id\n\n```go\nfunc (t *StateAggregate[T]) GetSequence() int64\n```\nImplement Aggregate interface for StateAggregate\n\n```go\nfunc (t *StateAggregate[T]) GetSnapshotFrequency() int64\n```\nGetSnapshotFrequency gets the snapshot frequency\n\n```go\nfunc (t *StateAggregate[T]) GetSnapshotState() (*string, error)\n```\nGetSnapshotState gets the snapshot state\n\n```go\nfunc (t *StateAggregate[T]) SetId(id int64)\n```\nSetId sets the aggregate id\n\n```go\nfunc (t *StateAggregate[T]) SetSequence(seq int64)\n```\nSetSequence sets the aggregate sequence\n\n```go\ntype StateEvent[T any] struct {\n\tState T\n}\n```\n\n```go\nfunc NewStateEvent[T any](state T) StateEvent[T]\n```\n\n```go\nfunc (ev *StateEvent[T]) Deserialize(serialized string) error\n```\n\n```go\nfunc (ev StateEvent[T]) GetEventType() string\n```\n\n```go\nfunc (ev StateEvent[T]) GetState() any\n```\n\n```go\nfunc (ev StateEvent[T]) Serialize() string\n```\n\n```go\ntype StorageEngine interface {\n\n\t// Gets the maximum length of a natural key\n\tGetMaxKeyLength() int\n\n\t// Gets the id for the event type string.  It is added if it does not already exist.\n\tGetEventTypeId(tx StorageEngineTxInfo, ctx context.Context, typeName string) (int64, error)\n\n\t// Gets the id for the aggregate type string.  It is added if it does not already exist.\n\tGetAggregateTypeId(tx StorageEngineTxInfo, ctx context.Context, typeName string) (int64, error)\n\n\t// Adds a new aggregate of the specified type to the store and returns the id.\n\tNewAggregate(tx StorageEngineTxInfo, ctx context.Context, aggregateTypeId int64) (int64, error)\n\n\t// Adds a new aggregate of the specified type with the natural key to the store and returns the id.\n\tNewAggregateWithKey(tx StorageEngineTxInfo, ctx context.Context, aggregateTypeId int64, natrualKey string) (int64, error)\n\n\t// Gets aggregate id and corresponding natural key that corresponds to the type and id.\n\tGetAggregateById(tx StorageEngineTxInfo, ctx context.Context, aggregateTypeId int64, aggregateId int64) (int64, *string, error)\n\n\t// Gets the aggregate id corresponding to the type and natural key.\n\tGetAggregateByKey(tx StorageEngineTxInfo, ctx context.Context, aggregateTypeId int64, naturalKey string) (int64, error)\n\n\t// Gets or creates an aggregate id for the given type and natural key.\n\t// If an aggregate with the given natural key already exists, returns false and its id.\n\t// Otherwise creates a new aggregate with the key and returns true and its new id.\n\t// Returns error if:\n\t// - The natural key exceeds maximum length (ErrorKeyExceedsMaximumLength)\n\t// - The aggregate type doesn't exist\n\t// - There are database errors\n\tGetOrCreateAggregateByKey(tx StorageEngineTxInfo, ctx context.Context, aggregateTypeId int64, naturalKey string) (bool, int64, error)\n\n\t// Changes the natural key of an aggregate.\n\tChangeAggregateNaturalKey(tx StorageEngineTxInfo, ctx context.Context, aggregateId int64, naturalKey string) error\n\n\t// Loads all the aggregate types.\n\tGetAggregateTypes(tx StorageEngineTxInfo, ctx context.Context) ([]IdNamePair, error)\n\n\t// Loads all the event types.\n\tGetEventTypes(tx StorageEngineTxInfo, ctx context.Context) ([]IdNamePair, error)\n\n\t// Gets a snapshot (if any) for the specified aggregate.\n\tGetSnapshotForAggregate(tx StorageEngineTxInfo, ctx context.Context, aggregateId int64) (*Snapshot, error)\n\n\t// Retrieve events for an aggregate which are after a sequence.\n\tGetEventsForAggregate(tx StorageEngineTxInfo, ctx context.Context, aggregateId int64, afterSequence int64) ([]SerializedEvent, error)\n\n\t// Writes events to storage.\n\tWriteState(tx StorageEngineTxInfo, ctx context.Context, events []StorageEngineEvent, snapshot SnapshotSlice) error\n\n\t// Gets a transaction state to track multiple\n\tGetTransactionInfo() (StorageEngineTxInfo, error)\n\n\t// Closes the storage engine.\n\tClose() error\n\n\t// -------- Durable Subscriptions --------\n\t// Create or update a subscription by name. If updating, last_event_id is not modified.\n\tUpsertSubscription(tx StorageEngineTxInfo, ctx context.Context, name string, aggregateTypeId *int64, eventTypeId *int64, aggregateKey *string, startFrom string, startEventId int64, startTimestamp *time.Time) (int64, error)\n\t// Optionally associate multiple event types to a subscription (enables multi-type filtering).\n\tAddSubscriptionEventType(tx StorageEngineTxInfo, ctx context.Context, subscriptionId int64, eventTypeId int64) error\n\t// Fetch a subscription by name.\n\tGetSubscriptionByName(tx StorageEngineTxInfo, ctx context.Context, name string) (*Subscription, error)\n\t// Activate/deactivate a subscription.\n\tSetSubscriptionActive(tx StorageEngineTxInfo, ctx context.Context, id int64, active bool) error\n\n\t// Cooperative lease management for distributed runners.\n\tClaimSubscription(tx StorageEngineTxInfo, ctx context.Context, name string, owner string, lease time.Duration) (bool, error)\n\tRenewSubscription(tx StorageEngineTxInfo, ctx context.Context, name string, owner string, lease time.Duration) (bool, error)\n\tReleaseSubscription(tx StorageEngineTxInfo, ctx context.Context, name string, owner string) error\n\n\t// Event streaming for a subscription and cursor advancement.\n\tGetEventsForSubscription(tx StorageEngineTxInfo, ctx context.Context, sub *Subscription, limit int) ([]SerializedEvent, error)\n\tAdvanceSubscriptionCursor(tx StorageEngineTxInfo, ctx context.Context, id int64, lastEventId int64) error\n\n\t// Helpers for initializing cursors.\n\tGetMaxEventId(tx StorageEngineTxInfo, ctx context.Context) (int64, error)\n\tGetFirstEventIdFromTimestamp(tx StorageEngineTxInfo, ctx context.Context, ts time.Time) (int64, error)\n}\n```\nA storage engine contains the raw methods for interacting with the event store database.\n\nThe storage engine implementations should implemented to be safe for calling from multiple goroutines simultaneously.\n\n```go\ntype StorageEngineError struct {\n\t// The underlying error that triggered this error\n\tErr error\n\t// A human-readable message describing the error\n\tMessage string\n\t// The type of error that occurred\n\tErrorType string\n}\n```\nStorageEngineError represents an error from the storage engine.\n\n```go\nfunc NewStorageEngineError(message string, err error) *StorageEngineError\n```\nNewStorageEngineError creates a new StorageEngineError.\n\n```go\nfunc (e *StorageEngineError) Error() string\n```\nError returns the string representation of the error.\n\n```go\nfunc (e *StorageEngineError) Unwrap() error\n```\nUnwrap returns the underlying error.\n\n```go\ntype StorageEngineEvent struct {\n\tAggregateID int64\n\tSequence    int64\n\tEventTypeID int64\n\tState       string\n\tEventTime   time.Time\n\tReference   string\n}\n```\nRepresents an event mapping to the storage engine.\n\n```go\ntype StorageEngineTxInfo interface {\n\tCommit() error\n\tRollback() error\n}\n```\nInterface represents transaction info needed to track the transaction.\n\n```go\ntype Subscription struct {\n\tID              int64\n\tName            string\n\tAggregateTypeID *int64\n\tEventTypeID     *int64\n\tAggregateKey    *string\n\tStartFrom       string\n\tStartEventID    int64\n\tStartTimestamp  *time.Time\n\tLastEventID     int64\n\tActive          bool\n\tLeaseOwner      *string\n\tLeaseExpiresAt  *time.Time\n}\n```\nSubscription describes a durable reader over the event log with optional filters and a durable cursor stored as last\\_event\\_id.\n\n```go\ntype SubscriptionFilter struct {\n\tAggregateType string   // optional; empty means all aggregates\n\tEventTypes    []string // optional; empty means all event types\n\tAggregateKey  *string  // optional\n}\n```\nSubscriptionFilter controls which events are read by a subscription.\n\n","path":"github.com/kernelplex/evercore/base","name":"evercore","synopsis":"","isRedistributable":true}
