postgresstore

package
v0.2.0-rc1 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2017 License: Apache-2.0 Imports: 13 Imported by: 6

Documentation

Overview

Package postgresstore implements a store that saves all the segments in a PostgreSQL database. It requires PostgreSQL >= 9.5 for "ON CONFLICT DO UPDATE" support.

Index

Constants

View Source
const (
	// Name is the name set in the store's information.
	Name = "postgres"

	// Description is the description set in the store's information.
	Description = "Stratumn PostgreSQL Store"

	// DefaultURL is the default URL of the database.
	DefaultURL = "postgres://postgres@postgres/postgres?sslmode=disable"
)

Variables

This section is empty.

Functions

func RegisterFlags

func RegisterFlags()

RegisterFlags registers the flags used by InitializeWithFlags.

Types

type Batch

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

Batch is the type that implements github.com/stratumn/sdk/store.Batch.

func NewBatch

func NewBatch(tx *sql.Tx) (*Batch, error)

NewBatch creates a new instance of a Postgres Batch.

func (a Batch) CreateLink(link *cs.Link) (*types.Bytes32, error)

CreateLink implements github.com/stratumn/sdk/store.Adapter.CreateLink.

func (Batch) DeleteValue

func (a Batch) DeleteValue(key []byte) ([]byte, error)

DeleteValue implements github.com/stratumn/sdk/store.KeyValueStore.DeleteValue.

func (Batch) FindSegments

func (a Batch) FindSegments(filter *store.SegmentFilter) (cs.SegmentSlice, error)

FindSegments implements github.com/stratumn/sdk/store.SegmentReader.FindSegments.

func (Batch) GetEvidences

func (a Batch) GetEvidences(linkHash *types.Bytes32) (*cs.Evidences, error)

GetEvidences implements github.com/stratumn/sdk/store.EvidenceReader.GetEvidences.

func (Batch) GetMapIDs

func (a Batch) GetMapIDs(filter *store.MapFilter) ([]string, error)

GetMapIDs implements github.com/stratumn/sdk/store.SegmentReader.GetMapIDs.

func (Batch) GetSegment

func (a Batch) GetSegment(linkHash *types.Bytes32) (*cs.Segment, error)

GetSegment implements github.com/stratumn/sdk/store.SegmentReader.GetSegment.

func (Batch) GetValue

func (a Batch) GetValue(key []byte) ([]byte, error)

GetValue implements github.com/stratumn/sdk/store.KeyValueStore.GetValue.

func (Batch) SetValue

func (a Batch) SetValue(key []byte, value []byte) error

SetValue implements github.com/stratumn/sdk/store.KeyValueStore.SetValue.

func (*Batch) Write

func (b *Batch) Write() error

Write implements github.com/stratumn/sdk/store.Batch.Write.

type Config

type Config struct {
	// A version string that will be set in the store's information.
	Version string

	// A git commit hash that will be set in the store's information.
	Commit string

	// The URL of the PostgreSQL database, such as
	// "postgres://postgres@localhost/store?sslmode=disable".
	URL string
}

Config contains configuration options for the store.

type Info

type Info struct {
	Name        string `json:"name"`
	Description string `json:"description"`
	Version     string `json:"version"`
	Commit      string `json:"commit"`
}

Info is the info returned by GetInfo.

type Store

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

Store is the type that implements github.com/stratumn/sdk/store.Adapter.

func Initialize

func Initialize(config *Config, create, drop bool) *Store

Initialize initializes a postgres store adapter

func InitializeWithFlags

func InitializeWithFlags(version, commit string) *Store

InitializeWithFlags should be called after RegisterFlags and flag.Parse to intialize a postgres adapter using flag values.

func New

func New(config *Config) (*Store, error)

New creates an instance of a Store.

func (*Store) AddEvidence

func (a *Store) AddEvidence(linkHash *types.Bytes32, evidence *cs.Evidence) error

AddEvidence implements github.com/stratumn/sdk/store.EvidenceWriter.AddEvidence.

func (*Store) AddStoreEventChannel

func (a *Store) AddStoreEventChannel(eventChan chan *store.Event)

AddStoreEventChannel implements github.com/stratumn/sdk/store.Adapter.AddStoreEventChannel

func (*Store) Close

func (a *Store) Close() error

Close closes the database connection.

func (*Store) Create

func (a *Store) Create() error

Create creates the database tables and indexes.

func (a *Store) CreateLink(link *cs.Link) (*types.Bytes32, error)

CreateLink implements github.com/stratumn/sdk/store.LinkWriter.CreateLink.

func (Store) DeleteValue

func (a Store) DeleteValue(key []byte) ([]byte, error)

DeleteValue implements github.com/stratumn/sdk/store.KeyValueStore.DeleteValue.

func (*Store) Drop

func (a *Store) Drop() error

Drop drops the database tables and indexes. It also rollbacks started batches.

func (Store) FindSegments

func (a Store) FindSegments(filter *store.SegmentFilter) (cs.SegmentSlice, error)

FindSegments implements github.com/stratumn/sdk/store.SegmentReader.FindSegments.

func (Store) GetEvidences

func (a Store) GetEvidences(linkHash *types.Bytes32) (*cs.Evidences, error)

GetEvidences implements github.com/stratumn/sdk/store.EvidenceReader.GetEvidences.

func (*Store) GetInfo

func (a *Store) GetInfo() (interface{}, error)

GetInfo implements github.com/stratumn/sdk/store.Adapter.GetInfo.

func (Store) GetMapIDs

func (a Store) GetMapIDs(filter *store.MapFilter) ([]string, error)

GetMapIDs implements github.com/stratumn/sdk/store.SegmentReader.GetMapIDs.

func (Store) GetSegment

func (a Store) GetSegment(linkHash *types.Bytes32) (*cs.Segment, error)

GetSegment implements github.com/stratumn/sdk/store.SegmentReader.GetSegment.

func (Store) GetValue

func (a Store) GetValue(key []byte) ([]byte, error)

GetValue implements github.com/stratumn/sdk/store.KeyValueStore.GetValue.

func (*Store) NewBatch

func (a *Store) NewBatch() (store.Batch, error)

NewBatch implements github.com/stratumn/sdk/store.Adapter.NewBatch.

func (*Store) Prepare

func (a *Store) Prepare() error

Prepare prepares the database stmts. It should be called once before interacting with segments. It assumes the tables have been created using Create().

func (Store) SetValue

func (a Store) SetValue(key []byte, value []byte) error

SetValue implements github.com/stratumn/sdk/store.KeyValueStore.SetValue.

Jump to

Keyboard shortcuts

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