postgres

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DB

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

DB implements the database.DB interface by storing data in Postgres. All the data is stored in a single table that acts as a key/value store.

func New

func New(
	ctx context.Context,
	l log.CtxLogger,
	connString string,
	table string,
) (*DB, error)

New connects to Postgres and creates the target table if it does not exist. It returns a *DB with a pool of connections used for future interactions with Postgres. Close needs to be called before exiting to close any open connections.

Refer to pgxpool.ParseConfig for details about the connection string format.

# Example DSN
user=jack password=secret host=pg.example.com port=5432 dbname=mydb sslmode=verify-ca pool_max_conns=10

# Example URL
postgres://jack:secret@pg.example.com:5432/mydb?sslmode=verify-ca&pool_max_conns=10

func (*DB) Close

func (d *DB) Close() error

Close closes all open connections.

func (*DB) Get

func (d *DB) Get(ctx context.Context, key string) ([]byte, error)

Get returns the value stored under the key. If no value is found it returns database.ErrKeyNotExist.

func (*DB) GetKeys

func (d *DB) GetKeys(ctx context.Context, prefix string) ([]string, error)

GetKeys returns all keys with the requested prefix. If prefix is an empty string it will return all keys.

func (*DB) NewTransaction

func (d *DB) NewTransaction(ctx context.Context, update bool) (database.Transaction, context.Context, error)

NewTransaction starts a new transaction. The `update` parameter controls the access mode ("read only" or "read write"). It returns the transaction as well as a context that contains the transaction. Passing the context in future calls to *DB will execute that action in that transaction.

func (*DB) Ping added in v0.5.1

func (d *DB) Ping(ctx context.Context) error

func (*DB) Set

func (d *DB) Set(ctx context.Context, key string, value []byte) error

Set will store the value under the key. If value is `nil` we consider that a delete.

type Txn

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

func (*Txn) Commit

func (t *Txn) Commit() error

func (*Txn) Discard

func (t *Txn) Discard()

Jump to

Keyboard shortcuts

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