Giter Site home page Giter Site logo

Comments (5)

slashdotdash avatar slashdotdash commented on April 28, 2024 1

@sunny-g You could use the existing in-memory adapter as a basis for an mnesia event store. That should give you an foundation to build on.

The behaviour you need to implement is given below:

defmodule Commanded.EventStore do
  @type stream_uuid :: String.t
  @type start_from :: :origin | :current | integer
  @type stream_version :: integer
  @type subscription_name :: String.t
  @type source_uuid :: String.t
  @type snapshot :: SnapshotData.t
  @type reason :: term

  @doc """
  Append one or more events to a stream atomically.
  """
  @callback append_to_stream(stream_uuid, expected_version :: non_neg_integer, events :: list(EventData.t)) :: {:ok, stream_version} | {:error, reason}

  @doc """
  Streams events from the given stream, in the order in which they were originally written.
  """
  @callback stream_forward(stream_uuid, start_version :: non_neg_integer, read_batch_size :: non_neg_integer) :: Enumerable.t | {:error, :stream_not_found} | {:error, reason}

  @doc """
  Subscriber will be notified of every event persisted to any stream.
  """
  @callback subscribe_to_all_streams(subscription_name, subscriber :: pid, start_from) :: {:ok, subscription :: pid}
    | {:error, :subscription_already_exists}
    | {:error, reason}

  @doc """
  Acknowledge receipt and successful processing of the given event received from a subscription to an event stream.
  """
  @callback ack_event(pid, RecordedEvent.t) :: any

  @doc """
  Unsubscribe an existing subscriber from all event notifications.
  """
  @callback unsubscribe_from_all_streams(subscription_name) :: :ok

  @doc """
  Read a snapshot, if available, for a given source.
  """
  @callback read_snapshot(source_uuid) :: {:ok, snapshot} | {:error, :snapshot_not_found}

  @doc """
  Record a snapshot of the data and metadata for a given source
  """
  @callback record_snapshot(snapshot) :: :ok | {:error, reason}

  @doc """
  Delete a previously recorded snapshop for a given source
  """
  @callback delete_snapshot(source_uuid) :: :ok | {:error, reason}
end

from commanded.

slashdotdash avatar slashdotdash commented on April 28, 2024 1

@sunny-g There are a number of event store adapter tests included in Commanded that you can use to verify your mnesia event store, if you decide to build one.

  1. Configure Commanded as a dependency (no runtime) in mix.exs:
defp deps do
  [
    {:commanded, "~> 0.10", runtime: false},
  ]
end
  1. Fetch & compile deps:
$ mix do deps.get, deps.compile
  1. Create a test file and include the event store adapter test files from Commanded:
# test/event_store_adapter_test.exs
# execute event store adapter tests from Commanded
Code.require_file "../deps/commanded/test/event_store_adapter/append_events_test.exs", __DIR__
Code.require_file "../deps/commanded/test/event_store_adapter/snapshot_test.exs", __DIR__
Code.require_file "../deps/commanded/test/event_store_adapter/subscription_test.exs", __DIR__
  1. Configure the event store adapter in test_helper.exs:
# test/test_helper.exs
ExUnit.start()

# configure this event store adapter for Commanded
Application.put_env(:commanded, :event_store_adapter, Commanded.EventStore.Adapters.Mnesia)

Application.put_env(:commanded, :reset_storage, fn ->
  # ... reset mnesia
end)
  1. Run the tests:
$ mix test

This approach is used by both the existing adapters: commanded-eventstore-adapter and commanded-extreme-adapter.

from commanded.

drozzy avatar drozzy commented on April 28, 2024

Mnesia is fun, but boy does it take a lot of time away from your life haha.

from commanded.

sunny-g avatar sunny-g commented on April 28, 2024

@slashdotdash that's what I thought, thanks!

from commanded.

sunny-g avatar sunny-g commented on April 28, 2024

@slashdotdash fantastic, thanks for this, I'll share the link here when I get around to it.

from commanded.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.