Docs / ArchitectureKit / Fundamentals / Creating a Store

Creating a Store

A store is how ArchitectureKit reads from and writes to EventSourcingDB. The functions that read or write events, such as Execute, Load, Read, and those that run projections, take it as an argument.

Import the package, create an EventSourcingDB client, and create a store by providing the client and the source to use for all events you write:

import (
  "net/url"

  "github.com/thenativeweb/architecturekit-golang/architecturekit"
  "github.com/thenativeweb/eventsourcingdb-client-golang/eventsourcingdb"
)

// ...

baseURL, err := url.Parse("http://localhost:3000")
if err != nil {
  // ...
}

apiToken := "secret"

client, err := eventsourcingdb.NewClient(baseURL, apiToken)
if err != nil {
  // ...
}

store := architecturekit.NewStore(client, "https://library.eventsourcingdb.io")

The NewStore function returns a *Store, which reads and writes the events of all commands. For details on the client, see the client SDK for Go.

Note that calling NewStore with nil as the client, or as one of the options, panics.

Choosing the Source#

The second argument of NewStore is the source for all events you write. Every event in EventSourcingDB has one, and it identifies the system that produced the event, such as https://library.eventsourcingdb.io. It must be a URI reference, such as a URL or a tag URI, and it does not affect how events are processed (see Sources).

Configuring the Store#

NewStore takes options after the source. They configure the new store before it exists, so they can not change a store that is in use. There are these options:

  • WithConflictRetries has Execute decide again on a conflict, up to the given number of times (see Guarding Against Concurrent Changes).
  • WithStateCache keeps the states of the most recently used subjects in memory (see Caching States).
  • WithReconnectDelays sets how long running projections wait before they read again after reading failed or the stream ended (see Running Projections).
  • WithReconnectObserver calls a function every time a running projection is about to wait before reading again, for example to log it (see Running Projections).
  • WithSignatureVerification checks the signature of every event the store reads, besides its hash (see Verifying Events).
  • WithoutHashVerification turns off checking the hash of every event the store reads, which the store does unless told otherwise (see Verifying Events).

Note that WithoutHashVerification can not be combined with WithSignatureVerification, since checking a signature includes checking the hash, so NewStore panics if it gets both.