postgres

package
v0.2.11 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package postgres implements the target storage interface backed by PostgreSQL.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client is a client for connecting to PostgreSQL.

func NewClient

func NewClient(connString string, l *log.Logger) (*Client, error)

NewClient creates a new PostgreSQL client.

func (*Client) Begin

func (c *Client) Begin(ctx context.Context) (storage.Tx, error)

Begin implements the storage.TargetStorage interface for Client.

func (*Client) Close

func (c *Client) Close()

Close implements the storage.TargetStorage interface for Client.

func (*Client) DisableTriggersAndFKConstraints

func (c *Client) DisableTriggersAndFKConstraints(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.

func (*Client) EnableTriggersAndFKConstraints

func (c *Client) EnableTriggersAndFKConstraints(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.

func (*Client) Name

func (c *Client) Name() string

Name implements the storage.TargetStorage interface for Client.

func (*Client) Query

func (c *Client) Query(ctx context.Context, sql string, args ...interface{}) (pgx.Rows, error)

Query submits a new read query to PostgreSQL.

func (*Client) QueryRow

func (c *Client) QueryRow(ctx context.Context, sql string, args ...interface{}) pgx.Row

QueryRow submits a new read query for a single row to PostgreSQL.

func (*Client) SendBatch

func (c *Client) SendBatch(ctx context.Context, batch *storage.QueryBatch) error

SendBatch submits a new batch of queries as an atomic transaction to PostgreSQL.

For now, updated row counts are discarded as this is not intended to be used by any nexus. We only care about atomic success or failure of the batch of queries corresponding to a new block.

func (*Client) SendBatchWithOptions

func (c *Client) SendBatchWithOptions(ctx context.Context, batch *storage.QueryBatch, opts pgx.TxOptions) error

func (*Client) Wipe

func (c *Client) Wipe(ctx context.Context) error

Wipe removes all contents of the database.

func (*Client) WithTx added in v0.2.9

func (c *Client) WithTx(
	ctx context.Context,
	txOptions pgx.TxOptions,
	fn func(pgx.Tx) error,
) error

Starts a new DB transaction and runs fn() with it. Takes care of committing or rolling back the transaction: If fn() returns an error, the transaction is rolled back, otherwise, it is committed. Adapted from https://github.com/jackc/pgx/blob/v4.18.1/tx.go#L108

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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