postgres

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2017 License: Apache-2.0 Imports: 9 Imported by: 0

README

Setup

  1. Setup envars

    NOTE: These are credentials the test will use to connect to postgres.

    export POSTGRES_USER=postgres
    export POSTGRES_PASSWORD=admin
    
  2. Install dependencies

    NOTE: If you're on a different platform and can't run the following command, there's a psql client inside the container as well so you can use that instead. More info regarding this below.

    sudo apt-get install postgresql-client-9.4
    

    And sqlx:

    go get github.com/jmoiron/sqlx
    
  3. Spawn postgres container

    NOTE: This will download the container if not present and feel free to change the password.

    docker run -d \
        --name pgtest \
        -e "POSTGRES_USER=$POSTGRES_USER" \
        -e "POSTGRES_PASSWORD=$POSTGRES_PASSWORD" \
        -p 5432:5432 \
        postgres:9.4.5
    
  4. Create database

    docker exec pgtest createdb -U $POSTGRES_USER cqrs_pg_test
    
  5. Load the schema

    cd $GOPATH/src/github.com/andrewwebber/cqrs
    psql -U $POSTGRES_USER -d cqrs_pg_test -h localhost -p 5432 -W < ./postgres/schema.sql
    

    NOTE: If you're on a different platform and can't install postgres client system wide, you can copy over the schema inside the container and execute it from there using the bundled psql command inside, like:

    # copy schema to container
    docker cp ./postgres/schema.sql pgtest:/tmp
    
    # jump inside the container
    docker exec -it pgtest bash
    
    # load the schema from inside the container
    psql -U $POSTGRES_USER -d cqrs_pg_test -W < /tmp/schema.sql
    

Run tests

cd postgres && go test

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrPgConnStr             = errors.New("invalid postgres connection string")
	ErrPgPrepInsertStmt      = errors.New("error prepapring insert statement")
	ErrPgPrepSelectStmt      = errors.New("error preparing select statement")
	ErrPgSelectSource        = errors.New("error querying for events using source id")
	ErrPgNoEventType         = errors.New("cannot find event type")
	ErrPgUnmarshalingEvent   = errors.New("error unmarshaling event")
	ErrPgMarshalingEvent     = errors.New("error marshaling event")
	ErrPgSavingEvent         = errors.New("error saving event")
	ErrPgSavingIntegEvent    = errors.New("error saving integration event")
	ErrPgSavingCorrelEvent   = errors.New("error saving correlation event")
	ErrPgIntegEventsByCorrel = errors.New("error querying for integration events using correlation id")
	ErrPgAllIntegEvents      = errors.New("error querying for all integration events")
)

Functions

This section is empty.

Types

type EventStreamRepository

type EventStreamRepository struct {
	// contains filtered or unexported fields
}

func NewEventStreamRepository

func NewEventStreamRepository(connStr string, typeRegistry cqrs.TypeRegistry) (*EventStreamRepository, error)

func (*EventStreamRepository) AllIntegrationEventsEverPublished

func (esr *EventStreamRepository) AllIntegrationEventsEverPublished() ([]cqrs.VersionedEvent, error)

func (*EventStreamRepository) Get

func (*EventStreamRepository) GetDb

func (esr *EventStreamRepository) GetDb() *sqlx.DB

func (*EventStreamRepository) GetIntegrationEventsByCorrelationID

func (esr *EventStreamRepository) GetIntegrationEventsByCorrelationID(correlationID string) ([]cqrs.VersionedEvent, error)

func (*EventStreamRepository) Save

func (esr *EventStreamRepository) Save(sourceID string, events []cqrs.VersionedEvent) error

func (*EventStreamRepository) SaveIntegrationEvent

func (esr *EventStreamRepository) SaveIntegrationEvent(event cqrs.VersionedEvent) error

type PgVersionedEvent

type PgVersionedEvent struct {
	ID            string         `db:"id"`
	CorrelationID string         `db:"correlationid"`
	SourceID      string         `db:"sourceid"`
	Version       int            `db:"version"`
	EventType     string         `db:"eventtype"`
	Created       time.Time      `db:"created"`
	Event         types.JSONText `db:"event"`
}

Jump to

Keyboard shortcuts

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