julio

package module
v0.0.0-...-cd8f222 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2019 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package julio enables to use PostgreSQL as storage for a simple JSON based event sourcing.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Filter

type Filter struct {
	Sqlizer  squirrel.Sqlizer
	Updates  bool
	OnlyNew  bool // subscribe only to new events, skip the "historic"
	Paginate bool // will increase performance on big queries, but is slow on small queries
	StartAt  uint64
}

Filter defines the SQL where predicate to filter existing and new rows alike.

type Julio

type Julio struct {
	DB *sql.DB
	// contains filtered or unexported fields
}

Julio wraps a PostgreSQL database connection to be used for event sourcing. The underlying connection is exposed as DB.

func Open

func Open(dataSource string) (*Julio, error)

Open opens a new database connection.

func (*Julio) Add

func (j *Julio) Add(table string, v interface{}) (int, error)

Add adds a new event entry to the given table. The payload v is json serialized in the database.

func (*Julio) Get

func (j *Julio) Get(table string, filter Filter) *Rows

Get fetches all events from table that match the given filter. It optionally listes for new events as well.

func (*Julio) Init

func (j *Julio) Init(table string) error

Init initializes a table for event sourcing. It is safe to call init for allready initialized tables, but not for existing tables with a different structure.

type Row

type Row struct {
	ID   int
	Data json.RawMessage
}

Row is a single row or event in the database

type Rows

type Rows struct {
	C   chan Row
	Err error
	// contains filtered or unexported fields
}

Rows is a collection of rows in the database. Both existing and new events can be retrieved via the attribute C. If you no longer are interested in events close it.

func (*Rows) Close

func (r *Rows) Close()

Close closes this notify subscription.

Jump to

Keyboard shortcuts

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