Giter VIP home page Giter VIP logo

cqrskit's Introduction

CQRSKit

Go Report Card Travis Build Status CircleCI

CQRSKit provides a base libary that implements a simple but extensive Event Sourcing + CQRS library. It's purpose is to provide multi-store event stores with a simple but robust API for handling CQRS style APIs. It is heavily inspired by John Oliver's EventStore.

Install

go get github.com/gokit/cqrskit/...

Storage Supported

Below are the available database able to be used as the event store technologies:

  • MongoDB
  • BadgerDB (Planned)
  • PostgreSQL (Planned)

Publisher Supported

Below are the implemented queueing technology available for use

  • NATS
  • Amazon SQS
  • NSQ (Planned)
  • Redis (Planned)

CLI Tooling

CQRSKit comes bundled with a command line code generation tool, that provides a means of avoiding the usage of reflect by generating an appropriate method on structs annotated with @escqrs to handle different events types, based on methods that have the HandlePrefix, except in cases there such methods have a @escqrs-skip annotation in comments.

//@escqrs
type User struct {
	Version  int
	Email    string
	Username string
}

type UserEmailUpdated struct {
	New string
}

func (u *User) HandleUserEmailUpdated(ev UserEmailUpdated) error {
	return nil
}

func (u *User) HandleUserNameUpdated(ev events.UserNameUpdated) error {
	return nil
}

//@escqrs-method-skip
func (u *User) HandleUserRackUpdated(ev UserEmailUpdated) error {
	return nil
}

Where the above produces the following after running cqrskit generate in terminal:

var (
	// UserAggregateID represents the unique aggregate id for all events
	// related to the User type. It is the typeName hashed using a md5 sum.
	UserAggregateID = "f7091ac77d9b52a3ec5609891cd9f54f"
)

//*******************************************************************************
// User Event Applier
//*******************************************************************************

// Apply embodies the internal logic necessary to apply specific events to a User by
// calling appropriate methods.
func (u *User) Apply(evs cqrskit.EventCommit) error {
	for _, event := range evs.Events {
		switch ev := event.Data.(type) {
		case UserEmailUpdated:
			return u.HandleUserEmailUpdated(ev)
		case events.UserNameUpdated:
			return u.HandleUserNameUpdated(ev)

		}
	}
	return nil
}

cqrskit's People

Contributors

influx6 avatar

Watchers

James Cloos avatar Lê Phước Mỹ avatar

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.