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
- func RegisterFlags()
- type Batch
- func (s Batch) AddEvidence(ctx context.Context, linkHash chainscript.LinkHash, ...) error
- func (b *Batch) CreateLink(ctx context.Context, link *chainscript.Link) (chainscript.LinkHash, error)
- func (s Batch) DeleteValue(ctx context.Context, key []byte) ([]byte, error)
- func (s Batch) FindSegments(ctx context.Context, filter *store.SegmentFilter) (*types.PaginatedSegments, error)
- func (s Batch) GetEvidences(ctx context.Context, linkHash chainscript.LinkHash) (types.EvidenceSlice, error)
- func (s Batch) GetMapIDs(ctx context.Context, filter *store.MapFilter) ([]string, error)
- func (s Batch) GetSegment(ctx context.Context, linkHash chainscript.LinkHash) (*chainscript.Segment, error)
- func (s Batch) GetValue(ctx context.Context, key []byte) ([]byte, error)
- func (s Batch) SetValue(ctx context.Context, key []byte, value []byte) error
- func (b *Batch) Write(ctx context.Context) (err error)
- type Config
- type Info
- type SQLPreparer
- type SQLPreparerQuerier
- type SQLQuerier
- type SingletonTxFactory
- type StandardTxFactory
- type Store
- func (a *Store) AddEvidence(ctx context.Context, linkHash chainscript.LinkHash, ...) error
- func (a *Store) AddStoreEventChannel(eventChan chan *store.Event)
- func (a *Store) Close() error
- func (a *Store) Create() error
- func (a *Store) CreateLink(ctx context.Context, link *chainscript.Link) (chainscript.LinkHash, error)
- func (s Store) DeleteValue(ctx context.Context, key []byte) ([]byte, error)
- func (a *Store) Drop() error
- func (a *Store) EnforceUniqueMapEntry() error
- func (s Store) FindSegments(ctx context.Context, filter *store.SegmentFilter) (*types.PaginatedSegments, error)
- func (s Store) GetEvidences(ctx context.Context, linkHash chainscript.LinkHash) (types.EvidenceSlice, error)
- func (a *Store) GetInfo(ctx context.Context) (interface{}, error)
- func (s Store) GetMapIDs(ctx context.Context, filter *store.MapFilter) ([]string, error)
- func (s Store) GetSegment(ctx context.Context, linkHash chainscript.LinkHash) (*chainscript.Segment, error)
- func (s Store) GetValue(ctx context.Context, key []byte) ([]byte, error)
- func (a *Store) NewBatch(ctx context.Context) (store.Batch, error)
- func (a *Store) Prepare() error
- func (s Store) SetValue(ctx context.Context, key []byte, value []byte) error
- type TxFactory
Constants ¶
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's PostgreSQL Store" // DefaultURL is the default URL of the database. DefaultURL = "postgres://postgres@postgres/postgres?sslmode=disable" )
const ( SQLCreateLink = `` /* 171-byte string literal not displayed */ SQLCreateLinkDegree = ` INSERT INTO store_private.links_degree ( link_hash, out_degree ) VALUES ($1, 0) ` SQLLockLinkDegree = ` SELECT out_degree FROM store_private.links_degree WHERE link_hash = $1 FOR UPDATE ` SQLUpdateLinkDegree = ` UPDATE store_private.links_degree SET out_degree = $2 WHERE link_hash = $1 ` SQLInitMap = ` INSERT INTO store_private.process_maps ( process, map_id ) VALUES ($1, $2) ` SQLAddReference = ` INSERT INTO store_private.refs ( link_hash, referenced_by ) VALUES ($1, $2) ` SQLReferencedBy = ` SELECT referenced_by FROM store_private.refs WHERE link_hash = $1 ` SQLGetSegment = `` /* 142-byte string literal not displayed */ SQLSaveValue = ` INSERT INTO store.values ( key, value ) VALUES ($1, $2) ON CONFLICT (key) DO UPDATE SET value = $2 ` SQLGetValue = ` SELECT value FROM store.values WHERE key = $1 ` SQLDeleteValue = ` DELETE FROM store.values WHERE key = $1 RETURNING value ` SQLGetEvidences = ` SELECT data FROM store.evidences WHERE link_hash = $1 ` SQLAddEvidence = `` /* 144-byte string literal not displayed */ )
Plain SQL statements. They need to be prepared before they can be used.
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/go-core/store.Batch.
func (Batch) AddEvidence ¶ added in v0.3.1
func (s Batch) AddEvidence(ctx context.Context, linkHash chainscript.LinkHash, evidence *chainscript.Evidence) error
AddEvidence implements github.com/stratumn/go-core/store.EvidenceWriter.AddEvidence.
func (*Batch) CreateLink ¶
func (b *Batch) CreateLink(ctx context.Context, link *chainscript.Link) (chainscript.LinkHash, error)
CreateLink wraps the underlying link creation and stops the batch as soon as an invalid link is encountered.
func (Batch) DeleteValue ¶
DeleteValue implements github.com/stratumn/go-core/store.KeyValueStore.DeleteValue.
func (Batch) FindSegments ¶
func (s Batch) FindSegments(ctx context.Context, filter *store.SegmentFilter) (*types.PaginatedSegments, error)
FindSegments implements github.com/stratumn/go-core/store.SegmentReader.FindSegments.
func (Batch) GetEvidences ¶
func (s Batch) GetEvidences(ctx context.Context, linkHash chainscript.LinkHash) (types.EvidenceSlice, error)
GetEvidences implements github.com/stratumn/go-core/store.EvidenceReader.GetEvidences.
func (Batch) GetMapIDs ¶
GetMapIDs implements github.com/stratumn/go-core/store.SegmentReader.GetMapIDs.
func (Batch) GetSegment ¶
func (s Batch) GetSegment(ctx context.Context, linkHash chainscript.LinkHash) (*chainscript.Segment, error)
GetSegment implements github.com/stratumn/go-core/store.SegmentReader.GetSegment.
func (Batch) GetValue ¶
GetValue implements github.com/stratumn/go-core/store.KeyValueStore.GetValue.
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 SQLPreparer ¶ added in v0.3.1
SQLPreparer prepares statements.
type SQLPreparerQuerier ¶ added in v0.3.1
type SQLPreparerQuerier interface { SQLPreparer SQLQuerier }
SQLPreparerQuerier prepares statements and executes queries.
type SQLQuerier ¶ added in v0.3.1
type SQLQuerier interface {
QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
}
SQLQuerier executes queries.
type SingletonTxFactory ¶ added in v0.3.1
type SingletonTxFactory struct {
// contains filtered or unexported fields
}
SingletonTxFactory uses a single transaction under the hood. It can be used for batches since a transaction cannot contain sub-transactions.
func (*SingletonTxFactory) CommitTx ¶ added in v0.3.1
func (f *SingletonTxFactory) CommitTx(tx *sql.Tx) error
CommitTx does nothing. The owner of the SingletonTxFactory will commit directly on the tx object when ready (batch.Write()).
func (*SingletonTxFactory) NewTx ¶ added in v0.3.1
func (f *SingletonTxFactory) NewTx() (*sql.Tx, error)
NewTx returns the DB transaction. Clients should not directly call tx.Commit() or tx.Rollback().
func (*SingletonTxFactory) RollbackTx ¶ added in v0.3.1
func (f *SingletonTxFactory) RollbackTx(tx *sql.Tx, err error)
RollbackTx marks the transaction as rolled back. The owner of the SingletonTxFactory should rollback the transaction.
type StandardTxFactory ¶ added in v0.3.1
type StandardTxFactory struct {
// contains filtered or unexported fields
}
StandardTxFactory is just a wrapper around SQL transactions.
func (*StandardTxFactory) CommitTx ¶ added in v0.3.1
func (f *StandardTxFactory) CommitTx(tx *sql.Tx) error
CommitTx commits the transaction to the DB.
func (*StandardTxFactory) NewTx ¶ added in v0.3.1
func (f *StandardTxFactory) NewTx() (*sql.Tx, error)
NewTx creates a new DB transaction.
func (*StandardTxFactory) RollbackTx ¶ added in v0.3.1
func (f *StandardTxFactory) RollbackTx(tx *sql.Tx, _ error)
RollbackTx rolls back the transaction and logs errors.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store is the type that implements github.com/stratumn/go-core/store.Adapter.
func Initialize ¶
Initialize a postgres store adapter.
func InitializeWithFlags ¶
InitializeWithFlags should be called after RegisterFlags and flag.Parse to initialize a postgres adapter using flag values.
func (*Store) AddEvidence ¶
func (a *Store) AddEvidence(ctx context.Context, linkHash chainscript.LinkHash, evidence *chainscript.Evidence) error
AddEvidence implements github.com/stratumn/go-core/store.EvidenceWriter.AddEvidence.
func (*Store) AddStoreEventChannel ¶
AddStoreEventChannel implements github.com/stratumn/go-core/store.Adapter.AddStoreEventChannel
func (*Store) CreateLink ¶
func (a *Store) CreateLink(ctx context.Context, link *chainscript.Link) (chainscript.LinkHash, error)
CreateLink implements github.com/stratumn/go-core/store.LinkWriter.CreateLink.
func (Store) DeleteValue ¶
DeleteValue implements github.com/stratumn/go-core/store.KeyValueStore.DeleteValue.
func (*Store) EnforceUniqueMapEntry ¶ added in v0.3.1
EnforceUniqueMapEntry makes sure each process map contains a single link without parent.
func (Store) FindSegments ¶
func (s Store) FindSegments(ctx context.Context, filter *store.SegmentFilter) (*types.PaginatedSegments, error)
FindSegments implements github.com/stratumn/go-core/store.SegmentReader.FindSegments.
func (Store) GetEvidences ¶
func (s Store) GetEvidences(ctx context.Context, linkHash chainscript.LinkHash) (types.EvidenceSlice, error)
GetEvidences implements github.com/stratumn/go-core/store.EvidenceReader.GetEvidences.
func (Store) GetMapIDs ¶
GetMapIDs implements github.com/stratumn/go-core/store.SegmentReader.GetMapIDs.
func (Store) GetSegment ¶
func (s Store) GetSegment(ctx context.Context, linkHash chainscript.LinkHash) (*chainscript.Segment, error)
GetSegment implements github.com/stratumn/go-core/store.SegmentReader.GetSegment.
func (Store) GetValue ¶
GetValue implements github.com/stratumn/go-core/store.KeyValueStore.GetValue.
type TxFactory ¶ added in v0.3.1
type TxFactory interface { NewTx() (*sql.Tx, error) CommitTx(tx *sql.Tx) error RollbackTx(tx *sql.Tx, err error) }
TxFactory creates and manages transactions.
func NewSingletonTxFactory ¶ added in v0.3.1
NewSingletonTxFactory creates a transaction factory using the underlying transaction. It makes sure all the work is done in a single transaction instead of many (since a transaction cannot contain nested sub-transactions).
func NewStandardTxFactory ¶ added in v0.3.1
NewStandardTxFactory creates a transaction factory using the underlying DB.