storage

package
v0.2.7 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package storage defines storage interfaces.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SanitizeString added in v0.1.16

func SanitizeString(msg string) string

Postgres requires valid UTF-8 with no 0x00.

func SanitizeStringP added in v0.1.23

func SanitizeStringP(msg *string) *string

Types

type BatchItem

type BatchItem struct {
	Cmd  string
	Args []interface{}
}

type QueryBatch

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

QueryBatch represents a batch of queries to be executed atomically. We use a custom type that mirrors `pgx.Batch`, but is thread-safe to use and allows introspection for debugging.

func (*QueryBatch) AsPgxBatch

func (b *QueryBatch) AsPgxBatch() pgx.Batch

AsPgxBatch converts a QueryBatch to a pgx.Batch.

func (*QueryBatch) Extend

func (b *QueryBatch) Extend(qb *QueryBatch)

Extend merges another batch into the current batch.

func (*QueryBatch) Len

func (b *QueryBatch) Len() int

Len returns the number of queries in the batch.

func (*QueryBatch) Queries

func (b *QueryBatch) Queries() []*BatchItem

Queries returns the queries in the batch. Each item of the returned slice is composed of the SQL command and its arguments.

func (*QueryBatch) Queue

func (b *QueryBatch) Queue(cmd string, args ...interface{})

Queue adds query to a batch.

type QueryResult

type QueryResult = pgx.Row

QueryResult represents the result from a read query.

type QueryResults

type QueryResults = pgx.Rows

QueryResults represents the results from a read query.

type TargetStorage

type TargetStorage interface {
	// SendBatch sends a batch of queries to be applied to target storage.
	SendBatch(ctx context.Context, batch *QueryBatch) error

	// SendBatchWithOptions is like SendBatch, with custom DB options (e.g. level of tx isolation).
	SendBatchWithOptions(ctx context.Context, batch *QueryBatch, opts TxOptions) error

	// Query submits a query to fetch data from target storage.
	Query(ctx context.Context, sql string, args ...interface{}) (QueryResults, error)

	// QueryRow submits a query to fetch a single row of data from target storage.
	QueryRow(ctx context.Context, sql string, args ...interface{}) QueryResult

	// Begin starts a new transaction.
	// XXX: Not the nicest that this exposes the underlying pgx.Tx interface. Could instead
	// return a `TargetStorage`-like interface wrapper, that only exposes Query/QueryRow/SendBatch/SendBatchWithOptions
	// and Commit/Rollback.
	Begin(ctx context.Context) (Tx, error)

	// Close shuts down the target storage client.
	Close()

	// Name returns the name of the target storage.
	Name() string

	// Wipe removes all contents of the target storage.
	Wipe(ctx context.Context) error

	// DisableTriggersAndFKConstraints disables all triggers and foreign key constraints
	// in nexus tables. This is useful when inserting blockchain data out of order,
	// so that later blocks can refer to (yet unindexed) earlier blocks without violating constraints.
	DisableTriggersAndFKConstraints(ctx context.Context) error

	// EnableTriggersAndFKConstraints enables all triggers and foreign key constraints
	// in the given schema.
	// WARNING: This might enable triggers not explicitly disabled by DisableTriggersAndFKConstraints.
	// WARNING: This does not enforce/check contraints on rows that were inserted while triggers were disabled.
	EnableTriggersAndFKConstraints(ctx context.Context) error
}

TargetStorage defines an interface for reading and writing processed block data.

type Tx

type Tx = pgx.Tx

Tx represents a database transaction.

type TxOptions

type TxOptions = pgx.TxOptions

TxOptions encodes the way DB transactions are executed.

Directories

Path Synopsis
Types for storage client responses.
Types for storage client responses.
Package oasis implements the source storage interface backed by oasis-node.
Package oasis implements the source storage interface backed by oasis-node.
Package postgres implements the target storage interface backed by PostgreSQL.
Package postgres implements the target storage interface backed by PostgreSQL.

Jump to

Keyboard shortcuts

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