incata

package module
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 3, 2016 License: Apache-2.0 Imports: 5 Imported by: 5

README

incata alt text build status Coverage Status Go Report Card

Event Sourcing Data Access Library

Package incata is a source eventing data access library. The name combines incremental (inc) and data (ata). Details about event sourcing can be read on Martin Fowlers site(http://martinfowler.com/eaaDev/EventSourcing.html).

Currently we support two relational DB's, MS Sql Server and Postgresql.

The stored Event has the following structure:

type Event struct {
  Id        int64
  SourceID  uuid.UUID
  Created   time.Time
  Payload   interface{}
  EventType string
  Version   int
}

The payload is the actual data that we like to store in our DB. Since the serializer can be anything the data type is set to interface{}. This means that our db table column for the Payload have to match the serializer's result data type.

In order to use the appender or retriever we have to provide the following

  1. a serializer or deserializer which implements the Serializer or Deserializer interface or the . A JSONMarshaller is provided.
  2. a writer or reader which implements the Writer or Reader interface. A SQLWriter and SQLReader is provided.
  3. a appender and retriever which implement the Appender and Retriever interface. Appender and Retriever are provided.

The supported relational DB's are MS Sql Server and PostgreSQL.

###Check out the examples in the examples folder for setting up the default marshaller and reader/writers.

###MS SQL Server Setup

SQL Server Driver used:

"github.com/denisenkom/go-mssqldb"

DB Table setup (Provide a table name)

    CREATE TABLE {TableName} (
      Id BIGINT IDENTITY
      ,SourceId UNIQUEIDENTIFIER NOT NULL
      ,Created DATETIME2 NOT NULL
      ,EventType NVARCHAR(250) NOT NULL
      ,Version INT NOT NULL
      ,Payload NVARCHAR(MAX) NOT NULL
      ,CONSTRAINT PK_Event PRIMARY KEY CLUSTERED (Id)
    ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

     GO

     CREATE INDEX IX_Event_SourceId
     ON {TableName} (SourceId)
     ON [PRIMARY]
     GO
PostgreSQL Setup

PostgreSQL Driver used:

"github.com/lib/pq" 

DB Table setup (Provide a table name)

  CREATE TABLE {TableName}
  (
   "Id" serial NOT NULL,
   "SourceId" uuid,
   "Created" timestamp without time zone,
   "EventType" character varying(250),
   "Version" integer,
   "Payload" text,
   CONSTRAINT "PK_Event" PRIMARY KEY ("Id")
  )
  WITH (
   OIDS=FALSE
  );

  CREATE INDEX "event_idx_sourceId"
   ON {TableName}
   USING btree
   ("SourceId");

Documentation

Overview

Package incata is a source eventing data access library. The name combines incremental (inc) and data (ata). Details about event sourcing can be read on Martin Fowlers site(http://martinfowler.com/eaaDev/EventSourcing.html).

Currently we support two relational DB's, MS Sql Server and Postgresql.

The stored Event has the following structure:

type Event struct {
  Id        int64
  SourceID  uuid.UUID
  Created   time.Time
  Payload   interface{}
  EventType string
  Version   int
}

The payload is the actual data that we like to store in our DB. Since the serializer can be anything the data type is set to interface{}. This means that our db table column for the Payload have to match the serializer's result data type.

In order to use the appender or retriever we have to provide the following:

1. a serializer or deserializer which implements the Serializer or Deserializer interface or the . A JSONMarshaller is provided.

2. a writer or reader which implements the Writer or Reader interface. A SQLWriter and SQLReader is provided.

3. a appender and retriever which implement the Appender and Retriever interface. Appender and Retriever are provided.

The supported relational DB's are MS Sql Server and PostgreSQL.

Check out the examples in the examples folder for setting up the default marshaller and reader/writers.

MS SQL Server Setup

SQL Server Driver used:

"github.com/denisenkom/go-mssqldb"

DB Table setup (Provide a table name)

CREATE TABLE {TableName} (
  Id BIGINT IDENTITY
  ,SourceId UNIQUEIDENTIFIER NOT NULL
  ,Created DATETIME2 NOT NULL
  ,EventType NVARCHAR(250) NOT NULL
  ,Version INT NOT NULL
  ,Payload NVARCHAR(MAX) NOT NULL
  ,CONSTRAINT PK_Event PRIMARY KEY CLUSTERED (Id)
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

 GO

 CREATE INDEX IX_Event_SourceId
 ON {TableName} (SourceId)
 ON [PRIMARY]
 GO

PostgreSQL Setup

PostgreSQL Driver used:

"github.com/lib/pq"

DB Table setup (Provide a table name)

CREATE TABLE {TableName}
(
 "Id" serial NOT NULL,
 "SourceId" uuid,
 "Created" timestamp without time zone,
 "EventType" character varying(250),
 "Version" integer,
 "Payload" text,
 CONSTRAINT "PK_Event" PRIMARY KEY ("Id")
)
WITH (
 OIDS=FALSE
);

CREATE INDEX "event_idx_sourceId"
 ON {TableName}
 USING btree
 ("SourceId");

For a full guide visit https://github.com/mantzas/incata

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetupAppender

func SetupAppender(writer writer.Writer)

SetupAppender setting up the appender

func SetupRetriever added in v0.2.0

func SetupRetriever(reader reader.Reader)

SetupRetriever setting up the retriever

Types

type Appender

type Appender interface {
	Append(interface{}) error
}

Appender interface

type EventAppender

type EventAppender struct {
	Writer writer.Writer
}

EventAppender Append events to storage

func NewAppender

func NewAppender() (*EventAppender, error)

NewAppender Creates a new event appender

func (*EventAppender) Append

func (appender *EventAppender) Append(event model.Event) error

Append Append the payload to the storage

type EventRetriever added in v0.2.0

type EventRetriever struct {
	Reader reader.Reader
}

EventRetriever Append events to storage

func NewRetriever added in v0.2.0

func NewRetriever() (*EventRetriever, error)

NewRetriever creates a new event retriever

func (*EventRetriever) Retrieve added in v0.2.0

func (appender *EventRetriever) Retrieve(sourceID uuid.UUID) ([]model.Event, error)

Retrieve events based on Source ID

type Retriever added in v0.2.0

type Retriever interface {
	Retrieve(uuid.UUID) ([]model.Event, error)
}

Retriever interface

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL