Build Status

Harvest

Harvest is a event store for Dart with multiple backends. Harvest creates and persists streams of events, where each persistent event stream is identified by a Guid for future retrival.

Quick Guide

1. Add the folowing to your pubspec.yaml and run pub install

    dependencies:
      harvest: any

2. Add harvest to some code and run it

	import 'package:harvest/harvest.dart';
	
	main() {
		var streamId = new Guid();
		var eventStore = new MemoryEventStore();
		// get a event stream for streamId 
		eventStore.openStream(streamId).then((eventStream) {
			// create some events
			var event1 = ...
			var event2 = ...
			
			// store them
			eventStream.addAll([event1, event2]);
			eventStrem.commitChanges();
		});
	}	

Why do this ?

Event sourcing is the concept of saving and retriving object state by the events that occured on them rather than by their current state. Consider the following bank use case:

  1. User creates account
  2. User deposits 10$
  3. User withdraws 2$

In a CRUD application you would now have a BankAccount object with an amount property with the value 8. In a event sourced application you have a BankAccount object and 3 events for it

  1. AccountCreated
  2. AmountDeposited
  3. AmountWithdrawn

Where is this useful?


  • For certain applications the eventlog can be useful in itself such as a audit trail in a financial system.

  • It can help manage complexity in large applications by forcing programmers to make event types for every action that can occur.

  • It makes debugging easy since you can replay the event log to recreate any former system state where an error occurred.

  • It makes mobile app synchronization a breeze, since the offline app can just queue up events and replay them on the backend once it comes online.

  • In applications using the CQRS architecture pattern.

For more information, see the provided example application.

Supported Storage Engines

Harvest supports the following event stores.

  • FileEventStore: Durable disk based event store
  • IndexeddbEventStore: Durable IndexedDB based event store, suitable for web applications.
  • MemoryEventStore: Non-durable memory based event store, suitable for testing purposes

Links

  • https://github.com/joliver/EventStore

Libraries

harvest

Event store API

harvest_cqrs

Eventstore API augmented for implementing CQRS applications

harvest_file

Eventstore backed by a file system

harvest_indexeddb

Eventstore backed by IndexedDB